FinnhubWebSocket

Types

Link copied to clipboard
object Companion

Functions

Link copied to clipboard
abstract fun connect()

Connect to the websocket server.

Link copied to clipboard
abstract fun disconnect()

Disconnect from websocket server.

Link copied to clipboard
abstract fun subscribeNews(symbol: String)

Subscribe to the news.

Link copied to clipboard
abstract fun subscribeTrades(symbol: String)

Subscribe to the trades.

Link copied to clipboard
abstract fun unsubscribeNews(symbol: String)

Unsubscribe from news.

Link copied to clipboard
abstract fun unsubscribeTrades(symbol: String)

Unsubscribe from trades.

Properties

Link copied to clipboard
abstract val newsFlow: SharedFlow<List<NewsItem>>

Flow of all news the client is subscribed to. If you are subscribed to multiple symbols, they might be mixed together and Finnhub currently doesn't seem to provide clear distinction from the response, but you can check the NewsItem.related item.

Link copied to clipboard
abstract var onConnected: () -> Unit

Called when the websocket succesfully connects to the server. You might want to include some initialization here and do the subscriptions.

Link copied to clipboard
abstract var onDisconnected: (Boolean) -> Unit

Called when the websocket disconnects. The lambda parameter indicates, whether the connection was closed on demand by user, or by some external factors, like connection problems. You might want to use this for auto-reconnect logic, if the connection was closed unexpectedly.

Link copied to clipboard
abstract var onError: (Throwable) -> Unit

Callback called when any error occurred. For finnhub error responses you will get FinnhubException with the received message. For all other errors the original exception will be emitted.

Link copied to clipboard
abstract val tradesFlow: SharedFlow<List<TradeItem>>

Flow of all trades the client is subscribed to. Each list contains only items of single symbol. If there are subscriptions for multiple symbols, each will emit in separate lists, you have to distinguish them by TradeItem.s of any item in the list.