MCPcopy Create free account
hub / github.com/ccxt/ccxt / createOrderRequest

Method createOrderRequest

ts/src/modetrade.ts:1458–1557  ·  view source on GitHub ↗
(symbol: string, type: OrderType, side: OrderSide, amount: number, price: Num = undefined, params = {})

Source from the content-addressed store, hash-verified

1456 }
1457
1458 createOrderRequest (symbol: string, type: OrderType, side: OrderSide, amount: number, price: Num = undefined, params = {}) {
1459 /**
1460 * @method
1461 * @ignore
1462 * @name modetrade#createOrderRequest
1463 * @description helper function to build the request
1464 * @param {string} symbol unified symbol of the market to create an order in
1465 * @param {string} type 'market' or 'limit'
1466 * @param {string} side 'buy' or 'sell'
1467 * @param {float} amount how much you want to trade in units of the base currency
1468 * @param {float} [price] the price that the order is to be fulfilled, in units of the quote currency, ignored in market orders
1469 * @param {object} [params] extra parameters specific to the exchange API endpoint
1470 * @returns {object} request to be sent to the exchange
1471 */
1472 const reduceOnly = this.safeBool2 (params, 'reduceOnly', 'reduce_only');
1473 const orderType = type.toUpperCase ();
1474 const market = this.market (symbol);
1475 const orderSide = side.toUpperCase ();
1476 const request: Dict = {
1477 'symbol': market['id'],
1478 'side': orderSide,
1479 };
1480 const triggerPrice = this.safeString2 (params, 'triggerPrice', 'stopPrice');
1481 const stopLoss = this.safeValue (params, 'stopLoss');
1482 const takeProfit = this.safeValue (params, 'takeProfit');
1483 const hasStopLoss = stopLoss !== undefined;
1484 const hasTakeProfit = takeProfit !== undefined;
1485 const algoType = this.safeString (params, 'algoType');
1486 const isConditional = triggerPrice !== undefined || hasStopLoss || hasTakeProfit || (this.safeValue (params, 'childOrders') !== undefined);
1487 const isMarket = orderType === 'MARKET';
1488 const timeInForce = this.safeStringLower (params, 'timeInForce');
1489 const postOnly = this.isPostOnly (isMarket, undefined, params);
1490 const orderQtyKey = isConditional ? 'quantity' : 'order_quantity';
1491 const priceKey = isConditional ? 'price' : 'order_price';
1492 const typeKey = isConditional ? 'type' : 'order_type';
1493 request[typeKey] = orderType; // LIMIT/MARKET/IOC/FOK/POST_ONLY/ASK/BID
1494 if (!isConditional) {
1495 if (postOnly) {
1496 request['order_type'] = 'POST_ONLY';
1497 } else if (timeInForce === 'fok') {
1498 request['order_type'] = 'FOK';
1499 } else if (timeInForce === 'ioc') {
1500 request['order_type'] = 'IOC';
1501 }
1502 }
1503 if (reduceOnly) {
1504 request['reduce_only'] = reduceOnly;
1505 }
1506 if (price !== undefined) {
1507 request[priceKey] = this.priceToPrecision (symbol, price);
1508 }
1509 if (isMarket && !isConditional) {
1510 request[orderQtyKey] = this.amountToPrecision (symbol, amount);
1511 } else if (algoType !== 'POSITIONAL_TP_SL') {
1512 request[orderQtyKey] = this.amountToPrecision (symbol, amount);
1513 }
1514 const clientOrderId = this.safeStringN (params, [ 'clOrdID', 'clientOrderId', 'client_order_id' ]);
1515 if (clientOrderId !== undefined) {

Callers 2

createOrderMethod · 0.95
createOrdersMethod · 0.95

Calls 14

pushMethod · 0.80
safeBool2Method · 0.45
marketMethod · 0.45
safeString2Method · 0.45
safeValueMethod · 0.45
safeStringMethod · 0.45
safeStringLowerMethod · 0.45
isPostOnlyMethod · 0.45
priceToPrecisionMethod · 0.45
amountToPrecisionMethod · 0.45
safeStringNMethod · 0.45
safeNumber2Method · 0.45

Tested by

no test coverage detected