ccxt 4.1.89 → 4.1.91

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 (65) hide show
  1. package/README.md +3 -3
  2. package/dist/ccxt.browser.js +936 -358
  3. package/dist/ccxt.browser.min.js +3 -3
  4. package/dist/cjs/ccxt.js +1 -1
  5. package/dist/cjs/src/base/Exchange.js +2 -2
  6. package/dist/cjs/src/binance.js +61 -0
  7. package/dist/cjs/src/bitforex.js +2 -0
  8. package/dist/cjs/src/bitget.js +11 -4
  9. package/dist/cjs/src/bitmex.js +2 -0
  10. package/dist/cjs/src/blockchaincom.js +0 -41
  11. package/dist/cjs/src/bybit.js +29 -14
  12. package/dist/cjs/src/coinlist.js +2 -0
  13. package/dist/cjs/src/coinsph.js +2 -0
  14. package/dist/cjs/src/cryptocom.js +2 -0
  15. package/dist/cjs/src/gate.js +276 -11
  16. package/dist/cjs/src/htx.js +264 -219
  17. package/dist/cjs/src/kucoin.js +1 -0
  18. package/dist/cjs/src/kucoinfutures.js +37 -0
  19. package/dist/cjs/src/kuna.js +2 -0
  20. package/dist/cjs/src/mexc.js +2 -0
  21. package/dist/cjs/src/okcoin.js +4 -1
  22. package/dist/cjs/src/phemex.js +160 -26
  23. package/dist/cjs/src/poloniex.js +28 -2
  24. package/dist/cjs/src/pro/binance.js +6 -6
  25. package/dist/cjs/src/pro/bitmart.js +19 -18
  26. package/dist/cjs/src/pro/poloniex.js +15 -10
  27. package/dist/cjs/src/tokocrypto.js +2 -0
  28. package/dist/cjs/src/wazirx.js +2 -0
  29. package/dist/cjs/src/whitebit.js +2 -0
  30. package/dist/cjs/src/zaif.js +2 -3
  31. package/js/ccxt.d.ts +1 -1
  32. package/js/ccxt.js +1 -1
  33. package/js/src/base/Exchange.js +2 -2
  34. package/js/src/binance.d.ts +3 -0
  35. package/js/src/binance.js +61 -0
  36. package/js/src/bitforex.js +2 -0
  37. package/js/src/bitget.js +11 -4
  38. package/js/src/bitmex.js +2 -0
  39. package/js/src/blockchaincom.d.ts +0 -2
  40. package/js/src/blockchaincom.js +0 -41
  41. package/js/src/bybit.js +29 -14
  42. package/js/src/coinlist.js +2 -0
  43. package/js/src/coinsph.js +2 -0
  44. package/js/src/cryptocom.js +2 -0
  45. package/js/src/gate.d.ts +47 -0
  46. package/js/src/gate.js +276 -11
  47. package/js/src/htx.js +264 -219
  48. package/js/src/kucoin.js +1 -0
  49. package/js/src/kucoinfutures.d.ts +1 -0
  50. package/js/src/kucoinfutures.js +37 -0
  51. package/js/src/kuna.js +2 -0
  52. package/js/src/mexc.js +2 -0
  53. package/js/src/okcoin.js +4 -1
  54. package/js/src/phemex.d.ts +1 -0
  55. package/js/src/phemex.js +160 -26
  56. package/js/src/poloniex.js +28 -2
  57. package/js/src/pro/binance.js +6 -6
  58. package/js/src/pro/bitmart.d.ts +1 -1
  59. package/js/src/pro/bitmart.js +19 -18
  60. package/js/src/pro/poloniex.js +16 -11
  61. package/js/src/tokocrypto.js +2 -0
  62. package/js/src/wazirx.js +2 -0
  63. package/js/src/whitebit.js +2 -0
  64. package/js/src/zaif.js +2 -3
  65. package/package.json +1 -1
@@ -490,6 +490,7 @@ class kucoin extends kucoin$1 {
490
490
  'commonCurrencies': {
491
491
  'BIFI': 'BIFIF',
492
492
  'VAI': 'VAIOT',
493
+ 'WAX': 'WAXP',
493
494
  },
494
495
  'options': {
495
496
  'version': 'v1',
@@ -35,6 +35,8 @@ class kucoinfutures extends kucoinfutures$1 {
35
35
  'createStopLimitOrder': true,
36
36
  'createStopMarketOrder': true,
37
37
  'createStopOrder': true,
38
+ 'closePosition': true,
39
+ 'closePositions': false,
38
40
  'fetchAccounts': true,
39
41
  'fetchBalance': true,
40
42
  'fetchBorrowRateHistories': false,
@@ -2412,6 +2414,41 @@ class kucoinfutures extends kucoinfutures$1 {
2412
2414
  'datetime': this.iso8601(timestamp),
2413
2415
  };
2414
2416
  }
2417
+ async closePosition(symbol, side = undefined, params = {}) {
2418
+ /**
2419
+ * @method
2420
+ * @name kucoinfutures#closePosition
2421
+ * @description closes open positions for a market
2422
+ * @see https://www.kucoin.com/docs/rest/futures-trading/orders/place-order
2423
+ * @param {string} symbol Unified CCXT market symbol
2424
+ * @param {string} side not used by kucoinfutures closePositions
2425
+ * @param {object} [params] extra parameters specific to the okx api endpoint
2426
+ * @param {string} [params.clientOrderId] client order id of the order
2427
+ * @returns {[object]} [A list of position structures]{@link https://docs.ccxt.com/#/?id=position-structure}
2428
+ */
2429
+ await this.loadMarkets();
2430
+ const market = this.market(symbol);
2431
+ let clientOrderId = this.safeString(params, 'clientOrderId');
2432
+ const testOrder = this.safeValue(params, 'test', false);
2433
+ params = this.omit(params, ['test', 'clientOrderId']);
2434
+ if (clientOrderId === undefined) {
2435
+ clientOrderId = this.numberToString(this.nonce());
2436
+ }
2437
+ const request = {
2438
+ 'symbol': market['id'],
2439
+ 'closeOrder': true,
2440
+ 'clientOid': clientOrderId,
2441
+ 'type': 'market',
2442
+ };
2443
+ let response = undefined;
2444
+ if (testOrder) {
2445
+ response = await this.futuresPrivatePostOrdersTest(this.extend(request, params));
2446
+ }
2447
+ else {
2448
+ response = await this.futuresPrivatePostOrders(this.extend(request, params));
2449
+ }
2450
+ return this.parseOrder(response, market);
2451
+ }
2415
2452
  }
2416
2453
 
2417
2454
  module.exports = kucoinfutures;
@@ -94,6 +94,8 @@ class kuna extends kuna$1 {
94
94
  'fetchWithdrawal': true,
95
95
  'fetchWithdrawals': true,
96
96
  'reduceMargin': false,
97
+ 'repayCrossMargin': false,
98
+ 'repayIsolatedMargin': false,
97
99
  'setLeverage': false,
98
100
  'setMargin': false,
99
101
  'setMarginMode': false,
@@ -106,6 +106,8 @@ class mexc extends mexc$1 {
106
106
  'fetchWithdrawal': undefined,
107
107
  'fetchWithdrawals': true,
108
108
  'reduceMargin': true,
109
+ 'repayCrossMargin': false,
110
+ 'repayIsolatedMargin': false,
109
111
  'setLeverage': true,
110
112
  'setMarginMode': undefined,
111
113
  'setPositionMode': true,
@@ -1423,7 +1423,7 @@ class okcoin extends okcoin$1 {
1423
1423
  }
1424
1424
  if (isMarketOrder || marketIOC) {
1425
1425
  request['ordType'] = 'market';
1426
- if ((side === 'buy')) {
1426
+ if (side === 'buy') {
1427
1427
  // spot market buy: "sz" can refer either to base currency units or to quote currency units
1428
1428
  // see documentation: https://www.okx.com/docs-v5/en/#rest-api-trade-place-order
1429
1429
  if (tgtCcy === 'quote_ccy') {
@@ -1456,6 +1456,9 @@ class okcoin extends okcoin$1 {
1456
1456
  request['sz'] = this.amountToPrecision(symbol, amount);
1457
1457
  }
1458
1458
  }
1459
+ else {
1460
+ request['sz'] = this.amountToPrecision(symbol, amount);
1461
+ }
1459
1462
  }
1460
1463
  else {
1461
1464
  request['sz'] = this.amountToPrecision(symbol, amount);
@@ -83,7 +83,7 @@ class phemex extends phemex$1 {
83
83
  'setMarginMode': true,
84
84
  'setPositionMode': true,
85
85
  'transfer': true,
86
- 'withdraw': undefined,
86
+ 'withdraw': true,
87
87
  },
88
88
  'urls': {
89
89
  'logo': 'https://user-images.githubusercontent.com/1294454/85225056-221eb600-b3d7-11ea-930d-564d2690e3f6.jpg',
@@ -222,6 +222,7 @@ class phemex extends phemex$1 {
222
222
  'assets/spots/sub-accounts/transfer': 5,
223
223
  'assets/futures/sub-accounts/transfer': 5,
224
224
  'assets/quote': 5, // ?fromCurrency=<currency>&toCurrency=<currency>&amountEv=<amount>
225
+ // deposit/withdraw
225
226
  },
226
227
  'post': {
227
228
  // spot
@@ -456,6 +457,7 @@ class phemex extends phemex$1 {
456
457
  'networks': {
457
458
  'TRC20': 'TRX',
458
459
  'ERC20': 'ETH',
460
+ 'BEP20': 'BNB',
459
461
  },
460
462
  'defaultNetworks': {
461
463
  'USDT': 'ETH',
@@ -465,6 +467,16 @@ class phemex extends phemex$1 {
465
467
  'spot': 'spot',
466
468
  'swap': 'future',
467
469
  },
470
+ 'stableCoins': [
471
+ 'BUSD',
472
+ 'FEI',
473
+ 'TUSD',
474
+ 'USD',
475
+ 'USDC',
476
+ 'USDD',
477
+ 'USDP',
478
+ 'USDT',
479
+ ],
468
480
  'transfer': {
469
481
  'fillResponseFromRequest': true,
470
482
  },
@@ -3384,6 +3396,19 @@ class phemex extends phemex$1 {
3384
3396
  const statuses = {
3385
3397
  'Success': 'ok',
3386
3398
  'Succeed': 'ok',
3399
+ 'Rejected': 'failed',
3400
+ 'Security check failed': 'failed',
3401
+ 'SecurityCheckFailed': 'failed',
3402
+ 'Expired': 'failed',
3403
+ 'Address Risk': 'failed',
3404
+ 'Security Checking': 'pending',
3405
+ 'SecurityChecking': 'pending',
3406
+ 'Pending Review': 'pending',
3407
+ 'Pending Transfer': 'pending',
3408
+ 'AmlCsApporve': 'pending',
3409
+ 'New': 'pending',
3410
+ 'Confirmed': 'pending',
3411
+ 'Cancelled': 'canceled',
3387
3412
  };
3388
3413
  return this.safeString(statuses, status, status);
3389
3414
  }
@@ -3391,36 +3416,68 @@ class phemex extends phemex$1 {
3391
3416
  //
3392
3417
  // withdraw
3393
3418
  //
3394
- // ...
3419
+ // {
3420
+ // "id": "10000001",
3421
+ // "freezeId": null,
3422
+ // "address": "44exxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
3423
+ // "amountRv": "100",
3424
+ // "chainCode": "11",
3425
+ // "chainName": "TRX",
3426
+ // "currency": "USDT",
3427
+ // "currencyCode": 3,
3428
+ // "email": "abc@gmail.com",
3429
+ // "expiredTime": "0",
3430
+ // "feeRv": "1",
3431
+ // "nickName": null,
3432
+ // "phone": null,
3433
+ // "rejectReason": "",
3434
+ // "submitedAt": "1670000000000",
3435
+ // "submittedAt": "1670000000000",
3436
+ // "txHash": null,
3437
+ // "userId": "10000001",
3438
+ // "status": "Success"
3395
3439
  //
3396
3440
  // fetchDeposits
3397
3441
  //
3398
3442
  // {
3399
- // "id":29200,
3400
- // "currency":"USDT",
3401
- // "currencyCode":3,
3402
- // "txHash":"0x0bdbdc47807769a03b158d5753f54dfc58b92993d2f5e818db21863e01238e5d",
3403
- // "address":"0x5bfbf60e0fa7f63598e6cfd8a7fd3ffac4ccc6ad",
3404
- // "amountEv":3000000000,
3405
- // "confirmations":13,
3406
- // "type":"Deposit",
3407
- // "status":"Success",
3408
- // "createdAt":1592722565000
3443
+ // "id": "29200",
3444
+ // "currency": "USDT",
3445
+ // "currencyCode": "3",
3446
+ // "chainName": "ETH",
3447
+ // "chainCode": "4",
3448
+ // "txHash": "0x0bdbdc47807769a03b158d5753f54dfc58b92993d2f5e818db21863e01238e5d",
3449
+ // "address": "0x5bfbf60e0fa7f63598e6cfd8a7fd3ffac4ccc6ad",
3450
+ // "amountEv": "3000000000",
3451
+ // "confirmations": "13",
3452
+ // "type": "Deposit",
3453
+ // "status": "Success",
3454
+ // "createdAt": "1592722565000",
3409
3455
  // }
3410
3456
  //
3411
3457
  // fetchWithdrawals
3412
3458
  //
3413
3459
  // {
3414
- // "address": "1Lxxxxxxxxxxx"
3415
- // "amountEv": 200000
3416
- // "currency": "BTC"
3417
- // "currencyCode": 1
3418
- // "expiredTime": 0
3419
- // "feeEv": 50000
3420
- // "rejectReason": null
3421
- // "status": "Succeed"
3422
- // "txHash": "44exxxxxxxxxxxxxxxxxxxxxx"
3423
- // "withdrawStatus: ""
3460
+ // "id": "10000001",
3461
+ // "userId": "10000001",
3462
+ // "freezeId": "10000002",
3463
+ // "phone": null,
3464
+ // "email": "abc@gmail.com",
3465
+ // "nickName": null,
3466
+ // "currency": "USDT",
3467
+ // "currencyCode": "3",
3468
+ // "status": "Succeed",
3469
+ // "withdrawStatus": "Succeed",
3470
+ // "amountEv": "8800000000",
3471
+ // "feeEv": "1200000000",
3472
+ // "address": "0x5xxxad",
3473
+ // "txHash: "0x0xxxx5d",
3474
+ // "submitedAt": "1702571922000",
3475
+ // "submittedAt": "1702571922000",
3476
+ // "expiredTime": "0",
3477
+ // "rejectReason": null,
3478
+ // "chainName": "ETH",
3479
+ // "chainCode": "4",
3480
+ // "proxyAddress": null
3424
3481
  // }
3425
3482
  //
3426
3483
  const id = this.safeString(transaction, 'id');
@@ -3430,9 +3487,13 @@ class phemex extends phemex$1 {
3430
3487
  const currencyId = this.safeString(transaction, 'currency');
3431
3488
  currency = this.safeCurrency(currencyId, currency);
3432
3489
  const code = currency['code'];
3433
- const timestamp = this.safeInteger2(transaction, 'createdAt', 'submitedAt');
3490
+ const networkId = this.safeString(transaction, 'chainName');
3491
+ const timestamp = this.safeIntegerN(transaction, ['createdAt', 'submitedAt', 'submittedAt']);
3434
3492
  let type = this.safeStringLower(transaction, 'type');
3435
- const feeCost = this.parseNumber(this.fromEn(this.safeString(transaction, 'feeEv'), currency['valueScale']));
3493
+ let feeCost = this.parseNumber(this.fromEn(this.safeString(transaction, 'feeEv'), currency['valueScale']));
3494
+ if (feeCost === undefined) {
3495
+ feeCost = this.safeNumber(transaction, 'feeRv');
3496
+ }
3436
3497
  let fee = undefined;
3437
3498
  if (feeCost !== undefined) {
3438
3499
  type = 'withdrawal';
@@ -3442,14 +3503,17 @@ class phemex extends phemex$1 {
3442
3503
  };
3443
3504
  }
3444
3505
  const status = this.parseTransactionStatus(this.safeString(transaction, 'status'));
3445
- const amount = this.parseNumber(this.fromEn(this.safeString(transaction, 'amountEv'), currency['valueScale']));
3506
+ let amount = this.parseNumber(this.fromEn(this.safeString(transaction, 'amountEv'), currency['valueScale']));
3507
+ if (amount === undefined) {
3508
+ amount = this.safeNumber(transaction, 'amountRv');
3509
+ }
3446
3510
  return {
3447
3511
  'info': transaction,
3448
3512
  'id': id,
3449
3513
  'txid': txid,
3450
3514
  'timestamp': timestamp,
3451
3515
  'datetime': this.iso8601(timestamp),
3452
- 'network': undefined,
3516
+ 'network': this.networkIdToCode(networkId),
3453
3517
  'address': address,
3454
3518
  'addressTo': address,
3455
3519
  'addressFrom': undefined,
@@ -4554,6 +4618,76 @@ class phemex extends phemex$1 {
4554
4618
  const sorted = this.sortBy(result, 'timestamp');
4555
4619
  return this.filterBySymbolSinceLimit(sorted, symbol, since, limit);
4556
4620
  }
4621
+ async withdraw(code, amount, address, tag = undefined, params = {}) {
4622
+ /**
4623
+ * @method
4624
+ * @name phemex#withdraw
4625
+ * @description make a withdrawal
4626
+ * @see https://phemex-docs.github.io/#create-withdraw-request
4627
+ * @param {string} code unified currency code
4628
+ * @param {float} amount the amount to withdraw
4629
+ * @param {string} address the address to withdraw to
4630
+ * @param {string} tag
4631
+ * @param {object} [params] extra parameters specific to the phemex api endpoint
4632
+ * @param {string} [params.network] unified network code
4633
+ * @returns {object} a [transaction structure]{@link https://github.com/ccxt/ccxt/wiki/Manual#transaction-structure}
4634
+ */
4635
+ [tag, params] = this.handleWithdrawTagAndParams(tag, params);
4636
+ await this.loadMarkets();
4637
+ this.checkAddress(address);
4638
+ const currency = this.currency(code);
4639
+ let networkCode = undefined;
4640
+ [networkCode, params] = this.handleNetworkCodeAndParams(params);
4641
+ let networkId = this.networkCodeToId(networkCode);
4642
+ const stableCoins = this.safeValue(this.options, 'stableCoins');
4643
+ if (networkId === undefined) {
4644
+ if (!(this.inArray(code, stableCoins))) {
4645
+ networkId = currency['id'];
4646
+ }
4647
+ else {
4648
+ throw new errors.ArgumentsRequired(this.id + ' withdraw () requires an extra argument params["network"]');
4649
+ }
4650
+ }
4651
+ const request = {
4652
+ 'currency': currency['id'],
4653
+ 'address': address,
4654
+ 'amount': amount,
4655
+ 'chainName': networkId.toUpperCase(),
4656
+ };
4657
+ if (tag !== undefined) {
4658
+ request['addressTag'] = tag;
4659
+ }
4660
+ const response = await this.privatePostPhemexWithdrawWalletsApiCreateWithdraw(this.extend(request, params));
4661
+ //
4662
+ // {
4663
+ // "code": 0,
4664
+ // "msg": "OK",
4665
+ // "data": {
4666
+ // "id": "10000001",
4667
+ // "freezeId": null,
4668
+ // "address": "44exxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
4669
+ // "amountRv": "100",
4670
+ // "chainCode": "11",
4671
+ // "chainName": "TRX",
4672
+ // "currency": "USDT",
4673
+ // "currencyCode": 3,
4674
+ // "email": "abc@gmail.com",
4675
+ // "expiredTime": "0",
4676
+ // "feeRv": "1",
4677
+ // "nickName": null,
4678
+ // "phone": null,
4679
+ // "rejectReason": "",
4680
+ // "submitedAt": "1670000000000",
4681
+ // "submittedAt": "1670000000000",
4682
+ // "txHash": null,
4683
+ // "userId": "10000001",
4684
+ // "status": "Success"
4685
+ // }
4686
+ // }
4687
+ //
4688
+ const data = this.safeValue(response, 'data', {});
4689
+ return this.parseTransaction(data, currency);
4690
+ }
4557
4691
  handleErrors(httpCode, reason, url, method, headers, body, response, requestHeaders, requestBody) {
4558
4692
  if (response === undefined) {
4559
4693
  return undefined; // fallback to default error handler
@@ -32,6 +32,9 @@ class poloniex extends poloniex$1 {
32
32
  'cancelAllOrders': true,
33
33
  'cancelOrder': true,
34
34
  'createDepositAddress': true,
35
+ 'createMarketBuyOrderWithCost': true,
36
+ 'createMarketOrderWithCost': false,
37
+ 'createMarketSellOrderWithCost': false,
35
38
  'createOrder': true,
36
39
  'editOrder': true,
37
40
  'fetchBalance': true,
@@ -225,6 +228,7 @@ class poloniex extends poloniex$1 {
225
228
  'UST': 'USTC',
226
229
  },
227
230
  'options': {
231
+ 'createMarketBuyOrderRequiresPrice': true,
228
232
  'networks': {
229
233
  'BEP20': 'BSC',
230
234
  'ERC20': 'ETH',
@@ -1248,6 +1252,7 @@ class poloniex extends poloniex$1 {
1248
1252
  * @param {float} [price] the price at which the order is to be fullfilled, in units of the quote currency, ignored in market orders
1249
1253
  * @param {object} [params] extra parameters specific to the exchange API endpoint
1250
1254
  * @param {float} [params.triggerPrice] *spot only* The price at which a trigger order is triggered at
1255
+ * @param {float} [params.cost] *spot market buy only* the quote quantity that can be used as an alternative for the amount
1251
1256
  * @returns {object} an [order structure]{@link https://docs.ccxt.com/#/?id=order-structure}
1252
1257
  */
1253
1258
  await this.loadMarkets();
@@ -1283,7 +1288,6 @@ class poloniex extends poloniex$1 {
1283
1288
  return this.parseOrder(response, market);
1284
1289
  }
1285
1290
  orderRequest(symbol, type, side, amount, request, price = undefined, params = {}) {
1286
- const market = this.market(symbol);
1287
1291
  let upperCaseType = type.toUpperCase();
1288
1292
  const isMarket = upperCaseType === 'MARKET';
1289
1293
  const isPostOnly = this.isPostOnly(isMarket, upperCaseType === 'LIMIT_MAKER', params);
@@ -1299,7 +1303,29 @@ class poloniex extends poloniex$1 {
1299
1303
  request['type'] = upperCaseType;
1300
1304
  if (isMarket) {
1301
1305
  if (side === 'buy') {
1302
- request['amount'] = this.currencyToPrecision(market['quote'], amount);
1306
+ let quoteAmount = undefined;
1307
+ let createMarketBuyOrderRequiresPrice = true;
1308
+ [createMarketBuyOrderRequiresPrice, params] = this.handleOptionAndParams(params, 'createOrder', 'createMarketBuyOrderRequiresPrice', true);
1309
+ const cost = this.safeNumber(params, 'cost');
1310
+ params = this.omit(params, 'cost');
1311
+ if (cost !== undefined) {
1312
+ quoteAmount = this.costToPrecision(symbol, cost);
1313
+ }
1314
+ else if (createMarketBuyOrderRequiresPrice) {
1315
+ if (price === undefined) {
1316
+ throw new errors.InvalidOrder(this.id + ' createOrder() requires the price argument for market buy orders to calculate the total cost to spend (amount * price), alternatively set the createMarketBuyOrderRequiresPrice option or param to false and pass the cost to spend (quote quantity) in the amount argument');
1317
+ }
1318
+ else {
1319
+ const amountString = this.numberToString(amount);
1320
+ const priceString = this.numberToString(price);
1321
+ const costRequest = Precise["default"].stringMul(amountString, priceString);
1322
+ quoteAmount = this.costToPrecision(symbol, costRequest);
1323
+ }
1324
+ }
1325
+ else {
1326
+ quoteAmount = this.costToPrecision(symbol, amount);
1327
+ }
1328
+ request['amount'] = quoteAmount;
1303
1329
  }
1304
1330
  else {
1305
1331
  request['quantity'] = this.amountToPrecision(symbol, amount);
@@ -481,7 +481,7 @@ class binance extends binance$1 {
481
481
  const subscribe = {
482
482
  'id': requestId,
483
483
  };
484
- const trades = await this.watch(url, subParams, this.extend(request, query), subParams, subscribe);
484
+ const trades = await this.watchMultiple(url, subParams, this.extend(request, query), subParams, subscribe);
485
485
  if (this.newUpdates) {
486
486
  const first = this.safeValue(trades, 0);
487
487
  const tradeSymbol = this.safeString(first, 'symbol');
@@ -1961,11 +1961,11 @@ class binance extends binance$1 {
1961
1961
  this.setBalanceCache(client, type);
1962
1962
  this.setPositionsCache(client, type);
1963
1963
  const message = undefined;
1964
- const newOrder = await this.watch(url, messageHash, message, type);
1964
+ const orders = await this.watch(url, messageHash, message, type);
1965
1965
  if (this.newUpdates) {
1966
- return newOrder;
1966
+ limit = orders.getLimit(symbol, limit);
1967
1967
  }
1968
- return this.filterBySymbolSinceLimit(this.orders, symbol, since, limit, true);
1968
+ return this.filterBySymbolSinceLimit(orders, symbol, since, limit, true);
1969
1969
  }
1970
1970
  parseWsOrder(order, market = undefined) {
1971
1971
  //
@@ -2626,8 +2626,8 @@ class binance extends binance$1 {
2626
2626
  cachedOrders.append(parsed);
2627
2627
  const messageHash = 'orders';
2628
2628
  const symbolSpecificMessageHash = 'orders:' + symbol;
2629
- client.resolve(parsed, messageHash);
2630
- client.resolve(parsed, symbolSpecificMessageHash);
2629
+ client.resolve(cachedOrders, messageHash);
2630
+ client.resolve(cachedOrders, symbolSpecificMessageHash);
2631
2631
  }
2632
2632
  }
2633
2633
  handleAcountUpdate(client, message) {
@@ -48,7 +48,7 @@ class bitmart extends bitmart$1 {
48
48
  'defaultType': 'spot',
49
49
  'watchBalance': {
50
50
  'fetchBalanceSnapshot': true,
51
- 'awaitBalanceSnapshot': true, // whether to wait for the balance snapshot before providing updates
51
+ 'awaitBalanceSnapshot': false, // whether to wait for the balance snapshot before providing updates
52
52
  },
53
53
  'watchOrderBook': {
54
54
  'depth': 'depth50', // depth5, depth20, depth50
@@ -128,30 +128,31 @@ class bitmart extends bitmart$1 {
128
128
  const messageHash = 'balance:' + type;
129
129
  const url = this.implodeHostname(this.urls['api']['ws'][type]['private']);
130
130
  const client = this.client(url);
131
- this.setBalanceCache(client, type);
132
- const fetchBalanceSnapshot = this.handleOptionAndParams(this.options, 'watchBalance', 'fetchBalanceSnapshot', true);
133
- const awaitBalanceSnapshot = this.handleOptionAndParams(this.options, 'watchBalance', 'awaitBalanceSnapshot', false);
131
+ this.setBalanceCache(client, type, messageHash);
132
+ let fetchBalanceSnapshot = undefined;
133
+ let awaitBalanceSnapshot = undefined;
134
+ [fetchBalanceSnapshot, params] = this.handleOptionAndParams(this.options, 'watchBalance', 'fetchBalanceSnapshot', true);
135
+ [awaitBalanceSnapshot, params] = this.handleOptionAndParams(this.options, 'watchBalance', 'awaitBalanceSnapshot', false);
134
136
  if (fetchBalanceSnapshot && awaitBalanceSnapshot) {
135
137
  await client.future(type + ':fetchBalanceSnapshot');
136
138
  }
137
139
  return await this.watch(url, messageHash, this.deepExtend(request, params), messageHash);
138
140
  }
139
- setBalanceCache(client, type) {
140
- if (type in client.subscriptions) {
141
- return undefined;
141
+ setBalanceCache(client, type, subscribeHash) {
142
+ if (subscribeHash in client.subscriptions) {
143
+ return;
142
144
  }
143
145
  const options = this.safeValue(this.options, 'watchBalance');
144
- const fetchBalanceSnapshot = this.handleOptionAndParams(options, 'watchBalance', 'fetchBalanceSnapshot', true);
145
- if (fetchBalanceSnapshot) {
146
- const messageHash = type + ':fetchBalanceSnapshot';
146
+ const snapshot = this.safeValue(options, 'fetchBalanceSnapshot', true);
147
+ if (snapshot) {
148
+ const messageHash = type + ':' + 'fetchBalanceSnapshot';
147
149
  if (!(messageHash in client.futures)) {
148
150
  client.future(messageHash);
149
151
  this.spawn(this.loadBalanceSnapshot, client, messageHash, type);
150
152
  }
151
153
  }
152
- else {
153
- this.balance[type] = {};
154
- }
154
+ this.balance[type] = {};
155
+ // without this comment, transpilation breaks for some reason...
155
156
  }
156
157
  async loadBalanceSnapshot(client, messageHash, type) {
157
158
  const response = await this.fetchBalance({ 'type': type });
@@ -198,15 +199,15 @@ class bitmart extends bitmart$1 {
198
199
  }
199
200
  const isSpot = (channel.indexOf('spot') >= 0);
200
201
  const type = isSpot ? 'spot' : 'swap';
201
- this.balance['info'] = message;
202
+ this.balance[type]['info'] = message;
202
203
  if (isSpot) {
203
204
  if (!Array.isArray(data)) {
204
205
  return;
205
206
  }
206
207
  for (let i = 0; i < data.length; i++) {
207
208
  const timestamp = this.safeInteger(message, 'event_time');
208
- this.balance['timestamp'] = timestamp;
209
- this.balance['datetime'] = this.iso8601(timestamp);
209
+ this.balance[type]['timestamp'] = timestamp;
210
+ this.balance[type]['datetime'] = this.iso8601(timestamp);
210
211
  const balanceDetails = this.safeValue(data[i], 'balance_details', []);
211
212
  for (let ii = 0; ii < balanceDetails.length; ii++) {
212
213
  const rawBalance = balanceDetails[i];
@@ -214,8 +215,8 @@ class bitmart extends bitmart$1 {
214
215
  const currencyId = this.safeString(rawBalance, 'ccy');
215
216
  const code = this.safeCurrencyCode(currencyId);
216
217
  account['free'] = this.safeString(rawBalance, 'av_bal');
217
- account['total'] = this.safeString(rawBalance, 'fz_bal');
218
- this.balance[code] = account;
218
+ account['used'] = this.safeString(rawBalance, 'fz_bal');
219
+ this.balance[type][code] = account;
219
220
  }
220
221
  }
221
222
  }
@@ -194,6 +194,7 @@ class poloniex extends poloniex$1 {
194
194
  * @param {object} [params] extra parameters specific to the poloniex api endpoint
195
195
  * @param {string} [params.timeInForce] GTC (default), IOC, FOK
196
196
  * @param {string} [params.clientOrderId] Maximum 64-character length.*
197
+ * @param {float} [params.cost] *spot market buy only* the quote quantity that can be used as an alternative for the amount
197
198
  *
198
199
  * EXCHANGE SPECIFIC PARAMETERS
199
200
  * @param {string} [params.amount] quote units for the order
@@ -217,25 +218,29 @@ class poloniex extends poloniex$1 {
217
218
  'type': type.toUpperCase(),
218
219
  };
219
220
  if ((uppercaseType === 'MARKET') && (uppercaseSide === 'BUY')) {
220
- let quoteAmount = this.safeString(params, 'amount');
221
- if ((quoteAmount === undefined) && (this.options['createMarketBuyOrderRequiresPrice'])) {
222
- const cost = this.safeNumber(params, 'cost');
223
- params = this.omit(params, 'cost');
224
- if (price === undefined && cost === undefined) {
225
- throw new errors.ArgumentsRequired(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 to supply the cost in the amount argument (the exchange-specific behaviour)');
221
+ let quoteAmount = undefined;
222
+ let createMarketBuyOrderRequiresPrice = true;
223
+ [createMarketBuyOrderRequiresPrice, params] = this.handleOptionAndParams(params, 'createOrder', 'createMarketBuyOrderRequiresPrice', true);
224
+ const cost = this.safeNumber(params, 'cost');
225
+ params = this.omit(params, 'cost');
226
+ if (cost !== undefined) {
227
+ quoteAmount = this.costToPrecision(symbol, cost);
228
+ }
229
+ else if (createMarketBuyOrderRequiresPrice) {
230
+ if (price === undefined) {
231
+ throw new errors.InvalidOrder(this.id + ' createOrder() requires the price argument for market buy orders to calculate the total cost to spend (amount * price), alternatively set the createMarketBuyOrderRequiresPrice option or param to false and pass the cost to spend (quote quantity) in the amount argument');
226
232
  }
227
233
  else {
228
234
  const amountString = this.numberToString(amount);
229
235
  const priceString = this.numberToString(price);
230
- const quote = Precise["default"].stringMul(amountString, priceString);
231
- amount = (cost !== undefined) ? cost : this.parseNumber(quote);
232
- quoteAmount = this.costToPrecision(symbol, amount);
236
+ const costRequest = Precise["default"].stringMul(amountString, priceString);
237
+ quoteAmount = this.costToPrecision(symbol, costRequest);
233
238
  }
234
239
  }
235
240
  else {
236
241
  quoteAmount = this.costToPrecision(symbol, amount);
237
242
  }
238
- request['amount'] = this.amountToPrecision(market['symbol'], quoteAmount);
243
+ request['amount'] = quoteAmount;
239
244
  }
240
245
  else {
241
246
  request['quantity'] = this.amountToPrecision(market['symbol'], amount);
@@ -105,6 +105,8 @@ class tokocrypto extends tokocrypto$1 {
105
105
  'fetchWithdrawals': true,
106
106
  'fetchWithdrawalWhitelist': false,
107
107
  'reduceMargin': false,
108
+ 'repayCrossMargin': false,
109
+ 'repayIsolatedMargin': false,
108
110
  'setLeverage': false,
109
111
  'setMargin': false,
110
112
  'setMarginMode': false,
@@ -87,6 +87,8 @@ class wazirx extends wazirx$1 {
87
87
  'fetchTransfers': false,
88
88
  'fetchWithdrawals': false,
89
89
  'reduceMargin': false,
90
+ 'repayCrossMargin': false,
91
+ 'repayIsolatedMargin': false,
90
92
  'setLeverage': false,
91
93
  'setMargin': false,
92
94
  'setMarginMode': false,
@@ -73,6 +73,8 @@ class whitebit extends whitebit$1 {
73
73
  'fetchTradingFee': false,
74
74
  'fetchTradingFees': true,
75
75
  'fetchTransactionFees': true,
76
+ 'repayCrossMargin': false,
77
+ 'repayIsolatedMargin': false,
76
78
  'setLeverage': true,
77
79
  'transfer': true,
78
80
  'withdraw': true,
@@ -299,15 +299,14 @@ class zaif extends zaif$1 {
299
299
  // }
300
300
  //
301
301
  const symbol = this.safeSymbol(undefined, market);
302
- const timestamp = this.milliseconds();
303
302
  const vwap = this.safeString(ticker, 'vwap');
304
303
  const baseVolume = this.safeString(ticker, 'volume');
305
304
  const quoteVolume = Precise["default"].stringMul(baseVolume, vwap);
306
305
  const last = this.safeString(ticker, 'last');
307
306
  return this.safeTicker({
308
307
  'symbol': symbol,
309
- 'timestamp': timestamp,
310
- 'datetime': this.iso8601(timestamp),
308
+ 'timestamp': undefined,
309
+ 'datetime': undefined,
311
310
  'high': this.safeString(ticker, 'high'),
312
311
  'low': this.safeString(ticker, 'low'),
313
312
  'bid': this.safeString(ticker, 'bid'),