Back to Articles

Crypto Portfolio Tracking: Real-Time Candle Charts with Kotlin and Room DB

How to build a cryptocurrency portfolio tracker with live WebSocket price feeds, interactive candle charts, and Room Database for offline caching in Kotlin.

Crypto Portfolio Tracking: Real-Time Candle Charts with Kotlin and Room DB

Crypto markets move 24/7. CryptoPulse keeps traders informed with live prices, candle charts, and instant price alerts.


1. WebSocket Price Feeds

We connect to exchange WebSocket APIs for sub-second price updates, using Kotlin Flows to stream data to composables:

kotlin
fun observePriceUpdates(symbol: String): Flow<PriceUpdate> = callbackFlow { val ws = OkHttpClient().newWebSocket(request, object : WebSocketListener() { override fun onMessage(webSocket: WebSocket, text: String) { trySend(parsePriceUpdate(text)) } }) awaitClose { ws.close(1000, null) } }

2. Room Database Caching

Historical OHLCV data is cached in Room so candle charts load instantly on app restart without network calls.


3. Price Alert Engine

Users set threshold alerts that trigger push notifications even when the app is backgrounded, using WorkManager for reliable delivery.


Summary

Combining WebSocket streaming with local caching and background alerts creates a crypto tracker that never misses a market move.