WsHandler

Trait WsHandler 

Source
pub trait WsHandler: Debug {
    // Required methods
    fn handle_subscribe(
        &mut self,
        topics: HashSet<Topic>,
    ) -> Result<Vec<Message>, WsError>;
    fn handle_jrpc(&mut self, jrpc: Value) -> Result<ResponseOrContent, WsError>;

    // Provided methods
    fn config(&self) -> Result<WsConfig, UrlError> { ... }
    fn handle_auth(&mut self) -> Result<Vec<Message>, WsError> { ... }
}
Expand description

handle exchange-level events on the WsConnection.

Required Methods§

Source

fn handle_subscribe( &mut self, topics: HashSet<Topic>, ) -> Result<Vec<Message>, WsError>

Source

fn handle_jrpc(&mut self, jrpc: Value) -> Result<ResponseOrContent, WsError>

Called when the WsConnection received a JSON-RPC value, returns messages to be sent to the server or the content with parsed event name. If not the desired content and no respose is to be sent (like after a confirmation for a subscription), return a Response with an empty Vec.

Provided Methods§

Source

fn config(&self) -> Result<WsConfig, UrlError>

Returns a WsConfig that will be applied for all WebSocket connections handled by this handler.

Source

fn handle_auth(&mut self) -> Result<Vec<Message>, WsError>

Called when the WsConnection is created and on reconnection. Returned messages will be sent back to the server as-is.

Handling of listen-keys or any other authentication methods exchange demands should be done here. Although oftentimes handling the auth will spread into the handle_message too. Can be ran multiple times (on every reconnect). Thus this inherently cannot be used to initiate connectionions based on a change of state (ie order creation).

Implementors§