Futures trading

USDⓈ-M perpetuals: leverage, orders, positions and TP/SL legs.

Futures routes live under https://bot.mywellat.com/fapi/v1, /fapi/v2 and /fapi/v3, matching Binance USDⓈ-M Futures. Every route here is signed. A key bound to a Spot strategy gets 400 -2010.

In CCXT set options.defaultType = 'future' and use the perpetual symbol form BTC/USDT:USDT. Plain BTC/USDT is the spot market and routes to /api/v3.

Endpoints

MethodPathCCXTWeight
GET/fapi/v3/account (alias /fapi/v2/account)fetchBalance5
GET/fapi/v3/positionRisk (alias /fapi/v2/positionRisk)fetchPositions5
GET/fapi/v1/leverageBracketfetchLeverageTiers1
GET/fapi/v1/commissionRatefetchTradingFee20
POST/fapi/v1/leveragesetLeverage1
POST/fapi/v1/marginTypesetMarginMode1
POST/fapi/v1/ordercreateOrder (MARKET, LIMIT)1 (+1 order)
DELETE/fapi/v1/ordercancelOrder1
DELETE/fapi/v1/allOpenOrderscancelAllOrders1
GET/fapi/v1/orderfetchOrder1
GET/fapi/v1/openOrdersfetchOpenOrders1 with symbol, 40 without
GET/fapi/v1/allOrdersfetchOrders5
GET/fapi/v1/userTradesfetchMyTrades5
POST/fapi/v1/algoOrderTP / SL legs1 (+1 order)
DELETE/fapi/v1/algoOrdercancel one leg1
DELETE/fapi/v1/algoOpenOrderscancel all legs on a symbol1
GET/fapi/v1/algoOrderquery a leg1
GET/fapi/v1/openAlgoOrdersopen legs1 with symbol, 40 without
POST/fapi/v1/wellat/strategy/closecloseStrategy (fapiPrivatePostWellatStrategyClose)1

Account and positions

GET /fapi/v3/account returns the Binance futures account shape: totalWalletBalance, availableBalance, assets[] and positions[]. In demo the wallet is the strategy's virtual 1,000 USDT custodian.

GET /fapi/v3/positionRisk (optional symbol) returns one entry per position with positionAmt, entryPrice, markPrice, unRealizedProfit, liquidationPrice, leverage, marginType.

Leverage and margin type

await exchange.setLeverage(5, 'BTC/USDT:USDT');   // POST /fapi/v1/leverage  { symbol, leverage }
  • GET /fapi/v1/leverageBracket lists each pair's maximum leverage and maintenance-margin tiers. Leverage above the pair's bracket is clamped to the maximum. With no symbol it returns every pair, as on Binance, so stock CCXT fetchPositions works.
  • An open position pins the symbol's leverage; lowering it under an open position is answers 400 -4161 Leverage reduction is not supported in Isolated Margin Mode with open positions.
  • Margin is ISOLATED only. POST /fapi/v1/marginType with ISOLATED is a no-op; CROSSED answers 400 -2010 "Only ISOLATED margin is supported…".

Placing an order

POST /fapi/v1/order

ParameterRequiredNotes
symbolyese.g. BTCUSDT
sideyesBUY or SELL
typeyesMARKET or LIMIT only
quantityyesContract amount in base asset
price, timeInForceLIMITtimeInForce is GTC only
reduceOnlynotrue to only close exposure
newClientOrderIdrecommendedIdempotency key
takeProfitPricenoWellat extension. Attaches a TAKE_PROFIT_MARKET closePosition leg to this entry in the same request.
stopLossPricenoWellat extension. Attaches a STOP_MARKET closePosition leg to this entry in the same request.
leveragenoWellat extension. Applies to this entry when no position is open on the symbol.

Sending STOP_MARKET, TAKE_PROFIT_MARKET or any conditional type here answers 400 -4120: conditional orders belong to the algo-order family below, as on Binance since December 2025.

Positions are one-way (no hedge mode): a SELL against a long reduces or flips it.

quantity and price must satisfy the symbol's LOT_SIZE, PRICE_FILTER and MIN_NOTIONAL filters from exchangeInfo; a resting LIMIT entry locks its initial margin at placement. Copiers receive the same order scaled to their collateral fraction and snapped down, and a scaled order under the minimum is skipped for that copier. See Rate limits for the open-order cap and minimum-size rules.

await exchange.createOrder('BTC/USDT:USDT', 'market', 'buy', 0.01, undefined, {
  takeProfitPrice: 70000,
  stopLossPrice: 60000,
});

Take-profit and stop-loss legs

To attach legs when opening, pass takeProfitPrice / stopLossPrice as extra params on createOrder as above. To add or replace a leg on an open position, post to the algo-order route:

POST /fapi/v1/algoOrder

ParameterRequiredNotes
symbolyes
sideyesOpposite of the position
typeyesSTOP_MARKET or TAKE_PROFIT_MARKET
stopPriceyesTrigger, compared against mark price. triggerPrice is accepted as an alias.
closePositionyestrue: closes the whole position when triggered
clientAlgoIdrecommendedIdempotency key for the leg
await exchange.fapiPrivatePostAlgoOrder({
  symbol: 'BTCUSDT', side: 'SELL', type: 'STOP_MARKET',
  stopPrice: '60000', closePosition: 'true', clientAlgoId: 'btc-sl-1',
});
await exchange.fapiPrivatePostAlgoOrder({
  symbol: 'BTCUSDT', side: 'SELL', type: 'TAKE_PROFIT_MARKET',
  stopPrice: '70000', closePosition: 'true', clientAlgoId: 'btc-tp-1',
});

Do not use stock CCXT's stopLossPrice / takeProfitPrice params on their own with ccxt.binance: that client posts a STOP_MARKET order to /fapi/v1/order and gets -4120. The wellat class routes them correctly.

Manage legs with GET /fapi/v1/openAlgoOrders, GET /fapi/v1/algoOrder (algoId or clientAlgoId), DELETE /fapi/v1/algoOrder, and DELETE /fapi/v1/algoOpenOrders (symbol). When one leg fires the other is cancelled.

Cancelling and querying

Same as spot, with Binance futures field names:

  • DELETE /fapi/v1/order with symbol and orderId or origClientOrderId.
  • DELETE /fapi/v1/allOpenOrders with symbol.
  • GET /fapi/v1/order, GET /fapi/v1/openOrders, GET /fapi/v1/allOrders, GET /fapi/v1/userTrades with the usual symbol, orderId, startTime, endTime, limit parameters.

Demo futures behaviour

The demo simulator is faithful enough to build a track record on:

  • Isolated margin and leverage per symbol, as you set them.
  • MARKET fills cross the spread (taker 0.05%); LIMIT fills at the limit price (maker 0.02%).
  • TP / SL legs trigger on mark price.
  • Unrealised and realised PnL, funding at Binance's published rate each settlement, and liquidation at the bracket's maintenance-margin price.

Closing the strategy

POST /fapi/v1/wellat/strategy/close (signed, no parameters beyond timestamp).

Cancels resting orders and legs, closes every position at market, and closes the strategy for the trader and every copier. It cannot be undone; create a new strategy to trade again.

await exchange.closeStrategy();                        // @wellat/ccxt
await exchange.request('wellat/strategy/close', 'fapiPrivate', 'POST'); // stock ccxt.binance

Closing an already-closed strategy answers 400 -2010.


Did this page help you?