We develop a trading screen for an exchange mobile application — one of the most technically dense UIs. A candlestick chart with hundreds of data points, a real-time order book, and an order form with instant validation must all run at 60 fps under a WebSocket stream with 10 updates per second. Rendering performance directly impacts the user's money. Our experience includes over 5 years in mobile exchange application development, with 30+ projects delivered. We guarantee stable operation under load.
Ensuring 60 fps under WebSocket Stream
Incoming data throttling is critical. WebSocket can send 20–50 updates per second for active pairs. Updating the UI on each message overloads the main thread. The correct approach: accumulate updates in a ConcurrentQueue on a background thread and apply them to the UI at 60 fps (using CADisplayLink on iOS or Choreographer on Android).
// iOS: accumulating updates private var pendingOrderBookUpdates: [OrderBookUpdate] = [] private let updateQueue = DispatchQueue(label: "orderbook.updates") func handleWebSocketMessage(_ update: OrderBookUpdate) { updateQueue.async { [weak self] in self?.pendingOrderBookUpdates.append(update) } } // CADisplayLink callback — on main thread, 60fps @objc func applyPendingUpdates() { var updates: [OrderBookUpdate] = [] updateQueue.sync { updates = pendingOrderBookUpdates; pendingOrderBookUpdates.removeAll() } guard !updates.isEmpty else { return } // Apply batch updates to UI applyToOrderBook(updates) } WebSocket and Data Flow Management
Exchange data arrives via WebSocket — subscribing to pairs, receiving ticks and order book updates. On iOS, URLSessionWebSocketTask (native, iOS 13+) or Starscream for more flexible reconnection logic. On Android, OkHttp WebSocket or Ktor WebSocket client. Upon connection loss: show a "No Connection" overlay over the chart (not replacing the entire screen), keep the last known data visible. On reconnection: automatic reconnect with exponential backoff (1s, 2s, 4s, 8s, max 30s), REST request for the current order book snapshot and recent candles, seamless resume without resetting the chart position.
Order Book Data Model
The order book is a sorted structure: bids (buy orders) sorted descending by price, asks (sell orders) ascending. We use SortedArray or TreeMap (Java) / custom AVLTree (Swift) for O(log n) insertion and deletion on updates. Updates are not full replacements but patches: a new level, changed volume, removed level (volume = 0). For iOS order book, we use an NSFetchedResultsController pattern without CoreData: store bids: [(price: Decimal, size: Decimal)] and asks: [(price: Decimal, size: Decimal)], on change we diff using DeepDiff or Swift's CollectionDifference for minimal UITableView updates.
Why Custom Metal Rendering Beats Ready Libraries?
Standard UIKit is too slow for an interactive candlestick chart with 1000+ candles. Comparison of approaches:
| Approach | Performance | Complexity | Use Case |
|---|---|---|---|
| Core Graphics | 8–12 ms for 500 candles | Low | Up to 1000 candles |
| CALayer per candle | Catastrophic | Medium | Not recommended |
| Metal | 1–2 ms for 10000 candles | High | Professional applications |
| LightweightCharts (WebView) | Depends on WebView | Low | Quick start |
Metal rendering is 10x faster than Core Graphics with 2000+ candles. For professional trading apps with animated scalable charts, we use MetalKit. We store vertex data in a MTLBuffer for candles, and a vertex shader draws rectangles in screen space. 10,000 candles render in 1–2 ms.
Gestures and Chart Navigation
Pinch to zoom, pan to move along the time axis. Use UIPinchGestureRecognizer + UIPanGestureRecognizer simultaneously via gestureRecognizer(_:shouldRecognizeSimultaneouslyWith:) -> true. On zoom, visibleRange changes and we load historical candles for the new range via REST API. Crosshair on long press: UILongPressGestureRecognizer with minimumPressDuration = 0.1. On finger movement, update crosshair position and OHLCV tooltip with candle data under cursor.
Implementing Infinite Scroll for the Chart
- Determine
visibleRangebased on contentOffset and candle width. - When approaching the left edge (e.g., offset < 3 candles), send a request to the server for historical data.
- Add the received candles to the beginning of the dataset without resetting the current position — update
contentOffsetby the width of added candles. - Similarly for the right side — load newer data when scrolling right.
Order Form
Use a UITextField with a custom numeric keypad (inputView) instead of the system keyboard. It includes buttons for 25%, 50%, 75%, 100% of available balance for quick input. Store values as Decimal, not Double. Instant validation on input: minimum volume, tick size, available balance. Use Combine publisher(for: \.text) on UITextField with debounce(0.1) and map { Decimal(string: $0) }. Real-time cost calculation: total = price * amount including commission.
Buy/Sell Switching
Animated transition between buy and sell modes: form background color smoothly changes (green ↔ red), button text and direction icons change. On iOS, UIView.animate(withDuration: 0.2) with backgroundColor change. Haptic .impact(.medium) on switch.
Order Confirmation
A bottom sheet with order details before submission. Use UISheetPresentationController (iOS 15+) or a custom bottom sheet. Upon confirmation, the button enters a loading state (UIActivityIndicatorView replaces text) and is disabled for repeated taps. On API response, show success animation (green checkmark with scale animation) or an error with the specific error text from the API.
Performance and Optimization
The order book is a UITableView with potentially infinite height. Use UITableView.performBatchUpdates() for animated insertion/deletion/update of rows. With 10 updates per second, batch changes: do not call performBatchUpdates on every tick, collect changes over 100 ms and apply at once. A custom order book cell includes a depth bar (visual bar proportional to volume at that level). The depth bar is a UIView with a width constraint, updated via UIView.animate. Only change the constraint constant, not redraw the entire cell.
Profiling
Use Xcode Instruments > Time Profiler to find hot spots in the update loop. Core Animation instrument for frame drops. Target metrics: <16 ms for WebSocket batch processing, <5 ms for UI updates, 0 dropped frames when scrolling the order book. On Android, use Android Profiler in CPU+Memory+Network mode and systrace for long frames in Choreographer.
What’s Included in the Work
- WebSocket integration with throttling and reconnection logic
- Realization of candlestick chart (Core Graphics or LightweightCharts)
- Order book with batch updates and depth bar
- Order form with validation and confirmation
- Integration documentation and source code for UI components
- Technical support for one month after deployment
Estimated Timelines
Basic implementation (WebSocket + chart + order book + order form) — 5 days. Extended functionality (custom Metal rendering, indicators, analytics) — additional 5–10 days. Pricing is calculated individually — contact us for an assessment of your project.







