package polymarket

  1. Overview
  2. Docs
Legend:
Page
Library
Module
Module type
Parameter
Class
Class type
Source

Module Websocket.ConnectionSource

WebSocket connection management with TLS and reconnection support.

Uses tls-eio for pure-OCaml TLS, avoiding OpenSSL dependencies.

Types

Sourcetype state =
  1. | Disconnected
  2. | Connecting
  3. | Connected
  4. | Closing
  5. | Closed

Connection state

Sourcetype config = {
  1. host : string;
  2. port : int;
  3. resource : string;
  4. initial_backoff : float;
  5. max_backoff : float;
  6. ping_interval : float;
}

Connection configuration

Sourcetype t

WebSocket connection handle.

Configuration

Sourceval default_config : host:string -> resource:string -> config

Create default configuration for a host and resource path.

Connection Management

Sourceval create : sw:Eio.Switch.t -> net:'a Eio.Net.t -> clock:float Eio.Time.clock_ty Eio.Resource.t -> host:string -> resource:string -> ?ping_interval:float -> ?buffer_size:int -> unit -> t

Create a new WebSocket connection. Does not connect immediately.

  • parameter ping_interval

    Ping interval in seconds (default: 30.0)

  • parameter buffer_size

    Message buffer size (default: 1000)

Sourceval start : t -> unit

Start the connection with automatic reconnection.

Sourceval close : t -> unit

Close the connection.

Messaging

Sourceval send : t -> string -> unit

Send a text message over the connection.

Sourceval send_ping : t -> unit

Send a ping frame.

Sourceval set_subscription : t -> string -> unit

Set the subscription message to send on (re)connect.

Sourceval message_stream : t -> string Eio.Stream.t

Get the stream of received messages.

Status

Sourceval is_connected : t -> bool

Check if currently connected.

Sourceval is_closed : t -> bool

Check if the connection has been closed.

Ping Loop

Sourceval start_ping : t -> unit

Start the periodic ping loop in a background fiber.

Message Parsing

Sourceval start_parsing_fiber : sw:Eio.Switch.t -> channel_name:string -> conn:t -> parse:(string -> 'a list) -> output_stream:'a Eio.Stream.t -> unit

Start a message parsing fiber that reads from a connection's raw stream, parses messages using the provided function, and adds them to the output stream.

Handles cancellation and errors with consistent logging.

  • parameter channel_name

    Name for log messages (e.g., "market", "user")

  • parameter parse

    Function to parse raw messages into typed messages

  • parameter output_stream

    Output stream for parsed messages