ccxt 4.1.26 → 4.1.27

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/js/src/bitopro.js CHANGED
@@ -214,6 +214,7 @@ export default class bitopro extends Exchange {
214
214
  * @method
215
215
  * @name bitopro#fetchCurrencies
216
216
  * @description fetches all available currencies on an exchange
217
+ * @see https://github.com/bitoex/bitopro-offical-api-docs/blob/master/api/v3/public/get_currency_info.md
217
218
  * @param {object} [params] extra parameters specific to the bitopro api endpoint
218
219
  * @returns {object} an associative dictionary of currencies
219
220
  */
@@ -276,6 +277,7 @@ export default class bitopro extends Exchange {
276
277
  * @method
277
278
  * @name bitopro#fetchMarkets
278
279
  * @description retrieves data on all markets for bitopro
280
+ * @see https://github.com/bitoex/bitopro-offical-api-docs/blob/master/api/v3/public/get_trading_pair_info.md
279
281
  * @param {object} [params] extra parameters specific to the exchange api endpoint
280
282
  * @returns {object[]} an array of objects representing market data
281
283
  */
@@ -410,6 +412,7 @@ export default class bitopro extends Exchange {
410
412
  * @method
411
413
  * @name bitopro#fetchTicker
412
414
  * @description fetches a price ticker, a statistical calculation with the information calculated over the past 24 hours for a specific market
415
+ * @see https://github.com/bitoex/bitopro-offical-api-docs/blob/master/api/v3/public/get_ticker_data.md
413
416
  * @param {string} symbol unified symbol of the market to fetch the ticker for
414
417
  * @param {object} [params] extra parameters specific to the bitopro api endpoint
415
418
  * @returns {object} a [ticker structure]{@link https://github.com/ccxt/ccxt/wiki/Manual#ticker-structure}
@@ -441,6 +444,7 @@ export default class bitopro extends Exchange {
441
444
  * @method
442
445
  * @name bitopro#fetchTickers
443
446
  * @description fetches price tickers for multiple markets, statistical calculations with the information calculated over the past 24 hours each market
447
+ * @see https://github.com/bitoex/bitopro-offical-api-docs/blob/master/api/v3/public/get_ticker_data.md
444
448
  * @param {string[]|undefined} symbols unified symbols of the markets to fetch the ticker for, all market tickers are returned if not assigned
445
449
  * @param {object} [params] extra parameters specific to the bitopro api endpoint
446
450
  * @returns {object} a dictionary of [ticker structures]{@link https://github.com/ccxt/ccxt/wiki/Manual#ticker-structure}
@@ -470,6 +474,7 @@ export default class bitopro extends Exchange {
470
474
  * @method
471
475
  * @name bitopro#fetchOrderBook
472
476
  * @description fetches information on open orders with bid (buy) and ask (sell) prices, volumes and other data
477
+ * @see https://github.com/bitoex/bitopro-offical-api-docs/blob/master/api/v3/public/get_orderbook_data.md
473
478
  * @param {string} symbol unified symbol of the market to fetch the order book for
474
479
  * @param {int} [limit] the maximum amount of order book entries to return
475
480
  * @param {object} [params] extra parameters specific to the bitopro api endpoint
@@ -600,6 +605,7 @@ export default class bitopro extends Exchange {
600
605
  * @method
601
606
  * @name bitopro#fetchTrades
602
607
  * @description get the list of most recent trades for a particular symbol
608
+ * @see https://github.com/bitoex/bitopro-offical-api-docs/blob/master/api/v3/public/get_trades_data.md
603
609
  * @param {string} symbol unified symbol of the market to fetch trades for
604
610
  * @param {int} [since] timestamp in ms of the earliest trade to fetch
605
611
  * @param {int} [limit] the maximum amount of trades to fetch
@@ -632,6 +638,7 @@ export default class bitopro extends Exchange {
632
638
  * @method
633
639
  * @name bitopro#fetchTradingFees
634
640
  * @description fetch the trading fees for multiple markets
641
+ * @see https://github.com/bitoex/bitopro-offical-api-docs/blob/master/api/v3/public/get_limitations_and_fees.md
635
642
  * @param {object} [params] extra parameters specific to the bitopro api endpoint
636
643
  * @returns {object} a dictionary of [fee structures]{@link https://github.com/ccxt/ccxt/wiki/Manual#fee-structure} indexed by market symbols
637
644
  */
@@ -731,6 +738,7 @@ export default class bitopro extends Exchange {
731
738
  * @method
732
739
  * @name bitopro#fetchOHLCV
733
740
  * @description fetches historical candlestick data containing the open, high, low, and close price, and the volume of a market
741
+ * @see https://github.com/bitoex/bitopro-offical-api-docs/blob/master/api/v3/public/get_ohlc_data.md
734
742
  * @param {string} symbol unified symbol of the market to fetch OHLCV data for
735
743
  * @param {string} timeframe the length of time each candle represents
736
744
  * @param {int} [since] timestamp in ms of the earliest candle to fetch
@@ -853,6 +861,7 @@ export default class bitopro extends Exchange {
853
861
  * @method
854
862
  * @name bitopro#fetchBalance
855
863
  * @description query for balance and get the amount of funds available for trading or funds locked in orders
864
+ * @see https://github.com/bitoex/bitopro-offical-api-docs/blob/master/api/v3/private/get_account_balance.md
856
865
  * @param {object} [params] extra parameters specific to the bitopro api endpoint
857
866
  * @returns {object} a [balance structure]{@link https://github.com/ccxt/ccxt/wiki/Manual#balance-structure}
858
867
  */
@@ -980,6 +989,7 @@ export default class bitopro extends Exchange {
980
989
  * @method
981
990
  * @name bitopro#createOrder
982
991
  * @description create a trade order
992
+ * @see https://github.com/bitoex/bitopro-offical-api-docs/blob/master/api/v3/private/create_an_order.md
983
993
  * @param {string} symbol unified symbol of the market to create an order in
984
994
  * @param {string} type 'market' or 'limit'
985
995
  * @param {string} side 'buy' or 'sell'
@@ -1041,6 +1051,7 @@ export default class bitopro extends Exchange {
1041
1051
  * @method
1042
1052
  * @name bitopro#cancelOrder
1043
1053
  * @description cancels an open order
1054
+ * @see https://github.com/bitoex/bitopro-offical-api-docs/blob/master/api/v3/private/cancel_an_order.md
1044
1055
  * @param {string} id order id
1045
1056
  * @param {string} symbol unified symbol of the market the order was made in
1046
1057
  * @param {object} [params] extra parameters specific to the bitopro api endpoint
@@ -1072,6 +1083,7 @@ export default class bitopro extends Exchange {
1072
1083
  * @method
1073
1084
  * @name bitopro#cancelOrders
1074
1085
  * @description cancel multiple orders
1086
+ * @see https://github.com/bitoex/bitopro-offical-api-docs/blob/master/api/v3/private/cancel_batch_orders.md
1075
1087
  * @param {string[]} ids order ids
1076
1088
  * @param {string} symbol unified market symbol
1077
1089
  * @param {object} [params] extra parameters specific to the bitopro api endpoint
@@ -1103,6 +1115,7 @@ export default class bitopro extends Exchange {
1103
1115
  * @method
1104
1116
  * @name bitopro#cancelAllOrders
1105
1117
  * @description cancel all open orders
1118
+ * @see https://github.com/bitoex/bitopro-offical-api-docs/blob/master/api/v3/private/cancel_all_orders.md
1106
1119
  * @param {string} symbol unified market symbol, only orders in the market of this symbol are cancelled when symbol is not undefined
1107
1120
  * @param {object} [params] extra parameters specific to the bitopro api endpoint
1108
1121
  * @returns {object[]} a list of [order structures]{@link https://github.com/ccxt/ccxt/wiki/Manual#order-structure}
@@ -1137,6 +1150,7 @@ export default class bitopro extends Exchange {
1137
1150
  * @method
1138
1151
  * @name bitopro#fetchOrder
1139
1152
  * @description fetches information on an order made by the user
1153
+ * @see https://github.com/bitoex/bitopro-offical-api-docs/blob/master/api/v3/private/get_an_order_data.md
1140
1154
  * @param {string} symbol unified symbol of the market the order was made in
1141
1155
  * @param {object} [params] extra parameters specific to the bitopro api endpoint
1142
1156
  * @returns {object} An [order structure]{@link https://github.com/ccxt/ccxt/wiki/Manual#order-structure}
@@ -1181,6 +1195,7 @@ export default class bitopro extends Exchange {
1181
1195
  * @method
1182
1196
  * @name bitopro#fetchOrders
1183
1197
  * @description fetches information on multiple orders made by the user
1198
+ * @see https://github.com/bitoex/bitopro-offical-api-docs/blob/master/api/v3/private/get_orders_data.md
1184
1199
  * @param {string} symbol unified market symbol of the market orders were made in
1185
1200
  * @param {int} [since] the earliest time in ms to fetch orders for
1186
1201
  * @param {int} [limit] the maximum number of orde structures to retrieve
@@ -1249,6 +1264,7 @@ export default class bitopro extends Exchange {
1249
1264
  * @method
1250
1265
  * @name bitopro#fetchClosedOrders
1251
1266
  * @description fetches information on multiple closed orders made by the user
1267
+ * @see https://github.com/bitoex/bitopro-offical-api-docs/blob/master/api/v3/private/get_orders_data.md
1252
1268
  * @param {string} symbol unified market symbol of the market orders were made in
1253
1269
  * @param {int} [since] the earliest time in ms to fetch orders for
1254
1270
  * @param {int} [limit] the maximum number of orde structures to retrieve
@@ -1265,6 +1281,7 @@ export default class bitopro extends Exchange {
1265
1281
  * @method
1266
1282
  * @name bitopro#fetchMyTrades
1267
1283
  * @description fetch all trades made by the user
1284
+ * @see https://github.com/bitoex/bitopro-offical-api-docs/blob/master/api/v3/private/get_trades_data.md
1268
1285
  * @param {string} symbol unified market symbol
1269
1286
  * @param {int} [since] the earliest time in ms to fetch trades for
1270
1287
  * @param {int} [limit] the maximum number of trades structures to retrieve
@@ -1402,6 +1419,7 @@ export default class bitopro extends Exchange {
1402
1419
  * @method
1403
1420
  * @name bitopro#fetchDeposits
1404
1421
  * @description fetch all deposits made to an account
1422
+ * @see https://github.com/bitoex/bitopro-offical-api-docs/blob/master/api/v3/private/get_deposit_invoices_data.md
1405
1423
  * @param {string} code unified currency code
1406
1424
  * @param {int} [since] the earliest time in ms to fetch deposits for
1407
1425
  * @param {int} [limit] the maximum number of deposits structures to retrieve
@@ -1453,6 +1471,7 @@ export default class bitopro extends Exchange {
1453
1471
  * @method
1454
1472
  * @name bitopro#fetchWithdrawals
1455
1473
  * @description fetch all withdrawals made from an account
1474
+ * @see https://github.com/bitoex/bitopro-offical-api-docs/blob/master/api/v3/private/get_withdraw_invoices_data.md
1456
1475
  * @param {string} code unified currency code
1457
1476
  * @param {int} [since] the earliest time in ms to fetch withdrawals for
1458
1477
  * @param {int} [limit] the maximum number of withdrawals structures to retrieve
@@ -1503,6 +1522,7 @@ export default class bitopro extends Exchange {
1503
1522
  * @method
1504
1523
  * @name bitopro#fetchWithdrawal
1505
1524
  * @description fetch data on a currency withdrawal via the withdrawal id
1525
+ * @see https://github.com/bitoex/bitopro-offical-api-docs/blob/master/api/v3/private/get_an_withdraw_invoice_data.md
1506
1526
  * @param {string} id withdrawal id
1507
1527
  * @param {string} code unified currency code of the currency withdrawn, default is undefined
1508
1528
  * @param {object} [params] extra parameters specific to the bitopro api endpoint
@@ -1542,6 +1562,7 @@ export default class bitopro extends Exchange {
1542
1562
  * @method
1543
1563
  * @name bitopro#withdraw
1544
1564
  * @description make a withdrawal
1565
+ * @see https://github.com/bitoex/bitopro-offical-api-docs/blob/master/api/v3/private/create_an_withdraw_invoice.md
1545
1566
  * @param {string} code unified currency code
1546
1567
  * @param {float} amount the amount to withdraw
1547
1568
  * @param {string} address the address to withdraw to
@@ -1617,7 +1638,7 @@ export default class bitopro extends Exchange {
1617
1638
  * @method
1618
1639
  * @name bitopro#fetchDepositWithdrawFees
1619
1640
  * @description fetch deposit and withdraw fees
1620
- * @see https://github.com/bitoex/bitopro-offical-api-docs/blob/master/v3-1/rest-1/open/currencies.md
1641
+ * @see https://github.com/bitoex/bitopro-offical-api-docs/blob/master/api/v3/public/get_currency_info.md
1621
1642
  * @param {string[]|undefined} codes list of unified currency codes
1622
1643
  * @param {object} [params] extra parameters specific to the bitopro api endpoint
1623
1644
  * @returns {object} a list of [fee structures]{@link https://github.com/ccxt/ccxt/wiki/Manual#fee-structure}
@@ -1,5 +1,5 @@
1
1
  import Exchange from './abstract/kucoin.js';
2
- import { Int, OrderSide, OrderType, Order, OHLCV, Trade, Balances } from './base/types.js';
2
+ import { Int, OrderSide, OrderType, Order, OHLCV, Trade, Balances, OrderRequest } from './base/types.js';
3
3
  /**
4
4
  * @class kucoin
5
5
  * @extends Exchange
@@ -78,6 +78,8 @@ export default class kucoin extends Exchange {
78
78
  fetchOrderBook(symbol: string, limit?: Int, params?: {}): Promise<import("./base/types.js").OrderBook>;
79
79
  handleTriggerPrices(params: any): any[];
80
80
  createOrder(symbol: string, type: OrderType, side: OrderSide, amount: any, price?: any, params?: {}): Promise<Order>;
81
+ createOrders(orders: OrderRequest[], params?: {}): Promise<Order[]>;
82
+ createOrderRequest(symbol: string, type: OrderType, side: OrderSide, amount: any, price?: any, params?: {}): any;
81
83
  editOrder(id: string, symbol: any, type: any, side: any, amount?: any, price?: any, params?: {}): Promise<Order>;
82
84
  cancelOrder(id: string, symbol?: string, params?: {}): Promise<any>;
83
85
  cancelAllOrders(symbol?: string, params?: {}): Promise<any>;
package/js/src/kucoin.js CHANGED
@@ -43,6 +43,7 @@ export default class kucoin extends Exchange {
43
43
  'cancelOrder': true,
44
44
  'createDepositAddress': true,
45
45
  'createOrder': true,
46
+ 'createOrders': true,
46
47
  'createPostOnlyOrder': true,
47
48
  'createStopLimitOrder': true,
48
49
  'createStopMarketOrder': true,
@@ -225,12 +226,14 @@ export default class kucoin extends Exchange {
225
226
  'deposit-addresses': 1,
226
227
  'withdrawals': 1,
227
228
  'orders': 4,
229
+ 'orders/test': 4,
228
230
  'orders/multi': 20,
229
231
  'isolated/borrow': 2,
230
232
  'isolated/repay/all': 2,
231
233
  'isolated/repay/single': 2,
232
234
  'margin/borrow': 1,
233
235
  'margin/order': 1,
236
+ 'margin/order/test': 1,
234
237
  'margin/repay/all': 1,
235
238
  'margin/repay/single': 1,
236
239
  'margin/lend': 1,
@@ -1830,6 +1833,8 @@ export default class kucoin extends Exchange {
1830
1833
  * @see https://docs.kucoin.com/spot#place-a-new-order-2
1831
1834
  * @see https://docs.kucoin.com/spot#place-a-margin-order
1832
1835
  * @see https://docs.kucoin.com/spot-hf/#place-hf-order
1836
+ * @see https://www.kucoin.com/docs/rest/spot-trading/orders/place-order-test
1837
+ * @see https://www.kucoin.com/docs/rest/margin-trading/orders/place-margin-order-test
1833
1838
  * @param {string} symbol Unified CCXT market symbol
1834
1839
  * @param {string} type 'limit' or 'market'
1835
1840
  * @param {string} side 'buy' or 'sell'
@@ -1859,9 +1864,140 @@ export default class kucoin extends Exchange {
1859
1864
  * @param {string} [params.stp] '', // self trade prevention, CN, CO, CB or DC
1860
1865
  * @param {bool} [params.autoBorrow] false, // The system will first borrow you funds at the optimal interest rate and then place an order for you
1861
1866
  * @param {bool} [params.hf] false, // true for hf order
1867
+ * @param {bool} [params.test] set to true to test an order, no order will be created but the request will be validated
1862
1868
  * @returns {object} an [order structure]{@link https://github.com/ccxt/ccxt/wiki/Manual#order-structure}
1863
1869
  */
1864
1870
  await this.loadMarkets();
1871
+ const market = this.market(symbol);
1872
+ const testOrder = this.safeValue(params, 'test', false);
1873
+ params = this.omit(params, 'test');
1874
+ const isHf = this.safeValue(params, 'hf', false);
1875
+ const [triggerPrice, stopLossPrice, takeProfitPrice] = this.handleTriggerPrices(params);
1876
+ const tradeType = this.safeString(params, 'tradeType'); // keep it for backward compatibility
1877
+ const isTriggerOrder = (triggerPrice || stopLossPrice || takeProfitPrice);
1878
+ const marginResult = this.handleMarginModeAndParams('createOrder', params);
1879
+ const marginMode = this.safeString(marginResult, 0);
1880
+ const isMarginOrder = tradeType === 'MARGIN_TRADE' || marginMode !== undefined;
1881
+ // don't omit anything before calling createOrderRequest
1882
+ const orderRequest = this.createOrderRequest(symbol, type, side, amount, price, params);
1883
+ let response = undefined;
1884
+ if (testOrder) {
1885
+ if (isMarginOrder) {
1886
+ response = await this.privatePostMarginOrderTest(orderRequest);
1887
+ }
1888
+ else {
1889
+ response = await this.privatePostOrdersTest(orderRequest);
1890
+ }
1891
+ }
1892
+ else if (isHf) {
1893
+ response = await this.privatePostHfOrders(orderRequest);
1894
+ }
1895
+ else if (isTriggerOrder) {
1896
+ response = await this.privatePostStopOrder(orderRequest);
1897
+ }
1898
+ else if (isMarginOrder) {
1899
+ response = await this.privatePostMarginOrder(orderRequest);
1900
+ }
1901
+ else {
1902
+ response = await this.privatePostOrders(orderRequest);
1903
+ }
1904
+ //
1905
+ // {
1906
+ // code: '200000',
1907
+ // data: {
1908
+ // "orderId": "5bd6e9286d99522a52e458de"
1909
+ // }
1910
+ // }
1911
+ //
1912
+ const data = this.safeValue(response, 'data', {});
1913
+ return this.parseOrder(data, market);
1914
+ }
1915
+ async createOrders(orders, params = {}) {
1916
+ /**
1917
+ * @method
1918
+ * @name kucoin#createOrders
1919
+ * @description create a list of trade orders
1920
+ * @see https://www.kucoin.com/docs/rest/spot-trading/orders/place-multiple-orders
1921
+ * @see https://www.kucoin.com/docs/rest/spot-trading/spot-hf-trade-pro-account/place-multiple-hf-orders
1922
+ * @param {array} orders list of orders to create, each object should contain the parameters required by createOrder, namely symbol, type, side, amount, price and params
1923
+ * @param {object} [params] Extra parameters specific to the exchange API endpoint
1924
+ * @param {bool} [params.hf] false, // true for hf orders
1925
+ * @returns {object} an [order structure]{@link https://github.com/ccxt/ccxt/wiki/Manual#order-structure}
1926
+ */
1927
+ await this.loadMarkets();
1928
+ const ordersRequests = [];
1929
+ let symbol = undefined;
1930
+ for (let i = 0; i < orders.length; i++) {
1931
+ const rawOrder = orders[i];
1932
+ const marketId = this.safeString(rawOrder, 'symbol');
1933
+ if (symbol === undefined) {
1934
+ symbol = marketId;
1935
+ }
1936
+ else {
1937
+ if (symbol !== marketId) {
1938
+ throw new BadRequest(this.id + ' createOrders() requires all orders to have the same symbol');
1939
+ }
1940
+ }
1941
+ const type = this.safeString(rawOrder, 'type');
1942
+ if (type !== 'limit') {
1943
+ throw new BadRequest(this.id + ' createOrders() only supports limit orders');
1944
+ }
1945
+ const side = this.safeString(rawOrder, 'side');
1946
+ const amount = this.safeValue(rawOrder, 'amount');
1947
+ const price = this.safeValue(rawOrder, 'price');
1948
+ const orderParams = this.safeValue(rawOrder, 'params', {});
1949
+ const orderRequest = this.createOrderRequest(marketId, type, side, amount, price, orderParams);
1950
+ ordersRequests.push(orderRequest);
1951
+ }
1952
+ const market = this.market(symbol);
1953
+ const request = {
1954
+ 'symbol': market['id'],
1955
+ 'orderList': ordersRequests,
1956
+ };
1957
+ const hf = this.safeValue(params, 'hf', false);
1958
+ params = this.omit(params, 'hf');
1959
+ let response = undefined;
1960
+ if (hf) {
1961
+ response = await this.privatePostHfOrdersMulti(this.extend(request, params));
1962
+ }
1963
+ else {
1964
+ response = await this.privatePostOrdersMulti(this.extend(request, params));
1965
+ }
1966
+ //
1967
+ // {
1968
+ // "code": "200000",
1969
+ // "data": {
1970
+ // "data": [
1971
+ // {
1972
+ // "symbol": "LTC-USDT",
1973
+ // "type": "limit",
1974
+ // "side": "sell",
1975
+ // "price": "90",
1976
+ // "size": "0.1",
1977
+ // "funds": null,
1978
+ // "stp": "",
1979
+ // "stop": "",
1980
+ // "stopPrice": null,
1981
+ // "timeInForce": "GTC",
1982
+ // "cancelAfter": 0,
1983
+ // "postOnly": false,
1984
+ // "hidden": false,
1985
+ // "iceberge": false,
1986
+ // "iceberg": false,
1987
+ // "visibleSize": null,
1988
+ // "channel": "API",
1989
+ // "id": "6539148443fcf500079d15e5",
1990
+ // "status": "success",
1991
+ // "failMsg": null,
1992
+ // "clientOid": "5c4c5398-8ab2-4b4e-af8a-e2d90ad2488f"
1993
+ // },
1994
+ // }
1995
+ //
1996
+ let data = this.safeValue(response, 'data', {});
1997
+ data = this.safeValue(data, 'data', []);
1998
+ return this.parseOrders(data);
1999
+ }
2000
+ createOrderRequest(symbol, type, side, amount, price = undefined, params = {}) {
1865
2001
  const market = this.market(symbol);
1866
2002
  // required param, cannot be used twice
1867
2003
  const clientOrderId = this.safeString2(params, 'clientOid', 'clientOrderId', this.uuid());
@@ -1894,15 +2030,12 @@ export default class kucoin extends Exchange {
1894
2030
  request['size'] = amountString;
1895
2031
  request['price'] = this.priceToPrecision(symbol, price);
1896
2032
  }
2033
+ const tradeType = this.safeString(params, 'tradeType'); // keep it for backward compatibility
1897
2034
  const [triggerPrice, stopLossPrice, takeProfitPrice] = this.handleTriggerPrices(params);
2035
+ const isTriggerOrder = (triggerPrice || stopLossPrice || takeProfitPrice);
2036
+ const isMarginOrder = tradeType === 'MARGIN_TRADE' || marginMode !== undefined;
1898
2037
  params = this.omit(params, ['stopLossPrice', 'takeProfitPrice', 'triggerPrice', 'stopPrice']);
1899
- const tradeType = this.safeString(params, 'tradeType'); // keep it for backward compatibility
1900
- let method = 'privatePostOrders';
1901
- const isHf = this.safeValue(params, 'hf', false);
1902
- if (isHf) {
1903
- method = 'privatePostHfOrders';
1904
- }
1905
- else if (triggerPrice || stopLossPrice || takeProfitPrice) {
2038
+ if (isTriggerOrder) {
1906
2039
  if (triggerPrice) {
1907
2040
  request['stopPrice'] = this.priceToPrecision(symbol, triggerPrice);
1908
2041
  }
@@ -1916,7 +2049,6 @@ export default class kucoin extends Exchange {
1916
2049
  request['stopPrice'] = this.priceToPrecision(symbol, takeProfitPrice);
1917
2050
  }
1918
2051
  }
1919
- method = 'privatePostStopOrder';
1920
2052
  if (marginMode === 'isolated') {
1921
2053
  throw new BadRequest(this.id + ' createOrder does not support isolated margin for stop orders');
1922
2054
  }
@@ -1924,8 +2056,7 @@ export default class kucoin extends Exchange {
1924
2056
  request['tradeType'] = this.options['marginModes'][marginMode];
1925
2057
  }
1926
2058
  }
1927
- else if (tradeType === 'MARGIN_TRADE' || marginMode !== undefined) {
1928
- method = 'privatePostMarginOrder';
2059
+ else if (isMarginOrder) {
1929
2060
  if (marginMode === 'isolated') {
1930
2061
  request['marginModel'] = 'isolated';
1931
2062
  }
@@ -1935,17 +2066,7 @@ export default class kucoin extends Exchange {
1935
2066
  if (postOnly) {
1936
2067
  request['postOnly'] = true;
1937
2068
  }
1938
- const response = await this[method](this.extend(request, params));
1939
- //
1940
- // {
1941
- // code: '200000',
1942
- // data: {
1943
- // "orderId": "5bd6e9286d99522a52e458de"
1944
- // }
1945
- // }
1946
- //
1947
- const data = this.safeValue(response, 'data', {});
1948
- return this.parseOrder(data, market);
2069
+ return this.extend(request, params);
1949
2070
  }
1950
2071
  async editOrder(id, symbol, type, side, amount = undefined, price = undefined, params = {}) {
1951
2072
  /**
@@ -2475,6 +2596,7 @@ export default class kucoin extends Exchange {
2475
2596
  const stop = responseStop !== undefined;
2476
2597
  const stopTriggered = this.safeValue(order, 'stopTriggered', false);
2477
2598
  const isActive = this.safeValue2(order, 'isActive', 'active');
2599
+ const responseStatus = this.safeString(order, 'status');
2478
2600
  let status = undefined;
2479
2601
  if (isActive !== undefined) {
2480
2602
  if (isActive === true) {
@@ -2485,7 +2607,6 @@ export default class kucoin extends Exchange {
2485
2607
  }
2486
2608
  }
2487
2609
  if (stop) {
2488
- const responseStatus = this.safeString(order, 'status');
2489
2610
  if (responseStatus === 'NEW') {
2490
2611
  status = 'open';
2491
2612
  }
@@ -2496,6 +2617,9 @@ export default class kucoin extends Exchange {
2496
2617
  if (cancelExist) {
2497
2618
  status = 'canceled';
2498
2619
  }
2620
+ if (responseStatus === 'fail') {
2621
+ status = 'rejected';
2622
+ }
2499
2623
  const stopPrice = this.safeNumber(order, 'stopPrice');
2500
2624
  return this.safeOrder({
2501
2625
  'info': order,
@@ -163,6 +163,7 @@ export default class kucoinfutures extends kucoin {
163
163
  'transfer-out': 1,
164
164
  'transfer-in': 1,
165
165
  'orders': 1.33,
166
+ 'orders/test': 1.33,
166
167
  'position/margin/auto-deposit-status': 1,
167
168
  'position/margin/deposit-margin': 1,
168
169
  'position/risk-limit-level/change': 1,
@@ -1109,6 +1110,7 @@ export default class kucoinfutures extends kucoin {
1109
1110
  * @param {string} [params.stop] 'up' or 'down', the direction the stopPrice is triggered from, requires stopPrice. down: Triggers when the price reaches or goes below the stopPrice. up: Triggers when the price reaches or goes above the stopPrice.
1110
1111
  * @param {string} [params.stopPriceType] TP, IP or MP, defaults to MP: Mark Price
1111
1112
  * @param {bool} [params.closeOrder] set to true to close position
1113
+ * @param {bool} [params.test] set to true to use the test order endpoint (does not submit order, use to validate params)
1112
1114
  * @param {bool} [params.forceHold] A mark to forcely hold the funds for an order, even though it's an order to reduce the position size. This helps the order stay on the order book and not get canceled when the position size changes. Set to false by default.
1113
1115
  * @returns {object} an [order structure]{@link https://github.com/ccxt/ccxt/wiki/Manual#order-structure}
1114
1116
  */
@@ -1185,7 +1187,15 @@ export default class kucoinfutures extends kucoin {
1185
1187
  }
1186
1188
  }
1187
1189
  params = this.omit(params, ['timeInForce', 'stopPrice', 'triggerPrice', 'stopLossPrice', 'takeProfitPrice']); // Time in force only valid for limit orders, exchange error when gtc for market orders
1188
- const response = await this.futuresPrivatePostOrders(this.extend(request, params));
1190
+ let response = undefined;
1191
+ const testOrder = this.safeValue(params, 'test', false);
1192
+ params = this.omit(params, 'test');
1193
+ if (testOrder) {
1194
+ response = await this.futuresPrivatePostOrdersTest(this.extend(request, params));
1195
+ }
1196
+ else {
1197
+ response = await this.futuresPrivatePostOrders(this.extend(request, params));
1198
+ }
1189
1199
  //
1190
1200
  // {
1191
1201
  // code: "200000",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ccxt",
3
- "version": "4.1.26",
3
+ "version": "4.1.27",
4
4
  "description": "A JavaScript / TypeScript / Python / C# / PHP cryptocurrency trading library with support for 130+ exchanges",
5
5
  "unpkg": "dist/ccxt.browser.js",
6
6
  "type": "module",