Binance Connector JS
    Preparing search index...

    TradeApi - object-oriented interface TradeApi

    Implements

    Index

    Constructors

    Methods

    • Eligibility

      • Binance Margin offers low-latency trading through a special key, available exclusively to users with VIP level 7 or higher.
      • If you are VIP level 6 or below, please contact your VIP manager for eligibility criterias.
      • All new Margin Special Key users are required to read, understand, and agree to the Margin Special Key Supplemental Product Terms at the master account level before creating a Margin Special Key.
      • Once signed at the master account level, the agreement applies to all sub-accounts. The master account and all sub-accounts (Cross Margin Classic and Portfolio Margin Pro) are authorized to create a Margin Special Key and are subject to the LiquidationLoan policy.

      For more information, please refer to FAQ.

      Supported Products:*

      • Cross Margin
      • Isolated Margin
      • Portfolio Margin Pro

      Unsupported Products:*

      • Portfolio Margin

      We support several types of API keys:

      Ed25519 (recommended) HMAC RSA

      We recommend to use Ed25519 API keys as it should provide the best performance and security out of all supported key types. We accept PKCS#8 (BEGIN PUBLIC KEY). For how to generate an RSA key pair to send API requests on Binance. Please refer to the document below FAQ .

      How to use the Margin Special Key*

      • Use the below sapi endpoint to create your margin special API Key.
      • For accessing the Cross Margin account, do not send the symbol parameter.
      • For accessing the Isolated Margin account(s), pass the relevant symbol parameter in the API Key creation request.
      • Use the generated API Key (and Secret key, if applicable) to perform margin trading and listenKey generation via Spot REST API (https://api.binance.com/api/v3/*) endpoints.

      Read REST API or WebSocket API documentation to learn how to use different API keys

      You need to enable Permits “Enable Spot & Margin Trading” option for the API Key which requests this endpoint.

      Weight(UID): 1

      Security Type: TRADE

      Response Notes:

      • Error Code Description

      • UNSUPPORTED_OPERATION : Portfolio Margin is an unsupported product, please change the account type to a supported margin product.

      • Forbidden: Cross Margin Pro accounts require additional agreements, please contact your relationship manager.

      Parameters

      Returns Promise<RestApiResponse<CreateSpecialKeyResponse>>

      TradeApi

    • Deleting your Margin Special Key alone does not exit you from the Margin Special Key framework or discharge your obligations under the Margin Special Key Supplemental Product Terms. To fully exit, you must:

      1. Delete your Margin Special Key.
      2. Ensure there are no outstanding liabilities on the account.
      3. Call the Exit Margin Special Key API endpoint.
      4. Confirm the exit status via the API response.

      Only after step 4 is completed and the exit status is confirmed by Binance will your account revert to standard liquidation logic and no longer be subject to the Margin Special Key Supplemental Product Terms.

      If apiKey is given, apiName will be ignored. If apiName is given with no apiKey, all apikeys with given apiName will be deleted.

      You need to enable Permits “Enable Spot & Margin” option for the API Key which requests this endpoint.

      Weight(UID): 1

      Security Type: TRADE

      Parameters

      Returns Promise<RestApiResponse<void>>

      TradeApi

    • Exit the Margin Special Key mode for Cross Margin Classic accounts.

      All outstanding liabilities under the Cross Margin Classic account must be fully repaid before calling this endpoint.* Deleting the Margin Special Key alone does not constitute a valid exit.

      When a user creates a Margin Special API Key, the account enters "Special Key Mode". Upon a successful request, the following actions will be performed atomically:

      1. All existing Margin Special API Keys under the Cross Margin Classic mode account will be deleted.
      2. All pre-execution margin checks (including Open-order-loss calculation) will revert to standard mode.
      3. A cooldown period (default: 24 hours) will be enforced, during which the account will not be permitted to create new Margin Special API Keys.

      For more information, please refer to FAQ.

      Preconditions:*

      The following conditions must be met; otherwise the request will be rejected:

      • Account type must be Cross Margin Classic.
      • Account must currently be in Special Key Mode. If not, the request silently succeeds.
      • Account must not be in liquidation.
      • Account must have no liability.

      You need to enable "Permits Enable Spot & Margin Trading" option for the API Key which requests this endpoint.

      Weight(UID): 10

      Security Type: TRADE

      Parameters

      Returns Promise<RestApiResponse<object>>

      TradeApi

    • Post a new OTO order for margin account:

      • 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 unfilled order count, EXCHANGE_MAX_NUM_ORDERS filter and MAX_NUM_ORDERS filter.

      Weight: 6(UID) or 1500(UID) when sideEffectType is MARGIN_BUY or AUTO_BORROW_REPAY

      Security Type: TRADE

      Notes:

      • autoRepayAtCancel is suggested to set as “FALSE” to keep liability unrepaid under high frequent new order/cancel order execution
      • 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 | | | pendingTrailingDelta is provided | pendingPrice | |

      Parameters

      Returns Promise<RestApiResponse<MarginAccountNewOtoResponse>>

      TradeApi

    • Post a new OTOCO order for margin account:

      • 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 against the unfilled order count, EXCHANGE_MAX_NUM_ORDERS filter, and MAX_NUM_ORDERS filter.

      Weight: 6(UID) or 1500(UID) when sideEffectType is MARGIN_BUY or AUTO_BORROW_REPAY

      Security Type: TRADE

      Notes:

      • autoRepayAtCancel is suggested to set as “FALSE” to keep liability unrepaid under high frequent new order/cancel order execution
      • 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 | pendingAboveStopPrice and/or pendingAboveTrailingDelta | | | pendingAboveType=STOP_LOSS_LIMIT | pendingAbovePrice, pendingAboveStopPrice and/or pendingAboveTrailingDelta, pendingAboveTimeInForce | | | pendingBelowType= LIMIT_MAKER | pendingBelowPrice | | | pendingBelowType= STOP_LOSS | pendingBelowStopPrice and/or pendingBelowTrailingDelta | | | pendingBelowType=STOP_LOSS_LIMIT | pendingBelowPrice, pendingBelowStopPrice and/or pendingBelowTrailingDelta, pendingBelowTimeInForce | | | pendingAboveTrailingDelta is provided | pendingAbovePrice | | | pendingBelowTrailingDelta is provided | pendingBelowPrice | |

      Parameters

      Returns Promise<RestApiResponse<MarginAccountNewOtocoResponse>>

      TradeApi