Giter Club home page Giter Club logo

binance-websocket-examples's Introduction

Binance Websocket Examples

Local orderbook (Spot)

# Cache local orderbook and echo best price
# btcusdt by default
npm run orderbook

# or provide the trading pair
SYMBOL=bnbusdt npm run orderbook

Spot user data stream

# get user data steam
APIKEY=xxxxxx npm run user

# Get margin account update from websocket
APIKEY=xxxxxx APISECRET=xxxxx npm run margin-user

Futures user data stream

# Get user data steam on production
APIKEY=xxxxxx APISECRET=xxxxx npm run futures-user

# On testnet
APIKEY=xxxxxx APISECRET=xxxxx WSS_BASE_URL="wss://stream.binancefuture.com/" HTTP_BASE_URL="https://testnet.binancefuture.com/" npm run futures-user

Delivery Futures user data stream

# Get user data steam - defaults to production
APIKEY=xxxxxx APISECRET=xxxxx npm run delivery-futures-user

Combined streams

# Get multi pairs stream, setting the pairs in src/multi-stream-depth
npm run multi-stream

Spot trade stream delay monitoring

npm run monitor-spot-trade

Spot depth stream delay monitoring

npm run monitor-spot-depth

Futures depth stream delay monitoring

npm run monitor-futures

How to setup

npm install

# run test
npm run test

License

MIT

binance-websocket-examples's People

Contributors

2pd avatar dependabot[bot] avatar iscjt avatar ishuen avatar jorisw avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

binance-websocket-examples's Issues

Futures stream prblem

Hi

Whenever I create a futures stream like this: wss://stream.binancefuture.com/stream?streams= ...
the data that I get from open, close etc. differs slightly with what I can see while having Binance open in the web browser. Some times by as much as ~3 to 5 units.

And when I open a normal stream like this: wss://stream.binance.com:9443/stream?streams= ...
the data is very accurate and even has more decimal places.

How can I solve this issue so that the data from the futures stream is just as accurate as the normal streams?

I tested on ETHUSDT perpetual on Futures and ETHUSDT on the FIAT markets

socketClient.js returning wrong part of message payload

src/lib/socketClient.js line 38: const message = JSON.parse(msg.data);

returns the whole message payload, not the data part of the payload. So when you run it, on each message received you get an “Unprocessed method” error.
It should be something like:

const payload = JSON.parse(msg.data);
const message = payload.data;

I also suggest to change the error message text on line 48 to “Unknown method” to distinguish it from the message on line 45.

Best,
Peter

Subscribe to several user streams with one websocket connection

When I subscribe to several user data streams (get listenkey for each account data stream for futures) and get message from one of the stream I can't find out which data stream send me that update message (there's no field like account id... ). Do you have any ideas?

{
  "e": "ACCOUNT_UPDATE",                // Event Type
  "E": 1564745798939,                   // Event Time
  "T": 1564745798938 ,                  // Transaction
  "a":                                  // Update Data
    {
      "m":"ORDER",                      // Event reason type
      "B":[                             // Balances
        {
          "a":"USDT",                   // Asset
          "wb":"122624.12345678",       // Wallet Balance
          "cw":"100.12345678"           // Cross Wallet Balance
        },
        {
          "a":"BNB",           
          "wb":"1.00000000",
          "cw":"0.00000000"         
        }
      ], 

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.