0.20.3 • Published 4 years ago

binance-us v0.20.3

Weekly downloads
42
License
ISC
Repository
gitlab
Last release
4 years ago

Binance US Client (WIP)

TypeScript License: ISC Node Version

pipeline status coverage report codecov

NPM

Install

# NPM
npm i binance-us

# Yarn
yarn add binance-us

Getting Started

Importing

modules

import { BinanceClient, PublicBinanceClient } from 'bianace-us'

// Authenticated
const key = 'xV7WDC9IbREgZ...'
const secret = 'KvBlbigseoZcv...'
const client = new BinanceClient({ key, secret })

// Public
const client = new PublicBinanceClient()

commonjs

const BinanceUS = require('binance-us')

// Authenticated
const key = 'xV7WDC9IbREgZ...'
const secret = 'KvBlbigseoZcv...'
const client = BinanceUS({ key, secret })


// Public
const client = BinanceUS()

Usage

async/await

const response = await client.time()
console.log(response)

callback

client.time().then(response => console.log(response))

Table of Contents

ping

Test connectivity to the API.

Weight: 1

console.log(await client.ping())
{}

time

Current server time.

Weight: 1

console.log(await client.time())
{
  serverTime: 1578369719229
}

exchangeInfo

Current exchange trading rules and symbol information.

Weight: 1

console.log(await client.exchangeInfo())
{
  timezone: "UTC",
  serverTime: 1578375682742,
  rateLimits: [
    {
      rateLimitType: "REQUEST_WEIGHT",
      interval: "MINUTE",
      intervalNum: 1,
      limit: 1200
    },
    {
      rateLimitType: "ORDERS",
      interval: "SECOND",
      intervalNum: 10,
      limit: 100
    },
    {
      rateLimitType: "ORDERS",
      interval: "DAY",
      intervalNum: 1,
      limit: 200000
    }
  ],
  exchangeFilters: [],
  symbols: [
    {
      symbol: "BTCUSD",
      status: "TRADING",
      baseAsset: "BTC",
      baseAssetPrecision: 8,
      quoteAsset: "USD",
      quotePrecision: 4,
      baseCommissionPrecision: 8,
      quoteCommissionPrecision: 2,
      orderTypes: ["LIMIT", "LIMIT_MAKER", "MARKET", "STOP_LOSS_LIMIT", "TAKE_PROFIT_LIMIT"],
      icebergAllowed: true,
      ocoAllowed: true,
      isSpotTradingAllowed: true,
      isMarginTradingAllowed: false,
      filters: [
        {
          filterType: "PRICE_FILTER",
          minPrice: "0.0100",
          maxPrice: "100000.0000",
          tickSize: "0.0100"
        },
        {
          filterType: "PERCENT_PRICE",
          multiplierUp: "5",
          multiplierDown: "0.2",
          avgPriceMins: 5
        },
        {
          filterType: "LOT_SIZE",
          minQty: "0.00000100",
          maxQty: "9000.00000000",
          stepSize: "0.00000100"
        }
      ]
    }
  ]
}

book

Order book.

Weight:

LimitWeight
5,10,20,50,1001
5005
100010
500050

Parameters

NameTypeMandatoryDefaultDescription
symbolstringYESN/A
limitnumberNO100valid:5,10,20,50,100,500,1000,5000
const symbol = 'BTCUSD'
const limit = 500

console.log(await client.book({ symbol }))
console.log(await client.book({ symbol, limit }))
{
  lastUpdateId: 1027024,
  bids: [
    {
      price: "4.00000000",
      quantity: "431.00000000"
    }
  ],
  asks: [
    {
      price: "4.00000200",
      quantity: "12.00000000"
    }
  ]
}

trades

Recent trades.

Weight: 1

Parameters

NameTypeMandatoryDefaultDescription
symbolstringYESN/A
limitnumberNO500max: 1000
const symbol = 'BTCUSD'
const limit = 850

console.log(await client.trades({ symbol }))
console.log(await client.trades({ symbol, limit }))
;[
  {
    id: 28457,
    price: '4.00000100',
    quantity: '12.00000000',
    quoteQuantity: '48.000012',
    time: 1499865549590,
    isBuyerMaker: true,
    isBestMatch: true
  }
]

aggTrades

Get compressed, aggregate trades. Trades that fill at the time, from the same order, with the same price will have the quantity aggregated.

Weight: 1

Parameters

NameTypeMandatoryDefaultDescription
symbolstringYESN/A
limitnumberNO500max: 1000
fromIdnumberNON/AID to get aggregate trades from INCLUSIVE
startTimenumberNON/ATimestamp in ms to get aggregate trades from INCLUSIVE
endTimenumberNON/ATimestamp in ms to get aggregate trades until INCLUSIVE
  • If both startTime and endTime are sent, time between startTime and endTime must be less than 1 hour.
  • If fromId, startTime, and endTime are not sent, the most recent aggregate trades will be returned.
const symbol = 'BTCUSD'
const limit = 625

console.log(await client.aggTrades({ symbol }))
console.log(await client.aggTrades({ symbol, limit }))
;[
  {
    id: 26129,
    price: '0.01633102',
    quantity: '4.70443515',
    firstId: 27781,
    lastId: 27781,
    time: 1498793709153,
    isBuyerMaker: true,
    isBestMatch: true
  }
]

candles

Kline/candlestick bars for a symbol. Candlesticks are uniquely identified by their open time.

Weight: 1

Parameters

NameTypeMandatoryDefaultDescription
symbolstringYESN/A
intervalenumYESN/A1m,3m,5m,15m,30m,1h,2h,4h,6h,8h,12h,1d,3d,1w,1M
startTimenumberNON/A
endTimenumberNON/A
limitnumberNO500max: 1000
  • If startTime and endTime are not sent, the most recent candlesticks are returned.
import { CandlestickInterval } from 'binance-us'

const symbol = 'BTCUSD'
const interval = CandlestickInterval.FIFTEEN_MINUTES
const limit = 920

console.log(await client.candles({ symbol, interval }))
console.log(await client.candles({ symbol, interval, limit }))
;[
  {
    openTime: 1499040000000,
    open: '0.01634790',
    high: '0.80000000',
    low: '0.01575800',
    close: '0.01577100',
    volume: '148976.11427815',
    closeTime: 1499644799999,
    quoteVolume: '2434.19055334',
    trades: 308,
    takerBuyVolume: '1756.87402397',
    tackerBuyQuoteVolume: '28.46694368'
  }
]

avgPrice

Current average price for a symbol.

Weight: 1

Parameters

NameTypeMandatoryDefaultDescription
symbolstringYESN/A
const symbol = 'BTCUSD'

console.log(await client.avgPrice({ symbol }))
{
  minutes: 5,
  price: "9.35751834"
}

ticker24Hour

24 hour rolling window price change statistics. Careful when accessing this with no symbol.

Weight: 1 for a single symbol; 40 when the symbol parameter is omitted

Parameters

NameTypeMandatoryDefaultDescription
symbolstringNON/A
const symbol = 'BTCUSD'

console.log(await client.ticker24Hour()) // weight: 40
console.log(await client.ticker24Hour({ symbol })) // weight: 1
;[
  {
    symbol: 'BNBBTC',
    priceChange: '-94.99999800',
    priceChangePercent: '-95.960',
    weightedAvgPrice: '0.29628482',
    prevClosePrice: '0.10002000',
    lastPrice: '4.00000200',
    lastQuantity: '200.00000000',
    bidPrice: '4.00000000',
    askPrice: '4.00000200',
    openPrice: '99.00000000',
    highPrice: '100.00000000',
    lowPrice: '0.10000000',
    volume: '8913.30000000',
    quoteVolume: '15.30000000',
    openTime: 1499783499040,
    closeTime: 1499869899040,
    firstId: 28385,
    lastId: 28460,
    trades: 76
  }
]

tickerPrice

Latest price for a symbol or symbols.

Weight: 1 for a single symbol; 2 when the symbol parameter is omitted

Parameters

NameTypeMandatoryDefaultDescription
symbolstringNON/A
const symbol = 'BTCUSD'

console.log(await client.tickerPrice()) // weight: 2
console.log(await client.tickerPrice({ symbol })) // weight: 1
;[
  {
    symbol: 'LTCBTC',
    price: '4.00000200'
  }
]

tickerBook

Best price/quantity on the order book for a symbol or symbols.

Weight: 1 for a single symbol; 2 when the symbol parameter is omitted

Parameters

NameTypeMandatoryDefaultDescription
symbolstringNON/A
const symbol = 'BTCUSD'

console.log(await client.tickerBook()) // weight: 2
console.log(await client.tickerBook({ symbol })) // weight: 1
;[
  {
    symbol: 'LTCBTC',
    bidPrice: '4.00000000',
    bidQuantity: '431.00000000',
    askPrice: '4.00000200',
    askQuantity: '9.00000000'
  }
]

historicalTrades

Get older trades.

Key Required

Weight: 5

Parameters

NameTypeMandatoryDefaultDescription
symbolstringNON/A
limitnumberNO500max: 1000
fromIdnumberNON/ATradeId to fetch from. Default gets most recent trades.
const symbol = 'BTCUSD'
const limit = 100

console.log(await client.historicalTrades({ symbol }))
console.log(await client.historicalTrades({ symbol, limit }))
[
  {
    id: 28457,
    price: '4.00000100',
    quantity: '12.00000000',
    quoteQuantity: '48.000012',
    time: 1499865549590,
    isBuyerMaker: true,
    isBestMatch: true
  }
]

License

This project is licensed under the ISC License - see the LICENSE file for details

0.20.3

4 years ago

0.20.2

4 years ago

0.20.1

4 years ago

0.20.0

4 years ago

0.19.2

4 years ago

0.19.1

4 years ago

0.19.0

4 years ago

0.18.1

4 years ago

0.18.0

4 years ago

0.17.5

4 years ago

0.17.4

4 years ago

0.17.3

4 years ago

0.17.2

4 years ago

0.17.1

4 years ago

0.17.0

4 years ago

0.16.5

4 years ago

0.16.2

4 years ago

0.16.1

4 years ago

0.16.0

4 years ago

0.15.10

4 years ago

0.15.9

4 years ago

0.15.8

4 years ago

0.15.7

4 years ago

0.15.6

4 years ago

0.15.5

4 years ago

0.15.4

4 years ago

0.15.3

4 years ago

0.15.1

4 years ago

0.15.2

4 years ago

0.15.0

4 years ago

0.14.6

4 years ago

0.14.5

4 years ago

0.14.4

4 years ago

0.14.3

4 years ago

0.14.2

4 years ago

0.13.1

4 years ago

0.12.0

4 years ago

0.11.1

4 years ago

0.13.0

4 years ago

0.11.2

4 years ago

0.11.3

4 years ago

0.11.0

4 years ago

0.10.1

4 years ago

0.10.0

4 years ago

0.9.2

4 years ago

0.9.1

4 years ago

0.9.0

4 years ago

0.8.0

4 years ago

0.7.0

4 years ago

0.6.0

4 years ago

0.5.0

4 years ago

0.4.1

4 years ago

0.4.0

4 years ago

0.3.0

4 years ago

0.2.1

4 years ago

0.2.2

4 years ago

0.2.0

4 years ago

0.1.0

4 years ago

0.0.4

4 years ago

0.0.3

4 years ago

0.0.2

4 years ago

0.0.1

4 years ago