ccxt 4.1.46 → 4.1.48

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 (137) hide show
  1. package/README.md +124 -124
  2. package/dist/ccxt.browser.js +662 -406
  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/base/Exchange.js +3 -0
  7. package/dist/cjs/src/binance.js +6 -0
  8. package/dist/cjs/src/bitmart.js +185 -64
  9. package/dist/cjs/src/hitbtc.js +79 -1
  10. package/dist/cjs/src/htx.js +8505 -0
  11. package/dist/cjs/src/huobi.js +5 -8503
  12. package/dist/cjs/src/kraken.js +0 -4
  13. package/dist/cjs/src/krakenfutures.js +13 -3
  14. package/dist/cjs/src/pro/binance.js +2 -2
  15. package/dist/cjs/src/pro/bitget.js +2 -2
  16. package/dist/cjs/src/pro/bybit.js +2 -2
  17. package/dist/cjs/src/pro/cryptocom.js +2 -2
  18. package/dist/cjs/src/pro/gate.js +2 -2
  19. package/dist/cjs/src/pro/htx.js +2356 -0
  20. package/dist/cjs/src/pro/huobi.js +5 -2345
  21. package/dist/cjs/src/pro/krakenfutures.js +2 -2
  22. package/dist/cjs/src/pro/okx.js +2 -2
  23. package/dist/cjs/src/timex.js +1 -1
  24. package/js/ccxt.d.ts +9 -3
  25. package/js/ccxt.js +6 -2
  26. package/js/src/abstract/binance.d.ts +6 -0
  27. package/js/src/abstract/binancecoinm.d.ts +6 -0
  28. package/js/src/abstract/binanceus.d.ts +6 -0
  29. package/js/src/abstract/binanceusdm.d.ts +6 -0
  30. package/js/src/abstract/htx.d.ts +544 -0
  31. package/js/src/abstract/htx.js +11 -0
  32. package/js/src/abstract/huobi.d.ts +4 -4
  33. package/js/src/ace.d.ts +2 -2
  34. package/js/src/ascendex.d.ts +5 -5
  35. package/js/src/base/Exchange.d.ts +3 -2
  36. package/js/src/base/Exchange.js +3 -0
  37. package/js/src/base/types.d.ts +5 -1
  38. package/js/src/bigone.d.ts +4 -4
  39. package/js/src/binance.d.ts +5 -58
  40. package/js/src/binance.js +6 -0
  41. package/js/src/bingx.d.ts +5 -57
  42. package/js/src/bitbns.d.ts +4 -4
  43. package/js/src/bitfinex.d.ts +4 -4
  44. package/js/src/bitfinex2.d.ts +4 -4
  45. package/js/src/bitflyer.d.ts +2 -2
  46. package/js/src/bitget.d.ts +5 -55
  47. package/js/src/bithumb.d.ts +2 -2
  48. package/js/src/bitmart.d.ts +6 -4
  49. package/js/src/bitmart.js +185 -64
  50. package/js/src/bitmex.d.ts +3 -3
  51. package/js/src/bitopro.d.ts +4 -4
  52. package/js/src/bitpanda.d.ts +4 -4
  53. package/js/src/bitrue.d.ts +4 -4
  54. package/js/src/bitso.d.ts +1 -1
  55. package/js/src/bitstamp.d.ts +4 -4
  56. package/js/src/bittrex.d.ts +6 -6
  57. package/js/src/bitvavo.d.ts +4 -4
  58. package/js/src/blockchaincom.d.ts +5 -5
  59. package/js/src/btcalpha.d.ts +4 -4
  60. package/js/src/btcmarkets.d.ts +3 -3
  61. package/js/src/btcturk.d.ts +2 -2
  62. package/js/src/bybit.d.ts +4 -4
  63. package/js/src/cex.d.ts +2 -2
  64. package/js/src/coinbase.d.ts +6 -6
  65. package/js/src/coinbasepro.d.ts +5 -5
  66. package/js/src/coincheck.d.ts +2 -2
  67. package/js/src/coinex.d.ts +9 -9
  68. package/js/src/coinfalcon.d.ts +4 -4
  69. package/js/src/coinlist.d.ts +3 -3
  70. package/js/src/coinmate.d.ts +1 -1
  71. package/js/src/coinone.d.ts +2 -2
  72. package/js/src/coinsph.d.ts +4 -4
  73. package/js/src/coinspot.d.ts +2 -2
  74. package/js/src/cryptocom.d.ts +4 -4
  75. package/js/src/currencycom.d.ts +7 -7
  76. package/js/src/delta.d.ts +2 -2
  77. package/js/src/deribit.d.ts +4 -4
  78. package/js/src/digifinex.d.ts +4 -4
  79. package/js/src/exmo.d.ts +5 -5
  80. package/js/src/gate.d.ts +4 -4
  81. package/js/src/gemini.d.ts +4 -52
  82. package/js/src/hitbtc.d.ts +6 -5
  83. package/js/src/hitbtc.js +79 -1
  84. package/js/src/hollaex.d.ts +4 -4
  85. package/js/src/htx.d.ts +257 -0
  86. package/js/src/htx.js +8506 -0
  87. package/js/src/huobi.d.ts +2 -255
  88. package/js/src/huobi.js +5 -8503
  89. package/js/src/huobijp.d.ts +4 -4
  90. package/js/src/idex.d.ts +4 -4
  91. package/js/src/indodax.d.ts +3 -3
  92. package/js/src/kraken.d.ts +4 -4
  93. package/js/src/kraken.js +0 -4
  94. package/js/src/krakenfutures.d.ts +2 -2
  95. package/js/src/krakenfutures.js +14 -4
  96. package/js/src/kucoin.d.ts +4 -4
  97. package/js/src/kucoinfutures.d.ts +3 -3
  98. package/js/src/kuna.d.ts +4 -4
  99. package/js/src/latoken.d.ts +3 -3
  100. package/js/src/lbank.d.ts +2 -2
  101. package/js/src/lbank2.d.ts +4 -4
  102. package/js/src/luno.d.ts +2 -2
  103. package/js/src/lykke.d.ts +3 -3
  104. package/js/src/mexc.d.ts +4 -4
  105. package/js/src/ndax.d.ts +2 -2
  106. package/js/src/novadax.d.ts +5 -5
  107. package/js/src/oceanex.d.ts +2 -2
  108. package/js/src/okcoin.d.ts +10 -10
  109. package/js/src/okx.d.ts +9 -9
  110. package/js/src/phemex.d.ts +7 -7
  111. package/js/src/poloniex.d.ts +5 -5
  112. package/js/src/poloniexfutures.d.ts +2 -2
  113. package/js/src/pro/binance.js +2 -2
  114. package/js/src/pro/bitget.js +2 -2
  115. package/js/src/pro/bybit.js +2 -2
  116. package/js/src/pro/cryptocom.js +2 -2
  117. package/js/src/pro/gate.js +2 -2
  118. package/js/src/pro/htx.d.ts +45 -0
  119. package/js/src/pro/htx.js +2357 -0
  120. package/js/src/pro/huobi.d.ts +2 -43
  121. package/js/src/pro/huobi.js +5 -2345
  122. package/js/src/pro/krakenfutures.js +2 -2
  123. package/js/src/pro/okx.js +2 -2
  124. package/js/src/probit.d.ts +4 -4
  125. package/js/src/tidex.d.ts +2 -2
  126. package/js/src/timex.d.ts +5 -55
  127. package/js/src/timex.js +1 -1
  128. package/js/src/tokocrypto.d.ts +6 -6
  129. package/js/src/upbit.d.ts +4 -4
  130. package/js/src/wavesexchange.d.ts +3 -3
  131. package/js/src/wazirx.d.ts +2 -2
  132. package/js/src/whitebit.d.ts +3 -3
  133. package/js/src/woo.d.ts +3 -3
  134. package/js/src/yobit.d.ts +2 -2
  135. package/js/src/zonda.d.ts +2 -2
  136. package/package.json +1 -1
  137. package/skip-tests.json +9 -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.46';
186
+ const version = '4.1.48';
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;
@@ -1349,6 +1349,9 @@ class Exchange {
1349
1349
  async fetchOrderBook(symbol, limit = undefined, params = {}) {
1350
1350
  throw new errors.NotSupported(this.id + ' fetchOrderBook() is not supported yet');
1351
1351
  }
1352
+ async fetchMarginMode(symbol = undefined, params = {}) {
1353
+ throw new errors.NotSupported(this.id + ' fetchMarginMode() is not supported yet');
1354
+ }
1352
1355
  async fetchRestOrderBookSafe(symbol, limit = undefined, params = {}) {
1353
1356
  const fetchSnapshotMaxRetries = this.handleOption('watchOrderBook', 'maxRetries', 3);
1354
1357
  for (let i = 0; i < fetchSnapshotMaxRetries; i++) {
@@ -960,7 +960,9 @@ class binance extends binance$1 {
960
960
  },
961
961
  'post': {
962
962
  'um/order': 1,
963
+ 'um/conditional/order': 1,
963
964
  'cm/order': 1,
965
+ 'cm/conditional/order': 1,
964
966
  'margin/order': 0.0133,
965
967
  'marginLoan': 0.1333,
966
968
  'repayLoan': 0.1333,
@@ -981,9 +983,13 @@ class binance extends binance$1 {
981
983
  },
982
984
  'delete': {
983
985
  'um/order': 1,
986
+ 'um/conditional/order': 1,
984
987
  'um/allOpenOrders': 1,
988
+ 'um/conditional/allOpenOrders': 1,
985
989
  'cm/order': 1,
990
+ 'cm/conditional/order': 1,
986
991
  'cm/allOpenOrders': 1,
992
+ 'cm/conditional/allOpenOrders': 1,
987
993
  'margin/order': 1,
988
994
  'margin/allOpenOrders': 5,
989
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
  }
@@ -1509,7 +1510,7 @@ class bitmart extends bitmart$1 {
1509
1510
  * @method
1510
1511
  * @name bitmart#fetchOHLCV
1511
1512
  * @description fetches historical candlestick data containing the open, high, low, and close price, and the volume of a market
1512
- * @see https://developer-pro.bitmart.com/en/spot/#get-latest-k-line-v3
1513
+ * @see https://developer-pro.bitmart.com/en/spot/#get-history-k-line-v3
1513
1514
  * @see https://developer-pro.bitmart.com/en/futures/#get-k-line
1514
1515
  * @param {string} symbol unified symbol of the market to fetch OHLCV data for
1515
1516
  * @param {string} timeframe the length of time each candle represents
@@ -1572,7 +1573,7 @@ class bitmart extends bitmart$1 {
1572
1573
  response = await this.publicGetContractPublicKline(this.extend(request, params));
1573
1574
  }
1574
1575
  else {
1575
- response = await this.publicGetSpotQuotationV3LiteKlines(this.extend(request, params));
1576
+ response = await this.publicGetSpotQuotationV3Klines(this.extend(request, params));
1576
1577
  }
1577
1578
  //
1578
1579
  // spot
@@ -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) {
@@ -60,7 +60,7 @@ class hitbtc extends hitbtc$1 {
60
60
  'fetchLeverage': true,
61
61
  'fetchLeverageTiers': undefined,
62
62
  'fetchLiquidations': false,
63
- 'fetchMarginMode': false,
63
+ 'fetchMarginMode': true,
64
64
  'fetchMarketLeverageTiers': false,
65
65
  'fetchMarkets': true,
66
66
  'fetchMarkOHLCV': true,
@@ -2346,6 +2346,84 @@ class hitbtc extends hitbtc$1 {
2346
2346
  'stopLossPrice': undefined,
2347
2347
  }, market);
2348
2348
  }
2349
+ async fetchMarginMode(symbol = undefined, params = {}) {
2350
+ /**
2351
+ * @method
2352
+ * @name hitbtc#fetchMarginMode
2353
+ * @description fetches margin mode of the user
2354
+ * @see https://api.hitbtc.com/#get-margin-position-parameters
2355
+ * @see https://api.hitbtc.com/#get-futures-position-parameters
2356
+ * @param {string} symbol unified symbol of the market the order was made in
2357
+ * @param {object} [params] extra parameters specific to the hitbtc api endpoint
2358
+ * @returns {object} Struct of MarginMode
2359
+ */
2360
+ await this.loadMarkets();
2361
+ let market = undefined;
2362
+ if (symbol !== undefined) {
2363
+ market = this.market(symbol);
2364
+ }
2365
+ let marketType = undefined;
2366
+ [marketType, params] = this.handleMarketTypeAndParams('fetchMarginMode', market, params);
2367
+ let response = undefined;
2368
+ if (marketType === 'margin') {
2369
+ response = await this.privateGetMarginConfig(params);
2370
+ }
2371
+ else if (marketType === 'swap') {
2372
+ response = await this.privateGetFuturesConfig(params);
2373
+ }
2374
+ else {
2375
+ throw new errors.BadSymbol(this.id + ' fetchMarginMode() supports swap contracts and margin only');
2376
+ }
2377
+ //
2378
+ // margin
2379
+ // {
2380
+ // "config": [{
2381
+ // "symbol": "BTCUSD",
2382
+ // "margin_call_leverage_mul": "1.50",
2383
+ // "liquidation_leverage_mul": "2.00",
2384
+ // "max_initial_leverage": "10.00",
2385
+ // "margin_mode": "Isolated",
2386
+ // "force_close_fee": "0.05",
2387
+ // "enabled": true,
2388
+ // "active": true,
2389
+ // "limit_base": "50000.00",
2390
+ // "limit_power": "2.2",
2391
+ // "unlimited_threshold": "10.0"
2392
+ // }]
2393
+ // }
2394
+ //
2395
+ // swap
2396
+ // {
2397
+ // "config": [{
2398
+ // "symbol": "BTCUSD_PERP",
2399
+ // "margin_call_leverage_mul": "1.20",
2400
+ // "liquidation_leverage_mul": "2.00",
2401
+ // "max_initial_leverage": "100.00",
2402
+ // "margin_mode": "Isolated",
2403
+ // "force_close_fee": "0.001",
2404
+ // "enabled": true,
2405
+ // "active": false,
2406
+ // "limit_base": "5000000.000000000000",
2407
+ // "limit_power": "1.25",
2408
+ // "unlimited_threshold": "2.00"
2409
+ // }]
2410
+ // }
2411
+ //
2412
+ const config = this.safeValue(response, 'config', []);
2413
+ const marginModes = [];
2414
+ for (let i = 0; i < config.length; i++) {
2415
+ const data = this.safeValue(config, i);
2416
+ const marketId = this.safeString(data, 'symbol');
2417
+ const marketInner = this.safeMarket(marketId);
2418
+ marginModes.push({
2419
+ 'info': data,
2420
+ 'symbol': this.safeString(marketInner, 'symbol'),
2421
+ 'marginMode': this.safeStringLower(data, 'margin_mode'),
2422
+ });
2423
+ }
2424
+ const filteredMargin = this.filterBySymbol(marginModes, symbol);
2425
+ return this.safeValue(filteredMargin, 0);
2426
+ }
2349
2427
  async transfer(code, amount, fromAccount, toAccount, params = {}) {
2350
2428
  /**
2351
2429
  * @method