ccxt 4.2.21 → 4.2.23

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 (63) hide show
  1. package/README.md +3 -3
  2. package/dist/ccxt.browser.js +574 -81
  3. package/dist/ccxt.browser.min.js +3 -3
  4. package/dist/cjs/ccxt.js +1 -1
  5. package/dist/cjs/src/bigone.js +1 -0
  6. package/dist/cjs/src/binance.js +14 -3
  7. package/dist/cjs/src/bitfinex2.js +89 -0
  8. package/dist/cjs/src/bitget.js +11 -1
  9. package/dist/cjs/src/bitrue.js +1 -0
  10. package/dist/cjs/src/bybit.js +57 -9
  11. package/dist/cjs/src/coinbasepro.js +1 -0
  12. package/dist/cjs/src/coinex.js +60 -14
  13. package/dist/cjs/src/deribit.js +164 -0
  14. package/dist/cjs/src/okcoin.js +3 -0
  15. package/dist/cjs/src/okx.js +81 -31
  16. package/dist/cjs/src/phemex.js +17 -5
  17. package/dist/cjs/src/poloniex.js +1 -0
  18. package/dist/cjs/src/pro/bequant.js +6 -1
  19. package/dist/cjs/src/pro/binance.js +8 -5
  20. package/dist/cjs/src/pro/binancecoinm.js +6 -1
  21. package/dist/cjs/src/pro/binanceus.js +6 -1
  22. package/dist/cjs/src/pro/bitcoincom.js +6 -1
  23. package/dist/cjs/src/pro/bitget.js +1 -1
  24. package/dist/cjs/src/pro/bitrue.js +6 -1
  25. package/dist/cjs/src/pro/hitbtc.js +6 -0
  26. package/dist/cjs/src/pro/okx.js +23 -5
  27. package/dist/cjs/src/woo.js +1 -1
  28. package/js/ccxt.d.ts +1 -1
  29. package/js/ccxt.js +1 -1
  30. package/js/src/abstract/binance.d.ts +3 -0
  31. package/js/src/abstract/binancecoinm.d.ts +3 -0
  32. package/js/src/abstract/binanceus.d.ts +4 -0
  33. package/js/src/abstract/binanceusdm.d.ts +3 -0
  34. package/js/src/bigone.js +1 -0
  35. package/js/src/binance.js +14 -3
  36. package/js/src/bitfinex2.d.ts +2 -0
  37. package/js/src/bitfinex2.js +89 -0
  38. package/js/src/bitget.js +11 -1
  39. package/js/src/bitrue.js +1 -0
  40. package/js/src/bybit.d.ts +2 -1
  41. package/js/src/bybit.js +57 -9
  42. package/js/src/coinbasepro.js +1 -0
  43. package/js/src/coinex.d.ts +1 -0
  44. package/js/src/coinex.js +60 -14
  45. package/js/src/deribit.d.ts +6 -1
  46. package/js/src/deribit.js +164 -0
  47. package/js/src/okcoin.js +3 -0
  48. package/js/src/okx.js +81 -31
  49. package/js/src/phemex.js +17 -5
  50. package/js/src/poloniex.js +1 -0
  51. package/js/src/pro/bequant.js +6 -1
  52. package/js/src/pro/binance.js +8 -5
  53. package/js/src/pro/binancecoinm.js +6 -1
  54. package/js/src/pro/binanceus.js +6 -1
  55. package/js/src/pro/bitcoincom.js +6 -1
  56. package/js/src/pro/bitget.js +1 -1
  57. package/js/src/pro/bitrue.js +6 -1
  58. package/js/src/pro/hitbtc.js +6 -0
  59. package/js/src/pro/okx.js +23 -5
  60. package/js/src/woo.js +1 -1
  61. package/jsdoc2md.js +38 -16
  62. package/package.json +4 -1
  63. package/skip-tests.json +4 -0
@@ -1,11 +1,16 @@
1
1
  import Exchange from './abstract/deribit.js';
2
- import type { Balances, Currency, FundingRateHistory, Greeks, Int, Liquidation, Market, OHLCV, Order, OrderBook, OrderSide, OrderType, Str, Strings, Ticker, Tickers, Trade, Transaction } from './base/types.js';
2
+ import type { Balances, Currency, FundingRateHistory, Greeks, Int, Liquidation, Market, OHLCV, Order, OrderBook, OrderSide, OrderType, Str, Strings, Ticker, Tickers, Trade, Transaction, MarketInterface } from './base/types.js';
3
3
  /**
4
4
  * @class deribit
5
5
  * @augments Exchange
6
6
  */
7
7
  export default class deribit extends Exchange {
8
8
  describe(): any;
9
+ convertExpireDate(date: any): string;
10
+ convertMarketIdExpireDate(date: any): string;
11
+ convertExpireDateToMarketIdDate(date: any): any;
12
+ createExpiredOptionMarket(symbol: any): MarketInterface;
13
+ safeMarket(marketId?: any, market?: any, delimiter?: any, marketType?: any): MarketInterface;
9
14
  fetchTime(params?: {}): Promise<number>;
10
15
  fetchCurrencies(params?: {}): Promise<{}>;
11
16
  codeFromOptions(methodName: any, params?: {}): any;
package/js/src/deribit.js CHANGED
@@ -405,6 +405,170 @@ export default class deribit extends Exchange {
405
405
  },
406
406
  });
407
407
  }
408
+ convertExpireDate(date) {
409
+ // parse YYMMDD to timestamp
410
+ const year = date.slice(0, 2);
411
+ const month = date.slice(2, 4);
412
+ const day = date.slice(4, 6);
413
+ const reconstructedDate = '20' + year + '-' + month + '-' + day + 'T00:00:00Z';
414
+ return reconstructedDate;
415
+ }
416
+ convertMarketIdExpireDate(date) {
417
+ // parse 19JAN24 to 240119
418
+ const monthMappping = {
419
+ 'JAN': '01',
420
+ 'FEB': '02',
421
+ 'MAR': '03',
422
+ 'APR': '04',
423
+ 'MAY': '05',
424
+ 'JUN': '06',
425
+ 'JUL': '07',
426
+ 'AUG': '08',
427
+ 'SEP': '09',
428
+ 'OCT': '10',
429
+ 'NOV': '11',
430
+ 'DEC': '12',
431
+ };
432
+ const year = date.slice(0, 2);
433
+ const monthName = date.slice(2, 5);
434
+ const month = this.safeString(monthMappping, monthName);
435
+ const day = date.slice(5, 7);
436
+ const reconstructedDate = day + month + year;
437
+ return reconstructedDate;
438
+ }
439
+ convertExpireDateToMarketIdDate(date) {
440
+ // parse 240119 to 19JAN24
441
+ const year = date.slice(0, 2);
442
+ const monthRaw = date.slice(2, 4);
443
+ let month = undefined;
444
+ const day = date.slice(4, 6);
445
+ if (monthRaw === '01') {
446
+ month = 'JAN';
447
+ }
448
+ else if (monthRaw === '02') {
449
+ month = 'FEB';
450
+ }
451
+ else if (monthRaw === '03') {
452
+ month = 'MAR';
453
+ }
454
+ else if (monthRaw === '04') {
455
+ month = 'APR';
456
+ }
457
+ else if (monthRaw === '05') {
458
+ month = 'MAY';
459
+ }
460
+ else if (monthRaw === '06') {
461
+ month = 'JUN';
462
+ }
463
+ else if (monthRaw === '07') {
464
+ month = 'JUL';
465
+ }
466
+ else if (monthRaw === '08') {
467
+ month = 'AUG';
468
+ }
469
+ else if (monthRaw === '09') {
470
+ month = 'SEP';
471
+ }
472
+ else if (monthRaw === '10') {
473
+ month = 'OCT';
474
+ }
475
+ else if (monthRaw === '11') {
476
+ month = 'NOV';
477
+ }
478
+ else if (monthRaw === '12') {
479
+ month = 'DEC';
480
+ }
481
+ const reconstructedDate = day + month + year;
482
+ return reconstructedDate;
483
+ }
484
+ createExpiredOptionMarket(symbol) {
485
+ // support expired option contracts
486
+ let quote = 'USD';
487
+ let settle = undefined;
488
+ const optionParts = symbol.split('-');
489
+ const symbolBase = symbol.split('/');
490
+ let base = undefined;
491
+ let expiry = undefined;
492
+ if (symbol.indexOf('/') > -1) {
493
+ base = this.safeString(symbolBase, 0);
494
+ expiry = this.safeString(optionParts, 1);
495
+ if (symbol.indexOf('USDC') > -1) {
496
+ base = base + '_USDC';
497
+ }
498
+ }
499
+ else {
500
+ base = this.safeString(optionParts, 0);
501
+ expiry = this.convertMarketIdExpireDate(this.safeString(optionParts, 1));
502
+ }
503
+ if (symbol.indexOf('USDC') > -1) {
504
+ quote = 'USDC';
505
+ settle = 'USDC';
506
+ }
507
+ else {
508
+ settle = base;
509
+ }
510
+ let splitBase = base;
511
+ if (base.indexOf('_') > -1) {
512
+ const splitSymbol = base.split('_');
513
+ splitBase = this.safeString(splitSymbol, 0);
514
+ }
515
+ const strike = this.safeString(optionParts, 2);
516
+ const optionType = this.safeString(optionParts, 3);
517
+ const datetime = this.convertExpireDate(expiry);
518
+ const timestamp = this.parse8601(datetime);
519
+ return {
520
+ 'id': base + '-' + this.convertExpireDateToMarketIdDate(expiry) + '-' + strike + '-' + optionType,
521
+ 'symbol': splitBase + '/' + quote + ':' + settle + '-' + expiry + '-' + strike + '-' + optionType,
522
+ 'base': base,
523
+ 'quote': quote,
524
+ 'settle': settle,
525
+ 'baseId': base,
526
+ 'quoteId': quote,
527
+ 'settleId': settle,
528
+ 'active': false,
529
+ 'type': 'option',
530
+ 'linear': undefined,
531
+ 'inverse': undefined,
532
+ 'spot': false,
533
+ 'swap': false,
534
+ 'future': false,
535
+ 'option': true,
536
+ 'margin': false,
537
+ 'contract': true,
538
+ 'contractSize': undefined,
539
+ 'expiry': timestamp,
540
+ 'expiryDatetime': datetime,
541
+ 'optionType': (optionType === 'C') ? 'call' : 'put',
542
+ 'strike': this.parseNumber(strike),
543
+ 'precision': {
544
+ 'amount': undefined,
545
+ 'price': undefined,
546
+ },
547
+ 'limits': {
548
+ 'amount': {
549
+ 'min': undefined,
550
+ 'max': undefined,
551
+ },
552
+ 'price': {
553
+ 'min': undefined,
554
+ 'max': undefined,
555
+ },
556
+ 'cost': {
557
+ 'min': undefined,
558
+ 'max': undefined,
559
+ },
560
+ },
561
+ 'info': undefined,
562
+ };
563
+ }
564
+ safeMarket(marketId = undefined, market = undefined, delimiter = undefined, marketType = undefined) {
565
+ const isOption = (marketId !== undefined) && ((marketId.endsWith('-C')) || (marketId.endsWith('-P')));
566
+ if (isOption && !(marketId in this.markets_by_id)) {
567
+ // handle expired option contracts
568
+ return this.createExpiredOptionMarket(marketId);
569
+ }
570
+ return super.safeMarket(marketId, market, delimiter, marketType);
571
+ }
408
572
  async fetchTime(params = {}) {
409
573
  /**
410
574
  * @method
package/js/src/okcoin.js CHANGED
@@ -49,6 +49,9 @@ export default class okcoin extends Exchange {
49
49
  'fetchCurrencies': true,
50
50
  'fetchDepositAddress': true,
51
51
  'fetchDeposits': true,
52
+ 'fetchFundingHistory': false,
53
+ 'fetchFundingRate': false,
54
+ 'fetchFundingRateHistory': false,
52
55
  'fetchLedger': true,
53
56
  'fetchMarkets': true,
54
57
  'fetchMyTrades': true,
package/js/src/okx.js CHANGED
@@ -2917,12 +2917,26 @@ export default class okx extends Exchange {
2917
2917
  const request = {
2918
2918
  'instId': market['id'],
2919
2919
  };
2920
+ let isAlgoOrder = undefined;
2921
+ if ((type === 'trigger') || (type === 'conditional') || (type === 'move_order_stop') || (type === 'oco') || (type === 'iceberg') || (type === 'twap')) {
2922
+ isAlgoOrder = true;
2923
+ }
2920
2924
  const clientOrderId = this.safeString2(params, 'clOrdId', 'clientOrderId');
2921
2925
  if (clientOrderId !== undefined) {
2922
- request['clOrdId'] = clientOrderId;
2926
+ if (isAlgoOrder) {
2927
+ request['algoClOrdId'] = clientOrderId;
2928
+ }
2929
+ else {
2930
+ request['clOrdId'] = clientOrderId;
2931
+ }
2923
2932
  }
2924
2933
  else {
2925
- request['ordId'] = id;
2934
+ if (isAlgoOrder) {
2935
+ request['algoId'] = id;
2936
+ }
2937
+ else {
2938
+ request['ordId'] = id;
2939
+ }
2926
2940
  }
2927
2941
  let stopLossTriggerPrice = this.safeValue2(params, 'stopLossPrice', 'newSlTriggerPx');
2928
2942
  let stopLossPrice = this.safeValue(params, 'newSlOrdPx');
@@ -2934,37 +2948,62 @@ export default class okx extends Exchange {
2934
2948
  const takeProfit = this.safeValue(params, 'takeProfit');
2935
2949
  const stopLossDefined = (stopLoss !== undefined);
2936
2950
  const takeProfitDefined = (takeProfit !== undefined);
2937
- if (stopLossTriggerPrice !== undefined) {
2938
- request['newSlTriggerPx'] = this.priceToPrecision(symbol, stopLossTriggerPrice);
2939
- request['newSlOrdPx'] = (type === 'market') ? '-1' : this.priceToPrecision(symbol, stopLossPrice);
2940
- request['newSlTriggerPxType'] = stopLossTriggerPriceType;
2941
- }
2942
- if (takeProfitTriggerPrice !== undefined) {
2943
- request['newTpTriggerPx'] = this.priceToPrecision(symbol, takeProfitTriggerPrice);
2944
- request['newTpOrdPx'] = (type === 'market') ? '-1' : this.priceToPrecision(symbol, takeProfitPrice);
2945
- request['newTpTriggerPxType'] = takeProfitTriggerPriceType;
2946
- }
2947
- if (stopLossDefined) {
2948
- stopLossTriggerPrice = this.safeValue(stopLoss, 'triggerPrice');
2949
- stopLossPrice = this.safeValue(stopLoss, 'price');
2950
- const stopLossType = this.safeString(stopLoss, 'type');
2951
- request['newSlTriggerPx'] = this.priceToPrecision(symbol, stopLossTriggerPrice);
2952
- request['newSlOrdPx'] = (stopLossType === 'market') ? '-1' : this.priceToPrecision(symbol, stopLossPrice);
2953
- request['newSlTriggerPxType'] = stopLossTriggerPriceType;
2954
- }
2955
- if (takeProfitDefined) {
2956
- takeProfitTriggerPrice = this.safeValue(takeProfit, 'triggerPrice');
2957
- takeProfitPrice = this.safeValue(takeProfit, 'price');
2958
- const takeProfitType = this.safeString(takeProfit, 'type');
2959
- request['newTpTriggerPx'] = this.priceToPrecision(symbol, takeProfitTriggerPrice);
2960
- request['newTpOrdPx'] = (takeProfitType === 'market') ? '-1' : this.priceToPrecision(symbol, takeProfitPrice);
2961
- request['newTpTriggerPxType'] = takeProfitTriggerPriceType;
2951
+ if (isAlgoOrder) {
2952
+ if ((stopLossTriggerPrice === undefined) && (takeProfitTriggerPrice === undefined)) {
2953
+ throw new BadRequest(this.id + ' editOrder() requires a stopLossPrice or takeProfitPrice parameter for editing an algo order');
2954
+ }
2955
+ if (stopLossTriggerPrice !== undefined) {
2956
+ if (stopLossPrice === undefined) {
2957
+ throw new BadRequest(this.id + ' editOrder() requires a newSlOrdPx parameter for editing an algo order');
2958
+ }
2959
+ request['newSlTriggerPx'] = this.priceToPrecision(symbol, stopLossTriggerPrice);
2960
+ request['newSlOrdPx'] = (type === 'market') ? '-1' : this.priceToPrecision(symbol, stopLossPrice);
2961
+ request['newSlTriggerPxType'] = stopLossTriggerPriceType;
2962
+ }
2963
+ if (takeProfitTriggerPrice !== undefined) {
2964
+ if (takeProfitPrice === undefined) {
2965
+ throw new BadRequest(this.id + ' editOrder() requires a newTpOrdPx parameter for editing an algo order');
2966
+ }
2967
+ request['newTpTriggerPx'] = this.priceToPrecision(symbol, takeProfitTriggerPrice);
2968
+ request['newTpOrdPx'] = (type === 'market') ? '-1' : this.priceToPrecision(symbol, takeProfitPrice);
2969
+ request['newTpTriggerPxType'] = takeProfitTriggerPriceType;
2970
+ }
2971
+ }
2972
+ else {
2973
+ if (stopLossTriggerPrice !== undefined) {
2974
+ request['newSlTriggerPx'] = this.priceToPrecision(symbol, stopLossTriggerPrice);
2975
+ request['newSlOrdPx'] = (type === 'market') ? '-1' : this.priceToPrecision(symbol, stopLossPrice);
2976
+ request['newSlTriggerPxType'] = stopLossTriggerPriceType;
2977
+ }
2978
+ if (takeProfitTriggerPrice !== undefined) {
2979
+ request['newTpTriggerPx'] = this.priceToPrecision(symbol, takeProfitTriggerPrice);
2980
+ request['newTpOrdPx'] = (type === 'market') ? '-1' : this.priceToPrecision(symbol, takeProfitPrice);
2981
+ request['newTpTriggerPxType'] = takeProfitTriggerPriceType;
2982
+ }
2983
+ if (stopLossDefined) {
2984
+ stopLossTriggerPrice = this.safeValue(stopLoss, 'triggerPrice');
2985
+ stopLossPrice = this.safeValue(stopLoss, 'price');
2986
+ const stopLossType = this.safeString(stopLoss, 'type');
2987
+ request['newSlTriggerPx'] = this.priceToPrecision(symbol, stopLossTriggerPrice);
2988
+ request['newSlOrdPx'] = (stopLossType === 'market') ? '-1' : this.priceToPrecision(symbol, stopLossPrice);
2989
+ request['newSlTriggerPxType'] = stopLossTriggerPriceType;
2990
+ }
2991
+ if (takeProfitDefined) {
2992
+ takeProfitTriggerPrice = this.safeValue(takeProfit, 'triggerPrice');
2993
+ takeProfitPrice = this.safeValue(takeProfit, 'price');
2994
+ const takeProfitType = this.safeString(takeProfit, 'type');
2995
+ request['newTpTriggerPx'] = this.priceToPrecision(symbol, takeProfitTriggerPrice);
2996
+ request['newTpOrdPx'] = (takeProfitType === 'market') ? '-1' : this.priceToPrecision(symbol, takeProfitPrice);
2997
+ request['newTpTriggerPxType'] = takeProfitTriggerPriceType;
2998
+ }
2962
2999
  }
2963
3000
  if (amount !== undefined) {
2964
3001
  request['newSz'] = this.amountToPrecision(symbol, amount);
2965
3002
  }
2966
- if (price !== undefined) {
2967
- request['newPx'] = this.priceToPrecision(symbol, price);
3003
+ if (!isAlgoOrder) {
3004
+ if (price !== undefined) {
3005
+ request['newPx'] = this.priceToPrecision(symbol, price);
3006
+ }
2968
3007
  }
2969
3008
  params = this.omit(params, ['clOrdId', 'clientOrderId', 'takeProfitPrice', 'stopLossPrice', 'stopLoss', 'takeProfit']);
2970
3009
  return this.extend(request, params);
@@ -2974,7 +3013,8 @@ export default class okx extends Exchange {
2974
3013
  * @method
2975
3014
  * @name okx#editOrder
2976
3015
  * @description edit a trade order
2977
- * @see https://www.okx.com/docs-v5/en/#rest-api-trade-amend-order
3016
+ * @see https://www.okx.com/docs-v5/en/#order-book-trading-trade-post-amend-order
3017
+ * @see https://www.okx.com/docs-v5/en/#order-book-trading-algo-trading-post-amend-algo-order
2978
3018
  * @param {string} id order id
2979
3019
  * @param {string} symbol unified symbol of the market to create an order in
2980
3020
  * @param {string} type 'market' or 'limit'
@@ -3002,7 +3042,17 @@ export default class okx extends Exchange {
3002
3042
  await this.loadMarkets();
3003
3043
  const market = this.market(symbol);
3004
3044
  const request = this.editOrderRequest(id, symbol, type, side, amount, price, params);
3005
- const response = await this.privatePostTradeAmendOrder(this.extend(request, params));
3045
+ let isAlgoOrder = undefined;
3046
+ if ((type === 'trigger') || (type === 'conditional') || (type === 'move_order_stop') || (type === 'oco') || (type === 'iceberg') || (type === 'twap')) {
3047
+ isAlgoOrder = true;
3048
+ }
3049
+ let response = undefined;
3050
+ if (isAlgoOrder) {
3051
+ response = await this.privatePostTradeAmendAlgos(this.extend(request, params));
3052
+ }
3053
+ else {
3054
+ response = await this.privatePostTradeAmendOrder(this.extend(request, params));
3055
+ }
3006
3056
  //
3007
3057
  // {
3008
3058
  // "code": "0",
package/js/src/phemex.js CHANGED
@@ -1918,16 +1918,19 @@ export default class phemex extends Exchange {
1918
1918
  * @method
1919
1919
  * @name phemex#fetchBalance
1920
1920
  * @description query for balance and get the amount of funds available for trading or funds locked in orders
1921
+ * @see https://phemex-docs.github.io/#query-wallets
1921
1922
  * @see https://github.com/phemex/phemex-api-docs/blob/master/Public-Hedged-Perpetual-API.md#query-account-positions
1923
+ * @see https://phemex-docs.github.io/#query-trading-account-and-positions
1922
1924
  * @param {object} [params] extra parameters specific to the exchange API endpoint
1923
1925
  * @param {string} [params.type] spot or swap
1926
+ * @param {string} [params.code] *swap only* currency code of the balance to query (USD, USDT, etc), default is USDT
1924
1927
  * @returns {object} a [balance structure]{@link https://docs.ccxt.com/#/?id=balance-structure}
1925
1928
  */
1926
1929
  await this.loadMarkets();
1927
1930
  let type = undefined;
1928
1931
  [type, params] = this.handleMarketTypeAndParams('fetchBalance', undefined, params);
1929
1932
  const code = this.safeString(params, 'code');
1930
- params = this.omit(params, ['type', 'code']);
1933
+ params = this.omit(params, ['code']);
1931
1934
  let response = undefined;
1932
1935
  const request = {};
1933
1936
  if ((type !== 'spot') && (type !== 'swap')) {
@@ -1935,7 +1938,7 @@ export default class phemex extends Exchange {
1935
1938
  }
1936
1939
  if (type === 'swap') {
1937
1940
  let settle = undefined;
1938
- [settle, params] = this.handleOptionAndParams(params, 'fetchBalance', 'settle');
1941
+ [settle, params] = this.handleOptionAndParams(params, 'fetchBalance', 'settle', 'USDT');
1939
1942
  if (code !== undefined || settle !== undefined) {
1940
1943
  let coin = undefined;
1941
1944
  if (code !== undefined) {
@@ -3545,8 +3548,10 @@ export default class phemex extends Exchange {
3545
3548
  * @description fetch all open positions
3546
3549
  * @see https://github.com/phemex/phemex-api-docs/blob/master/Public-Contract-API-en.md#query-trading-account-and-positions
3547
3550
  * @see https://github.com/phemex/phemex-api-docs/blob/master/Public-Hedged-Perpetual-API.md#query-account-positions
3548
- * @param {string[]|undefined} symbols list of unified market symbols
3551
+ * @see https://phemex-docs.github.io/#query-account-positions-with-unrealized-pnl
3552
+ * @param {string[]} [symbols] list of unified market symbols
3549
3553
  * @param {object} [params] extra parameters specific to the exchange API endpoint
3554
+ * @param {string} [param.method] *USDT contracts only* 'privateGetGAccountsAccountPositions' or 'privateGetAccountsPositions' default is 'privateGetGAccountsAccountPositions'
3550
3555
  * @returns {object[]} a list of [position structure]{@link https://docs.ccxt.com/#/?id=position-structure}
3551
3556
  */
3552
3557
  await this.loadMarkets();
@@ -3581,7 +3586,14 @@ export default class phemex extends Exchange {
3581
3586
  };
3582
3587
  let response = undefined;
3583
3588
  if (isUSDTSettled) {
3584
- response = await this.privateGetGAccountsAccountPositions(this.extend(request, params));
3589
+ let method = undefined;
3590
+ [method, params] = this.handleOptionAndParams(params, 'fetchPositions', 'method', 'privateGetGAccountsAccountPositions');
3591
+ if (method === 'privateGetGAccountsAccountPositions') {
3592
+ response = await this.privateGetGAccountsAccountPositions(this.extend(request, params));
3593
+ }
3594
+ else {
3595
+ response = await this.privateGetAccountsPositions(this.extend(request, params));
3596
+ }
3585
3597
  }
3586
3598
  else {
3587
3599
  response = await this.privateGetAccountsAccountPositions(this.extend(request, params));
@@ -3757,7 +3769,7 @@ export default class phemex extends Exchange {
3757
3769
  const contracts = this.safeString(position, 'size');
3758
3770
  const contractSize = this.safeValue(market, 'contractSize');
3759
3771
  const contractSizeString = this.numberToString(contractSize);
3760
- const leverage = this.safeNumber2(position, 'leverage', 'leverageRr');
3772
+ const leverage = this.parseNumber(Precise.stringAbs((this.safeString(position, 'leverage', 'leverageRr'))));
3761
3773
  const entryPriceString = this.safeString2(position, 'avgEntryPrice', 'avgEntryPriceRp');
3762
3774
  const rawSide = this.safeString(position, 'side');
3763
3775
  let side = undefined;
@@ -48,6 +48,7 @@ export default class poloniex extends Exchange {
48
48
  'fetchDepositsWithdrawals': true,
49
49
  'fetchDepositWithdrawFee': 'emulated',
50
50
  'fetchDepositWithdrawFees': true,
51
+ 'fetchFundingRate': false,
51
52
  'fetchMarginMode': false,
52
53
  'fetchMarkets': true,
53
54
  'fetchMyTrades': true,
@@ -6,10 +6,15 @@
6
6
 
7
7
  // ---------------------------------------------------------------------------
8
8
  import hitbtc from './hitbtc.js';
9
+ import bequantRest from '../bequant.js';
9
10
  // ---------------------------------------------------------------------------
10
11
  export default class bequant extends hitbtc {
11
12
  describe() {
12
- return this.deepExtend(super.describe(), {
13
+ // eslint-disable-next-line new-cap
14
+ const restInstance = new bequantRest();
15
+ const restDescribe = restInstance.describe();
16
+ const extended = this.deepExtend(super.describe(), restDescribe);
17
+ return this.deepExtend(extended, {
13
18
  'id': 'bequant',
14
19
  'name': 'Bequant',
15
20
  'countries': ['MT'],
@@ -47,7 +47,7 @@ export default class binance extends binanceRest {
47
47
  'ws': {
48
48
  'spot': 'wss://testnet.binance.vision/ws',
49
49
  'margin': 'wss://testnet.binance.vision/ws',
50
- 'future': 'wss://stream.binancefuture.com/ws',
50
+ 'future': 'wss://fstream.binancefuture.com/ws',
51
51
  'delivery': 'wss://dstream.binancefuture.com/ws',
52
52
  'ws': 'wss://testnet.binance.vision/ws-api/v3',
53
53
  },
@@ -989,7 +989,7 @@ export default class binance extends binanceRest {
989
989
  }
990
990
  else {
991
991
  // take the timestamp of the closing price for candlestick streams
992
- timestamp = this.safeInteger(message, 'C');
992
+ timestamp = this.safeInteger2(message, 'C', 'E');
993
993
  }
994
994
  const marketId = this.safeString(message, 's');
995
995
  const symbol = this.safeSymbol(marketId, undefined, undefined, marketType);
@@ -1980,12 +1980,13 @@ export default class binance extends binanceRest {
1980
1980
  /**
1981
1981
  * @method
1982
1982
  * @name binance#watchOrders
1983
- * @see https://binance-docs.github.io/apidocs/spot/en/#payload-order-update
1984
1983
  * @description watches information on multiple orders made by the user
1985
- * @param {string} symbol unified market symbol of the market orders were made in
1984
+ * @see https://binance-docs.github.io/apidocs/spot/en/#payload-order-update
1985
+ * @param {string} symbol unified market symbol of the market the orders were made in
1986
1986
  * @param {int} [since] the earliest time in ms to fetch orders for
1987
1987
  * @param {int} [limit] the maximum number of order structures to retrieve
1988
1988
  * @param {object} [params] extra parameters specific to the exchange API endpoint
1989
+ * @param {string|undefined} [params.marginMode] 'cross' or 'isolated', for spot margin
1989
1990
  * @returns {object[]} a list of [order structures]{@link https://docs.ccxt.com/#/?id=order-structure}
1990
1991
  */
1991
1992
  await this.loadMarkets();
@@ -2008,8 +2009,10 @@ export default class binance extends binanceRest {
2008
2009
  }
2009
2010
  params = this.extend(params, { 'type': type, 'symbol': symbol }); // needed inside authenticate for isolated margin
2010
2011
  await this.authenticate(params);
2012
+ let marginMode = undefined;
2013
+ [marginMode, params] = this.handleMarginModeAndParams('watchOrders', params);
2011
2014
  let urlType = type;
2012
- if (type === 'margin') {
2015
+ if ((type === 'margin') || ((type === 'spot') && (marginMode !== undefined))) {
2013
2016
  urlType = 'spot'; // spot-margin shares the same stream as regular spot
2014
2017
  }
2015
2018
  const url = this.urls['api']['ws'][urlType] + '/' + this.options[type]['listenKey'];
@@ -6,10 +6,15 @@
6
6
 
7
7
  // ---------------------------------------------------------------------------
8
8
  import binance from './binance.js';
9
+ import binancecoinmRest from '../binancecoinm.js';
9
10
  // ---------------------------------------------------------------------------
10
11
  export default class binancecoinm extends binance {
11
12
  describe() {
12
- return this.deepExtend(super.describe(), {
13
+ // eslint-disable-next-line new-cap
14
+ const restInstance = new binancecoinmRest();
15
+ const restDescribe = restInstance.describe();
16
+ const extended = this.deepExtend(super.describe(), restDescribe);
17
+ return this.deepExtend(extended, {
13
18
  'id': 'binancecoinm',
14
19
  'name': 'Binance COIN-M',
15
20
  'urls': {
@@ -6,10 +6,15 @@
6
6
 
7
7
  // ---------------------------------------------------------------------------
8
8
  import binance from './binance.js';
9
+ import binanceusRest from '../binanceus.js';
9
10
  // ---------------------------------------------------------------------------
10
11
  export default class binanceus extends binance {
11
12
  describe() {
12
- return this.deepExtend(super.describe(), {
13
+ // eslint-disable-next-line new-cap
14
+ const restInstance = new binanceusRest();
15
+ const restDescribe = restInstance.describe();
16
+ const extended = this.deepExtend(super.describe(), restDescribe);
17
+ return this.deepExtend(extended, {
13
18
  'id': 'binanceus',
14
19
  'name': 'Binance US',
15
20
  'countries': ['US'],
@@ -6,10 +6,15 @@
6
6
 
7
7
  // ---------------------------------------------------------------------------
8
8
  import hitbtc from './hitbtc.js';
9
+ import bequantRest from '../bequant.js';
9
10
  // ---------------------------------------------------------------------------
10
11
  export default class bitcoincom extends hitbtc {
11
12
  describe() {
12
- return this.deepExtend(super.describe(), {
13
+ // eslint-disable-next-line new-cap
14
+ const restInstance = new bequantRest();
15
+ const restDescribe = restInstance.describe();
16
+ const extended = this.deepExtend(super.describe(), restDescribe);
17
+ return this.deepExtend(extended, {
13
18
  'id': 'bitcoincom',
14
19
  'name': 'bitcoin.com',
15
20
  'countries': ['KN'],
@@ -1248,7 +1248,7 @@ export default class bitget extends bitgetRest {
1248
1248
  'price': this.safeString(order, 'price'),
1249
1249
  'stopPrice': triggerPrice,
1250
1250
  'triggerPrice': triggerPrice,
1251
- 'amount': this.safeString2(order, 'size', 'baseSize'),
1251
+ 'amount': this.safeString(order, 'baseVolume'),
1252
1252
  'cost': this.safeStringN(order, ['notional', 'notionalUsd', 'quoteSize']),
1253
1253
  'average': this.omitZero(this.safeString2(order, 'priceAvg', 'fillPrice')),
1254
1254
  'filled': this.safeString2(order, 'accBaseVolume', 'baseVolume'),
@@ -349,7 +349,12 @@ export default class bitrue extends bitrueRest {
349
349
  const symbol = market['symbol'];
350
350
  const timestamp = this.safeInteger(message, 'ts');
351
351
  const tick = this.safeValue(message, 'tick', {});
352
- const orderbook = this.parseOrderBook(tick, symbol, timestamp, 'buys', 'asks');
352
+ let orderbook = this.safeValue(this.orderbooks, symbol);
353
+ if (orderbook === undefined) {
354
+ orderbook = this.orderBook();
355
+ }
356
+ const snapshot = this.parseOrderBook(tick, symbol, timestamp, 'buys', 'asks');
357
+ orderbook.reset(snapshot);
353
358
  this.orderbooks[symbol] = orderbook;
354
359
  const messageHash = 'orderbook:' + symbol;
355
360
  client.resolve(orderbook, messageHash);
@@ -35,6 +35,12 @@ export default class hitbtc extends hitbtcRest {
35
35
  'private': 'wss://api.hitbtc.com/api/3/ws/trading',
36
36
  },
37
37
  },
38
+ 'test': {
39
+ 'ws': {
40
+ 'public': 'wss://api.demo.hitbtc.com/api/3/ws/public',
41
+ 'private': 'wss://api.demo.hitbtc.com/api/3/ws/trading',
42
+ },
43
+ },
38
44
  },
39
45
  'options': {
40
46
  'tradesLimit': 1000,