Binance Connector JS
    Preparing search index...
    Index

    Constructors

    Methods

    adjustCrossMarginMaxLeverage closeUserDataStream createSpecialKey crossMarginCollateralRatio deleteSpecialKey disableIsolatedMarginAccount editIpForSpecialKey enableIsolatedMarginAccount exitSpecialKeyMode getAllCrossMarginPairs getAllIsolatedMarginSymbol getAllMarginAssets getBnbBurnStatus getCrossMarginTransferHistory getDelistSchedule getForceLiquidationRecord getFutureHourlyInterestRate getInterestHistory getLimitPricePairs getListSchedule getMarginAssetRiskBasedLiquidationRatio getMarginRestrictedAssets getSmallLiabilityExchangeCoinList getSmallLiabilityExchangeHistory getSummaryOfMarginAccount keepaliveUserDataStream liquidationLoanRepay marginAccountBorrowRepay marginAccountCancelAllOpenOrdersOnASymbol marginAccountCancelOco marginAccountCancelOrder marginAccountNewOco marginAccountNewOrder marginAccountNewOto marginAccountNewOtoco marginManualLiquidation queryBorrowRepayRecordsInMarginAccount queryCrossIsolatedMarginCapitalFlow queryCrossMarginAccountDetails queryCrossMarginFeeData queryCurrentMarginOrderCountUsage queryEnabledIsolatedMarginAccountLimit queryIsolatedMarginAccountInfo queryIsolatedMarginFeeData queryIsolatedMarginTierData queryLiabilityCoinLeverageBracketInCrossMarginProMode queryLiquidationLoan queryLiquidationLoanRepayHistory queryMarginAccountsAllOco queryMarginAccountsAllOrders queryMarginAccountsOco queryMarginAccountsOpenOco queryMarginAccountsOpenOrders queryMarginAccountsOrder queryMarginAccountsTradeList queryMarginAvailableInventory queryMarginInterestRateHistory queryMarginPriceindex queryMaxBorrow queryMaxTransferOutAmount queryPreventedMatches querySpecialKey querySpecialKeyList sendRequest sendSignedRequest smallLiabilityExchange startUserDataStream

    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>>

    • 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>>

    • 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>>

    • Get Interest History

      Weight(IP): 1

      Security Type: USER_DATA

      Notes:

      • Response in descending order

      • If isolatedSymbol is not sent, crossed margin data will be returned

      • The max interval between startTime and endTime is 30 days. It is a MUST to ensure data correctness.

      • If startTimeand endTime not sent, return records of the last 7 days by default.

      • If startTime is sent and endTime is not sent, return records of [max(startTime, now-30d), now].

      • If startTime is not sent and endTime is sent, return records of [endTime-7, endTime]

      • type in response has 4 enums:

      • PERIODIC interest charged per hour

      • ON_BORROW first interest charged on borrow

      • PERIODIC_CONVERTED interest charged per hour converted into BNB

      • ON_BORROW_CONVERTED first interest charged on borrow converted into BNB

      • PORTFOLIO interest charged daily on the portfolio margin negative balance

      Parameters

      Returns Promise<RestApiResponse<GetInterestHistoryResponse>>

    • Query trading pairs with restriction on limit price range.

      In margin trading, you can place orders with limit price. Limit price should be within (-15%, 15%) of current index price for a list of margin trading pairs. This rule only impacts limit sell orders with limit price that is lower than current index price and limit buy orders with limit price that is higher than current index price.

      • Buy order: Your order will be rejected with an error message notification if the limit price is 15% above the index price.

      • Sell order: Your order will be rejected with an error message notification if the limit price is 15% below the index price.

      Please review the limit price order placing strategy, backtest and calibrate the planned order size with the trading volume and order book depth to prevent trading loss.

      Weight(IP): 1

      Security Type: MARKET_DATA

      Returns Promise<RestApiResponse<GetLimitPricePairsResponse>>

    • 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>>

    • 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>>

    • Generic function to send a request.

      Type Parameters

      • T

      Parameters

      • endpoint: string

        The API endpoint to call.

      • method: "GET" | "POST" | "DELETE" | "PUT" | "PATCH"

        HTTP method to use (GET, POST, DELETE, etc.).

      • queryParams: Record<string, unknown> = {}

        Query parameters for the request.

      • bodyParams: Record<string, unknown> = {}

        Body parameters for the request.

      Returns Promise<RestApiResponse<T>>

      A promise resolving to the response data object.

    • Generic function to send a signed request.

      Type Parameters

      • T

      Parameters

      • endpoint: string

        The API endpoint to call.

      • method: "GET" | "POST" | "DELETE" | "PUT" | "PATCH"

        HTTP method to use (GET, POST, DELETE, etc.).

      • queryParams: Record<string, unknown> = {}

        Query parameters for the request.

      • bodyParams: Record<string, unknown> = {}

        Body parameters for the request.

      Returns Promise<RestApiResponse<T>>

      A promise resolving to the response data object.