npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@nikita_isay/binance-api-client

v1.0.1

Published

JavaScript library for interacting with the Binance API

Downloads

3

Readme

Logo

JavaScript & TypeScript Binance API SDK

JavaScript SDK for the Binance APIs and WebSockets, with TypeScript support. This project is designed to help you make your own projects that interact with the Binance API. You can stream candlestick chart data, market depth, or use other advanced features such as setting stop losses and iceberg orders. This project seeks to have complete API coverage including WebSockets.

Installation

  npm i @nikita_isay/binance-api-client

Getting started

  import { BinanceApi } from '@nikita_isay/binance-api-client';

  const apiClient = new BinanceApi({
    enableTestnet: false,
    apiKey: 'YOUR-API-KEY',
    apiSecret: 'YOUR-API-SECRET'
  });

Binance spot market API

Get exchange info

const res = await apiClient.spot.market.getExchangeInfo({
    symbol: 'ETHBTC'
});

Get order book

const res = await apiClient.spot.market.getOrderBook({
    symbol: 'ETHBTC'
});

Get recent trades list

const res = await apiClient.spot.market.getRecentTradesList({
    symbol: 'ETHBTC'
});

Get aggregate trades list

const res = await apiClient.spot.market.getAggregateTradesList({
    symbol: 'ETHBTC',
    limit: 500,
    fromId: 'TRADE_ID',
    startTime: 1684335862286,
    endTime: 1684335862286
});

Get candlestick data

const res = await apiClient.spot.market.getCandlestickData({
    symbol: 'ETHBTC',
    interval: '1m', // 1m, 1h, 1d, etc
    startTime: 1684335862286,
    endTime: 1684335862286,
    limit: 100, // Default 100; max 1000
});

Get 24hr ticker price change statistics

const res = await apiClient.spot.market.get24hrTickerPriceChangeStatistics({
    symbol: 'ETHBTC,
    type: 'FULL', // Supported values: FULL or MINI.
});

Get current average price

const res = await apiClient.spot.market.getCurrentAveragePrice({
    symbol: 'ETHBTC,
});

Get symbol price ticker

const res = await apiClient.spot.market.getSymbolPriceTicker({
    symbol: 'ETHBTC',
});

Get symbol order book ticker

const res = await apiClient.spot.market.getSymbolOrderBookTicker({
    symbol: 'ETHBTC',
});

Get rolling window price change statistics

const res = await apiClient.spot.market.getRollingWindowPriceChangeStatistics({
    symbol: 'ETHBTC',
    symbols: ['ETHBTC', 'BTCUSDT'], // Either symbol or symbols must be provided
    windowSize: '1d', // 1d 1m 1h etc
    type: 'FULL'; // FULL or MINI
});

Binance spot trade API

Query order

const res = await apiClient.spot.trade.queryOrder({
    symbol: 'BNBUSDT',
    orderId: 'some-order-id',
    origClientOrderId?: 'some-client-order-id',
});

Get all orders

const res = await apiClient.spot.trade.getAllOrders({
    symbol: 'BNBUSDT',
    orderId: 'some-order-id',
    startTime: 1684335862286,
    endTime: 1684335862286,
    limit: 500,
});

Get current open orders

const res = await apiClient.spot.trade.getCurrentOpenOrders({
    symbol: 'BNBUSDT',
});

Query oco

const res = await apiClient.spot.trade.queryOco({
   orderListId: 'some-order-list-id', // Order list id
   origClientOrderId: 'id-from-the-client', // Order id from client
});

Query all oco

const res = await apiClient.spot.trade.queryAllOco({
    fromId: 'Trade id to fetch from',
    startTime: 1684335862286,
    endTime: 1684335862286,
    limit: 500,
});

Query open oco

const res = await apiClient.spot.trade.queryOpenOco();

Get account information

const res = await apiClient.spot.trade.getAccountInformation();

Get account trade list

const res = await apiClient.spot.trade.getAccountTradeList({
    symbol: 'BNBUSDT',
    orderId: 'order-id', // This can only be used in combination with symbol.
    startTime: 1684335862286,
    endTime: 1684335862286,
    fromId: 'trade-id-to-fetch-from',
    limit: 500,
});

Query current order count usage

const res = await apiClient.spot.trade.queryCurrentOrderCountUsage();

Create new limit order

const res = await apiClient.spot.trade.newLimitOrder({
  symbol: 'BNBUSDT',
  side: 'SELL',
  timeInForce: 'GTC', // GTC/FOK/IOC
  quantity: 1,
  price: 2400,
});

Create new market order

const res = await apiClient.spot.trade.newMarketOrder({
  symbol: 'BNBUSDT',
  side: 'SELL',
  quoteOrderQty: 1,
  quantity: 1
});

Create new stop loss limit order

const res = await apiClient.spot.trade.newStopLossLimitOrder({
  symbol: 'BNBUSDT',
  side: 'BUY',
  timeInForce: 'GTC', // GTC/FOK/IOC
  quantity: 1,
  price: 2345,
  stopPrice: 2345,
  trailingDelta: 2345,
});

Create new take profit limit order

const res = await apiClient.spot.trade.newTakeProfitLimitOrder({
  symbol: 'BNBUSDT',
  side: 'BUY',
  timeInForce: 'GTC', // GTC/FOK/IOC
  quantity: 1,
  price: 2345,
  stopPrice: 2345,
  trailingDelta: 2345,
});

Create new limit maker order

const res = await apiClient.spot.trade.newLimitMakerOrder({
  symbol: 'BNBUSDT',
  side: 'BUY',
  quantity: 1,
  price: 2345
});

Cancel all open orders on symbol

const res = await apiClient.spot.trade.cancelAllOpenOrdersOnSymbol({
  symbol: 'BNBUSDT',
});

Cancel order

const res = await apiClient.spot.trade.cancelOrder({
  symbol: 'BNBUSDT',
  orderId: 1,
  origClientOrderId: 'ID',
  newClientOrderId: 'ID',
});

Create new oco order

const res = await apiClient.spot.trade.newOco({
  symbol: 'BNBUSDT',
  listClientOrderId: 'ID',
  side: 'SELL',
  quantity: 1,
  limitClientOrderId: 'ID',
  isIsolated: 'FALSE', // for isolated margin or not, "TRUE", "FALSE",default "FALSE"
  price: 2500,
  limitIcebergQty: 2500,
  stopClientOrderId: 'ID', // A unique Id for the stop loss/stop loss limit leg
  stopPrice: 2500,
  stopLimitPrice: 2500, // If provided, stopLimitTimeInForce is required.
  stopIcebergQty: 1,
  stopLimitTimeInForce: 'GTC', // Valid values are GTC/FOK/IOC
  sideEffectType: 'NO_SIDE_EFFECT', // NO_SIDE_EFFECT, MARGIN_BUY, AUTO_REPAY; default NO_SIDE_EFFECT.
});

Cancel oco order

const res = await apiClient.spot.trade.cancelOco({
  symbol: 'BNBUSDT',
  orderListId: 1,
  listClientOrderId: 'ID', // Either orderListId or listClientOrderId must be provided
  newClientOrderId: 'ID', // Used to uniquely identify this cancel. Automatically generated by default
});

Cancel existing order and send new one

const res = await apiClient.spot.trade.cancelExistingOrderAndSendNew({
  symbol: 'BNBUSDT',
  side: 'SELL',
  type: 'LIMIT_MAKER',
  cancelReplaceMode: 'STOP_ON_FAILURE', // - `STOP_ON_FAILURE` If the cancel request fails, the new order placement will not be attempted. `ALLOW_FAILURES` If new order placement will be attempted even if cancel request fails.
  timeInForce: 'GTC',
  quantity: 1,
  quoteOrderQty: 1,
  price: 2500,
  cancelNewClientOrderId: 'ID', // Used to uniquely identify this cancel. Automatically generated by default
  cancelOrigClientOrderId: 'ID', // Either the cancelOrigClientOrderId or cancelOrderId must be provided. If both are provided, cancelOrderId takes precedence.
  cancelOrderId: 1, // Either the cancelOrigClientOrderId or cancelOrderId must be provided. If both are provided, cancelOrderId takes precedence.
  newClientOrderId: 'ID', // Used to identify the new order.
  strategyId: 1,
  strategyType: 1000000, // The value cannot be less than 1000000
  stopPrice: 2500, // Used with STOP_LOSS, STOP_LOSS_LIMIT, TAKE_PROFIT, and TAKE_PROFIT_LIMIT orders.
  trailingDelta: 2500, // Used with STOP_LOSS, STOP_LOSS_LIMIT, TAKE_PROFIT, and TAKE_PROFIT_LIMIT orders.
  icebergQty: 2500, // Used with LIMIT, STOP_LOSS_LIMIT, and TAKE_PROFIT_LIMIT to create an iceberg order.
});

Binance spot WebSocket API

Subscribe to trade data stream

const res = await apiClient.realtime.spot.subscribeTradeStream({
    callback: (data) => handleData(data),
    errorCallback: (error) => handleError(error),
    closeCallback: (code, reason) => handleClosing(code, reason),
    connectionCallback: () => handleConnection(),
    id: 1,
    symbol: 'BNBUSDT',
});

Subscribe to kline/candlestick data stream

const res = await apiClient.realtime.spot.subscribeKlineCandlestickStream({
    callback: (data) => handleData(data),
    errorCallback: (error) => handleError(error),
    closeCallback: (code, reason) => handleClosing(code, reason),
    connectionCallback: () => handleConnection(),
    id: 1,
    symbol: 'BNBUSDT',
    interval: '1m',
});

Subscribe to individual symbol mini ticker data stream

const res = await apiClient.realtime.spot.subscribeIndividualSymbolMiniTickerStream({
    callback: (data) => handleData(data),
    errorCallback: (error) => handleError(error),
    closeCallback: (code, reason) => handleClosing(code, reason),
    connectionCallback: () => handleConnection(),
    id: 1,
    symbol: 'BNBUSDT',
});

Subscribe to all market mini tickers data stream

const res = await apiClient.realtime.spot.subscribeAllMarketMiniTickersStream({
    callback: (data) => handleData(data),
    errorCallback: (error) => handleError(error),
    closeCallback: (code, reason) => handleClosing(code, reason),
    connectionCallback: () => handleConnection(),
    id: 1,
});

Subscribe to individual symbol ticker data stream

const res = await apiClient.realtime.spot.subscribeIndividualSymbolTickerStream({
    callback: (data) => handleData(data),
    errorCallback: (error) => handleError(error),
    closeCallback: (code, reason) => handleClosing(code, reason),
    connectionCallback: () => handleConnection(),
    id: 1,
    symbol: 'BNBUSDT',
});

Subscribe to all market tickers data stream

const res = await apiClient.realtime.spot.subscribeAllMarketTickersStream({
    callback: (data) => handleData(data),
    errorCallback: (error) => handleError(error),
    closeCallback: (code, reason) => handleClosing(code, reason),
    connectionCallback: () => handleConnection(),
    id: 1,
});

Subscribe to individual symbol rolling window statistics data stream

const res = await apiClient.realtime.spot.subscribeIndividualSymbolRollingWindowStatisticsStream({
    callback: (data) => handleData(data),
    errorCallback: (error) => handleError(error),
    closeCallback: (code, reason) => handleClosing(code, reason),
    connectionCallback: () => handleConnection(),
    id: 1,
    symbol: 'BNBUSDT',
    window_size: '1h',
});

Subscribe to all market rolling window statistics data stream

const res = await apiClient.realtime.spot.subscribeAllMarketRollingWindowStatisticsStream({
    callback: (data) => handleData(data),
    errorCallback: (error) => handleError(error),
    closeCallback: (code, reason) => handleClosing(code, reason),
    connectionCallback: () => handleConnection(),
    id: 1,
    window_size: '1h',
});

Subscribe to individual symbol book ticker data stream

const res = await apiClient.realtime.spot.subscribeIndividualSymbolBookTickerStream({
    callback: (data) => handleData(data),
    errorCallback: (error) => handleError(error),
    closeCallback: (code, reason) => handleClosing(code, reason),
    connectionCallback: () => handleConnection(),
    id: 1,
   symbol: 'BNBUSDT',
});

Subscribe to partial book depth data stream

const res = await apiClient.realtime.spot.subscribePartialBookDepthStream({
    callback: (data) => handleData(data),
    errorCallback: (error) => handleError(error),
    closeCallback: (code, reason) => handleClosing(code, reason),
    connectionCallback: () => handleConnection(),
    id: 1,
    symbol: 'BNBUSDT',
    levels: 1,
});

Subscribe to diff depth data stream

const res = await apiClient.realtime.spot.subscribeDiffDepthStream({
    callback: (data) => handleData(data),
    errorCallback: (error) => handleError(error),
    closeCallback: (code, reason) => handleClosing(code, reason),
    connectionCallback: () => handleConnection(),
    id: 1,
    symbol: 'BNBUSDT',
    updateSpeed: '1000ms',
});

Subscribe to aggregate trade data stream

const res = await apiClient.realtime.spot.subscribeAggregateTradeStream({
    callback: (data) => handleData(data),
    errorCallback: (error) => handleError(error),
    closeCallback: (code, reason) => handleClosing(code, reason),
    connectionCallback: () => handleConnection(),
    id: 1,
    symbol: 'BNBUSDT',
});

Binance user data WebSocket API

Subscribe to user data stream

const res = await apiClient.realtime.userData.subscribeUserDataStream({
    callback: (data) => handleData(data),
    errorCallback: (error) => handleError(error),
    closeCallback: (code, reason) => handleClosing(code, reason),
    connectionCallback: () => handleConnection(),
    id: 1,
});