Binance Futures JavaScript SDK example: rest-future-bracket-order.ts

Binance Futures REST future bracket order JavaScript example for the Siebly Binance SDK, covering exchange REST API and WebSocket integration, setup, and production SDK docs.

We use environment variables in our examples for API keys. It is your responsibility to manage and secure your keys appropriately.

examples/Binance/Rest/Futures/rest-future-bracket-order.ts

What this example covers

  • Binance REST API JavaScript example.
  • Uses the Siebly Binance SDK package binance instead of hand-written HTTP request plumbing.
  • Source path: Binance/Rest/Futures/rest-future-bracket-order.ts.
  • Example category: Futures.
  • Imports SDK symbols including USDMClient.
  • Calls SDK methods such as getMarkPrice().

How to use this example

  • Start here for the specific request or stream pattern, then check the matching SDK guide for install, credentials, and operational notes.
  • Open the repository source when you need the latest committed version: GitHub source file.
import { NewFuturesOrderParams, USDMClient } from 'binance'; const key = process.env.API_KEY_COM || 'APIKEY';const secret = process.env.API_SECRET_COM || 'APISECRET'; const client = new USDMClient({  api_key: key,  api_secret: secret,  beautifyResponses: true,}); (async () => {  try {    // TODO: check balance and do other validations     const assetPrices = await client.getMarkPrice({      symbol: 'ETHUSDT',    });    const markPrice: number = Number(assetPrices.markPrice);    const stopLossPrice = Number((markPrice * 99.9) / 100).toFixed(2);    const takeProfitPrice = Number((markPrice * 100.1) / 100).toFixed(2);     // create three orders    // 1. entry order (GTC),    // 2. take profit order (GTE_GTC),    // 3. stop loss order (GTE_GTC)     const entryOrder: NewFuturesOrderParams<string> = {      positionSide: 'BOTH',      quantity: '0.01',      reduceOnly: 'false',      side: 'BUY',      symbol: 'ETHUSDT',      type: 'MARKET',    };     const takeProfitOrder: NewFuturesOrderParams<string> = {      positionSide: 'BOTH',      priceProtect: 'TRUE',      quantity: '0.01',      side: 'SELL',      stopPrice: takeProfitPrice,      symbol: 'ETHUSDT',      timeInForce: 'GTE_GTC',      type: 'TAKE_PROFIT_MARKET',      workingType: 'MARK_PRICE',      closePosition: 'true',    };     const stopLossOrder: NewFuturesOrderParams<string> = {      positionSide: 'BOTH',      priceProtect: 'TRUE',      quantity: '0.01',      side: 'SELL',      stopPrice: stopLossPrice,      symbol: 'ETHUSDT',      timeInForce: 'GTE_GTC',      type: 'STOP_MARKET',      workingType: 'MARK_PRICE',      closePosition: 'true',    };     const openedOrder = await client      .submitMultipleOrders([entryOrder, takeProfitOrder, stopLossOrder])      .catch((e) => console.log(e?.body || e));    console.log(openedOrder);  } catch (e) {    console.log(e);  }})(); 

Subscribe on Substack

Complete the Substack form below to join our newsletter. Substack handles all subscriber data directly.