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

Code before:
            'ordType': type,
            // 'ordType': type, // privatePostTradeOrder: market, limit, post_only, fok, ioc, optimal_limit_ioc
            // 'ordType': type, // privatePostTradeOrderAlgo: conditional, oco, trigger, move_order_stop, iceberg, twap
            // 'sz': this.amountToPrecision (symbol, amount),
            // 'px': this.priceToPrecision (symbol, price), // limit orders only
            // 'reduceOnly': false, // MARGIN orders only
            //
            // 'triggerPx': 10, // stopPrice (trigger orders)
            // 'orderPx': 10, // Order price if -1, the order will be executed at the market price. (trigger orders)
            // 'triggerPxType': 'last', // Conditional default is last, mark or index (trigger orders)
            //
            // 'tpTriggerPx': 10, // takeProfitPrice (conditional orders)
            // 'tpTriggerPxType': 'last', // Conditional default is last, mark or index (conditional orders)
            // 'tpOrdPx': 10, // Order price for Take-Profit orders, if -1 will be executed at market price (conditional orders)
            //
            // 'slTriggerPx': 10, // stopLossPrice (conditional orders)
            // 'slTriggerPxType': 'last', // Conditional default is last, mark or index (conditional orders)
            // 'slOrdPx': 10, // Order price for Stop-Loss orders, if -1 will be executed at market price (conditional orders)
        };
        const spot = market['spot'];
        const swap = market['swap'];
        const future = market['future'];
        const contract = market['contract'];
        const stopPrice = this.safeString2 (params, 'stopPrice', 'triggerPx');
        const timeInForce = this.safeString (params, 'timeInForce', 'GTC');
        const takeProfitPrice = this.safeString2 (params, 'takeProfitPrice', 'tpTriggerPrice');
        let tpOrdPx = this.safeString (params, 'tpOrdPx');
        const tpTriggerPxType = this.safeString (params, 'tpTriggerPxType', 'last');
        const stopLossPrice = this.safeString2 (params, 'stopLossPrice', 'slTriggerPx');
        let slOrdPx = this.safeString (params, 'slOrdPx');
        const slTriggerPxType = this.safeString (params, 'slTriggerPxType', 'last');
        const clientOrderId = this.safeString2 (params, 'clOrdId', 'clientOrderId');
        const tdMode = this.safeStringLower (params, 'tdMode'); // not ommited so as to be extended into the request
        if (spot) {
            request['tdMode'] = 'cash';
        } else if (contract) {
            if (tdMode === undefined) {
                throw new ArgumentsRequired (this.id + ' params["tdMode"] is required to be either "isolated" or "cross"');
            } else if ((tdMode !== 'isolated') && (tdMode !== 'cross')) {
                throw new BadRequest (this.id + ' params["tdMode"] must be either "isolated" or "cross"');
            }
        }
        const postOnly = this.isPostOnly (type, type === 'post_only', params);
        params = this.omit (params, [ 'timeInForce', 'stopPrice', 'triggerPx', 'cloOrdId', 'clientOrderId', 'stopLossPrice', 'takeProfitPrice', 'slTriggerPx', 'tpTriggerPrice', 'tpOrdPx', 'slOrdPx', 'tpTriggerPxType', 'slTriggerPxType' ]);
        const ioc = ((timeInForce === 'IOC') || (type === 'ioc'));
        const fok = ((timeInForce === 'FOK') || (type === 'fok'));
        const trigger = ((stopPrice !== undefined) || (type === 'trigger'));
        const conditional = ((stopLossPrice !== undefined) || (takeProfitPrice !== undefined) || (type === 'conditional'));
        const marketIOC = (((type === 'market') && (ioc)) || (type === 'optimal_limit_ioc'));
        const defaultMethod = this.safeString (this.options, 'createOrder', 'privatePostTradeBatchOrders');
        let method = defaultMethod;

Review comment (suggestion):
Typo fix:
```suggestion
        const takeProfitPrice = this.safeString2 (params, 'takeProfitPrice', 'tpTriggerPx');
```

Code after:
            // 'posSide': 'long', // long, short, // required in the long/short mode, and can only be long or short (only for future or swap)
            'ordType': type,
            // 'ordType': type, // privatePostTradeOrder: market, limit, post_only, fok, ioc, optimal_limit_ioc
            // 'ordType': type, // privatePostTradeOrderAlgo: conditional, oco, trigger, move_order_stop, iceberg, twap
            'sz': this.amountToPrecision (symbol, amount),
            // 'px': this.priceToPrecision (symbol, price), // limit orders only
            // 'reduceOnly': false, // MARGIN orders only
            //
            // 'triggerPx': 10, // stopPrice (trigger orders)
            // 'orderPx': 10, // Order price if -1, the order will be executed at the market price. (trigger orders)
            // 'triggerPxType': 'last', // Conditional default is last, mark or index (trigger orders)
            //
            // 'tpTriggerPx': 10, // takeProfitPrice (conditional orders)
            // 'tpTriggerPxType': 'last', // Conditional default is last, mark or index (conditional orders)
            // 'tpOrdPx': 10, // Order price for Take-Profit orders, if -1 will be executed at market price (conditional orders)
            //
            // 'slTriggerPx': 10, // stopLossPrice (conditional orders)
            // 'slTriggerPxType': 'last', // Conditional default is last, mark or index (conditional orders)
            // 'slOrdPx': 10, // Order price for Stop-Loss orders, if -1 will be executed at market price (conditional orders)
        };
        const spot = market['spot'];
        const contract = market['contract'];
        const stopPrice = this.safeString2 (params, 'stopPrice', 'triggerPx');
        const timeInForce = this.safeString (params, 'timeInForce', 'GTC');
        const takeProfitPrice = this.safeString2 (params, 'takeProfitPrice', 'tpTriggerPx');
        const tpOrdPx = this.safeString (params, 'tpOrdPx');
        const tpTriggerPxType = this.safeString (params, 'tpTriggerPxType', 'last');
        const stopLossPrice = this.safeString2 (params, 'stopLossPrice', 'slTriggerPx');
        const slOrdPx = this.safeString (params, 'slOrdPx');
        const slTriggerPxType = this.safeString (params, 'slTriggerPxType', 'last');
        const clientOrderId = this.safeString2 (params, 'clOrdId', 'clientOrderId');
        if (spot) {
            request['tdMode'] = 'cash';
        } else if (contract) {
            const marginMode = this.safeString2 (this.options, 'defaultMarginMode', 'marginMode', 'cross');
            request['tdMode'] = this.safeStringLower (params, 'tdMode', marginMode); // not ommited so as to be extended into the request
        }
        const isMarketOrder = type === 'market';
        const postOnly = this.isPostOnly (isMarketOrder, type === 'post_only', params);
        params = this.omit (params, [ 'timeInForce', 'stopPrice', 'triggerPx', 'cloOrdId', 'clientOrderId', 'stopLossPrice', 'takeProfitPrice', 'slTriggerPx', 'tpTriggerPrice', 'tpOrdPx', 'slOrdPx', 'tpTriggerPxType', 'slTriggerPxType' ]);
        const ioc = (timeInForce === 'IOC') || (type === 'ioc');
        const fok = (timeInForce === 'FOK') || (type === 'fok');
        const trigger = (stopPrice !== undefined) || (type === 'trigger');
        const conditional = (stopLossPrice !== undefined) || (takeProfitPrice !== undefined) || (type === 'conditional');
        const marketIOC = (isMarketOrder && ioc) || (type === 'optimal_limit_ioc');
        const defaultMethod = this.safeString (this.options, 'createOrder', 'privatePostTradeBatchOrders');
        let method = defaultMethod;
        if (isMarketOrder || marketIOC) {
            request['ordType'] = 'market';
            if (spot && (side === 'buy')) {
                // spot market buy: "sz" can refer either to base currency units or to quote currency units