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.
binance instead of hand-written HTTP request plumbing.Binance/Rest/Futures/rest-future-bracket-order.ts.USDMClient.getMarkPrice().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); }})(); We use essential cookies and optional analytics. Read the Privacy Policy.
Essential cookies stay on. Toggle analytics if you want to share anonymous usage insights. You can revisit this anytime via Cookie Settings in the footer.