MCPcopy Create free account
hub / github.com/ccxt/node-binance-api / futuresOrder

Method futuresOrder

src/node-binance-api.ts:1213–1257  ·  view source on GitHub ↗

* @see https://developers.binance.com/docs/derivatives/usds-margined-futures/trade/rest-api/New-Order * @see https://developers.binance.com/docs/derivatives/usds-margined-futures/trade/rest-api/New-Algo-Order * @param type * @param side * @param symbol symbol if the market *

(type: OrderType, side: string, symbol: string, quantity: number, price?: number, params: Dict = {})

Source from the content-addressed store, hash-verified

1211 * @returns
1212 */
1213 async futuresOrder(type: OrderType, side: string, symbol: string, quantity: number, price?: number, params: Dict = {}): Promise<FuturesOrder> {
1214 params.symbol = symbol;
1215 params.side = side;
1216 params.type = type;
1217 if (quantity) params.quantity = quantity;
1218 // if in the binance futures setting Hedged mode is active, positionSide parameter is mandatory
1219 if (!params.positionSide && this.Options.hedgeMode) {
1220 params.positionSide = side === 'BUY' ? 'LONG' : 'SHORT';
1221 }
1222 // LIMIT STOP MARKET STOP_MARKET TAKE_PROFIT TAKE_PROFIT_MARKET
1223 // reduceOnly stopPrice
1224 if (price) {
1225 params.price = price;
1226 }
1227 if (!params.timeInForce && (params.type.includes('LIMIT') || params.type === 'STOP' || params.type === 'TAKE_PROFIT')) {
1228 params.timeInForce = 'GTX'; // Post only by default. Use GTC for limit orders.
1229 }
1230
1231 if (!params.newClientOrderId) {
1232 params.newClientOrderId = this.CONTRACT_PREFIX + this.uuid22();
1233 }
1234 // check if it is algoOrder
1235 const conditionalTypes = [
1236 'STOP',
1237 'STOP_MARKET',
1238 'TAKE_PROFIT',
1239 'TAKE_PROFIT_MARKET',
1240 'TRAILING_STOP_MARKET',
1241 ];
1242 const typeUpperCase = type.toUpperCase();
1243 if (typeUpperCase && conditionalTypes.includes(typeUpperCase)) {
1244 const algoPayload = { ...params };
1245 if (!algoPayload.clientAlgoId) {
1246 algoPayload.clientAlgoId = this.CONTRACT_PREFIX + this.uuid22();
1247 }
1248 delete algoPayload.newClientOrderId;
1249 algoPayload.algoType = 'CONDITIONAL';
1250 if (algoPayload.stopPrice && !algoPayload.triggerPrice) {
1251 algoPayload.triggerPrice = algoPayload.stopPrice;
1252 delete algoPayload.stopPrice;
1253 }
1254 return await this.privateFuturesRequest('v1/algoOrder', algoPayload, 'POST');
1255 }
1256 return await this.privateFuturesRequest('v1/order', params, 'POST');
1257 }
1258
1259 // Futures internal functions
1260 /**

Callers 8

futuresBuyMethod · 0.95
futuresSellMethod · 0.95
futuresMarketBuyMethod · 0.95
futuresLimitOrderMethod · 0.95
futuresMarketSellMethod · 0.95
static-tests.mjsFile · 0.80

Calls 2

uuid22Method · 0.95
privateFuturesRequestMethod · 0.95

Tested by

no test coverage detected