class Binance::Websocket

Defined in:

binance/client/websocket.cr

Constructors

Instance Method Summary

Macro Summary

Constructor Detail

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

[View source]

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.


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

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

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

[View source]
def api_key : String #

[View source]
def api_key=(api_key : String) #

[View source]
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.


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

[View source]
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: @depth OR @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.

[View source]
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.


[View source]
def secret_key : String #

[View source]
def secret_key=(secret_key : String) #

[View source]
def service : Service #

[View source]
def service=(service : Service) #

[View source]
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.


[View source]
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.


[View source]

Macro Detail

macro stream(method_name, stream_name) #

[View source]
macro stream_all(method_name, stream_name) #

[View source]