ccxt 4.1.47 → 4.1.49

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.
Files changed (114) hide show
  1. package/README.md +124 -124
  2. package/dist/ccxt.browser.js +670 -460
  3. package/dist/ccxt.browser.min.js +3 -3
  4. package/dist/cjs/ccxt.js +6 -1
  5. package/dist/cjs/src/abstract/htx.js +9 -0
  6. package/dist/cjs/src/binance.js +2 -0
  7. package/dist/cjs/src/bitmart.js +183 -62
  8. package/dist/cjs/src/coinex.js +67 -18
  9. package/dist/cjs/src/htx.js +8505 -0
  10. package/dist/cjs/src/huobi.js +5 -8503
  11. package/dist/cjs/src/kraken.js +0 -4
  12. package/dist/cjs/src/mexc.js +21 -21
  13. package/dist/cjs/src/pro/htx.js +2356 -0
  14. package/dist/cjs/src/pro/huobi.js +5 -2345
  15. package/dist/cjs/src/timex.js +1 -1
  16. package/js/ccxt.d.ts +8 -2
  17. package/js/ccxt.js +6 -2
  18. package/js/src/abstract/binance.d.ts +2 -0
  19. package/js/src/abstract/binancecoinm.d.ts +2 -0
  20. package/js/src/abstract/binanceus.d.ts +2 -0
  21. package/js/src/abstract/binanceusdm.d.ts +2 -0
  22. package/js/src/abstract/htx.d.ts +544 -0
  23. package/js/src/abstract/htx.js +11 -0
  24. package/js/src/abstract/huobi.d.ts +4 -4
  25. package/js/src/abstract/huobi.js +3 -3
  26. package/js/src/ace.d.ts +2 -2
  27. package/js/src/ascendex.d.ts +2 -2
  28. package/js/src/base/Exchange.d.ts +2 -2
  29. package/js/src/base/types.d.ts +0 -1
  30. package/js/src/bigone.d.ts +2 -2
  31. package/js/src/binance.d.ts +3 -56
  32. package/js/src/binance.js +2 -0
  33. package/js/src/bingx.d.ts +3 -55
  34. package/js/src/bitbns.d.ts +2 -2
  35. package/js/src/bitfinex.d.ts +2 -2
  36. package/js/src/bitfinex2.d.ts +2 -2
  37. package/js/src/bitget.d.ts +3 -53
  38. package/js/src/bithumb.d.ts +2 -2
  39. package/js/src/bitmart.d.ts +4 -2
  40. package/js/src/bitmart.js +183 -62
  41. package/js/src/bitmex.d.ts +2 -2
  42. package/js/src/bitopro.d.ts +2 -2
  43. package/js/src/bitpanda.d.ts +2 -2
  44. package/js/src/bitrue.d.ts +2 -2
  45. package/js/src/bitstamp.d.ts +2 -2
  46. package/js/src/bittrex.d.ts +2 -2
  47. package/js/src/bitvavo.d.ts +2 -2
  48. package/js/src/blockchaincom.d.ts +2 -2
  49. package/js/src/btcalpha.d.ts +2 -2
  50. package/js/src/btcturk.d.ts +2 -2
  51. package/js/src/bybit.d.ts +2 -2
  52. package/js/src/cex.d.ts +2 -2
  53. package/js/src/coinbase.d.ts +2 -2
  54. package/js/src/coinbasepro.d.ts +2 -2
  55. package/js/src/coinex.d.ts +2 -2
  56. package/js/src/coinex.js +67 -18
  57. package/js/src/coinfalcon.d.ts +2 -2
  58. package/js/src/coinlist.d.ts +2 -2
  59. package/js/src/coinone.d.ts +2 -2
  60. package/js/src/coinsph.d.ts +2 -2
  61. package/js/src/coinspot.d.ts +2 -2
  62. package/js/src/cryptocom.d.ts +2 -2
  63. package/js/src/currencycom.d.ts +2 -2
  64. package/js/src/delta.d.ts +2 -2
  65. package/js/src/deribit.d.ts +2 -2
  66. package/js/src/digifinex.d.ts +2 -2
  67. package/js/src/exmo.d.ts +2 -2
  68. package/js/src/gate.d.ts +2 -2
  69. package/js/src/gemini.d.ts +3 -51
  70. package/js/src/hitbtc.d.ts +2 -2
  71. package/js/src/hollaex.d.ts +2 -2
  72. package/js/src/htx.d.ts +257 -0
  73. package/js/src/htx.js +8506 -0
  74. package/js/src/huobi.d.ts +2 -255
  75. package/js/src/huobi.js +5 -8503
  76. package/js/src/huobijp.d.ts +2 -2
  77. package/js/src/idex.d.ts +2 -2
  78. package/js/src/indodax.d.ts +2 -2
  79. package/js/src/kraken.d.ts +2 -2
  80. package/js/src/kraken.js +0 -4
  81. package/js/src/krakenfutures.d.ts +2 -2
  82. package/js/src/kucoin.d.ts +2 -2
  83. package/js/src/kuna.d.ts +2 -2
  84. package/js/src/latoken.d.ts +2 -2
  85. package/js/src/lbank.d.ts +2 -2
  86. package/js/src/lbank2.d.ts +2 -2
  87. package/js/src/luno.d.ts +2 -2
  88. package/js/src/lykke.d.ts +2 -2
  89. package/js/src/mexc.d.ts +2 -2
  90. package/js/src/mexc.js +21 -21
  91. package/js/src/novadax.d.ts +2 -2
  92. package/js/src/oceanex.d.ts +2 -2
  93. package/js/src/okcoin.d.ts +3 -3
  94. package/js/src/okx.d.ts +3 -3
  95. package/js/src/phemex.d.ts +2 -2
  96. package/js/src/poloniex.d.ts +2 -2
  97. package/js/src/poloniexfutures.d.ts +2 -2
  98. package/js/src/pro/htx.d.ts +45 -0
  99. package/js/src/pro/htx.js +2357 -0
  100. package/js/src/pro/huobi.d.ts +2 -43
  101. package/js/src/pro/huobi.js +5 -2345
  102. package/js/src/probit.d.ts +2 -2
  103. package/js/src/tidex.d.ts +2 -2
  104. package/js/src/timex.d.ts +3 -53
  105. package/js/src/timex.js +1 -1
  106. package/js/src/tokocrypto.d.ts +2 -2
  107. package/js/src/upbit.d.ts +2 -2
  108. package/js/src/wavesexchange.d.ts +2 -2
  109. package/js/src/wazirx.d.ts +2 -2
  110. package/js/src/whitebit.d.ts +2 -2
  111. package/js/src/yobit.d.ts +2 -2
  112. package/js/src/zonda.d.ts +2 -2
  113. package/package.json +1 -1
  114. package/skip-tests.json +4 -4
package/dist/cjs/ccxt.js CHANGED
@@ -76,6 +76,7 @@ var gemini = require('./src/gemini.js');
76
76
  var hitbtc = require('./src/hitbtc.js');
77
77
  var hitbtc3 = require('./src/hitbtc3.js');
78
78
  var hollaex = require('./src/hollaex.js');
79
+ var htx = require('./src/htx.js');
79
80
  var huobi = require('./src/huobi.js');
80
81
  var huobijp = require('./src/huobijp.js');
81
82
  var huobipro = require('./src/huobipro.js');
@@ -154,6 +155,7 @@ var gateio$1 = require('./src/pro/gateio.js');
154
155
  var gemini$1 = require('./src/pro/gemini.js');
155
156
  var hitbtc$1 = require('./src/pro/hitbtc.js');
156
157
  var hollaex$1 = require('./src/pro/hollaex.js');
158
+ var htx$1 = require('./src/pro/htx.js');
157
159
  var huobi$1 = require('./src/pro/huobi.js');
158
160
  var huobijp$1 = require('./src/pro/huobijp.js');
159
161
  var huobipro$1 = require('./src/pro/huobipro.js');
@@ -181,7 +183,7 @@ var woo$1 = require('./src/pro/woo.js');
181
183
 
182
184
  //-----------------------------------------------------------------------------
183
185
  // this is updated by vss.js when building
184
- const version = '4.1.47';
186
+ const version = '4.1.49';
185
187
  Exchange["default"].ccxtVersion = version;
186
188
  const exchanges = {
187
189
  'ace': ace,
@@ -248,6 +250,7 @@ const exchanges = {
248
250
  'hitbtc': hitbtc,
249
251
  'hitbtc3': hitbtc3,
250
252
  'hollaex': hollaex,
253
+ 'htx': htx,
251
254
  'huobi': huobi,
252
255
  'huobijp': huobijp,
253
256
  'huobipro': huobipro,
@@ -328,6 +331,7 @@ const pro = {
328
331
  'gemini': gemini$1,
329
332
  'hitbtc': hitbtc$1,
330
333
  'hollaex': hollaex$1,
334
+ 'htx': htx$1,
331
335
  'huobi': huobi$1,
332
336
  'huobijp': huobijp$1,
333
337
  'huobipro': huobipro$1,
@@ -458,6 +462,7 @@ exports.gemini = gemini;
458
462
  exports.hitbtc = hitbtc;
459
463
  exports.hitbtc3 = hitbtc3;
460
464
  exports.hollaex = hollaex;
465
+ exports.htx = htx;
461
466
  exports.huobi = huobi;
462
467
  exports.huobijp = huobijp;
463
468
  exports.huobipro = huobipro;
@@ -0,0 +1,9 @@
1
+ 'use strict';
2
+
3
+ var Exchange$1 = require('../base/Exchange.js');
4
+
5
+ // -------------------------------------------------------------------------------
6
+ class Exchange extends Exchange$1["default"] {
7
+ }
8
+
9
+ module.exports = Exchange;
@@ -985,9 +985,11 @@ class binance extends binance$1 {
985
985
  'um/order': 1,
986
986
  'um/conditional/order': 1,
987
987
  'um/allOpenOrders': 1,
988
+ 'um/conditional/allOpenOrders': 1,
988
989
  'cm/order': 1,
989
990
  'cm/conditional/order': 1,
990
991
  'cm/allOpenOrders': 1,
992
+ 'cm/conditional/allOpenOrders': 1,
991
993
  'margin/order': 1,
992
994
  'margin/allOpenOrders': 5,
993
995
  'margin/orderList': 2,
@@ -575,6 +575,7 @@ class bitmart extends bitmart$1 {
575
575
  'swap': 'swap',
576
576
  },
577
577
  'createMarketBuyOrderRequiresPrice': true,
578
+ 'brokerId': 'CCXTxBitmart000',
578
579
  },
579
580
  });
580
581
  }
@@ -1981,6 +1982,12 @@ class bitmart extends bitmart$1 {
1981
1982
  // "order_id": 2707217580
1982
1983
  // }
1983
1984
  //
1985
+ // swap
1986
+ // "data": {
1987
+ // "order_id": 231116359426639,
1988
+ // "price": "market price"
1989
+ // },
1990
+ //
1984
1991
  // cancelOrder
1985
1992
  //
1986
1993
  // "2707217580" // order id
@@ -2063,6 +2070,10 @@ class bitmart extends bitmart$1 {
2063
2070
  type = 'limit';
2064
2071
  timeInForce = 'IOC';
2065
2072
  }
2073
+ let priceString = this.safeString(order, 'price');
2074
+ if (priceString === 'market price') {
2075
+ priceString = undefined;
2076
+ }
2066
2077
  return this.safeOrder({
2067
2078
  'id': id,
2068
2079
  'clientOrderId': this.safeString(order, 'client_order_id'),
@@ -2075,7 +2086,7 @@ class bitmart extends bitmart$1 {
2075
2086
  'timeInForce': timeInForce,
2076
2087
  'postOnly': postOnly,
2077
2088
  'side': this.parseOrderSide(this.safeString(order, 'side')),
2078
- 'price': this.omitZero(this.safeString(order, 'price')),
2089
+ 'price': this.omitZero(priceString),
2079
2090
  'stopPrice': undefined,
2080
2091
  'triggerPrice': undefined,
2081
2092
  'amount': this.omitZero(this.safeString(order, 'size')),
@@ -2129,6 +2140,7 @@ class bitmart extends bitmart$1 {
2129
2140
  * @description create a trade order
2130
2141
  * @see https://developer-pro.bitmart.com/en/spot/#place-spot-order
2131
2142
  * @see https://developer-pro.bitmart.com/en/spot/#place-margin-order
2143
+ * @see https://developer-pro.bitmart.com/en/futures/#submit-order-signed
2132
2144
  * @param {string} symbol unified symbol of the market to create an order in
2133
2145
  * @param {string} type 'market' or 'limit'
2134
2146
  * @param {string} side 'buy' or 'sell'
@@ -2136,11 +2148,153 @@ class bitmart extends bitmart$1 {
2136
2148
  * @param {float} [price] the price at which the order is to be fullfilled, in units of the quote currency, ignored in market orders
2137
2149
  * @param {object} [params] extra parameters specific to the bitmart api endpoint
2138
2150
  * @param {string} [params.marginMode] 'cross' or 'isolated'
2151
+ * @param {string} [params.leverage] *swap only* leverage level
2152
+ * @param {string} [params.clientOrderId] client order id of the order
2153
+ * @param {boolean} [params.reduceOnly] *swap only* reduce only
2154
+ * @param {boolean} [params.postOnly] make sure the order is posted to the order book and not matched immediately
2139
2155
  * @returns {object} an [order structure]{@link https://github.com/ccxt/ccxt/wiki/Manual#order-structure}
2140
2156
  */
2141
2157
  await this.loadMarkets();
2142
2158
  const market = this.market(symbol);
2143
- const request = {};
2159
+ const result = this.handleMarginModeAndParams('createOrder', params);
2160
+ const marginMode = this.safeString(result, 0);
2161
+ let response = undefined;
2162
+ if (market['spot']) {
2163
+ const spotRequest = this.createSpotOrderRequest(symbol, type, side, amount, price, params);
2164
+ if (marginMode === 'isolated') {
2165
+ response = await this.privatePostSpotV1MarginSubmitOrder(spotRequest);
2166
+ }
2167
+ else {
2168
+ response = await this.privatePostSpotV2SubmitOrder(spotRequest);
2169
+ }
2170
+ }
2171
+ else {
2172
+ const swapRequest = this.createSwapOrderRequest(symbol, type, side, amount, price, params);
2173
+ response = await this.privatePostContractPrivateSubmitOrder(swapRequest);
2174
+ }
2175
+ //
2176
+ // spot and margin
2177
+ //
2178
+ // {
2179
+ // "code": 1000,
2180
+ // "trace":"886fb6ae-456b-4654-b4e0-d681ac05cea1",
2181
+ // "message": "OK",
2182
+ // "data": {
2183
+ // "order_id": 2707217580
2184
+ // }
2185
+ // }
2186
+ //
2187
+ // swap
2188
+ // {"code":1000,"message":"Ok","data":{"order_id":231116359426639,"price":"market price"},"trace":"7f9c94e10f9d4513bc08a7bfc2a5559a.62.16996369620521911"}
2189
+ //
2190
+ const data = this.safeValue(response, 'data', {});
2191
+ const order = this.parseOrder(data, market);
2192
+ order['type'] = type;
2193
+ order['side'] = side;
2194
+ order['amount'] = amount;
2195
+ order['price'] = price;
2196
+ return order;
2197
+ }
2198
+ createSwapOrderRequest(symbol, type, side, amount, price = undefined, params = {}) {
2199
+ /**
2200
+ * @method
2201
+ * @name bitmart#createSwapOrderRequest
2202
+ * @description create a trade order
2203
+ * @see https://developer-pro.bitmart.com/en/futures/#submit-order-signed
2204
+ * @param {string} symbol unified symbol of the market to create an order in
2205
+ * @param {string} type 'market' or 'limit'
2206
+ * @param {string} side 'buy' or 'sell'
2207
+ * @param {float} amount how much of currency you want to trade in units of base currency
2208
+ * @param {float} [price] the price at which the order is to be fullfilled, in units of the quote currency, ignored in market orders
2209
+ * @param {object} [params] extra parameters specific to the bitmart api endpoint
2210
+ * @param {int} [params.leverage] leverage level
2211
+ * @param {boolean} [params.reduceOnly] *swap only* reduce only
2212
+ * @param {string} [params.marginMode] 'cross' or 'isolated', default is 'cross'
2213
+ * @param {string} [params.clientOrderId] client order id of the order
2214
+ * @returns {object} an [order structure]{@link https://github.com/ccxt/ccxt/wiki/Manual#order-structure}
2215
+ */
2216
+ const market = this.market(symbol);
2217
+ const request = {
2218
+ 'symbol': market['id'],
2219
+ 'type': type,
2220
+ 'size': parseInt(this.amountToPrecision(symbol, amount)),
2221
+ };
2222
+ const timeInForce = this.safeString(params, 'timeInForce');
2223
+ const mode = this.safeInteger(params, 'mode'); // only for swap
2224
+ const isMarketOrder = type === 'market';
2225
+ let postOnly = undefined;
2226
+ const reduceOnly = this.safeValue(params, 'reduceOnly');
2227
+ const isExchangeSpecificPo = (mode === 4);
2228
+ [postOnly, params] = this.handlePostOnly(isMarketOrder, isExchangeSpecificPo, params);
2229
+ params = this.omit(params, ['timeInForce', 'postOnly', 'reduceOnly']);
2230
+ const ioc = ((timeInForce === 'IOC') || (mode === 3));
2231
+ const isLimitOrder = (type === 'limit') || postOnly || ioc;
2232
+ if (timeInForce === 'GTC') {
2233
+ request['mode'] = 1;
2234
+ }
2235
+ else if (timeInForce === 'FOK') {
2236
+ request['mode'] = 2;
2237
+ }
2238
+ else if (timeInForce === 'IOC') {
2239
+ request['mode'] = 3;
2240
+ }
2241
+ if (postOnly) {
2242
+ request['mode'] = 4;
2243
+ }
2244
+ if (isLimitOrder) {
2245
+ request['price'] = this.priceToPrecision(symbol, price);
2246
+ }
2247
+ if (side === 'buy') {
2248
+ if (reduceOnly) {
2249
+ request['side'] = 2; // sell close long
2250
+ }
2251
+ else {
2252
+ request['side'] = 1; // buy open long
2253
+ }
2254
+ }
2255
+ else if (side === 'sell') {
2256
+ if (reduceOnly) {
2257
+ request['side'] = 3; // sell close long
2258
+ }
2259
+ else {
2260
+ request['side'] = 4; // sell open short
2261
+ }
2262
+ }
2263
+ let marginMode = undefined;
2264
+ [marginMode, params] = this.handleMarginModeAndParams('createOrder', params, 'cross');
2265
+ request['open_type'] = marginMode;
2266
+ const clientOrderId = this.safeString(params, 'clientOrderId');
2267
+ if (clientOrderId !== undefined) {
2268
+ params = this.omit(params, 'clientOrderId');
2269
+ request['client_order_id'] = clientOrderId;
2270
+ }
2271
+ const leverage = this.safeInteger(params, 'leverage', 1);
2272
+ params = this.omit(params, 'leverage');
2273
+ request['leverage'] = this.numberToString(leverage);
2274
+ return this.extend(request, params);
2275
+ }
2276
+ createSpotOrderRequest(symbol, type, side, amount, price = undefined, params = {}) {
2277
+ /**
2278
+ * @method
2279
+ * @name bitmart#createSpotOrderRequest
2280
+ * @description create a spot order request
2281
+ * @see https://developer-pro.bitmart.com/en/spot/#place-spot-order
2282
+ * @see https://developer-pro.bitmart.com/en/spot/#place-margin-order
2283
+ * @param {string} symbol unified symbol of the market to create an order in
2284
+ * @param {string} type 'market' or 'limit'
2285
+ * @param {string} side 'buy' or 'sell'
2286
+ * @param {float} amount how much of currency you want to trade in units of base currency
2287
+ * @param {float} [price] the price at which the order is to be fullfilled, in units of the quote currency, ignored in market orders
2288
+ * @param {object} [params] extra parameters specific to the bitmart api endpoint
2289
+ * @param {string} [params.marginMode] 'cross' or 'isolated'
2290
+ * @returns {object} an [order structure]{@link https://github.com/ccxt/ccxt/wiki/Manual#order-structure}
2291
+ */
2292
+ const market = this.market(symbol);
2293
+ const request = {
2294
+ 'symbol': market['id'],
2295
+ 'side': side,
2296
+ 'type': type,
2297
+ };
2144
2298
  const timeInForce = this.safeString(params, 'timeInForce');
2145
2299
  if (timeInForce === 'FOK') {
2146
2300
  throw new errors.InvalidOrder(this.id + ' createOrder() only accepts timeInForce parameter values of IOC or PO');
@@ -2153,45 +2307,36 @@ class bitmart extends bitmart$1 {
2153
2307
  params = this.omit(params, ['timeInForce', 'postOnly']);
2154
2308
  const ioc = ((timeInForce === 'IOC') || (type === 'ioc'));
2155
2309
  const isLimitOrder = (type === 'limit') || postOnly || ioc;
2156
- let method = undefined;
2157
- if (market['spot']) {
2158
- request['symbol'] = market['id'];
2159
- request['side'] = side;
2160
- request['type'] = type;
2161
- method = 'privatePostSpotV2SubmitOrder';
2162
- if (isLimitOrder) {
2163
- request['size'] = this.amountToPrecision(symbol, amount);
2164
- request['price'] = this.priceToPrecision(symbol, price);
2165
- }
2166
- else if (isMarketOrder) {
2167
- // for market buy it requires the amount of quote currency to spend
2168
- if (side === 'buy') {
2169
- let notional = this.safeNumber(params, 'notional');
2170
- const createMarketBuyOrderRequiresPrice = this.safeValue(this.options, 'createMarketBuyOrderRequiresPrice', true);
2171
- if (createMarketBuyOrderRequiresPrice) {
2172
- if (price !== undefined) {
2173
- if (notional === undefined) {
2174
- const amountString = this.numberToString(amount);
2175
- const priceString = this.numberToString(price);
2176
- notional = this.parseNumber(Precise["default"].stringMul(amountString, priceString));
2177
- }
2178
- }
2179
- else if (notional === undefined) {
2180
- throw new errors.InvalidOrder(this.id + " createOrder () requires the price argument with market buy orders to calculate total order cost (amount to spend), where cost = amount * price. Supply a price argument to createOrder() call if you want the cost to be calculated for you from price and amount, or, alternatively, add .options['createMarketBuyOrderRequiresPrice'] = false and supply the total cost value in the 'amount' argument or in the 'notional' extra parameter (the exchange-specific behaviour)");
2310
+ // method = 'privatePostSpotV2SubmitOrder';
2311
+ if (isLimitOrder) {
2312
+ request['size'] = this.amountToPrecision(symbol, amount);
2313
+ request['price'] = this.priceToPrecision(symbol, price);
2314
+ }
2315
+ else if (isMarketOrder) {
2316
+ // for market buy it requires the amount of quote currency to spend
2317
+ if (side === 'buy') {
2318
+ let notional = this.safeNumber(params, 'notional');
2319
+ const createMarketBuyOrderRequiresPrice = this.safeValue(this.options, 'createMarketBuyOrderRequiresPrice', true);
2320
+ if (createMarketBuyOrderRequiresPrice) {
2321
+ if (price !== undefined) {
2322
+ if (notional === undefined) {
2323
+ const amountString = this.numberToString(amount);
2324
+ const priceString = this.numberToString(price);
2325
+ notional = this.parseNumber(Precise["default"].stringMul(amountString, priceString));
2181
2326
  }
2182
2327
  }
2183
- else {
2184
- notional = (notional === undefined) ? amount : notional;
2328
+ else if (notional === undefined) {
2329
+ throw new errors.InvalidOrder(this.id + " createOrder () requires the price argument with market buy orders to calculate total order cost (amount to spend), where cost = amount * price. Supply a price argument to createOrder() call if you want the cost to be calculated for you from price and amount, or, alternatively, add .options['createMarketBuyOrderRequiresPrice'] = false and supply the total cost value in the 'amount' argument or in the 'notional' extra parameter (the exchange-specific behaviour)");
2185
2330
  }
2186
- request['notional'] = this.decimalToPrecision(notional, number.TRUNCATE, market['precision']['price'], this.precisionMode);
2187
2331
  }
2188
- else if (side === 'sell') {
2189
- request['size'] = this.amountToPrecision(symbol, amount);
2332
+ else {
2333
+ notional = (notional === undefined) ? amount : notional;
2190
2334
  }
2335
+ request['notional'] = this.decimalToPrecision(notional, number.TRUNCATE, market['precision']['price'], this.precisionMode);
2336
+ }
2337
+ else if (side === 'sell') {
2338
+ request['size'] = this.amountToPrecision(symbol, amount);
2191
2339
  }
2192
- }
2193
- else if (market['swap']) {
2194
- throw new errors.NotSupported(this.id + ' createOrder() does not accept swap orders, only spot orders are allowed');
2195
2340
  }
2196
2341
  if (postOnly) {
2197
2342
  request['type'] = 'limit_maker';
@@ -2199,33 +2344,7 @@ class bitmart extends bitmart$1 {
2199
2344
  if (ioc) {
2200
2345
  request['type'] = 'ioc';
2201
2346
  }
2202
- const [marginMode, query] = this.handleMarginModeAndParams('createOrder', params);
2203
- if (marginMode !== undefined) {
2204
- if (marginMode !== 'isolated') {
2205
- throw new errors.NotSupported(this.id + ' only isolated margin is supported');
2206
- }
2207
- method = 'privatePostSpotV1MarginSubmitOrder';
2208
- }
2209
- const response = await this[method](this.extend(request, query));
2210
- //
2211
- // spot and margin
2212
- //
2213
- // {
2214
- // "code": 1000,
2215
- // "trace":"886fb6ae-456b-4654-b4e0-d681ac05cea1",
2216
- // "message": "OK",
2217
- // "data": {
2218
- // "order_id": 2707217580
2219
- // }
2220
- // }
2221
- //
2222
- const data = this.safeValue(response, 'data', {});
2223
- const order = this.parseOrder(data, market);
2224
- order['type'] = type;
2225
- order['side'] = side;
2226
- order['amount'] = amount;
2227
- order['price'] = price;
2228
- return order;
2347
+ return this.extend(request, params);
2229
2348
  }
2230
2349
  async cancelOrder(id, symbol = undefined, params = {}) {
2231
2350
  /**
@@ -4061,9 +4180,11 @@ class bitmart extends bitmart$1 {
4061
4180
  if (api === 'private') {
4062
4181
  this.checkRequiredCredentials();
4063
4182
  const timestamp = this.milliseconds().toString();
4183
+ const brokerId = this.safeString(this.options, 'brokerId', 'CCXTxBitmart000');
4064
4184
  headers = {
4065
4185
  'X-BM-KEY': this.apiKey,
4066
4186
  'X-BM-TIMESTAMP': timestamp,
4187
+ 'X-BM-BROKER-ID': brokerId,
4067
4188
  'Content-Type': 'application/json',
4068
4189
  };
4069
4190
  if (!getOrDelete) {
@@ -283,6 +283,7 @@ class coinex extends coinex$1 {
283
283
  },
284
284
  },
285
285
  'options': {
286
+ 'brokerId': 'x-167673045',
286
287
  'createMarketBuyOrderRequiresPrice': true,
287
288
  'defaultType': 'spot',
288
289
  'defaultSubType': 'linear',
@@ -302,6 +303,26 @@ class coinex extends coinex$1 {
302
303
  'ACM': 'Actinium',
303
304
  },
304
305
  'precisionMode': number.TICK_SIZE,
306
+ 'exceptions': {
307
+ 'exact': {
308
+ // https://github.com/coinexcom/coinex_exchange_api/wiki/013error_code
309
+ '23': errors.PermissionDenied,
310
+ '24': errors.AuthenticationError,
311
+ '25': errors.AuthenticationError,
312
+ '34': errors.AuthenticationError,
313
+ '35': errors.ExchangeNotAvailable,
314
+ '36': errors.RequestTimeout,
315
+ '213': errors.RateLimitExceeded,
316
+ '107': errors.InsufficientFunds,
317
+ '600': errors.OrderNotFound,
318
+ '601': errors.InvalidOrder,
319
+ '602': errors.InvalidOrder,
320
+ '606': errors.InvalidOrder,
321
+ },
322
+ 'broad': {
323
+ 'ip not allow visit': errors.PermissionDenied,
324
+ },
325
+ },
305
326
  });
306
327
  }
307
328
  async fetchCurrencies(params = {}) {
@@ -1539,6 +1560,7 @@ class coinex extends coinex$1 {
1539
1560
  // "status": "done",
1540
1561
  // "taker_fee_rate": "0.0005",
1541
1562
  // "type": "sell",
1563
+ // "client_id": "",
1542
1564
  // }
1543
1565
  //
1544
1566
  // Spot and Margin createOrder, cancelOrder, fetchOrder
@@ -1566,6 +1588,7 @@ class coinex extends coinex$1 {
1566
1588
  // "stock_fee":"0",
1567
1589
  // "taker_fee_rate":"0.002",
1568
1590
  // "type":"buy"
1591
+ // "client_id": "",
1569
1592
  // }
1570
1593
  //
1571
1594
  // Swap createOrder, cancelOrder, fetchOrder
@@ -1781,9 +1804,13 @@ class coinex extends coinex$1 {
1781
1804
  else {
1782
1805
  type = rawType;
1783
1806
  }
1807
+ let clientOrderId = this.safeString(order, 'client_id');
1808
+ if (clientOrderId === '') {
1809
+ clientOrderId = undefined;
1810
+ }
1784
1811
  return this.safeOrder({
1785
1812
  'id': this.safeString2(order, 'id', 'order_id'),
1786
- 'clientOrderId': undefined,
1813
+ 'clientOrderId': clientOrderId,
1787
1814
  'datetime': this.iso8601(timestamp),
1788
1815
  'timestamp': timestamp,
1789
1816
  'lastTradeTimestamp': this.safeTimestamp(order, 'update_time'),
@@ -1840,6 +1867,7 @@ class coinex extends coinex$1 {
1840
1867
  await this.loadMarkets();
1841
1868
  const market = this.market(symbol);
1842
1869
  const swap = market['swap'];
1870
+ const clientOrderId = this.safeString2(params, 'client_id', 'clientOrderId');
1843
1871
  const stopPrice = this.safeValue2(params, 'stopPrice', 'triggerPrice');
1844
1872
  const stopLossPrice = this.safeValue(params, 'stopLossPrice');
1845
1873
  const takeProfitPrice = this.safeValue(params, 'takeProfitPrice');
@@ -1861,6 +1889,14 @@ class coinex extends coinex$1 {
1861
1889
  const request = {
1862
1890
  'market': market['id'],
1863
1891
  };
1892
+ if (clientOrderId === undefined) {
1893
+ const defaultId = 'x-167673045';
1894
+ const brokerId = this.safeString(this.options, 'brokerId', defaultId);
1895
+ request['client_id'] = brokerId + '-' + this.uuid16();
1896
+ }
1897
+ else {
1898
+ request['client_id'] = clientOrderId;
1899
+ }
1864
1900
  if (swap) {
1865
1901
  if (stopLossPrice || takeProfitPrice) {
1866
1902
  request['stop_type'] = this.safeInteger(params, 'stop_type', 1); // 1: triggered by the latest transaction, 2: mark price, 3: index price
@@ -4762,6 +4798,32 @@ class coinex extends coinex$1 {
4762
4798
  let url = this.urls['api'][api] + '/' + this.version + '/' + path;
4763
4799
  let query = this.omit(params, this.extractParams(path));
4764
4800
  const nonce = this.nonce().toString();
4801
+ if (method === 'POST') {
4802
+ const parts = path.split('/');
4803
+ const firstPart = this.safeString(parts, 0, '');
4804
+ const numParts = parts.length;
4805
+ const lastPart = this.safeString(parts, numParts - 1, '');
4806
+ const lastWords = lastPart.split('_');
4807
+ const numWords = lastWords.length;
4808
+ const lastWord = this.safeString(lastWords, numWords - 1, '');
4809
+ if ((firstPart === 'order') && (lastWord === 'limit' || lastWord === 'market')) {
4810
+ // inject in implicit API calls
4811
+ // POST /order/limit - Place limit orders
4812
+ // POST /order/market - Place market orders
4813
+ // POST /order/stop/limit - Place stop limit orders
4814
+ // POST /order/stop/market - Place stop market orders
4815
+ // POST /perpetual/v1/order/put_limit - Place limit orders
4816
+ // POST /perpetual/v1/order/put_market - Place market orders
4817
+ // POST /perpetual/v1/order/put_stop_limit - Place stop limit orders
4818
+ // POST /perpetual/v1/order/put_stop_market - Place stop market orders
4819
+ const clientOrderId = this.safeString(params, 'client_id');
4820
+ if (clientOrderId === undefined) {
4821
+ const defaultId = 'x-167673045';
4822
+ const brokerId = this.safeValue(this.options, 'brokerId', defaultId);
4823
+ query['client_id'] = brokerId + '_' + this.uuid16();
4824
+ }
4825
+ }
4826
+ }
4765
4827
  if (api === 'perpetualPrivate' || url === 'https://api.coinex.com/perpetual/v1/market/user_deals') {
4766
4828
  this.checkRequiredCredentials();
4767
4829
  query = this.extend({
@@ -4818,23 +4880,10 @@ class coinex extends coinex$1 {
4818
4880
  const data = this.safeValue(response, 'data');
4819
4881
  const message = this.safeString(response, 'message');
4820
4882
  if ((code !== '0') || ((message !== 'Success') && (message !== 'Succeeded') && (message !== 'Ok') && !data)) {
4821
- const responseCodes = {
4822
- // https://github.com/coinexcom/coinex_exchange_api/wiki/013error_code
4823
- '23': errors.PermissionDenied,
4824
- '24': errors.AuthenticationError,
4825
- '25': errors.AuthenticationError,
4826
- '34': errors.AuthenticationError,
4827
- '35': errors.ExchangeNotAvailable,
4828
- '36': errors.RequestTimeout,
4829
- '213': errors.RateLimitExceeded,
4830
- '107': errors.InsufficientFunds,
4831
- '600': errors.OrderNotFound,
4832
- '601': errors.InvalidOrder,
4833
- '602': errors.InvalidOrder,
4834
- '606': errors.InvalidOrder,
4835
- };
4836
- const ErrorClass = this.safeValue(responseCodes, code, errors.ExchangeError);
4837
- throw new ErrorClass(response['message']);
4883
+ const feedback = this.id + ' ' + message;
4884
+ this.throwBroadlyMatchedException(this.exceptions['broad'], message, feedback);
4885
+ this.throwExactlyMatchedException(this.exceptions['exact'], code, feedback);
4886
+ throw new errors.ExchangeError(feedback);
4838
4887
  }
4839
4888
  return undefined;
4840
4889
  }