(symbol: string, type: OrderType, side: OrderSide, amount: number, price: Num = undefined, params = {})
| 3014 | } |
| 3015 | |
| 3016 | createOrderRequest (symbol: string, type: OrderType, side: OrderSide, amount: number, price: Num = undefined, params = {}) { |
| 3017 | /** |
| 3018 | * @method |
| 3019 | * @ignore |
| 3020 | * @name bingx#createOrderRequest |
| 3021 | * @description helper function to build request |
| 3022 | * @param {string} symbol unified symbol of the market to create an order in |
| 3023 | * @param {string} type 'market' or 'limit' |
| 3024 | * @param {string} side 'buy' or 'sell' |
| 3025 | * @param {float} amount how much you want to trade in units of the base currency |
| 3026 | * @param {float} [price] the price at which the order is to be fulfilled, in units of the quote currency, ignored in market orders |
| 3027 | * @param {object} [params] extra parameters specific to the exchange API endpoint |
| 3028 | * @returns {object} request to be sent to the exchange |
| 3029 | */ |
| 3030 | const market = this.market (symbol); |
| 3031 | let postOnly: Bool = undefined; |
| 3032 | let marketType: Str = undefined; |
| 3033 | [ marketType, params ] = this.handleMarketTypeAndParams ('createOrder', market, params); |
| 3034 | type = type.toUpperCase (); |
| 3035 | const request: Dict = { |
| 3036 | 'symbol': market['id'], |
| 3037 | 'type': type, |
| 3038 | 'side': (side as string).toUpperCase (), |
| 3039 | }; |
| 3040 | const isMarketOrder = type === 'MARKET'; |
| 3041 | const isSpot = marketType === 'spot'; |
| 3042 | const isTwapOrder = type === 'TWAP'; |
| 3043 | if (isTwapOrder && isSpot) { |
| 3044 | throw new BadSymbol (this.id + ' createOrder() twap order supports swap contracts only'); |
| 3045 | } |
| 3046 | const stopLossPrice = this.safeString (params, 'stopLossPrice'); |
| 3047 | const takeProfitPrice = this.safeString (params, 'takeProfitPrice'); |
| 3048 | const triggerPrice = this.safeString2 (params, 'stopPrice', 'triggerPrice'); |
| 3049 | const isTriggerOrder = triggerPrice !== undefined; |
| 3050 | const isStopLossPriceOrder = stopLossPrice !== undefined; |
| 3051 | const isTakeProfitPriceOrder = takeProfitPrice !== undefined; |
| 3052 | const exchangeClientOrderId = isSpot ? 'newClientOrderId' : 'clientOrderID'; |
| 3053 | const clientOrderId = this.safeString2 (params, exchangeClientOrderId, 'clientOrderId'); |
| 3054 | if (clientOrderId !== undefined) { |
| 3055 | request[exchangeClientOrderId] = clientOrderId; |
| 3056 | } |
| 3057 | const timeInForce = this.safeStringUpper (params, 'timeInForce'); |
| 3058 | [ postOnly, params ] = this.handlePostOnly (isMarketOrder, timeInForce === 'PostOnly', params); |
| 3059 | if (postOnly || (timeInForce === 'PostOnly')) { |
| 3060 | request['timeInForce'] = 'PostOnly'; |
| 3061 | } else if (timeInForce === 'IOC') { |
| 3062 | request['timeInForce'] = 'IOC'; |
| 3063 | } else if (timeInForce === 'GTC') { |
| 3064 | request['timeInForce'] = 'GTC'; |
| 3065 | } |
| 3066 | if (isSpot) { |
| 3067 | const cost = this.safeString2 (params, 'cost', 'quoteOrderQty'); |
| 3068 | params = this.omit (params, 'cost'); |
| 3069 | if (cost !== undefined) { |
| 3070 | request['quoteOrderQty'] = this.parseToNumeric (this.costToPrecision (symbol, cost)); |
| 3071 | } else { |
| 3072 | if (isMarketOrder && (price !== undefined)) { |
| 3073 | // keep the legacy behavior, to avoid breaking the old spot-market-buying code |
no test coverage detected