Module Polymarket.Rtds

Real-Time Data Socket (RTDS) client for streaming data.

Provides real-time updates for:

Uses pure-OCaml TLS (tls-eio) for cross-platform compatibility.

Crypto Prices (Binance)

Subscribe to real-time crypto prices from Binance:

  Eio_main.run @@ fun env ->
  Eio.Switch.run @@ fun sw ->
  let net = Eio.Stdenv.net env in
  let clock = Eio.Stdenv.clock env in
  let client =
    Rtds.Crypto_prices.connect_binance ~sw ~net ~clock
      ~symbols:[ "btcusdt"; "ethusdt" ] ()
  in
  let stream = Rtds.Crypto_prices.stream client in
  match Eio.Stream.take stream with
  | Binance msg -> Printf.printf "BTC: %.2f\n" msg.payload.value
  | _ -> ()

Crypto Prices (Chainlink)

Subscribe to oracle prices from Chainlink:

  let client =
    Rtds.Crypto_prices.connect_chainlink ~sw ~net ~clock ~symbol:"eth/usd"
      ()
  in
  let stream = Rtds.Crypto_prices.stream client in
  match Eio.Stream.take stream with
  | Chainlink msg -> Printf.printf "ETH: %.2f\n" msg.payload.value
  | _ -> ()

Comments

Subscribe to real-time comment updates:

  let client = Rtds.Comments.connect ~sw ~net ~clock () in
  let stream = Rtds.Comments.stream client in
  match Eio.Stream.take stream with
  | Comment_created msg ->
      Printf.printf "New comment: %s\n" msg.payload.body
  | _ -> ()

Unified Client

Subscribe to multiple topics with a single connection:

  let client = Rtds.connect ~sw ~net ~clock () in
  let subscriptions =
    [
      Rtds.Types.crypto_prices_subscription ();
      Rtds.Types.comments_subscription ();
    ]
  in
  Rtds.subscribe client ~subscriptions;
  let stream = Rtds.stream client in
  match Eio.Stream.take stream with
  | Crypto (Binance msg) -> Printf.printf "Price: %.2f\n" msg.payload.value
  | Comment (Comment_created msg) ->
      Printf.printf "Comment: %s\n" msg.payload.body
  | _ -> ()
include module type of struct include Rtds.Client end

Unified RTDS Client

type t = Rtds.Client.t

RTDS client handle.

val connect : sw:Eio.Switch.t -> net:'a Eio.Net.t -> clock:float Eio.Time.clock_ty Eio.Resource.t -> unit -> t

Connect to the RTDS WebSocket.

val stream : t -> Types.message Eio.Stream.t

Get the stream of parsed messages.

val subscribe : t -> subscriptions:Types.subscription list -> unit

Subscribe to topics.

val unsubscribe : t -> subscriptions:Types.subscription list -> unit

Unsubscribe from topics.

val close : t -> unit

Close the connection.

Convenience Clients

module Crypto_prices = Rtds.Client.Crypto_prices
module Comments = Rtds.Client.Comments
module Types : sig ... end

Real-Time Data Socket (RTDS) message types for Polymarket.