class

Binance::Websocket

Inherits Reference < Object

Constructors

new(api_key : String = "", secret_key : String = "", service : Binance::Service = Binance::Service::Com)
Source

Instance methods

aggregate_trade(markets : Array(String) | String, handler : Binance::Handler | Binance::Handler.class, timeout : Time::Span = 0.seconds)

The Aggregate Trade Streams push trade information that is aggregated for a single taker order.

Source
all_book_tickers(handler : Binance::Handler | Binance::Handler.class, timeout : Time::Span = 0.seconds)
Source
all_mini_tickers(handler : Binance::Handler | Binance::Handler.class, timeout : Time::Span = 0.seconds)
Source
all_tickers(handler : Binance::Handler | Binance::Handler.class, timeout : Time::Span = 0.seconds)
Source
api_key
Source
api_key=(api_key : String)
Source
book_ticker(markets : Array(String) | String, handler : Binance::Handler | Binance::Handler.class, timeout : Time::Span = 0.seconds)

Pushes any update to the best bid or ask's price or quantity in real-time for a specified symbol.

Source
combo(markets, streams, handler, timeout = 0.seconds) : Listener
Source
depth(markets, handler, speed = "", timeout = 0.seconds) : Listener

Diff. Depth Stream Order book price and quantity depth updates used to locally manage an order book.

Stream Name: <symbol>@depth OR <symbol>@depth@100ms

Update Speed: 1000ms or 100ms

How to manage a local order book correctly

  1. Open a stream to wss://stream.binance.com:9443/ws/bnbbtc@depth.
  2. Buffer the events you receive from the stream.
  3. Get a depth snapshot from https://api.binance.com/api/v3/depth?symbol=BNBBTC&limit=1000 .
  4. Drop any event where u is <= lastUpdateId in the snapshot.
  5. The first processed event should have U <= lastUpdateId+1 AND u >= lastUpdateId+1.
  6. While listening to the stream, each new event's U should be equal to the previous event's u+1.
  7. The data in each event is the absolute quantity for a price level.
  8. If the quantity is 0, remove the price level.
  9. Receiving an event that removes a price level that is not in your local order book can happen and is normal.
Source
mini_ticker(markets : Array(String) | String, handler : Binance::Handler | Binance::Handler.class, timeout : Time::Span = 0.seconds)

24hr rolling window mini-ticker statistics for all symbols that changed in an array. These are NOT the statistics of the UTC day, but a 24hr rolling window for the previous 24hrs. Note that only tickers that have changed will be present in the array.

Source
secret_key
Source
secret_key=(secret_key : String)
Source
service
Source
service=(service : Service)
Source
ticker(markets : Array(String) | String, handler : Binance::Handler | Binance::Handler.class, timeout : Time::Span = 0.seconds)

24hr rolling window ticker statistics for a single symbol. These are NOT the statistics of the UTC day, but a 24hr rolling window for the previous 24hrs.

Source
trade(markets : Array(String) | String, handler : Binance::Handler | Binance::Handler.class, timeout : Time::Span = 0.seconds)

The Trade Streams push raw trade information; each trade has a unique buyer and seller.

Source

Macros

stream(method_name, stream_name)
Source
stream_all(method_name, stream_name)
Source