Margin Trading in Mobile Exchange App

NOVASOLUTIONS.TECHNOLOGY is engaged in the development, support and maintenance of iOS, Android, PWA mobile applications. We have extensive experience and expertise in publishing mobile applications in popular markets like Google Play, App Store, Amazon, AppGallery and others.
Development and support of all types of mobile applications:
Information and entertainment mobile applications
News apps, games, reference guides, online catalogs, weather apps, fitness and health apps, travel apps, educational apps, social networks and messengers, quizzes, blogs and podcasts, forums, aggregators
E-commerce mobile applications
Online stores, B2B apps, marketplaces, online exchanges, cashback services, exchanges, dropshipping platforms, loyalty programs, food and goods delivery, payment systems.
Business process management mobile applications
CRM systems, ERP systems, project management, sales team tools, financial management, production management, logistics and delivery management, HR management, data monitoring systems
Electronic services mobile applications
Classified ads platforms, online schools, online cinemas, electronic service platforms, cashback platforms, video hosting, thematic portals, online booking and scheduling platforms, online trading platforms

These are just some of the types of mobile applications we work with, and each of them may have its own specific features and functionality, tailored to the specific needs and goals of the client.

Showing 1 of 1 servicesAll 1735 services
Margin Trading in Mobile Exchange App
Complex
from 2 weeks to 3 months
FAQ
Our competencies:
Development stages
Latest works
  • image_mobile-applications_feedme_467_0.webp
    Development of a mobile application for FEEDME
    756
  • image_mobile-applications_xoomer_471_0.webp
    Development of a mobile application for XOOMER
    624
  • image_mobile-applications_rhl_428_0.webp
    Development of a mobile application for RHL
    1054
  • image_mobile-applications_zippy_411_0.webp
    Development of a mobile application for ZIPPY
    947
  • image_mobile-applications_affhome_429_0.webp
    Development of a mobile application for Affhome
    862
  • image_mobile-applications_flavors_409_0.webp
    Development of a mobile application for the FLAVORS company
    445

Implementing Margin Trading in a Mobile Exchange App

Margin trading uses borrowed funds. Users deposit collateral (margin) and the exchange provides leverage 3x, 5x, 10x. Profit and loss are calculated on the full position size, not collateral. If loss approaches the margin amount, the exchange force-closes the position (liquidation). Implementing this on mobile means building a complex real-time risk display system.

Margin Accounts: Isolated and Cross

Two modes with different logic:

Cross Margin — entire margin account balance serves as collateral for all positions. One position "eats" another's margin. Liquidation price is calculated for the whole account.

Isolated Margin — each trading pair has a separate isolated margin wallet. Maximum loss is capped at what's deposited in that wallet. For mobile UX, isolated margin is simpler: users understand they only lose what they deposited for that pair.

The UI must clearly distinguish these modes. A toggle with brief explanation (tooltip or bottom sheet with example) is mandatory.

Calculating Liquidation Price

Liquidation Price is the key indicator for a margin position. Users must see it before opening a position.

Simplified formula for ISOLATED LONG (Binance):

LiquidationPrice = EntryPrice × (1 - 1/Leverage + MaintenanceMarginRate)

Maintenance Margin Rate for most Binance pairs: 0.5–1.5% depending on tier.

// iOS — liquidation price calculation for isolated long position
struct MarginPositionCalculator {
    static func liquidationPriceLong(
        entryPrice: Decimal,
        leverage: Int,
        maintenanceMarginRate: Decimal = 0.005
    ) -> Decimal {
        let leverageDecimal = Decimal(leverage)
        return entryPrice * (1 - 1 / leverageDecimal + maintenanceMarginRate)
    }

    static func liquidationPriceShort(
        entryPrice: Decimal,
        leverage: Int,
        maintenanceMarginRate: Decimal = 0.005
    ) -> Decimal {
        let leverageDecimal = Decimal(leverage)
        return entryPrice * (1 + 1 / leverageDecimal - maintenanceMarginRate)
    }
}

Update liquidation price on each leverage change or margin adjustment. Display in red with distance percentage from current price — "Liquidation at 14.3% below current."

Margin Ratio and Margin Call

Margin Ratio = Maintenance Margin / Account Capital × 100%.

  • Below 100% — account is safe
  • 80–100% — yellow zone, push "Deposit additional margin"
  • Above 100% — forced position closure (liquidation)

On the open position screen, display Margin Ratio as a progress bar with color gradient (green → yellow → red). WebSocket updates balance and P&L in real-time.

Borrowing and Repayment

Margin borrowing flow:

  1. Borrow: user specifies amount and currency. Exchange returns tranId. UI shows available limit, current interest rate (hourly/annual), max available.

  2. Repay: interest is paid first, then principal. Button "Repay All" calculates full repayment amount including accrued interest.

Binance API: POST /sapi/v1/margin/loan and POST /sapi/v1/margin/repay. Rates via GET /sapi/v1/margin/interestRateHistory.

Risk Notifications

Margin trading requires proactive alerts:

  • Margin Ratio > 75% → push "Approaching liquidation on BTC/USDT"
  • Margin interest accrual > X USDT → periodic reminder
  • Position force-closed → immediate push with loss amount

Firebase Cloud Messaging with high priority for liquidation alerts — APNs apns-priority: 10, FCM priority: high. Regular priority can delay notifications minutes, critical for margin.

Open Position Screen

Open position card displays:

Field Update
Unrealized PnL (USDT and %) Real-time WebSocket
Liquidation Price On margin change
Margin Ratio Real-time
Leverage Static at opening
Entry Price / Mark Price Real-time

Mark Price (fair price via index) is different from Last Price. P&L and liquidation calculate from Mark Price, not Last Price.

Timeline and Scope

Component Timeline
Cross/Isolated toggle with explanations 3 days
Order form with leverage and liquidation calc 1 week
Borrowing and repayment + rate UI 1 week
Real-time P&L and Margin Ratio in WebSocket 1 week
Risk push alerts (Margin Call, Liquidation) 3 days
Position history and trades 3 days

Minimum margin module: 4–5 weeks. Full system with Cross/Isolated, borrowing history, detailed analytics — 2–3 months.