glupbit/websocket/connection

WebSocket connection management via stratus actors.

Handles public and private (authenticated) connections with automatic message routing based on the type field in incoming JSON.

Types

User message type for the WebSocket actor.

pub type WsCommand {
  Subscribe(
    List(subscription.Subscription),
    subscription.WsFormat,
  )
}

Constructors

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)
  StatusMsg(String)
  ErrorMsg(name: String, message: String)
  RawMsg(String)
}

Constructors

Internal WebSocket state.

pub type WsState(user_state) {
  WsState(
    on_message: fn(user_state, WsMessage) -> user_state,
    user_state: user_state,
  )
}

Constructors

  • WsState(
      on_message: fn(user_state, WsMessage) -> user_state,
      user_state: user_state,
    )

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 subscribe(
  conn: process.Subject(stratus.InternalMessage(WsCommand)),
  subscriptions: List(subscription.Subscription),
  format: subscription.WsFormat,
) -> Nil

Send a subscription request over the WebSocket.

Search Document