BinanceElixir.Spot.MarketStream (binance_elixir v0.2.1)

Copy Markdown View Source

Supervised Binance Spot market WebSocket stream with a bounded event queue.

Subscriptions can change while connected and are restored after reconnect. dropped in stats/1 means events were lost; consumers must resynchronize any derived state.

Summary

Functions

Builds a symbol aggregate-trade stream name.

Builds the all-symbol mini-ticker array stream name.

Builds a symbol best-bid/ask stream name.

Returns a specification to start this module under a supervisor.

Builds a partial-depth stream name.

Pops the oldest decoded event, or returns :empty.

Pops and normalizes the oldest market event.

Closes and reopens the connection with its existing streams.

Starts a supervised market stream. Example: streams: ["btcusdt@trade"].

Returns connection and queue counters.

Adds a market stream subscription. The server confirms receipt asynchronously.

Returns the desired market stream subscriptions.

Builds a symbol 24-hour ticker stream name.

Builds a symbol trade stream name.

Removes a market stream subscription; at least one stream must remain.

Builds and validates a Spot combined-stream URL.

Types

event()

@type event() :: map() | list()

Functions

aggregate_trades(symbol)

Builds a symbol aggregate-trade stream name.

all_mini_tickers()

Builds the all-symbol mini-ticker array stream name.

book_ticker(symbol)

Builds a symbol best-bid/ask stream name.

child_spec(init_arg)

Returns a specification to start this module under a supervisor.

See Supervisor.

partial_depth(symbol, levels, speed_ms \\ 1000)

Builds a partial-depth stream name.

pop(server)

@spec pop(GenServer.server()) :: {:ok, event()} | :empty

Pops the oldest decoded event, or returns :empty.

pop_normalized(server)

@spec pop_normalized(GenServer.server()) :: {:ok, map()} | :empty

Pops and normalizes the oldest market event.

renew(server)

@spec renew(GenServer.server()) :: :ok | {:error, :disconnected}

Closes and reopens the connection with its existing streams.

start_link(opts)

@spec start_link(keyword()) :: GenServer.on_start()

Starts a supervised market stream. Example: streams: ["btcusdt@trade"].

stats(server)

@spec stats(GenServer.server()) :: map()

Returns connection and queue counters.

subscribe(server, stream)

@spec subscribe(GenServer.server(), String.t()) :: :ok | {:error, String.t()}

Adds a market stream subscription. The server confirms receipt asynchronously.

subscriptions(server)

@spec subscriptions(GenServer.server()) :: [String.t()]

Returns the desired market stream subscriptions.

symbol_ticker(symbol)

Builds a symbol 24-hour ticker stream name.

trades(symbol)

Builds a symbol trade stream name.

unsubscribe(server, stream)

@spec unsubscribe(GenServer.server(), String.t()) :: :ok | {:error, String.t()}

Removes a market stream subscription; at least one stream must remain.

url(streams, opts \\ [])

@spec url([String.t()], keyword()) :: {:ok, String.t()} | {:error, String.t()}

Builds and validates a Spot combined-stream URL.