Polymarket.RtdsReal-Time Data Socket (RTDS) client for streaming data.
Provides real-time updates for:
Uses pure-OCaml TLS (tls-eio) for cross-platform compatibility.
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
| _ -> ()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
| _ -> ()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
| _ -> ()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 endtype t = Rtds.Client.tRTDS client handle.
val connect :
sw:Eio.Switch.t ->
net:'a Eio.Net.t ->
clock:float Eio.Time.clock_ty Eio.Resource.t ->
unit ->
tConnect to the RTDS WebSocket.
val stream : t -> Types.message Eio.Stream.tGet the stream of parsed messages.
val subscribe : t -> subscriptions:Types.subscription list -> unitSubscribe to topics.
val unsubscribe : t -> subscriptions:Types.subscription list -> unitUnsubscribe from topics.
val close : t -> unitClose the connection.
module Crypto_prices = Rtds.Client.Crypto_pricesmodule Comments = Rtds.Client.Commentsmodule Types : sig ... endReal-Time Data Socket (RTDS) message types for Polymarket.