binance-futures-node

0.0.8 • Public • Published

binance-futures-node

A Node JavaScript wrapper for the Binance(Futures) API.

Note: This wrapper uses Promises, if they are not supported in your environment, you might want to add a polyfill for them.

For PRs or issues, head over to the source repository.

Installation

yarn add binance-futures-node

Getting started

Import the module and create a new client. Passing api keys is optional only if you don't plan on doing authenticated calls. You can create an api key here.

import BinanceFutures from 'binance-futures-node'
 
new BinanceFutures().init('public','private').then(instance=>{
    instance.depth('BTCUSDT', DepthLimit.fiveHundred).then(res => res.json())
        .then((json) => {
            const find = (prev, cur) => {
                const current = {
                    price: cur[0],
                    amount: cur[1]
                }
                return current.amount > prev.amount ? current : prev
            }
            const start = {
                price: 0,
                amount: 0,
            }
            const lowest = json.bids.reduce(find, start)
            const biggest = json.asks.reduce(find, start)
            console.log('Looking at frame: [' + json.bids[json.bids.length - 1][0]
                + ']-[' + json.asks[json.asks.length - 1][0]+']')
            console.log(lowest)
            console.log(biggest)
            console.log("current prices: ["+json.bids[0][0] +"]-["+json.asks[0][0]+"]")
        })
})
 
BinanceFutures.time().then(res => res.json()).then(json => console.log(json.serverTime))

If you do not have an appropriate babel config, you will need to use the basic commonjs requires.

const BinanceFutures = require('binance-futures-node').default

Every REST method returns a Promise, making this library async await ready. Following examples will use the await form, which requires some configuration you will have to lookup.

Table of Contents

Public REST Endpoints

ping

Test connectivity to the API.

console.log(await client.ping())

time

Test connectivity to the Rest API and get the current server time.

console.log(await client.time())
Output
1508478457643

exchangeInfo

Get the current exchange trading rules and symbol information.

console.log(await client.exchangeInfo())
Output
{
  "timezone": "UTC",
  "serverTime": 1508631584636,
  "rateLimits": [
    {
      "rateLimitType": "REQUEST_WEIGHT",
      "interval": "MINUTE",
      "intervalNum": 1,
      "limit": 1200
    },
    {
      "rateLimitType": "ORDERS",
      "interval": "SECOND",
      "intervalNum": 1,
      "limit": 10
    },
    {
      "rateLimitType": "ORDERS",
      "interval": "DAY",
      "intervalNum": 1,
      "limit": 100000
    }
  ],
  "exchangeFilters": [],
  "symbols": [{
    "symbol": "ETHBTC",
    "status": "TRADING",
    "baseAsset": "ETH",
    "baseAssetPrecision": 8,
    "quoteAsset": "BTC",
    "quotePrecision": 8,
    "orderTypes": ["LIMIT", "MARKET"],
    "icebergAllowed": false,
    "filters": [{
      "filterType": "PRICE_FILTER",
      "minPrice": "0.00000100",
      "maxPrice": "100000.00000000",
      "tickSize": "0.00000100"
    }, {
      "filterType": "LOT_SIZE",
      "minQty": "0.00100000",
      "maxQty": "100000.00000000",
      "stepSize": "0.00100000"
    }, {
      "filterType": "MIN_NOTIONAL",
      "minNotional": "0.00100000"
    }]
  }]
}

Readme

Keywords

none

Package Sidebar

Install

npm i binance-futures-node

Weekly Downloads

0

Version

0.0.8

License

MIT

Unpacked Size

8.96 kB

Total Files

6

Last publish

Collaborators

  • upsage