glupbit/websocket/connection
WebSocket connection management via stratus actors.
Handles public and private (authenticated) connections with automatic
message routing based on type / method fields in incoming JSON.
Types
User message type for the WebSocket actor.
pub type WsCommand {
Subscribe(
List(subscription.Subscription),
subscription.WsFormat,
)
ListSubscriptions
}
Constructors
-
Subscribe(List(subscription.Subscription), subscription.WsFormat) -
ListSubscriptions
Handle returned from connecting to a WebSocket.
pub type WsHandle =
process.Subject(stratus.InternalMessage(WsCommand))
Decoded WebSocket message.
pub type WsMessage {
TickerMsg(subscription.TickerData)
TradeMsg(subscription.TradeData)
OrderbookMsg(subscription.OrderbookData)
SubscriptionListMsg(subscription.ListSubscriptionsResponse)
StatusMsg(String)
ErrorMsg(name: String, message: String)
RawMsg(String)
}
Constructors
-
TickerMsg(subscription.TickerData) -
TradeMsg(subscription.TradeData) -
OrderbookMsg(subscription.OrderbookData) -
SubscriptionListMsg(subscription.ListSubscriptionsResponse) -
StatusMsg(String) -
ErrorMsg(name: String, message: String) -
RawMsg(String)
Values
pub fn connect_private(
credentials creds: auth.Credentials,
state user_state: user_state,
on_message handler: fn(user_state, WsMessage) -> user_state,
) -> Result(
process.Subject(stratus.InternalMessage(WsCommand)),
stratus.InitializationError,
)
Connect to the private WebSocket with authentication.
pub fn connect_public(
state user_state: user_state,
on_message handler: fn(user_state, WsMessage) -> user_state,
) -> Result(
process.Subject(stratus.InternalMessage(WsCommand)),
stratus.InitializationError,
)
Connect to the public WebSocket.
pub fn list_subscriptions(
conn: process.Subject(stratus.InternalMessage(WsCommand)),
) -> Nil
Query the list of active subscriptions on the WebSocket.
pub fn subscribe(
conn: process.Subject(stratus.InternalMessage(WsCommand)),
subscriptions: List(subscription.Subscription),
format: subscription.WsFormat,
) -> Nil
Send a subscription request over the WebSocket.