Binance Connector JS
    Preparing search index...
    Index

    Constructors

    Methods

    • Query information about all your order lists, filtered by time range.

      Weight(IP): 20

      Security Type: USER_DATA

      Notes: Data Source:* Database

      Notes: If startTime and/or endTime are specified, fromId is ignored. Order lists are filtered by transactionTime of the last order list execution status update. If fromId is specified, return order lists with order list ID >= fromId. If no condition is specified, the most recent order lists are returned. The time between startTime and endTime can't be longer than 24 hours.

      Parameters

      Returns Promise<WebsocketApiResponse<AllOrderListsResponse>>

      Promise<WebsocketApiResponse>

    • Disconnects from the WebSocket server. If there is no active connection, a warning is logged. Otherwise, all connections in the connection pool are closed gracefully, and a message is logged indicating that the connection has been disconnected.

      Returns Promise<void>

      A Promise that resolves when all connections have been closed.

      Error if the WebSocket client is not set.

    • Query current exchange trading rules, rate limits, and symbol information.

      Weight(IP): 20

      Security Type: NONE

      Notes: Data Source:* Memory

      Notes:* If the value provided to symbol or symbols do not exist, the endpoint will throw an error saying the symbol is invalid. All parameters are optional. Only one of symbol, symbols, permissions parameters can be specified. Without parameters, exchangeInfo displays all symbols with ["SPOT", "MARGIN", "LEVERAGED"] permissions. In order to list all active symbols on the exchange, you need to explicitly request all permissions. permissions accepts either a list of permissions, or a single permission name. E.g. "SPOT".

      Examples of Symbol Permissions Interpretation from the Response:*

      [["A","B"]] means you may place an order if your account has either permission "A" or permission "B". [["A"],["B"]] means you can place an order if your account has permission "A" and permission "B". [["A"],["B","C"]] means you can place an order if your account has permission "A" and permission "B" or permission "C". (Inclusive or is applied here, not exclusive or, so your account may have both permission "B" and permission "C".)

      Parameters

      Returns Promise<WebsocketApiResponse<SpotWebsocketAPI.ExchangeInfoResponse>>

      Promise<WebsocketApiResponse>

    • Get klines (candlestick bars).

      Klines are uniquely identified by their open & close time.

      If you need access to real-time kline updates, please consider using WebSocket Streams: <symbol>@kline_<interval>

      If you need historical kline data, please consider using data.binance.vision.

      Weight(IP): 2

      Security Type: NONE

      Notes: Data Source:* Database

      Supported kline intervals (case-sensitive):

      Interval interval value
      seconds 1s
      minutes 1m, 3m, 5m, 15m, 30m
      hours 1h, 2h, 4h, 6h, 8h, 12h
      days 1d, 3d
      weeks 1w
      months 1M

      Notes:*

      If startTime and endTime are not sent, the most recent klines are returned. Supported values for timeZone: Hours and minutes (e.g. -1:00, 05:45) Only hours (e.g. 0, 8, 4) Accepted range is strictly [-12:00 to +14:00] inclusive If timeZone provided, kline intervals are interpreted in that timezone instead of UTC. Note that startTime and endTime are always interpreted in UTC, regardless of timeZone.

      Parameters

      Returns Promise<WebsocketApiResponse<SpotWebsocketAPI.KlinesResponse>>

      Promise<WebsocketApiResponse>

    • Query information about all your trades, filtered by time range.

      Weight: Condition Weight
      Without orderId 20
      With orderId 5

      Security Type: USER_DATA

      Notes: Data Source: Memory => Database

      Notes:

      • If fromId is specified, return trades with trade ID >= fromId.
      • If startTime and/or endTime are specified, trades are filtered by execution time (time).
      • fromId cannot be used together with startTime and endTime.
      • If orderId is specified, only trades related to that order are returned.
      • startTime and endTime cannot be used together with orderId.
      • If no condition is specified, the most recent trades are returned.
      • The time between startTime and endTime can't be longer than 24 hours.

      Parameters

      Returns Promise<WebsocketApiResponse<SpotWebsocketAPI.MyTradesResponse>>

      Promise<WebsocketApiResponse>

    • Parameters

      • event: "open" | "message" | "error" | "close" | "ping" | "pong"
      • listener: (...args: any[]) => void

      Returns void

    • Parameters

      • event: "open" | "message" | "error" | "close" | "ping" | "pong"
      • listener: (...args: any[]) => void

      Returns void

    • Cancel an active order.

      Weight(IP): 1

      Security Type: TRADE

      Notes: Data Source:* Matching Engine

      Notes:

      If both orderId and origClientOrderId parameters are provided, the orderId is searched first, then the origClientOrderId from that result is checked against that order. If both conditions are not met the request will be rejected.

      newClientOrderId will replace clientOrderId of the canceled order, freeing it up for new orders.

      If you cancel an order that is a part of an order list, the entire order list is canceled.

      The performance for canceling an order (single cancel or as part of a cancel-replace) is always better when only orderId is sent. Sending origClientOrderId or both orderId + origClientOrderId will be slower.

      Parameters

      Returns Promise<WebsocketApiResponse<OrderCancelResponse>>

      Promise<WebsocketApiResponse>

      • Cancel an existing order and immediately place a new order instead of the canceled one. A new order that was not attempted (i.e. when newOrderResult: NOT_ATTEMPTED), will still increase the unfilled order count by 1. You can only cancel an individual order from an orderList using this method, but the result is the same as canceling the entire orderList.not attempted (i.e. when newOrderResult: NOT_ATTEMPTED), will still increase the unfilled order count by 1.

      Weight(IP): 1

      Unfilled Order Count: 1

      Security Type: TRADE

      Notes: Data Source:* Matching Engine

      Similar to the order.place request, additional mandatory parameters (*) are determined by the new order type.

      Available cancelReplaceMode options:

      STOP_ON_FAILURE – if cancellation request fails, new order placement will not be attempted. ALLOW_FAILURE – new order placement will be attempted even if the cancel request fails.

      Request Response
      cancelReplaceMode orderRateLimitExceededMode Unfilled Order Count cancelResult newOrderResult status
      STOP_ON_FAILURE DO_NOTHING Within Limits SUCCESS SUCCESS 200
      FAILURE NOT_ATTEMPTED 400
      SUCCESS FAILURE 409
      Exceeds Limits SUCCESS SUCCESS N/A
      FAILURE NOT_ATTEMPTED N/A
      SUCCESS FAILURE N/A
      CANCEL_ONLY Within Limits SUCCESS SUCCESS 200
      FAILURE NOT_ATTEMPTED 400
      SUCCESS FAILURE 409
      Exceeds Limits FAILURE NOT_ATTEMPTED 429
      SUCCESS FAILURE 429
      ALLOW_FAILURE DO_NOTHING Within Limits SUCCESS SUCCESS 200
      FAILURE FAILURE 400
      FAILURE SUCCESS 409
      SUCCESS FAILURE 409
      Exceeds Limits SUCCESS SUCCESS N/A
      FAILURE FAILURE N/A
      FAILURE SUCCESS N/A
      SUCCESS FAILURE N/A
      CANCEL_ONLY Within Limits SUCCESS SUCCESS 200
      FAILURE FAILURE 400
      FAILURE SUCCESS 409
      SUCCESS FAILURE 409
      Exceeds Limits SUCCESS SUCCESS 200
      FAILURE FAILURE 400
      FAILURE SUCCESS N/A
      SUCCESS FAILURE 409

      Notes:

      If both cancelOrderId and cancelOrigClientOrderId parameters are provided, the cancelOrderId is searched first, then the cancelOrigClientOrderId from that result is checked against that order. If both conditions are not met the request will be rejected.

      cancelNewClientOrderId will replace clientOrderId of the canceled order, freeing it up for new orders.

      newClientOrderId specifies clientOrderId value for the placed order.

      A new order with the same clientOrderId is accepted only when the previous one is filled or expired.

      The new order can reuse old clientOrderId of the canceled order.

      This cancel-replace operation is not transactional.

      If one operation succeeds but the other one fails, the successful operation is still executed.

      For example, in STOP_ON_FAILURE mode, if the new order placement fails, the old order is still canceled.

      Filters and order count limits are evaluated before cancellation and order placement occurs.

      If new order placement is not attempted, your order count is still incremented.

      Like order.cancel, if you cancel an individual order from an order list, the entire order list is canceled.

      The performance for canceling an order (single cancel or as part of a cancel-replace) is always better when only orderId is sent. Sending origClientOrderId or both orderId + origClientOrderId will be slower.

      Parameters

      Returns Promise<WebsocketApiResponse<SpotWebsocketAPI.OrderCancelReplaceResponse>>

      Promise<WebsocketApiResponse>

    • Send in a new one-cancels-the-other (OCO) pair: LIMIT_MAKER + STOP_LOSS/STOP_LOSS_LIMIT orders (called legs), where activation of one order immediately cancels the other.

      This adds 1 order to EXCHANGE_MAX_ORDERS filter and the MAX_NUM_ORDERS filter

      Weight(IP): 1

      Unfilled Order Count: 1

      Security Type: TRADE

      Notes: Data Source:* Matching Engine

      Notes:

      listClientOrderId parameter specifies listClientOrderId for the OCO pair.

      A new OCO with the same listClientOrderId is accepted only when the previous one is filled or completely expired.

      listClientOrderId is distinct from clientOrderId of individual orders.

      limitClientOrderId and stopClientOrderId specify clientOrderId values for both legs of the OCO.

      A new order with the same clientOrderId is accepted only when the previous one is filled or expired.

      Price restrictions on the legs:

      side Price relation
      BUY price < market price < stopPrice
      SELL price > market price > stopPrice

      Both legs have the same quantity.

      However, you can set different iceberg quantity for individual legs.

      If stopIcebergQty is used, stopLimitTimeInForce must be GTC.

      trailingDelta applies only to the STOP_LOSS/STOP_LOSS_LIMIT leg of the OCO.

      Parameters

      Returns Promise<WebsocketApiResponse<OrderListPlaceResponse>>

      Promise<WebsocketApiResponse>

    • Send in an one-cancels-the-other (OCO) pair, where activation of one order immediately cancels the other.

      An OCO has 2 orders called the above order and below order.

      One of the orders must be a LIMIT_MAKER/TAKE_PROFIT/TAKE_PROFIT_LIMIT order and the other must be STOP_LOSS or STOP_LOSS_LIMIT order.

      Price restrictions: If the OCO is on the SELL side: LIMIT_MAKER/TAKE_PROFIT_LIMIT price > Last Traded Price > STOP_LOSS/STOP_LOSS_LIMIT stopPrice TAKE_PROFIT stopPrice > Last Traded Price > STOP_LOSS/STOP_LOSS_LIMIT stopPrice If the OCO is on the BUY side: LIMIT_MAKER price < Last Traded Price < STOP_LOSS/STOP_LOSS_LIMIT stopPrice TAKE_PROFIT stopPrice > Last Traded Price > STOP_LOSS/STOP_LOSS_LIMIT stopPrice OCOs add 2 orders to the EXCHANGE_MAX_ORDERS filter and MAX_NUM_ORDERS filter.

      Weight(IP): 1

      Unfilled Order Count: 2

      Security Type: TRADE

      Notes: Data Source:* Matching Engine

      Parameters

      Returns Promise<WebsocketApiResponse<OrderListPlaceOcoResponse>>

      Promise<WebsocketApiResponse>

    • Places an OTO.

      An OTO (One-Triggers-the-Other) is an order list comprised of 2 orders.

      The first order is called the working order and must be LIMIT or LIMIT_MAKER. Initially, only the working order goes on the order book.

      The second order is called the pending order. It can be any order type except for MARKET orders using parameter quoteOrderQty. The pending order is only placed on the order book when the working order gets fully filled*.

      If either the working order or the pending order is cancelled individually, the other order in the order list will also be canceled or expired.

      When the order list is placed, if the working order gets immediately fully filled, the placement response will show the working order as FILLED but the pending order will still appear as PENDING_NEW. You need to query the status of the pending order again to see its updated status.

      OTOs add 2 orders to the EXCHANGE_MAX_NUM_ORDERS filter and MAX_NUM_ORDERS filter.

      Weight(IP): 1

      Unfilled Order Count: 2

      Security Type: TRADE

      Notes: Data Source:* Matching Engine

      Mandatory parameters based on pendingType or workingType*

      Depending on the pendingType or workingType, some optional parameters will become mandatory.

      Type Additional mandatory parameters Additional information
      workingType = LIMIT workingTimeInForce
      pendingType = LIMIT pendingPrice, pendingTimeInForce
      pendingType = STOP_LOSS or TAKE_PROFIT pendingStopPrice and/or pendingTrailingDelta
      pendingType =STOP_LOSS_LIMIT or TAKE_PROFIT_LIMIT pendingPrice, pendingStopPrice and/or pendingTrailingDelta, pendingTimeInForce

      Parameters

      Returns Promise<WebsocketApiResponse<OrderListPlaceOtoResponse>>

      Promise<WebsocketApiResponse>

    • Place an OTOCO.

      An OTOCO (One-Triggers-One-Cancels-the-Other) is an order list comprised of 3 orders. The first order is called the working order and must be LIMIT or LIMIT_MAKER. Initially, only the working order goes on the order book. The behavior of the working order is the same as the OTO. OTOCO has 2 pending orders (pending above and pending below), forming an OCO pair. The pending orders are only placed on the order book when the working order gets fully filled. The rules of the pending above and pending below follow the same rules as the Order list OCO. OTOCOs add 3 orders to the EXCHANGE_MAX_NUM_ORDERS filter and MAX_NUM_ORDERS filter.

      Weight(IP): 1

      Unfilled Order Count: 3

      Security Type: TRADE

      Notes: Data Source:* Matching Engine

      Mandatory parameters based on pendingAboveType, pendingBelowType or workingType*

      Depending on the pendingAboveType/pendingBelowType or workingType, some optional parameters will become mandatory.

      Type Additional mandatory parameters Additional information
      workingType = LIMIT workingTimeInForce
      pendingAboveType= LIMIT_MAKER pendingAbovePrice
      pendingAboveType = STOP_LOSS/TAKE_PROFIT pendingAboveStopPrice and/or pendingAboveTrailingDelta
      pendingAboveType=STOP_LOSS_LIMIT/TAKE_PROFIT_LIMIT pendingAbovePrice, pendingAboveStopPrice and/or pendingAboveTrailingDelta, pendingAboveTimeInForce
      pendingBelowType= LIMIT_MAKER pendingBelowPrice
      pendingBelowType= STOP_LOSS/TAKE_PROFIT pendingBelowStopPrice and/or pendingBelowTrailingDelta
      pendingBelowType=STOP_LOSS_LIMIT/TAKE_PROFIT_LIMIT pendingBelowPrice, pendingBelowStopPrice and/or pendingBelowTrailingDelta, pendingBelowTimeInForce

      Parameters

      Returns Promise<WebsocketApiResponse<OrderListPlaceOtocoResponse>>

      Promise<WebsocketApiResponse>

    • Send in a new order.

      This adds 1 order to the EXCHANGE_MAX_ORDERS filter and the MAX_NUM_ORDERS filter.

      Weight(IP): 1

      Unfilled Order Count: 1

      Security Type: TRADE

      Notes: Data Source:* Matching Engine

      Certain parameters (*) become mandatory based on the order type:

      Order type Mandatory parameters
      LIMIT
      • timeInForce
      • price
      • quantity
      LIMIT_MAKER
      • price
      • quantity
      MARKET
      • quantity or quoteOrderQty
      STOP_LOSS
      • quantity
      • stopPrice or trailingDelta
      STOP_LOSS_LIMIT
      • timeInForce
      • price
      • quantity
      • stopPrice or trailingDelta
      TAKE_PROFIT
      • quantity
      • stopPrice or trailingDelta
      TAKE_PROFIT_LIMIT
      • timeInForce
      • price
      • quantity
      • stopPrice or trailingDelta

      Supported order types:

      Order type Description
      LIMIT

      Buy or sell quantity at the specified price or better.

      LIMIT_MAKER

      LIMIT order that will be rejected if it immediately matches and trades as a taker.

      This order type is also known as a POST-ONLY order.

      MARKET

      Buy or sell at the best available market price.

      • MARKET order with quantity parameter specifies the amount of the base asset you want to buy or sell. Actually executed quantity of the quote asset will be determined by available market liquidity.

        E.g., a MARKET BUY order on BTCUSDT for "quantity": "0.1000" specifies that you want to buy 0.1 BTC at the best available price. If there is not enough BTC at the best price, keep buying at the next best price, until either your order is filled, or you run out of USDT, or market runs out of BTC.

      • MARKET order with quoteOrderQty parameter specifies the amount of the quote asset you want to spend (when buying) or receive (when selling). Actually executed quantity of the base asset will be determined by available market liquidity.

        E.g., a MARKET BUY on BTCUSDT for "quoteOrderQty": "100.00" specifies that you want to buy as much BTC as you can for 100 USDT at the best available price. Similarly, a SELL order will sell as much available BTC as needed for you to receive 100 USDT (before commission).

      STOP_LOSS

      Execute a MARKET order for given quantity when specified conditions are met.

      I.e., when stopPrice is reached, or when trailingDelta is activated.

      STOP_LOSS_LIMIT

      Place a LIMIT order with given parameters when specified conditions are met.

      TAKE_PROFIT

      Like STOP_LOSS but activates when market price moves in the favorable direction.

      TAKE_PROFIT_LIMIT

      Like STOP_LOSS_LIMIT but activates when market price moves in the favorable direction.

      Notes on using parameters for Pegged Orders:

      These parameters are allowed for LIMIT, LIMIT_MAKER, STOP_LOSS_LIMIT, TAKE_PROFIT_LIMIT orders. If pegPriceType is specified, price becomes optional. Otherwise, it is still mandatory. pegPriceType=PRIMARY_PEG means the primary peg, that is the best price on the same side of the order book as your order. pegPriceType=MARKET_PEG means the market peg, that is the best price on the opposite side of the order book from your order. Use pegOffsetType and pegOffsetValue to request a price level other than the best one. These parameters must be specified together.

      Available timeInForce options, setting how long the order should be active before expiration:

      TIF Description
      GTC Good 'til Canceled – the order will remain on the book until you cancel it, or the order is completely filled.
      IOC Immediate or Cancel – the order will be filled for as much as possible, the unfilled quantity immediately expires.
      FOK Fill or Kill – the order will expire unless it cannot be immediately filled for the entire quantity.

      Notes:

      newClientOrderId specifies clientOrderId value for the order.

      A new order with the same clientOrderId is accepted only when the previous one is filled or expired.

      Any LIMIT or LIMIT_MAKER order can be made into an iceberg order by specifying the icebergQty.

      An order with an icebergQty must have timeInForce set to GTC.

      Trigger order price rules for STOP_LOSS/TAKE_PROFIT orders:

      stopPrice must be above market price: STOP_LOSS BUY, TAKE_PROFIT SELL stopPrice must be below market price: STOP_LOSS SELL, TAKE_PROFIT BUY

      MARKET orders using quoteOrderQty follow LOT_SIZE filter rules.

      The order will execute a quantity that has notional value as close as possible to requested quoteOrderQty.

      Parameters

      Returns Promise<WebsocketApiResponse<OrderPlaceResponse>>

      Promise<WebsocketApiResponse>

    • Test connectivity to the WebSocket API.

      Note: You can use regular WebSocket ping frames to test connectivity as well, WebSocket API will respond with pong frames as soon as possible. ping request along with time is a safe way to test request-response handling in your application.

      Weight(IP): 1

      Security Type: NONE

      Notes: Data Source:* Memory

      Parameters

      • requestParameters: PingRequest = {}

        Request parameters.

      Returns Promise<WebsocketApiResponse<PingResponse>>

      Promise<WebsocketApiResponse>

    • Sends a ping message to all connected Websocket servers in the pool. If no connections are ready, a warning is logged. For each active connection, the ping message is sent, and debug logs provide details.

      Returns void

      Error if a Websocket client is not set for a connection.

    • Sends an unsigned message to the WebSocket server

      Parameters

      • method: string

        The API method to call

      • payload: WebsocketSendMsgOptions = {}

        Message parameters and options

      Returns Promise<WebsocketApiResponse<unknown>>

      Promise that resolves with the server response

      Error if not connected

    • Sends a signed message to the WebSocket server with authentication

      Parameters

      • method: string

        The API method to call

      • payload: WebsocketSendMsgOptions = {}

        Message parameters and options

      Returns Promise<WebsocketApiResponse<unknown>>

      Promise that resolves with the server response

      Error if not connected

    • Get rolling window price change statistics with a custom window.

      This request is similar to ticker.24hr but statistics are computed on demand using the arbitrary window you specify.

      Note:* Window size precision is limited to 1 minute. While the closeTime is the current time of the request, openTime always start on a minute boundary. As such, the effective window might be up to 59999 ms wider than the requested windowSize.

      Window computation example

      For example, a request for "windowSize": "7d" might result in the following window:

      {
      "openTime": 1659580020000,
      "closeTime": 1660184865291
      }

      Time of the request – closeTime – is 1660184865291 (August 11, 2022 02:27:45.291). Requested window size should put the openTime 7 days before that – August 4, 02:27:45.291 – but due to limited precision it ends up a bit earlier: 1659580020000 (August 4, 2022 02:27:00), exactly at the start of a minute.

      If you need to continuously monitor trading statistics, please consider using WebSocket Streams: <symbol>@ticker_<window_size> or !ticker_<window-size>@arr

      Weight: Adjusted based on the number of requested symbols:

      Symbols Weight
      1–50 4 per symbol
      51–100 200

      Security Type: NONE

      Notes: Data Source:* Database

      Supported window sizes:

      Unit windowSize value
      minutes 1m, 2m ... 59m
      hours 1h, 2h ... 23h
      days 1d, 2d ... 7d

      Notes:

      Either symbol or symbols must be specified.

      Maximum number of symbols in one request: 200.

      Window size units cannot be combined. E.g., 1d 2h is not supported.

      Parameters

      Returns Promise<WebsocketApiResponse<SpotWebsocketAPI.TickerResponse>>

      Promise<WebsocketApiResponse>

    • Get the current best price and quantity on the order book.

      If you need access to real-time order book ticker updates, please consider using WebSocket Streams:

      <symbol>@bookTicker

      Weight: Adjusted based on the number of requested symbols:

      Parameter Symbols Provided Weight
      symbol 1 2
      omitted 4
      symbols Any 4

      Security Type: NONE

      Notes: Data Source:* Memory

      Notes:

      symbol and symbols cannot be used together.

      If no symbol is specified, returns information about all symbols currently trading on the exchange.

      Parameters

      Returns Promise<WebsocketApiResponse<TickerBookResponse>>

      Promise<WebsocketApiResponse>

    • Get aggregate trades.

      An aggregate trade (aggtrade) represents one or more individual trades.

      Trades that fill at the same time, from the same taker order, with the same price –

      those trades are collected into an aggregate trade with total quantity of the individual trades.

      If you need access to real-time trading activity, please consider using WebSocket Streams:

      <symbol>@aggTrade

      If you need historical aggregate trade data, please consider using data.binance.vision.

      Weight(IP): 4

      Security Type: NONE

      Notes: Data Source:* Database

      • If fromId is specified, return aggtrades with aggregate trade ID >= fromId. Use fromId and limit to page through all aggtrades.
      • If startTime and/or endTime are specified, aggtrades are filtered by execution time (T). fromId cannot be used together with startTime and endTime.
      • If no condition is specified, the most recent aggregate trades are returned.

      Parameters

      Returns Promise<WebsocketApiResponse<TradesAggregateResponse>>

      Promise<WebsocketApiResponse>

    • Get klines (candlestick bars) optimized for presentation.

      This request is similar to klines, having the same parameters and response. uiKlines return modified kline data, optimized for presentation of candlestick charts.

      Weight(IP): 2

      Security Type: NONE

      Notes: Data Source:* Database

      • If startTime and endTime are not sent, the most recent klines are returned.
      • Supported values for timeZone:
      • Hours and minutes (e.g. -1:00, 05:45)
      • Only hours (e.g. 0, 8, 4)
      • Accepted range is strictly [-12:00 to +14:00] inclusive
      • If timeZone provided, kline intervals are interpreted in that timezone instead of UTC.
      • Note that startTime and endTime are always interpreted in UTC, regardless of timeZone.

      Parameters

      Returns Promise<WebsocketApiResponse<SpotWebsocketAPI.UiKlinesResponse>>

      Promise<WebsocketApiResponse>