class Binance::Websocket

Defined in:

binance/client/websocket.cr

Constructors

Instance Method Summary

Macro Summary

Constructor Detail

def self.new(api_key = "", secret_key = "", service = Binance::Service::Com) #

Instance Method Detail

def 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.


def all_book_tickers(handler : Binance::Handler | Binance::Handler.class, timeout : Time::Span = 0.seconds) #

def all_mini_tickers(handler : Binance::Handler | Binance::Handler.class, timeout : Time::Span = 0.seconds) #

def all_tickers(handler : Binance::Handler | Binance::Handler.class, timeout : Time::Span = 0.seconds) #

def api_key : String #

def api_key=(api_key : String) #

def 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.


def combo(markets, streams, handler, timeout = 0.seconds) : Listener #

def 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.

def 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.


def secret_key : String #

def secret_key=(secret_key : String) #

def service : Service #

def service=(service : Service) #

def 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.


def 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.


Macro Detail

macro stream(method_name, stream_name) #

macro stream_all(method_name, stream_name) #