(symbol: string, type: OrderType, side: OrderSide, amount: number, price: Num = undefined, params = {})
| 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) { |
no test coverage detected