ccxt 4.1.56 → 4.1.58

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 (318) hide show
  1. package/.git-templates/hooks/pre-push +2 -2
  2. package/README.md +3 -3
  3. package/build.sh +30 -18
  4. package/dist/ccxt.browser.js +3893 -3214
  5. package/dist/ccxt.browser.min.js +10 -10
  6. package/dist/cjs/ccxt.js +1 -1
  7. package/dist/cjs/src/ace.js +17 -13
  8. package/dist/cjs/src/alpaca.js +6 -6
  9. package/dist/cjs/src/ascendex.js +35 -29
  10. package/dist/cjs/src/base/Exchange.js +39 -26
  11. package/dist/cjs/src/base/Precise.js +1 -3
  12. package/dist/cjs/src/base/ws/Client.js +1 -1
  13. package/dist/cjs/src/bigone.js +24 -20
  14. package/dist/cjs/src/binance.js +97 -76
  15. package/dist/cjs/src/bingx.js +63 -44
  16. package/dist/cjs/src/bit2c.js +18 -15
  17. package/dist/cjs/src/bitbank.js +16 -15
  18. package/dist/cjs/src/bitbns.js +28 -18
  19. package/dist/cjs/src/bitfinex.js +23 -21
  20. package/dist/cjs/src/bitfinex2.js +32 -28
  21. package/dist/cjs/src/bitflyer.js +28 -20
  22. package/dist/cjs/src/bitforex.js +25 -18
  23. package/dist/cjs/src/bitget.js +184 -147
  24. package/dist/cjs/src/bithumb.js +23 -16
  25. package/dist/cjs/src/bitmart.js +110 -89
  26. package/dist/cjs/src/bitmex.js +104 -64
  27. package/dist/cjs/src/bitopro.js +38 -26
  28. package/dist/cjs/src/bitpanda.js +24 -23
  29. package/dist/cjs/src/bitrue.js +33 -24
  30. package/dist/cjs/src/bitso.js +24 -23
  31. package/dist/cjs/src/bitstamp.js +24 -23
  32. package/dist/cjs/src/bittrex.js +30 -29
  33. package/dist/cjs/src/bitvavo.js +38 -30
  34. package/dist/cjs/src/bl3p.js +11 -10
  35. package/dist/cjs/src/blockchaincom.js +20 -20
  36. package/dist/cjs/src/btcalpha.js +18 -17
  37. package/dist/cjs/src/btcbox.js +13 -12
  38. package/dist/cjs/src/btcmarkets.js +20 -19
  39. package/dist/cjs/src/btcturk.js +14 -13
  40. package/dist/cjs/src/bybit.js +84 -54
  41. package/dist/cjs/src/cex.js +16 -14
  42. package/dist/cjs/src/coinbase.js +29 -27
  43. package/dist/cjs/src/coinbasepro.js +27 -25
  44. package/dist/cjs/src/coincheck.js +15 -14
  45. package/dist/cjs/src/coinex.js +100 -77
  46. package/dist/cjs/src/coinlist.js +28 -27
  47. package/dist/cjs/src/coinmate.js +20 -17
  48. package/dist/cjs/src/coinone.js +21 -16
  49. package/dist/cjs/src/coinsph.js +37 -28
  50. package/dist/cjs/src/coinspot.js +12 -11
  51. package/dist/cjs/src/cryptocom.js +40 -202
  52. package/dist/cjs/src/currencycom.js +32 -25
  53. package/dist/cjs/src/delta.js +34 -28
  54. package/dist/cjs/src/deribit.js +39 -36
  55. package/dist/cjs/src/digifinex.js +64 -44
  56. package/dist/cjs/src/exmo.js +29 -27
  57. package/dist/cjs/src/gate.js +67 -53
  58. package/dist/cjs/src/gemini.js +23 -20
  59. package/dist/cjs/src/hitbtc.js +65 -56
  60. package/dist/cjs/src/hollaex.js +30 -27
  61. package/dist/cjs/src/htx.js +132 -143
  62. package/dist/cjs/src/huobijp.js +22 -20
  63. package/dist/cjs/src/idex.js +22 -21
  64. package/dist/cjs/src/independentreserve.js +15 -14
  65. package/dist/cjs/src/indodax.js +30 -26
  66. package/dist/cjs/src/kraken.js +29 -27
  67. package/dist/cjs/src/krakenfutures.js +29 -22
  68. package/dist/cjs/src/kucoin.js +48 -43
  69. package/dist/cjs/src/kucoinfutures.js +33 -28
  70. package/dist/cjs/src/kuna.js +25 -24
  71. package/dist/cjs/src/latoken.js +24 -22
  72. package/dist/cjs/src/lbank.js +45 -30
  73. package/dist/cjs/src/luno.js +22 -19
  74. package/dist/cjs/src/lykke.js +19 -17
  75. package/dist/cjs/src/mercado.js +30 -19
  76. package/dist/cjs/src/mexc.js +60 -49
  77. package/dist/cjs/src/ndax.js +23 -22
  78. package/dist/cjs/src/novadax.js +23 -22
  79. package/dist/cjs/src/oceanex.js +22 -19
  80. package/dist/cjs/src/okcoin.js +29 -23
  81. package/dist/cjs/src/okx.js +87 -82
  82. package/dist/cjs/src/p2b.js +79 -82
  83. package/dist/cjs/src/paymium.js +10 -10
  84. package/dist/cjs/src/phemex.js +63 -40
  85. package/dist/cjs/src/poloniex.js +22 -22
  86. package/dist/cjs/src/poloniexfutures.js +23 -19
  87. package/dist/cjs/src/pro/alpaca.js +5 -5
  88. package/dist/cjs/src/pro/ascendex.js +4 -4
  89. package/dist/cjs/src/pro/binance.js +16 -16
  90. package/dist/cjs/src/pro/bingx.js +1 -1
  91. package/dist/cjs/src/pro/bitfinex.js +4 -4
  92. package/dist/cjs/src/pro/bitfinex2.js +6 -6
  93. package/dist/cjs/src/pro/bitget.js +7 -7
  94. package/dist/cjs/src/pro/bitmart.js +7 -5
  95. package/dist/cjs/src/pro/bitmex.js +6 -6
  96. package/dist/cjs/src/pro/bitopro.js +4 -4
  97. package/dist/cjs/src/pro/bitpanda.js +6 -6
  98. package/dist/cjs/src/pro/bitrue.js +2 -2
  99. package/dist/cjs/src/pro/bitstamp.js +6 -4
  100. package/dist/cjs/src/pro/bittrex.js +15 -6
  101. package/dist/cjs/src/pro/bitvavo.js +11 -7
  102. package/dist/cjs/src/pro/blockchaincom.js +8 -8
  103. package/dist/cjs/src/pro/bybit.js +7 -7
  104. package/dist/cjs/src/pro/cex.js +13 -9
  105. package/dist/cjs/src/pro/coinbase.js +5 -5
  106. package/dist/cjs/src/pro/coinbasepro.js +11 -10
  107. package/dist/cjs/src/pro/coinex.js +7 -9
  108. package/dist/cjs/src/pro/cryptocom.js +9 -9
  109. package/dist/cjs/src/pro/currencycom.js +4 -4
  110. package/dist/cjs/src/pro/deribit.js +6 -6
  111. package/dist/cjs/src/pro/exmo.js +12 -14
  112. package/dist/cjs/src/pro/gate.js +7 -7
  113. package/dist/cjs/src/pro/gemini.js +3 -3
  114. package/dist/cjs/src/pro/hitbtc.js +263 -4
  115. package/dist/cjs/src/pro/hollaex.js +5 -5
  116. package/dist/cjs/src/pro/htx.js +6 -6
  117. package/dist/cjs/src/pro/huobijp.js +3 -3
  118. package/dist/cjs/src/pro/idex.js +4 -4
  119. package/dist/cjs/src/pro/independentreserve.js +2 -2
  120. package/dist/cjs/src/pro/kraken.js +10 -10
  121. package/dist/cjs/src/pro/krakenfutures.js +41 -17
  122. package/dist/cjs/src/pro/kucoin.js +7 -7
  123. package/dist/cjs/src/pro/kucoinfutures.js +8 -6
  124. package/dist/cjs/src/pro/luno.js +2 -2
  125. package/dist/cjs/src/pro/mexc.js +6 -6
  126. package/dist/cjs/src/pro/ndax.js +3 -3
  127. package/dist/cjs/src/pro/okcoin.js +5 -5
  128. package/dist/cjs/src/pro/okx.js +12 -12
  129. package/dist/cjs/src/pro/phemex.js +6 -6
  130. package/dist/cjs/src/pro/poloniex.js +7 -7
  131. package/dist/cjs/src/pro/poloniexfutures.js +5 -5
  132. package/dist/cjs/src/pro/probit.js +6 -6
  133. package/dist/cjs/src/pro/upbit.js +3 -3
  134. package/dist/cjs/src/pro/wazirx.js +8 -8
  135. package/dist/cjs/src/pro/whitebit.js +12 -8
  136. package/dist/cjs/src/pro/woo.js +1 -1
  137. package/dist/cjs/src/probit.js +28 -23
  138. package/dist/cjs/src/tidex.js +16 -15
  139. package/dist/cjs/src/timex.js +19 -18
  140. package/dist/cjs/src/tokocrypto.js +27 -22
  141. package/dist/cjs/src/upbit.js +19 -19
  142. package/dist/cjs/src/wavesexchange.js +22 -19
  143. package/dist/cjs/src/wazirx.js +24 -17
  144. package/dist/cjs/src/whitebit.js +33 -27
  145. package/dist/cjs/src/woo.js +44 -34
  146. package/dist/cjs/src/yobit.js +25 -20
  147. package/dist/cjs/src/zaif.js +9 -9
  148. package/dist/cjs/src/zonda.js +18 -17
  149. package/js/ccxt.d.ts +1 -1
  150. package/js/ccxt.js +1 -1
  151. package/js/src/abstract/bybit.d.ts +1 -0
  152. package/js/src/abstract/cryptocom.d.ts +0 -20
  153. package/js/src/ace.js +18 -14
  154. package/js/src/alpaca.js +6 -6
  155. package/js/src/ascendex.js +35 -29
  156. package/js/src/base/Exchange.d.ts +37 -34
  157. package/js/src/base/Exchange.js +39 -26
  158. package/js/src/base/Precise.d.ts +4 -4
  159. package/js/src/base/Precise.js +1 -3
  160. package/js/src/base/functions/type.d.ts +25 -25
  161. package/js/src/base/types.d.ts +21 -14
  162. package/js/src/base/ws/Client.js +1 -1
  163. package/js/src/bigone.js +25 -21
  164. package/js/src/binance.d.ts +2 -2
  165. package/js/src/binance.js +97 -76
  166. package/js/src/bingx.js +63 -44
  167. package/js/src/bit2c.js +19 -16
  168. package/js/src/bitbank.js +16 -15
  169. package/js/src/bitbns.js +28 -18
  170. package/js/src/bitfinex.js +23 -21
  171. package/js/src/bitfinex2.js +32 -28
  172. package/js/src/bitflyer.js +28 -20
  173. package/js/src/bitforex.js +26 -19
  174. package/js/src/bitget.d.ts +25 -3
  175. package/js/src/bitget.js +184 -147
  176. package/js/src/bithumb.js +23 -16
  177. package/js/src/bitmart.d.ts +1 -1
  178. package/js/src/bitmart.js +110 -89
  179. package/js/src/bitmex.d.ts +2 -2
  180. package/js/src/bitmex.js +104 -64
  181. package/js/src/bitopro.js +38 -26
  182. package/js/src/bitpanda.js +24 -23
  183. package/js/src/bitrue.js +33 -24
  184. package/js/src/bitso.js +24 -23
  185. package/js/src/bitstamp.d.ts +2 -2
  186. package/js/src/bitstamp.js +24 -23
  187. package/js/src/bittrex.js +30 -29
  188. package/js/src/bitvavo.js +38 -30
  189. package/js/src/bl3p.js +11 -10
  190. package/js/src/blockchaincom.js +20 -20
  191. package/js/src/btcalpha.js +18 -17
  192. package/js/src/btcbox.js +13 -12
  193. package/js/src/btcmarkets.js +20 -19
  194. package/js/src/btcturk.js +14 -13
  195. package/js/src/bybit.d.ts +1 -1
  196. package/js/src/bybit.js +84 -54
  197. package/js/src/cex.js +16 -14
  198. package/js/src/coinbase.js +29 -27
  199. package/js/src/coinbasepro.js +27 -25
  200. package/js/src/coincheck.js +15 -14
  201. package/js/src/coinex.d.ts +1 -1
  202. package/js/src/coinex.js +100 -77
  203. package/js/src/coinlist.js +28 -27
  204. package/js/src/coinmate.js +21 -18
  205. package/js/src/coinone.js +21 -16
  206. package/js/src/coinsph.js +37 -28
  207. package/js/src/coinspot.js +12 -11
  208. package/js/src/cryptocom.d.ts +0 -23
  209. package/js/src/cryptocom.js +40 -202
  210. package/js/src/currencycom.js +32 -25
  211. package/js/src/delta.js +35 -29
  212. package/js/src/deribit.js +39 -36
  213. package/js/src/digifinex.d.ts +2 -2
  214. package/js/src/digifinex.js +65 -45
  215. package/js/src/exmo.js +29 -27
  216. package/js/src/gate.d.ts +1 -1
  217. package/js/src/gate.js +67 -53
  218. package/js/src/gemini.js +23 -20
  219. package/js/src/hitbtc.d.ts +1 -0
  220. package/js/src/hitbtc.js +65 -56
  221. package/js/src/hollaex.js +30 -27
  222. package/js/src/htx.d.ts +11 -3
  223. package/js/src/htx.js +132 -143
  224. package/js/src/huobijp.js +23 -21
  225. package/js/src/idex.js +22 -21
  226. package/js/src/independentreserve.js +15 -14
  227. package/js/src/indodax.js +30 -26
  228. package/js/src/kraken.js +29 -27
  229. package/js/src/krakenfutures.js +29 -22
  230. package/js/src/kucoin.d.ts +1 -1
  231. package/js/src/kucoin.js +48 -43
  232. package/js/src/kucoinfutures.js +33 -28
  233. package/js/src/kuna.js +25 -24
  234. package/js/src/latoken.js +25 -23
  235. package/js/src/lbank.js +46 -31
  236. package/js/src/luno.js +22 -19
  237. package/js/src/lykke.js +19 -17
  238. package/js/src/mercado.js +30 -19
  239. package/js/src/mexc.d.ts +1 -1
  240. package/js/src/mexc.js +60 -49
  241. package/js/src/ndax.js +23 -22
  242. package/js/src/novadax.js +23 -22
  243. package/js/src/oceanex.js +22 -19
  244. package/js/src/okcoin.js +29 -23
  245. package/js/src/okx.d.ts +2 -2
  246. package/js/src/okx.js +87 -82
  247. package/js/src/p2b.d.ts +8 -7
  248. package/js/src/p2b.js +79 -81
  249. package/js/src/paymium.js +10 -10
  250. package/js/src/phemex.js +63 -40
  251. package/js/src/poloniex.js +22 -22
  252. package/js/src/poloniexfutures.js +23 -19
  253. package/js/src/pro/alpaca.js +5 -5
  254. package/js/src/pro/ascendex.js +4 -4
  255. package/js/src/pro/binance.js +16 -16
  256. package/js/src/pro/bingx.js +1 -1
  257. package/js/src/pro/bitfinex.js +4 -4
  258. package/js/src/pro/bitfinex2.d.ts +1 -1
  259. package/js/src/pro/bitfinex2.js +6 -6
  260. package/js/src/pro/bitget.js +7 -7
  261. package/js/src/pro/bitmart.js +7 -5
  262. package/js/src/pro/bitmex.js +6 -6
  263. package/js/src/pro/bitopro.js +4 -4
  264. package/js/src/pro/bitpanda.js +6 -6
  265. package/js/src/pro/bitrue.js +2 -2
  266. package/js/src/pro/bitstamp.js +7 -5
  267. package/js/src/pro/bittrex.js +15 -6
  268. package/js/src/pro/bitvavo.js +12 -8
  269. package/js/src/pro/blockchaincom.js +8 -8
  270. package/js/src/pro/bybit.js +7 -7
  271. package/js/src/pro/cex.js +14 -10
  272. package/js/src/pro/coinbase.js +5 -5
  273. package/js/src/pro/coinbasepro.js +12 -11
  274. package/js/src/pro/coinex.js +7 -9
  275. package/js/src/pro/cryptocom.js +9 -9
  276. package/js/src/pro/currencycom.js +4 -4
  277. package/js/src/pro/deribit.js +6 -6
  278. package/js/src/pro/exmo.js +12 -14
  279. package/js/src/pro/gate.js +7 -7
  280. package/js/src/pro/gemini.js +3 -3
  281. package/js/src/pro/hitbtc.d.ts +8 -1
  282. package/js/src/pro/hitbtc.js +264 -5
  283. package/js/src/pro/hollaex.js +5 -5
  284. package/js/src/pro/htx.js +6 -6
  285. package/js/src/pro/huobijp.js +3 -3
  286. package/js/src/pro/idex.js +4 -4
  287. package/js/src/pro/independentreserve.js +2 -2
  288. package/js/src/pro/kraken.js +10 -10
  289. package/js/src/pro/krakenfutures.d.ts +1 -0
  290. package/js/src/pro/krakenfutures.js +42 -18
  291. package/js/src/pro/kucoin.js +7 -7
  292. package/js/src/pro/kucoinfutures.js +8 -6
  293. package/js/src/pro/luno.js +2 -2
  294. package/js/src/pro/mexc.js +6 -6
  295. package/js/src/pro/ndax.js +3 -3
  296. package/js/src/pro/okcoin.js +5 -5
  297. package/js/src/pro/okx.js +12 -12
  298. package/js/src/pro/phemex.js +6 -6
  299. package/js/src/pro/poloniex.js +7 -7
  300. package/js/src/pro/poloniexfutures.js +5 -5
  301. package/js/src/pro/probit.js +6 -6
  302. package/js/src/pro/upbit.js +3 -3
  303. package/js/src/pro/wazirx.js +8 -8
  304. package/js/src/pro/whitebit.js +13 -9
  305. package/js/src/pro/woo.js +1 -1
  306. package/js/src/probit.js +29 -24
  307. package/js/src/tidex.js +16 -15
  308. package/js/src/timex.js +19 -18
  309. package/js/src/tokocrypto.js +28 -23
  310. package/js/src/upbit.js +19 -19
  311. package/js/src/wavesexchange.js +23 -20
  312. package/js/src/wazirx.js +25 -18
  313. package/js/src/whitebit.js +33 -27
  314. package/js/src/woo.js +45 -35
  315. package/js/src/yobit.js +25 -20
  316. package/js/src/zaif.js +9 -9
  317. package/js/src/zonda.js +18 -17
  318. package/package.json +1 -1
package/js/src/bitmex.js CHANGED
@@ -393,9 +393,7 @@ export default class bitmex extends Exchange {
393
393
  convertToRealAmount(code, amount) {
394
394
  const currency = this.currency(code);
395
395
  const precision = this.safeString(currency, 'precision');
396
- const amountString = this.numberToString(amount);
397
- const finalAmount = Precise.stringMul(amountString, precision);
398
- return this.parseNumber(finalAmount);
396
+ return Precise.stringMul(amount, precision);
399
397
  }
400
398
  amountToPrecision(symbol, amount) {
401
399
  symbol = this.safeSymbol(symbol);
@@ -417,7 +415,7 @@ export default class bitmex extends Exchange {
417
415
  }
418
416
  const market = this.market(symbol);
419
417
  if (market['spot']) {
420
- return this.convertToRealAmount(market[currencySide], rawQuantity);
418
+ return this.parseNumber(this.convertToRealAmount(market[currencySide], rawQuantity));
421
419
  }
422
420
  return this.parseNumber(rawQuantity);
423
421
  }
@@ -432,7 +430,7 @@ export default class bitmex extends Exchange {
432
430
  * @param {object} [params] extra parameters specific to the exchange api endpoint
433
431
  * @returns {object[]} an array of objects representing market data
434
432
  */
435
- const response = await this.publicGetInstrumentActiveAndIndices(params);
433
+ const response = await this.publicGetInstrumentActive(params);
436
434
  //
437
435
  // [
438
436
  // {
@@ -548,30 +546,38 @@ export default class bitmex extends Exchange {
548
546
  }
549
547
  parseMarket(market) {
550
548
  const id = this.safeString(market, 'symbol');
551
- const baseId = this.safeString(market, 'underlying');
552
- const quoteId = this.safeString(market, 'quoteCurrency');
549
+ let baseId = this.safeString(market, 'underlying');
550
+ let quoteId = this.safeString(market, 'quoteCurrency');
553
551
  const settleId = this.safeString(market, 'settlCurrency');
554
- const base = this.safeCurrencyCode(baseId);
555
- const quote = this.safeCurrencyCode(quoteId);
556
552
  const settle = this.safeCurrencyCode(settleId);
557
553
  // 'positionCurrency' may be empty ("", as Bitmex currently returns for ETHUSD)
558
554
  // so let's take the settlCurrency first and then adjust if needed
559
555
  const typ = this.safeString(market, 'typ'); // type definitions at: https://www.bitmex.com/api/explorer/#!/Instrument/Instrument_get
560
- const types = {
561
- 'FFWCSX': 'swap',
562
- 'FFWCSF': 'swap',
563
- 'IFXXXP': 'spot',
564
- 'FFCCSX': 'future',
565
- 'MRBXXX': 'index',
566
- 'MRCXXX': 'index',
567
- 'MRFXXX': 'index',
568
- 'MRRXXX': 'index',
569
- 'MRIXXX': 'index',
570
- };
571
- const type = this.safeString(types, typ, typ);
572
- const swap = type === 'swap';
573
- const future = type === 'future';
574
- const spot = type === 'spot';
556
+ let type;
557
+ let swap = false;
558
+ let spot = false;
559
+ let future = false;
560
+ if (typ === 'FFWCSX') {
561
+ type = 'swap';
562
+ swap = true;
563
+ }
564
+ else if (typ === 'IFXXXP') {
565
+ type = 'spot';
566
+ spot = true;
567
+ }
568
+ else if (typ === 'FFCCSX') {
569
+ type = 'future';
570
+ future = true;
571
+ }
572
+ else if (typ === 'FFICSX') {
573
+ // prediction markets (without any volume)
574
+ quoteId = baseId;
575
+ baseId = this.safeString(market, 'rootSymbol');
576
+ type = 'future';
577
+ future = true;
578
+ }
579
+ const base = this.safeCurrencyCode(baseId);
580
+ const quote = this.safeCurrencyCode(quoteId);
575
581
  const contract = swap || future;
576
582
  let contractSize = undefined;
577
583
  const isInverse = this.safeValue(market, 'isInverse'); // this is true when BASE and SETTLE are same, i.e. BTC/XXX:BTC
@@ -587,11 +593,12 @@ export default class bitmex extends Exchange {
587
593
  }
588
594
  else if (contract) {
589
595
  symbol = base + '/' + quote + ':' + settle;
590
- const multiplierString = Precise.stringAbs(this.safeString(market, 'multiplier'));
591
596
  if (linear) {
592
- contractSize = this.parseNumber(Precise.stringDiv('1', market['underlyingToPositionMultiplier']));
597
+ const multiplierString = this.safeString2(market, 'underlyingToPositionMultiplier', 'underlyingToSettleMultiplier');
598
+ contractSize = this.parseNumber(Precise.stringDiv('1', multiplierString));
593
599
  }
594
600
  else {
601
+ const multiplierString = Precise.stringAbs(this.safeString(market, 'multiplier'));
595
602
  contractSize = this.parseNumber(multiplierString);
596
603
  }
597
604
  if (future) {
@@ -731,7 +738,7 @@ export default class bitmex extends Exchange {
731
738
  * @name bitmex#fetchBalance
732
739
  * @description query for balance and get the amount of funds available for trading or funds locked in orders
733
740
  * @param {object} [params] extra parameters specific to the bitmex api endpoint
734
- * @returns {object} a [balance structure]{@link https://github.com/ccxt/ccxt/wiki/Manual#balance-structure}
741
+ * @returns {object} a [balance structure]{@link https://docs.ccxt.com/#/?id=balance-structure}
735
742
  */
736
743
  await this.loadMarkets();
737
744
  const request = {
@@ -795,7 +802,7 @@ export default class bitmex extends Exchange {
795
802
  * @param {string} symbol unified symbol of the market to fetch the order book for
796
803
  * @param {int} [limit] the maximum amount of order book entries to return
797
804
  * @param {object} [params] extra parameters specific to the bitmex api endpoint
798
- * @returns {object} A dictionary of [order book structures]{@link https://github.com/ccxt/ccxt/wiki/Manual#order-book-structure} indexed by market symbols
805
+ * @returns {object} A dictionary of [order book structures]{@link https://docs.ccxt.com/#/?id=order-book-structure} indexed by market symbols
799
806
  */
800
807
  await this.loadMarkets();
801
808
  const market = this.market(symbol);
@@ -837,7 +844,7 @@ export default class bitmex extends Exchange {
837
844
  * @description fetches information on an order made by the user
838
845
  * @param {string} symbol unified symbol of the market the order was made in
839
846
  * @param {object} [params] extra parameters specific to the bitmex api endpoint
840
- * @returns {object} An [order structure]{@link https://github.com/ccxt/ccxt/wiki/Manual#order-structure}
847
+ * @returns {object} An [order structure]{@link https://docs.ccxt.com/#/?id=order-structure}
841
848
  */
842
849
  const filter = {
843
850
  'filter': {
@@ -863,7 +870,7 @@ export default class bitmex extends Exchange {
863
870
  * @param {object} [params] extra parameters specific to the bitmex api endpoint
864
871
  * @param {int} [params.until] the earliest time in ms to fetch orders for
865
872
  * @param {boolean} [params.paginate] default false, when true will automatically paginate by calling this endpoint multiple times. See in the docs all the [availble parameters](https://github.com/ccxt/ccxt/wiki/Manual#pagination-params)
866
- * @returns {Order[]} a list of [order structures]{@link https://github.com/ccxt/ccxt/wiki/Manual#order-structure}
873
+ * @returns {Order[]} a list of [order structures]{@link https://docs.ccxt.com/#/?id=order-structure}
867
874
  */
868
875
  await this.loadMarkets();
869
876
  let paginate = false;
@@ -907,7 +914,7 @@ export default class bitmex extends Exchange {
907
914
  * @param {int} [since] the earliest time in ms to fetch open orders for
908
915
  * @param {int} [limit] the maximum number of open orders structures to retrieve
909
916
  * @param {object} [params] extra parameters specific to the bitmex api endpoint
910
- * @returns {Order[]} a list of [order structures]{@link https://github.com/ccxt/ccxt/wiki/Manual#order-structure}
917
+ * @returns {Order[]} a list of [order structures]{@link https://docs.ccxt.com/#/?id=order-structure}
911
918
  */
912
919
  const request = {
913
920
  'filter': {
@@ -925,7 +932,7 @@ export default class bitmex extends Exchange {
925
932
  * @param {int} [since] the earliest time in ms to fetch orders for
926
933
  * @param {int} [limit] the maximum number of orde structures to retrieve
927
934
  * @param {object} [params] extra parameters specific to the bitmex api endpoint
928
- * @returns {Order[]} a list of [order structures]{@link https://github.com/ccxt/ccxt/wiki/Manual#order-structure}
935
+ * @returns {Order[]} a list of [order structures]{@link https://docs.ccxt.com/#/?id=order-structure}
929
936
  */
930
937
  // Bitmex barfs if you set 'open': false in the filter...
931
938
  const orders = await this.fetchOrders(symbol, since, limit, params);
@@ -942,7 +949,7 @@ export default class bitmex extends Exchange {
942
949
  * @param {int} [limit] the maximum number of trades structures to retrieve
943
950
  * @param {object} [params] extra parameters specific to the bitmex api endpoint
944
951
  * @param {boolean} [params.paginate] default false, when true will automatically paginate by calling this endpoint multiple times. See in the docs all the [availble parameters](https://github.com/ccxt/ccxt/wiki/Manual#pagination-params)
945
- * @returns {Trade[]} a list of [trade structures]{@link https://github.com/ccxt/ccxt/wiki/Manual#trade-structure}
952
+ * @returns {Trade[]} a list of [trade structures]{@link https://docs.ccxt.com/#/?id=trade-structure}
946
953
  */
947
954
  await this.loadMarkets();
948
955
  let paginate = false;
@@ -1100,15 +1107,15 @@ export default class bitmex extends Exchange {
1100
1107
  // for unrealized pnl and other transactions without a timestamp
1101
1108
  timestamp = 0; // see comments above
1102
1109
  }
1103
- let feeCost = this.safeNumber(item, 'fee', 0);
1110
+ let feeCost = this.safeString(item, 'fee');
1104
1111
  if (feeCost !== undefined) {
1105
1112
  feeCost = this.convertToRealAmount(code, feeCost);
1106
1113
  }
1107
1114
  const fee = {
1108
- 'cost': feeCost,
1115
+ 'cost': this.parseNumber(feeCost),
1109
1116
  'currency': code,
1110
1117
  };
1111
- let after = this.safeNumber(item, 'walletBalance');
1118
+ let after = this.safeString(item, 'walletBalance');
1112
1119
  if (after !== undefined) {
1113
1120
  after = this.convertToRealAmount(code, after);
1114
1121
  }
@@ -1135,7 +1142,7 @@ export default class bitmex extends Exchange {
1135
1142
  'currency': code,
1136
1143
  'amount': amount,
1137
1144
  'before': before,
1138
- 'after': after,
1145
+ 'after': this.parseNumber(after),
1139
1146
  'status': status,
1140
1147
  'fee': fee,
1141
1148
  };
@@ -1149,7 +1156,7 @@ export default class bitmex extends Exchange {
1149
1156
  * @param {int} [since] timestamp in ms of the earliest ledger entry, default is undefined
1150
1157
  * @param {int} [limit] max number of ledger entrys to return, default is undefined
1151
1158
  * @param {object} [params] extra parameters specific to the bitmex api endpoint
1152
- * @returns {object} a [ledger structure]{@link https://github.com/ccxt/ccxt/wiki/Manual#ledger-structure}
1159
+ * @returns {object} a [ledger structure]{@link https://docs.ccxt.com/#/?id=ledger-structure}
1153
1160
  */
1154
1161
  await this.loadMarkets();
1155
1162
  const request = {
@@ -1200,7 +1207,7 @@ export default class bitmex extends Exchange {
1200
1207
  * @param {int} [since] timestamp in ms of the earliest deposit/withdrawal, default is undefined
1201
1208
  * @param {int} [limit] max number of deposit/withdrawals to return, default is undefined
1202
1209
  * @param {object} [params] extra parameters specific to the bitmex api endpoint
1203
- * @returns {object} a list of [transaction structure]{@link https://github.com/ccxt/ccxt/wiki/Manual#transaction-structure}
1210
+ * @returns {object} a list of [transaction structure]{@link https://docs.ccxt.com/#/?id=transaction-structure}
1204
1211
  */
1205
1212
  await this.loadMarkets();
1206
1213
  const request = {
@@ -1289,7 +1296,7 @@ export default class bitmex extends Exchange {
1289
1296
  'type': type,
1290
1297
  'currency': currency['code'],
1291
1298
  'network': this.networkIdToCode(this.safeString(transaction, 'network'), currency['code']),
1292
- 'amount': amount,
1299
+ 'amount': this.parseNumber(amount),
1293
1300
  'status': status,
1294
1301
  'timestamp': transactTime,
1295
1302
  'datetime': this.iso8601(transactTime),
@@ -1304,7 +1311,7 @@ export default class bitmex extends Exchange {
1304
1311
  'comment': undefined,
1305
1312
  'fee': {
1306
1313
  'currency': currency['code'],
1307
- 'cost': feeCost,
1314
+ 'cost': this.parseNumber(feeCost),
1308
1315
  'rate': undefined,
1309
1316
  },
1310
1317
  };
@@ -1316,7 +1323,7 @@ export default class bitmex extends Exchange {
1316
1323
  * @description fetches a price ticker, a statistical calculation with the information calculated over the past 24 hours for a specific market
1317
1324
  * @param {string} symbol unified symbol of the market to fetch the ticker for
1318
1325
  * @param {object} [params] extra parameters specific to the bitmex api endpoint
1319
- * @returns {object} a [ticker structure]{@link https://github.com/ccxt/ccxt/wiki/Manual#ticker-structure}
1326
+ * @returns {object} a [ticker structure]{@link https://docs.ccxt.com/#/?id=ticker-structure}
1320
1327
  */
1321
1328
  await this.loadMarkets();
1322
1329
  const market = this.market(symbol);
@@ -1337,7 +1344,7 @@ export default class bitmex extends Exchange {
1337
1344
  * @description fetches price tickers for multiple markets, statistical calculations with the information calculated over the past 24 hours each market
1338
1345
  * @param {string[]|undefined} symbols unified symbols of the markets to fetch the ticker for, all market tickers are returned if not assigned
1339
1346
  * @param {object} [params] extra parameters specific to the bitmex api endpoint
1340
- * @returns {object} a dictionary of [ticker structures]{@link https://github.com/ccxt/ccxt/wiki/Manual#ticker-structure}
1347
+ * @returns {object} a dictionary of [ticker structures]{@link https://docs.ccxt.com/#/?id=ticker-structure}
1341
1348
  */
1342
1349
  await this.loadMarkets();
1343
1350
  symbols = this.marketSymbols(symbols);
@@ -1742,7 +1749,7 @@ export default class bitmex extends Exchange {
1742
1749
  * @param {int} [limit] the maximum amount of trades to fetch
1743
1750
  * @param {object} [params] extra parameters specific to the bitmex api endpoint
1744
1751
  * @param {boolean} [params.paginate] default false, when true will automatically paginate by calling this endpoint multiple times. See in the docs all the [availble parameters](https://github.com/ccxt/ccxt/wiki/Manual#pagination-params)
1745
- * @returns {Trade[]} a list of [trade structures]{@link https://github.com/ccxt/ccxt/wiki/Manual#public-trades}
1752
+ * @returns {Trade[]} a list of [trade structures]{@link https://docs.ccxt.com/#/?id=public-trades}
1746
1753
  */
1747
1754
  await this.loadMarkets();
1748
1755
  let paginate = false;
@@ -1805,12 +1812,15 @@ export default class bitmex extends Exchange {
1805
1812
  * @method
1806
1813
  * @name bitmex#createOrder
1807
1814
  * @description create a trade order
1815
+ * @see https://www.bitmex.com/api/explorer/#!/Order/Order_new
1808
1816
  * @param {string} symbol unified symbol of the market to create an order in
1809
1817
  * @param {string} type 'market' or 'limit'
1810
1818
  * @param {string} side 'buy' or 'sell'
1811
1819
  * @param {float} amount how much of currency you want to trade in units of base currency
1812
1820
  * @param {float} [price] the price at which the order is to be fullfilled, in units of the quote currency, ignored in market orders
1813
1821
  * @param {object} [params] extra parameters specific to the bitmex api endpoint
1822
+ * @param {object} [params.triggerPrice] the price at which a trigger order is triggered at
1823
+ * @param {object} [params.triggerDirection] the direction whenever the trigger happens with relation to price - 'above' or 'below'
1814
1824
  * @returns {object} an [order structure]{@link https://github.com/ccxt/ccxt/wiki/Manual#order-structure}
1815
1825
  */
1816
1826
  await this.loadMarkets();
@@ -1831,15 +1841,41 @@ export default class bitmex extends Exchange {
1831
1841
  'ordType': orderType,
1832
1842
  'text': brokerId,
1833
1843
  };
1834
- if ((orderType === 'Stop') || (orderType === 'StopLimit') || (orderType === 'MarketIfTouched') || (orderType === 'LimitIfTouched')) {
1835
- const stopPrice = this.safeNumber2(params, 'stopPx', 'stopPrice');
1836
- if (stopPrice === undefined) {
1837
- throw new ArgumentsRequired(this.id + ' createOrder() requires a stopPx or stopPrice parameter for the ' + orderType + ' order type');
1844
+ const customTriggerType = (orderType === 'Stop') || (orderType === 'StopLimit') || (orderType === 'MarketIfTouched') || (orderType === 'LimitIfTouched');
1845
+ // support for unified trigger format
1846
+ const triggerPrice = this.safeNumberN(params, ['triggerPrice', 'stopPx', 'stopPrice']);
1847
+ if ((triggerPrice !== undefined) && !customTriggerType) {
1848
+ request['stopPx'] = parseFloat(this.priceToPrecision(symbol, triggerPrice));
1849
+ const triggerDirection = this.safeString(params, 'triggerDirection');
1850
+ params = this.omit(params, ['triggerPrice', 'stopPrice', 'stopPx', 'triggerDirection']);
1851
+ const triggerAbove = (triggerDirection === 'above');
1852
+ this.checkRequiredArgument('createOrder', triggerDirection, 'triggerDirection', ['above', 'below']);
1853
+ this.checkRequiredArgument('createOrder', side, 'side', ['buy', 'sell']);
1854
+ if (type === 'limit') {
1855
+ request['price'] = parseFloat(this.priceToPrecision(symbol, price));
1856
+ if (side === 'buy') {
1857
+ request['ordType'] = triggerAbove ? 'StopLimit' : 'LimitIfTouched';
1858
+ }
1859
+ else {
1860
+ request['ordType'] = triggerAbove ? 'LimitIfTouched' : 'StopLimit';
1861
+ }
1838
1862
  }
1839
- else {
1840
- request['stopPx'] = parseFloat(this.priceToPrecision(symbol, stopPrice));
1841
- params = this.omit(params, ['stopPx', 'stopPrice']);
1863
+ else if (type === 'market') {
1864
+ if (side === 'buy') {
1865
+ request['ordType'] = triggerAbove ? 'Stop' : 'MarketIfTouched';
1866
+ }
1867
+ else {
1868
+ request['ordType'] = triggerAbove ? 'MarketIfTouched' : 'Stop';
1869
+ }
1870
+ }
1871
+ }
1872
+ else if (customTriggerType) {
1873
+ if (triggerPrice === undefined) {
1874
+ // if exchange specific trigger types were provided
1875
+ throw new ArgumentsRequired(this.id + ' createOrder() requires a triggerPrice (stopPx|stopPrice) parameter for the ' + orderType + ' order type');
1842
1876
  }
1877
+ params = this.omit(params, ['triggerPrice', 'stopPrice', 'stopPx']);
1878
+ request['stopPx'] = parseFloat(this.priceToPrecision(symbol, triggerPrice));
1843
1879
  }
1844
1880
  if ((orderType === 'Limit') || (orderType === 'StopLimit') || (orderType === 'LimitIfTouched')) {
1845
1881
  request['price'] = parseFloat(this.priceToPrecision(symbol, price));
@@ -1887,7 +1923,7 @@ export default class bitmex extends Exchange {
1887
1923
  * @param {string} id order id
1888
1924
  * @param {string} symbol not used by bitmex cancelOrder ()
1889
1925
  * @param {object} [params] extra parameters specific to the bitmex api endpoint
1890
- * @returns {object} An [order structure]{@link https://github.com/ccxt/ccxt/wiki/Manual#order-structure}
1926
+ * @returns {object} An [order structure]{@link https://docs.ccxt.com/#/?id=order-structure}
1891
1927
  */
1892
1928
  await this.loadMarkets();
1893
1929
  // https://github.com/ccxt/ccxt/issues/6507
@@ -1918,7 +1954,7 @@ export default class bitmex extends Exchange {
1918
1954
  * @param {string[]} ids order ids
1919
1955
  * @param {string} symbol not used by bitmex cancelOrders ()
1920
1956
  * @param {object} [params] extra parameters specific to the bitmex api endpoint
1921
- * @returns {object} an list of [order structures]{@link https://github.com/ccxt/ccxt/wiki/Manual#order-structure}
1957
+ * @returns {object} an list of [order structures]{@link https://docs.ccxt.com/#/?id=order-structure}
1922
1958
  */
1923
1959
  // return await this.cancelOrder (ids, symbol, params);
1924
1960
  await this.loadMarkets();
@@ -1942,7 +1978,7 @@ export default class bitmex extends Exchange {
1942
1978
  * @description cancel all open orders
1943
1979
  * @param {string} symbol unified market symbol, only orders in the market of this symbol are cancelled when symbol is not undefined
1944
1980
  * @param {object} [params] extra parameters specific to the bitmex api endpoint
1945
- * @returns {object[]} a list of [order structures]{@link https://github.com/ccxt/ccxt/wiki/Manual#order-structure}
1981
+ * @returns {object[]} a list of [order structures]{@link https://docs.ccxt.com/#/?id=order-structure}
1946
1982
  */
1947
1983
  await this.loadMarkets();
1948
1984
  const request = {};
@@ -2000,7 +2036,7 @@ export default class bitmex extends Exchange {
2000
2036
  * @description fetch all open positions
2001
2037
  * @param {string[]|undefined} symbols list of unified market symbols
2002
2038
  * @param {object} [params] extra parameters specific to the bitmex api endpoint
2003
- * @returns {object[]} a list of [position structure]{@link https://github.com/ccxt/ccxt/wiki/Manual#position-structure}
2039
+ * @returns {object[]} a list of [position structure]{@link https://docs.ccxt.com/#/?id=position-structure}
2004
2040
  */
2005
2041
  await this.loadMarkets();
2006
2042
  const response = await this.privateGetPosition(params);
@@ -2261,7 +2297,7 @@ export default class bitmex extends Exchange {
2261
2297
  * @param {string} address the address to withdraw to
2262
2298
  * @param {string} tag
2263
2299
  * @param {object} [params] extra parameters specific to the bitmex api endpoint
2264
- * @returns {object} a [transaction structure]{@link https://github.com/ccxt/ccxt/wiki/Manual#transaction-structure}
2300
+ * @returns {object} a [transaction structure]{@link https://docs.ccxt.com/#/?id=transaction-structure}
2265
2301
  */
2266
2302
  [tag, params] = this.handleWithdrawTagAndParams(tag, params);
2267
2303
  this.checkAddress(address);
@@ -2305,7 +2341,7 @@ export default class bitmex extends Exchange {
2305
2341
  * @description fetch the funding rate for multiple markets
2306
2342
  * @param {string[]|undefined} symbols list of unified market symbols
2307
2343
  * @param {object} [params] extra parameters specific to the bitmex api endpoint
2308
- * @returns {object} a dictionary of [funding rates structures]{@link https://github.com/ccxt/ccxt/wiki/Manual#funding-rates-structure}, indexe by market symbols
2344
+ * @returns {object} a dictionary of [funding rates structures]{@link https://docs.ccxt.com/#/?id=funding-rates-structure}, indexe by market symbols
2309
2345
  */
2310
2346
  await this.loadMarkets();
2311
2347
  const response = await this.publicGetInstrumentActiveAndIndices(params);
@@ -2356,14 +2392,14 @@ export default class bitmex extends Exchange {
2356
2392
  * @description Fetches the history of funding rates
2357
2393
  * @param {string} symbol unified symbol of the market to fetch the funding rate history for
2358
2394
  * @param {int} [since] timestamp in ms of the earliest funding rate to fetch
2359
- * @param {int} [limit] the maximum amount of [funding rate structures]{@link https://github.com/ccxt/ccxt/wiki/Manual#funding-rate-history-structure} to fetch
2395
+ * @param {int} [limit] the maximum amount of [funding rate structures]{@link https://docs.ccxt.com/#/?id=funding-rate-history-structure} to fetch
2360
2396
  * @param {object} [params] extra parameters specific to the bitmex api endpoint
2361
2397
  * @param {int} [params.until] timestamp in ms for ending date filter
2362
2398
  * @param {bool} [params.reverse] if true, will sort results newest first
2363
2399
  * @param {int} [params.start] starting point for results
2364
2400
  * @param {string} [params.columns] array of column names to fetch in info, if omitted, will return all columns
2365
2401
  * @param {string} [params.filter] generic table filter, send json key/value pairs, such as {"key": "value"}, you can key on individual fields, and do more advanced querying on timestamps, see the [timestamp docs]{@link https://www.bitmex.com/app/restAPI#Timestamp-Filters} for more details
2366
- * @returns {object[]} a list of [funding rate structures]{@link https://github.com/ccxt/ccxt/wiki/Manual#funding-rate-history-structure}
2402
+ * @returns {object[]} a list of [funding rate structures]{@link https://docs.ccxt.com/#/?id=funding-rate-history-structure}
2367
2403
  */
2368
2404
  await this.loadMarkets();
2369
2405
  const request = {};
@@ -2442,7 +2478,9 @@ export default class bitmex extends Exchange {
2442
2478
  * @param {object} [params] extra parameters specific to the bitmex api endpoint
2443
2479
  * @returns {object} response from the exchange
2444
2480
  */
2445
- this.checkRequiredSymbol('setLeverage', symbol);
2481
+ if (symbol === undefined) {
2482
+ throw new ArgumentsRequired(this.id + ' setLeverage() requires a symbol argument');
2483
+ }
2446
2484
  if ((leverage < 0.01) || (leverage > 100)) {
2447
2485
  throw new BadRequest(this.id + ' leverage should be between 0.01 and 100');
2448
2486
  }
@@ -2467,7 +2505,9 @@ export default class bitmex extends Exchange {
2467
2505
  * @param {object} [params] extra parameters specific to the bitmex api endpoint
2468
2506
  * @returns {object} response from the exchange
2469
2507
  */
2470
- this.checkRequiredSymbol('setMarginMode', symbol);
2508
+ if (symbol === undefined) {
2509
+ throw new ArgumentsRequired(this.id + ' setMarginMode() requires a symbol argument');
2510
+ }
2471
2511
  marginMode = marginMode.toLowerCase();
2472
2512
  if (marginMode !== 'isolated' && marginMode !== 'cross') {
2473
2513
  throw new BadRequest(this.id + ' setMarginMode() marginMode argument should be isolated or cross');
@@ -2493,7 +2533,7 @@ export default class bitmex extends Exchange {
2493
2533
  * @param {string} code unified currency code
2494
2534
  * @param {object} [params] extra parameters specific to the bitmex api endpoint
2495
2535
  * @param {string} [params.network] deposit chain, can view all chains via this.publicGetWalletAssets, default is eth, unless the currency has a default chain within this.options['networks']
2496
- * @returns {object} an [address structure]{@link https://github.com/ccxt/ccxt/wiki/Manual#address-structure}
2536
+ * @returns {object} an [address structure]{@link https://docs.ccxt.com/#/?id=address-structure}
2497
2537
  */
2498
2538
  await this.loadMarkets();
2499
2539
  let networkCode = undefined;
@@ -2593,7 +2633,7 @@ export default class bitmex extends Exchange {
2593
2633
  * @see https://www.bitmex.com/api/explorer/#!/Wallet/Wallet_getAssetsConfig
2594
2634
  * @param {string[]|undefined} codes list of unified currency codes
2595
2635
  * @param {object} [params] extra parameters specific to the bitmex api endpoint
2596
- * @returns {object} a list of [fee structures]{@link https://github.com/ccxt/ccxt/wiki/Manual#fee-structure}
2636
+ * @returns {object} a list of [fee structures]{@link https://docs.ccxt.com/#/?id=fee-structure}
2597
2637
  */
2598
2638
  await this.loadMarkets();
2599
2639
  const assets = await this.publicGetWalletAssets(params);
@@ -2653,7 +2693,7 @@ export default class bitmex extends Exchange {
2653
2693
  * @param {object} [params] exchange specific parameters for the bitmex api endpoint
2654
2694
  * @param {int} [params.until] timestamp in ms of the latest liquidation
2655
2695
  * @param {boolean} [params.paginate] default false, when true will automatically paginate by calling this endpoint multiple times. See in the docs all the [availble parameters](https://github.com/ccxt/ccxt/wiki/Manual#pagination-params)
2656
- * @returns {object} an array of [liquidation structures]{@link https://github.com/ccxt/ccxt/wiki/Manual#liquidation-structure}
2696
+ * @returns {object} an array of [liquidation structures]{@link https://docs.ccxt.com/#/?id=liquidation-structure}
2657
2697
  */
2658
2698
  await this.loadMarkets();
2659
2699
  let paginate = false;