Repository: ccxt/ccxt
File: js/okx.js (JavaScript)

Code before:
            }
        }
        if (postOnly) {
            method = defaultMethod;
            request['ordType'] = 'post_only';
        } else if ((ioc) && (!marketIOC)) {
            method = defaultMethod;
            request['ordType'] = 'ioc';
        } else if (fok) {
            method = defaultMethod;
            request['ordType'] = 'fok';
        } else if (trigger) {
            method = 'privatePostTradeOrderAlgo';
            request['ordType'] = 'trigger';
            request['triggerPx'] = this.priceToPrecision (symbol, stopPrice);
            if (type === 'market') {
                price = -1;
            }
            request['orderPx'] = this.priceToPrecision (symbol, price);
        } else if (conditional) {
            method = 'privatePostTradeOrderAlgo';
            request['ordType'] = 'conditional';
            const twoWayCondition = ((takeProfitPrice !== undefined) && (stopLossPrice !== undefined));
            if (type !== 'market') {
                if ((twoWayCondition) && ((!slOrdPx) || (!tpOrdPx))) {
                    throw new InvalidOrder (this.id + ' createOrder() will cannot use the same price for two-way conditional orders to be created, please supply tpOrdPx and slOrdPx params');
                }
            }
            // if TP and SL are sent together
            // as ordType 'conditional' only stop-loss order will be applied
            if (twoWayCondition) {
                request['ordType'] = 'oco';
            }
            if (takeProfitPrice !== undefined) {
                request['tpTriggerPx'] = this.priceToPrecision (symbol, takeProfitPrice);
                tpOrdPx = (tpOrdPx !== undefined) ? tpOrdPx : price;
                request['tpOrdPx'] = (type === 'market') ? '-1' : this.priceToPrecision (symbol, tpOrdPx);
                request['tpTriggerPxType'] = tpTriggerPxType;
            }
            if (stopLossPrice !== undefined) {
                request['slTriggerPx'] = this.priceToPrecision (symbol, stopLossPrice);
                slOrdPx = (slOrdPx !== undefined) ? slOrdPx : price;
                request['slOrdPx'] = (type === 'market') ? '-1' : this.priceToPrecision (symbol, slOrdPx);
                request['slTriggerPxType'] = slTriggerPxType;
            }
        }
        if ((type === 'oco') || (type === 'move_order_stop') || (type === 'iceberg') || (type === 'twap')) {
            method = 'privatePostTradeOrderAlgo';
        }
        if (clientOrderId === undefined) {
            const brokerId = this.safeString (this.options, 'brokerId');

Review comment (suggestion):
Typo fix:
```suggestion
                    throw new InvalidOrder (this.id + ' createOrder() cannot use the same price for two-way conditional orders to be created, please supply takeProfitPrice and stopLossPrice params or tpOrdPx and slOrdPx params');
```

Code after:
            request['ordType'] = 'trigger';
            request['triggerPx'] = this.priceToPrecision (symbol, stopPrice);
            request['orderPx'] = isMarketOrder ? '-1' : this.priceToPrecision (symbol, price);
        } else if (conditional) {
            method = 'privatePostTradeOrderAlgo';
            request['ordType'] = 'conditional';
            const twoWayCondition = ((takeProfitPrice !== undefined) && (stopLossPrice !== undefined));
            // if TP and SL are sent together
            // as ordType 'conditional' only stop-loss order will be applied
            if (twoWayCondition) {
                request['ordType'] = 'oco';
            }
            if (takeProfitPrice !== undefined) {
                request['tpTriggerPx'] = this.priceToPrecision (symbol, takeProfitPrice);
                request['tpOrdPx'] = (tpOrdPx === undefined) ? '-1' : this.priceToPrecision (symbol, tpOrdPx);
                request['tpTriggerPxType'] = tpTriggerPxType;
            }
            if (stopLossPrice !== undefined) {
                request['slTriggerPx'] = this.priceToPrecision (symbol, stopLossPrice);
                request['slOrdPx'] = (slOrdPx === undefined) ? '-1' : this.priceToPrecision (symbol, slOrdPx);
                request['slTriggerPxType'] = slTriggerPxType;
            }
        }
        if ((type === 'oco') || (type === 'move_order_stop') || (type === 'iceberg') || (type === 'twap')) {
            method = 'privatePostTradeOrderAlgo';
        }
        if (clientOrderId === undefined) {
            const brokerId = this.safeString (this.options, 'brokerId');
            if (brokerId !== undefined) {
                request['clOrdId'] = brokerId + this.uuid16 ();
            }
        } else {
            request['clOrdId'] = clientOrderId;
            params = this.omit (params, [ 'clOrdId', 'clientOrderId' ]);
        }
        let extendedRequest = undefined;
        if ((method === 'privatePostTradeOrder') || (method === 'privatePostTradeOrderAlgo')) {
            extendedRequest = this.extend (request, params);
        } else if (method === 'privatePostTradeBatchOrders') {
            // keep the request body the same
            // submit a single order in an array to the batch order endpoint
            // because it has a lower ratelimit
            extendedRequest = [ this.extend (request, params) ];
        } else {
            throw new ExchangeError (this.id + ' createOrder() this.options["createOrder"] must be either privatePostTradeBatchOrders or privatePostTradeOrder');
        }
        const response = await this[method] (extendedRequest);
        const data = this.safeValue (response, 'data', []);
        const first = this.safeValue (data, 0);
        const order = this.parseOrder (first, market);
        return this.extend (order, {