Binance API
This project will help you make your own app that interact with Binance API. Package includes REST and STREAM (Websocket) for client and server.
REST requests are caching (60m).
Name | Description |
---|---|
rest-api.md | Details on the Rest API |
web-socket-streams | Details on available streams and payloads |
user-data-stream | Details on the dedicated account stream |
errors | Descriptions of possible error messages from the Rest API |
Menu
Introduction
For ease to use, we renamed object keys.
Server response
=> Rename keys with "schema.js"
=> Updated response
schema.js
Schema snippet /aggTrades: a: 'aggTradeId' p: 'price' q: 'quantity' f: 'firstTradeId' l: 'lastTradeId' T: 'timestamp' m: 'maker' M: 'bestPriceMatch'
Updated response
"aggTradeId": 26129 "price": "0.01633102" "quantity": "4.70443515" "firstTradeId": 27781 "lastTradeId": 27781 "timestamp": 1498793709153 "maker": true "bestPriceMatch": true ...
If you need to update the keys, you can do this in schema.js
Install
Package manager
$ yarn add @marcius-capital/binance-api$ npm install @marcius-capital/binance-api
const api = // RESTapirest<REQUEST_NAME><OPTIONS> // Streamapistream<REQUEST_NAME><PARAMS> console apistreamclose<REQUEST_NAME><PARAMS> // Close single connectionapistreamcloseall // Close all connections // Close with "uniqueID"apistream<REQUEST_NAME><PARAMS> uniqueID:<string_id> consoleapistreamclose<REQUEST_NAME>uniqueID:<string_id>
<PARAMS>
valid from Official Binance API. <REQUEST_NAME>
You can find below in REST and WebSocket stack.
uniqueID - a unique key by which you can open and close the connection. With different IDs you can open different connections in same time. To control connections, repeated are prohibited.
Rest
All symbols for rest are uppercase.
List of REST requests
https://github.com/binance-exchange/binance-official-api-docs/blob/master/rest-api.md
const api = // Public requestsapirestapirestapirestapirest // Single tickerapirest // All tickersapirestapirestapirestapirest // Private requestsapirestapirest // Balanceapirestapirestapirestapirest
Proxy
Proxies can be used with all REST requests.
apirest<request_name>proxy: host: 'http://localhost' port: '3000'apirest<request_name>proxy: host: 'http://super-proxy-service.com' port: 'some_port_if_is' auth: username: 'my-username' password: 'my-password' // Exampleapirest // Publicapirest // Private
If you are familiar with Axios, can read docs.
Websocket
https://github.com/binance-exchange/binance-official-api-docs/blob/master/web-socket-streams.md
List of STREAM requests
All symbols for streams can be lowercase or uppercase.
const api = apistream // updateSpeed: 1000ms default, can be 100 (100ms)apistream // level: 100 default, updateSpeed: 1000ms default, can be 100 (100ms)apistreamapistreamapistreamapistreamapistreamapistreamapistream // Add new// Attention! Much data.apistream // Update Speed: Real-timeapistream // Update Speed: Real-time
Close connection
// Close connectionsapistreamcloseall // Close connectionapistreamclose // Params for close stream are used similar for open stream // Close with uniqueIDapistreamclose apistreamclose
Close connection have similar params for closing. Difference: api.stream.kline(<params>, cb)
=> api.stream.close.kline(<params>, cb)
.
User data stream
https://github.com/binance-exchange/binance-official-api-docs/blob/master/user-data-stream.md
Upon changes in the account, returns data about balance, orders etc.
Start a new user data stream. The stream will close after 60 minutes unless a keepalive is sent. If the account has an active listenKey, that listenKey will be returned and its validity will be extended for 60 minutes. (c) Binance
Stream alive 24 hours. Every 30 minutes, package automatically sends a request to keep alive listenKey
User data has been partially tested. Use carefully. If you have problems, open issue.
// Simple open and close "user data stream"// this is enough if you have a connection for one userapistreamapistreamclose // For comfort you can add "uniqueID"apistreamapistreamclose // With proxyapistream
Error
https://github.com/binance-exchange/binance-official-api-docs/blob/master/errors.md
The error response is returned in JSON format with a lot of information, we minimized the response to simplify understanding. Will responce string format: '-1003 TOO_MANY_REQUESTS'
(as example) instead JSON.
console // Using example // Exampleapirest // api.error(<ERR_RESPONSE>)
Full list requests
Full list of requests in test.js. For testing local, uncomment request and run node:
$ node test.js
TODO
SpotWebsocket spotWebsocket spot - "User Data Stream"Proxy- Futures with testnet
Stay in touch
Feel free to ask questions 😊
- Reddit: https://reddit.com/r/MarciusCapital
- Discord: https://discordapp.com/invite/DaWfrPx
License
MIT | Copyright (c) 2019-present