ccxt 4.4.91 → 4.4.93

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 (64) hide show
  1. package/README.md +3 -3
  2. package/dist/ccxt.browser.min.js +2 -2
  3. package/dist/cjs/ccxt.js +1 -1
  4. package/dist/cjs/src/ascendex.js +9 -8
  5. package/dist/cjs/src/base/Exchange.js +81 -33
  6. package/dist/cjs/src/binance.js +44 -1
  7. package/dist/cjs/src/bitmart.js +7 -0
  8. package/dist/cjs/src/bitmex.js +4 -4
  9. package/dist/cjs/src/bitvavo.js +10 -1
  10. package/dist/cjs/src/bybit.js +83 -8
  11. package/dist/cjs/src/coinbaseexchange.js +53 -0
  12. package/dist/cjs/src/coincheck.js +47 -4
  13. package/dist/cjs/src/coinex.js +19 -14
  14. package/dist/cjs/src/cryptomus.js +30 -53
  15. package/dist/cjs/src/deribit.js +6 -6
  16. package/dist/cjs/src/exmo.js +72 -59
  17. package/dist/cjs/src/htx.js +1 -1
  18. package/dist/cjs/src/hyperliquid.js +3 -2
  19. package/dist/cjs/src/krakenfutures.js +1 -1
  20. package/dist/cjs/src/kucoin.js +13 -15
  21. package/dist/cjs/src/latoken.js +19 -74
  22. package/dist/cjs/src/lbank.js +118 -34
  23. package/dist/cjs/src/okx.js +158 -2
  24. package/dist/cjs/src/paradex.js +54 -0
  25. package/dist/cjs/src/phemex.js +3 -3
  26. package/dist/cjs/src/pro/bitstamp.js +55 -16
  27. package/dist/cjs/src/pro/bybit.js +6 -7
  28. package/js/ccxt.d.ts +1 -1
  29. package/js/ccxt.js +1 -1
  30. package/js/src/abstract/lbank.d.ts +1 -0
  31. package/js/src/ascendex.js +9 -8
  32. package/js/src/base/Exchange.d.ts +5 -1
  33. package/js/src/base/Exchange.js +81 -33
  34. package/js/src/binance.d.ts +10 -0
  35. package/js/src/binance.js +44 -1
  36. package/js/src/bitmart.d.ts +7 -0
  37. package/js/src/bitmart.js +7 -0
  38. package/js/src/bitmex.d.ts +1 -1
  39. package/js/src/bitmex.js +4 -4
  40. package/js/src/bitvavo.js +10 -1
  41. package/js/src/bybit.d.ts +12 -1
  42. package/js/src/bybit.js +83 -8
  43. package/js/src/coinbaseexchange.js +53 -0
  44. package/js/src/coincheck.js +48 -5
  45. package/js/src/coinex.js +16 -13
  46. package/js/src/cryptomus.js +30 -53
  47. package/js/src/deribit.js +6 -6
  48. package/js/src/exmo.js +72 -59
  49. package/js/src/htx.js +1 -1
  50. package/js/src/hyperliquid.js +3 -2
  51. package/js/src/krakenfutures.js +1 -1
  52. package/js/src/kucoin.js +13 -15
  53. package/js/src/latoken.d.ts +0 -1
  54. package/js/src/latoken.js +19 -74
  55. package/js/src/lbank.d.ts +9 -1
  56. package/js/src/lbank.js +118 -34
  57. package/js/src/okx.d.ts +13 -1
  58. package/js/src/okx.js +158 -2
  59. package/js/src/paradex.d.ts +10 -0
  60. package/js/src/paradex.js +54 -0
  61. package/js/src/phemex.js +3 -3
  62. package/js/src/pro/bitstamp.js +55 -16
  63. package/js/src/pro/bybit.js +7 -8
  64. package/package.json +1 -1
package/js/src/bybit.js CHANGED
@@ -60,6 +60,7 @@ export default class bybit extends Exchange {
60
60
  'createTriggerOrder': true,
61
61
  'editOrder': true,
62
62
  'editOrders': true,
63
+ 'fetchAllGreeks': true,
63
64
  'fetchBalance': true,
64
65
  'fetchBidsAsks': 'emulated',
65
66
  'fetchBorrowInterest': false,
@@ -1158,6 +1159,7 @@ export default class bybit extends Exchange {
1158
1159
  '4h': '4h',
1159
1160
  '1d': '1d',
1160
1161
  },
1162
+ 'useMarkPriceForPositionCollateral': false, // use mark price for position collateral
1161
1163
  },
1162
1164
  'features': {
1163
1165
  'default': {
@@ -3887,7 +3889,7 @@ export default class bybit extends Exchange {
3887
3889
  * @param {int} [params.isLeverage] *unified spot only* false then spot trading true then margin trading
3888
3890
  * @param {string} [params.tpslMode] *contract only* 'full' or 'partial'
3889
3891
  * @param {string} [params.mmp] *option only* market maker protection
3890
- * @param {string} [params.triggerDirection] *contract only* the direction for trigger orders, 'above' or 'below'
3892
+ * @param {string} [params.triggerDirection] *contract only* the direction for trigger orders, 'ascending' or 'descending'
3891
3893
  * @param {float} [params.triggerPrice] The price at which a trigger order is triggered at
3892
3894
  * @param {float} [params.stopLossPrice] The price at which a stop loss order is triggered at
3893
3895
  * @param {float} [params.takeProfitPrice] The price at which a take profit order is triggered at
@@ -4142,9 +4144,9 @@ export default class bybit extends Exchange {
4142
4144
  }
4143
4145
  else {
4144
4146
  if (triggerDirection === undefined) {
4145
- throw new ArgumentsRequired(this.id + ' stop/trigger orders require a triggerDirection parameter, either "above" or "below" to determine the direction of the trigger.');
4147
+ throw new ArgumentsRequired(this.id + ' stop/trigger orders require a triggerDirection parameter, either "ascending" or "descending" to determine the direction of the trigger.');
4146
4148
  }
4147
- const isAsending = ((triggerDirection === 'above') || (triggerDirection === '1'));
4149
+ const isAsending = ((triggerDirection === 'ascending') || (triggerDirection === 'above') || (triggerDirection === '1'));
4148
4150
  request['triggerDirection'] = isAsending ? 1 : 2;
4149
4151
  }
4150
4152
  request['triggerPrice'] = this.getPrice(symbol, triggerPrice);
@@ -6556,12 +6558,14 @@ export default class bybit extends Exchange {
6556
6558
  }
6557
6559
  let collateralString = this.safeString(position, 'positionBalance');
6558
6560
  const entryPrice = this.omitZero(this.safeStringN(position, ['entryPrice', 'avgPrice', 'avgEntryPrice']));
6561
+ const markPrice = this.safeString(position, 'markPrice');
6559
6562
  const liquidationPrice = this.omitZero(this.safeString(position, 'liqPrice'));
6560
6563
  const leverage = this.safeString(position, 'leverage');
6561
6564
  if (liquidationPrice !== undefined) {
6562
6565
  if (market['settle'] === 'USDC') {
6563
6566
  // (Entry price - Liq price) * Contracts + Maintenance Margin + (unrealised pnl) = Collateral
6564
- const difference = Precise.stringAbs(Precise.stringSub(entryPrice, liquidationPrice));
6567
+ const price = this.safeBool(this.options, 'useMarkPriceForPositionCollateral', false) ? markPrice : entryPrice;
6568
+ const difference = Precise.stringAbs(Precise.stringSub(price, liquidationPrice));
6565
6569
  collateralString = Precise.stringAdd(Precise.stringAdd(Precise.stringMul(difference, size), maintenanceMarginString), unrealisedPnl);
6566
6570
  }
6567
6571
  else {
@@ -6617,7 +6621,7 @@ export default class bybit extends Exchange {
6617
6621
  'contractSize': this.safeNumber(market, 'contractSize'),
6618
6622
  'marginRatio': this.parseNumber(marginRatio),
6619
6623
  'liquidationPrice': this.parseNumber(liquidationPrice),
6620
- 'markPrice': this.safeNumber(position, 'markPrice'),
6624
+ 'markPrice': this.parseNumber(markPrice),
6621
6625
  'lastPrice': this.safeNumber(position, 'avgExitPrice'),
6622
6626
  'collateral': this.parseNumber(collateralString),
6623
6627
  'marginMode': marginMode,
@@ -8037,6 +8041,77 @@ export default class bybit extends Exchange {
8037
8041
  'datetime': this.iso8601(timestamp),
8038
8042
  });
8039
8043
  }
8044
+ /**
8045
+ * @method
8046
+ * @name bybit#fetchAllGreeks
8047
+ * @description fetches all option contracts greeks, financial metrics used to measure the factors that affect the price of an options contract
8048
+ * @see https://bybit-exchange.github.io/docs/api-explorer/v5/market/tickers
8049
+ * @param {string[]} [symbols] unified symbols of the markets to fetch greeks for, all markets are returned if not assigned
8050
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
8051
+ * @param {string} [params.baseCoin] the baseCoin of the symbol, default is BTC
8052
+ * @returns {object} a [greeks structure]{@link https://docs.ccxt.com/#/?id=greeks-structure}
8053
+ */
8054
+ async fetchAllGreeks(symbols = undefined, params = {}) {
8055
+ await this.loadMarkets();
8056
+ symbols = this.marketSymbols(symbols, undefined, true, true, true);
8057
+ const baseCoin = this.safeString(params, 'baseCoin', 'BTC');
8058
+ const request = {
8059
+ 'category': 'option',
8060
+ 'baseCoin': baseCoin,
8061
+ };
8062
+ let market = undefined;
8063
+ if (symbols !== undefined) {
8064
+ const symbolsLength = symbols.length;
8065
+ if (symbolsLength === 1) {
8066
+ market = this.market(symbols[0]);
8067
+ request['symbol'] = market['id'];
8068
+ }
8069
+ }
8070
+ const response = await this.publicGetV5MarketTickers(this.extend(request, params));
8071
+ //
8072
+ // {
8073
+ // "retCode": 0,
8074
+ // "retMsg": "SUCCESS",
8075
+ // "result": {
8076
+ // "category": "option",
8077
+ // "list": [
8078
+ // {
8079
+ // "symbol": "BTC-26JAN24-39000-C",
8080
+ // "bid1Price": "3205",
8081
+ // "bid1Size": "7.1",
8082
+ // "bid1Iv": "0.5478",
8083
+ // "ask1Price": "3315",
8084
+ // "ask1Size": "1.98",
8085
+ // "ask1Iv": "0.5638",
8086
+ // "lastPrice": "3230",
8087
+ // "highPrice24h": "3255",
8088
+ // "lowPrice24h": "3200",
8089
+ // "markPrice": "3273.02263032",
8090
+ // "indexPrice": "36790.96",
8091
+ // "markIv": "0.5577",
8092
+ // "underlyingPrice": "37649.67254894",
8093
+ // "openInterest": "19.67",
8094
+ // "turnover24h": "170140.33875912",
8095
+ // "volume24h": "4.56",
8096
+ // "totalVolume": "22",
8097
+ // "totalTurnover": "789305",
8098
+ // "delta": "0.49640971",
8099
+ // "gamma": "0.00004131",
8100
+ // "vega": "69.08651675",
8101
+ // "theta": "-24.9443226",
8102
+ // "predictedDeliveryPrice": "0",
8103
+ // "change24h": "0.18532111"
8104
+ // }
8105
+ // ]
8106
+ // },
8107
+ // "retExtInfo": {},
8108
+ // "time": 1699584008326
8109
+ // }
8110
+ //
8111
+ const result = this.safeDict(response, 'result', {});
8112
+ const data = this.safeList(result, 'list', []);
8113
+ return this.parseAllGreeks(data, symbols);
8114
+ }
8040
8115
  parseGreeks(greeks, market = undefined) {
8041
8116
  //
8042
8117
  // {
@@ -9182,7 +9257,7 @@ export default class bybit extends Exchange {
9182
9257
  }
9183
9258
  else {
9184
9259
  authFull = auth_base + queryEncoded;
9185
- url += '?' + this.rawencode(query);
9260
+ url += '?' + queryEncoded;
9186
9261
  }
9187
9262
  let signature = undefined;
9188
9263
  if (this.secret.indexOf('PRIVATE KEY') > -1) {
@@ -9200,7 +9275,7 @@ export default class bybit extends Exchange {
9200
9275
  'timestamp': timestamp,
9201
9276
  });
9202
9277
  const sortedQuery = this.keysort(query);
9203
- const auth = this.rawencode(sortedQuery);
9278
+ const auth = this.rawencode(sortedQuery, true);
9204
9279
  let signature = undefined;
9205
9280
  if (this.secret.indexOf('PRIVATE KEY') > -1) {
9206
9281
  signature = rsa(auth, this.secret, sha256);
@@ -9227,7 +9302,7 @@ export default class bybit extends Exchange {
9227
9302
  }
9228
9303
  }
9229
9304
  else {
9230
- url += '?' + this.rawencode(sortedQuery);
9305
+ url += '?' + this.rawencode(sortedQuery, true);
9231
9306
  url += '&sign=' + signature;
9232
9307
  }
9233
9308
  }
@@ -31,31 +31,73 @@ export default class coinbaseexchange extends Exchange {
31
31
  'swap': false,
32
32
  'future': false,
33
33
  'option': false,
34
+ 'addMargin': false,
35
+ 'borrowCrossMargin': false,
36
+ 'borrowIsolatedMargin': false,
37
+ 'borrowMargin': false,
34
38
  'cancelAllOrders': true,
35
39
  'cancelOrder': true,
40
+ 'closeAllPositions': false,
41
+ 'closePosition': false,
36
42
  'createDepositAddress': true,
37
43
  'createOrder': true,
44
+ 'createOrderWithTakeProfitAndStopLoss': false,
45
+ 'createOrderWithTakeProfitAndStopLossWs': false,
46
+ 'createPostOnlyOrder': false,
38
47
  'createReduceOnlyOrder': false,
39
48
  'createStopLimitOrder': true,
40
49
  'createStopMarketOrder': true,
41
50
  'createStopOrder': true,
42
51
  'fetchAccounts': true,
43
52
  'fetchBalance': true,
53
+ 'fetchBorrowInterest': false,
54
+ 'fetchBorrowRate': false,
55
+ 'fetchBorrowRateHistories': false,
56
+ 'fetchBorrowRateHistory': false,
57
+ 'fetchBorrowRates': false,
58
+ 'fetchBorrowRatesPerSymbol': false,
44
59
  'fetchClosedOrders': true,
60
+ 'fetchCrossBorrowRate': false,
61
+ 'fetchCrossBorrowRates': false,
45
62
  'fetchCurrencies': true,
46
63
  'fetchDepositAddress': false,
47
64
  'fetchDeposits': true,
48
65
  'fetchDepositsWithdrawals': true,
49
66
  'fetchFundingHistory': false,
67
+ 'fetchFundingInterval': false,
68
+ 'fetchFundingIntervals': false,
50
69
  'fetchFundingRate': false,
51
70
  'fetchFundingRateHistory': false,
52
71
  'fetchFundingRates': false,
72
+ 'fetchGreeks': false,
73
+ 'fetchIndexOHLCV': false,
74
+ 'fetchIsolatedBorrowRate': false,
75
+ 'fetchIsolatedBorrowRates': false,
76
+ 'fetchIsolatedPositions': false,
53
77
  'fetchLedger': true,
78
+ 'fetchLeverage': false,
79
+ 'fetchLeverages': false,
80
+ 'fetchLeverageTiers': false,
81
+ 'fetchLiquidations': false,
82
+ 'fetchLongShortRatio': false,
83
+ 'fetchLongShortRatioHistory': false,
84
+ 'fetchMarginAdjustmentHistory': false,
54
85
  'fetchMarginMode': false,
86
+ 'fetchMarginModes': false,
87
+ 'fetchMarketLeverageTiers': false,
55
88
  'fetchMarkets': true,
89
+ 'fetchMarkOHLCV': false,
90
+ 'fetchMarkPrices': false,
91
+ 'fetchMyLiquidations': false,
92
+ 'fetchMySettlementHistory': false,
56
93
  'fetchMyTrades': true,
57
94
  'fetchOHLCV': true,
95
+ 'fetchOpenInterest': false,
96
+ 'fetchOpenInterestHistory': false,
97
+ 'fetchOpenInterests': false,
58
98
  'fetchOpenOrders': true,
99
+ 'fetchOption': false,
100
+ 'fetchOptionChain': false,
59
101
  'fetchOrder': true,
60
102
  'fetchOrderBook': true,
61
103
  'fetchOrders': true,
@@ -67,6 +109,8 @@ export default class coinbaseexchange extends Exchange {
67
109
  'fetchPositionsForSymbol': false,
68
110
  'fetchPositionsHistory': false,
69
111
  'fetchPositionsRisk': false,
112
+ 'fetchPremiumIndexOHLCV': false,
113
+ 'fetchSettlementHistory': false,
70
114
  'fetchTicker': true,
71
115
  'fetchTickers': true,
72
116
  'fetchTime': true,
@@ -74,7 +118,16 @@ export default class coinbaseexchange extends Exchange {
74
118
  'fetchTradingFee': false,
75
119
  'fetchTradingFees': true,
76
120
  'fetchTransactions': 'emulated',
121
+ 'fetchVolatilityHistory': false,
77
122
  'fetchWithdrawals': true,
123
+ 'reduceMargin': false,
124
+ 'repayCrossMargin': false,
125
+ 'repayIsolatedMargin': false,
126
+ 'repayMargin': false,
127
+ 'setLeverage': false,
128
+ 'setMargin': false,
129
+ 'setMarginMode': false,
130
+ 'setPositionMode': false,
78
131
  'withdraw': true,
79
132
  },
80
133
  'timeframes': {
@@ -6,7 +6,7 @@
6
6
 
7
7
  // ---------------------------------------------------------------------------
8
8
  import Exchange from './abstract/coincheck.js';
9
- import { BadSymbol, ExchangeError, AuthenticationError } from './base/errors.js';
9
+ import { BadSymbol, ExchangeError, AuthenticationError, ArgumentsRequired } from './base/errors.js';
10
10
  import { TICK_SIZE } from './base/functions/number.js';
11
11
  import { sha256 } from './static_dependencies/noble-hashes/sha256.js';
12
12
  // ---------------------------------------------------------------------------
@@ -29,30 +29,59 @@ export default class coincheck extends Exchange {
29
29
  'future': false,
30
30
  'option': false,
31
31
  'addMargin': false,
32
+ 'borrowCrossMargin': false,
33
+ 'borrowIsolatedMargin': false,
34
+ 'borrowMargin': false,
32
35
  'cancelOrder': true,
33
36
  'closeAllPositions': false,
34
37
  'closePosition': false,
35
38
  'createOrder': true,
39
+ 'createOrderWithTakeProfitAndStopLoss': false,
40
+ 'createOrderWithTakeProfitAndStopLossWs': false,
41
+ 'createPostOnlyOrder': false,
36
42
  'createReduceOnlyOrder': false,
37
43
  'fetchBalance': true,
44
+ 'fetchBorrowInterest': false,
45
+ 'fetchBorrowRate': false,
38
46
  'fetchBorrowRateHistories': false,
39
47
  'fetchBorrowRateHistory': false,
48
+ 'fetchBorrowRates': false,
49
+ 'fetchBorrowRatesPerSymbol': false,
40
50
  'fetchCrossBorrowRate': false,
41
51
  'fetchCrossBorrowRates': false,
42
52
  'fetchDeposits': true,
43
53
  'fetchFundingHistory': false,
54
+ 'fetchFundingInterval': false,
55
+ 'fetchFundingIntervals': false,
44
56
  'fetchFundingRate': false,
45
57
  'fetchFundingRateHistory': false,
46
58
  'fetchFundingRates': false,
59
+ 'fetchGreeks': false,
47
60
  'fetchIndexOHLCV': false,
48
61
  'fetchIsolatedBorrowRate': false,
49
62
  'fetchIsolatedBorrowRates': false,
63
+ 'fetchIsolatedPositions': false,
50
64
  'fetchLeverage': false,
65
+ 'fetchLeverages': false,
66
+ 'fetchLeverageTiers': false,
67
+ 'fetchLiquidations': false,
68
+ 'fetchLongShortRatio': false,
69
+ 'fetchLongShortRatioHistory': false,
70
+ 'fetchMarginAdjustmentHistory': false,
51
71
  'fetchMarginMode': false,
72
+ 'fetchMarginModes': false,
73
+ 'fetchMarketLeverageTiers': false,
52
74
  'fetchMarkOHLCV': false,
75
+ 'fetchMarkPrices': false,
76
+ 'fetchMyLiquidations': false,
77
+ 'fetchMySettlementHistory': false,
53
78
  'fetchMyTrades': true,
79
+ 'fetchOpenInterest': false,
54
80
  'fetchOpenInterestHistory': false,
81
+ 'fetchOpenInterests': false,
55
82
  'fetchOpenOrders': true,
83
+ 'fetchOption': false,
84
+ 'fetchOptionChain': false,
56
85
  'fetchOrderBook': true,
57
86
  'fetchPosition': false,
58
87
  'fetchPositionHistory': false,
@@ -62,13 +91,19 @@ export default class coincheck extends Exchange {
62
91
  'fetchPositionsHistory': false,
63
92
  'fetchPositionsRisk': false,
64
93
  'fetchPremiumIndexOHLCV': false,
94
+ 'fetchSettlementHistory': false,
65
95
  'fetchTicker': true,
66
96
  'fetchTrades': true,
67
97
  'fetchTradingFee': false,
68
98
  'fetchTradingFees': true,
99
+ 'fetchVolatilityHistory': false,
69
100
  'fetchWithdrawals': true,
70
101
  'reduceMargin': false,
102
+ 'repayCrossMargin': false,
103
+ 'repayIsolatedMargin': false,
104
+ 'repayMargin': false,
71
105
  'setLeverage': false,
106
+ 'setMargin': false,
72
107
  'setMarginMode': false,
73
108
  'setPositionMode': false,
74
109
  'ws': true,
@@ -648,10 +683,18 @@ export default class coincheck extends Exchange {
648
683
  'pair': market['id'],
649
684
  };
650
685
  if (type === 'market') {
651
- const order_type = type + '_' + side;
652
- request['order_type'] = order_type;
653
- const prefix = (side === 'buy') ? (order_type + '_') : '';
654
- request[prefix + 'amount'] = amount;
686
+ request['order_type'] = type + '_' + side;
687
+ if (side === 'sell') {
688
+ request['amount'] = amount;
689
+ }
690
+ else {
691
+ const cost = this.safeNumber(params, 'cost');
692
+ params = this.omit(params, 'cost');
693
+ if (cost !== undefined) {
694
+ throw new ArgumentsRequired(this.id + ' createOrder() : you should use "cost" parameter instead of "amount" argument to create market buy orders');
695
+ }
696
+ request['market_buy_amount'] = cost;
697
+ }
655
698
  }
656
699
  else {
657
700
  request['order_type'] = side;
package/js/src/coinex.js CHANGED
@@ -6,7 +6,7 @@
6
6
 
7
7
  // ---------------------------------------------------------------------------
8
8
  import Exchange from './abstract/coinex.js';
9
- import { ExchangeError, ArgumentsRequired, BadSymbol, InsufficientFunds, OrderNotFound, InvalidOrder, AuthenticationError, PermissionDenied, ExchangeNotAvailable, RequestTimeout, BadRequest, RateLimitExceeded, NotSupported, AccountSuspended } from './base/errors.js';
9
+ import { ExchangeError, ArgumentsRequired, BadSymbol, InsufficientFunds, OrderNotFound, InvalidOrder, AuthenticationError, PermissionDenied, ExchangeNotAvailable, RequestTimeout, BadRequest, RateLimitExceeded, NotSupported, AccountSuspended, OperationFailed } from './base/errors.js';
10
10
  import { Precise } from './base/Precise.js';
11
11
  import { TICK_SIZE } from './base/functions/number.js';
12
12
  import { sha256 } from './static_dependencies/noble-hashes/sha256.js';
@@ -660,6 +660,7 @@ export default class coinex extends Exchange {
660
660
  'broad': {
661
661
  'ip not allow visit': PermissionDenied,
662
662
  'service too busy': ExchangeNotAvailable,
663
+ 'Service is not available during funding fee settlement': OperationFailed,
663
664
  },
664
665
  },
665
666
  });
@@ -787,7 +788,7 @@ export default class coinex extends Exchange {
787
788
  'max': undefined,
788
789
  },
789
790
  },
790
- 'networks': {},
791
+ 'networks': networks,
791
792
  'type': 'crypto',
792
793
  'info': coin,
793
794
  });
@@ -820,17 +821,19 @@ export default class coinex extends Exchange {
820
821
  // "code": 0,
821
822
  // "data": [
822
823
  // {
823
- // "base_ccy": "SORA",
824
+ // "market": "BTCUSDT",
825
+ // "taker_fee_rate": "0.002",
826
+ // "maker_fee_rate": "0.002",
827
+ // "min_amount": "0.0005",
828
+ // "base_ccy": "BTC",
829
+ // "quote_ccy": "USDT",
824
830
  // "base_ccy_precision": 8,
831
+ // "quote_ccy_precision": 2,
825
832
  // "is_amm_available": true,
826
- // "is_margin_available": false,
827
- // "maker_fee_rate": "0.003",
828
- // "market": "SORAUSDT",
829
- // "min_amount": "500",
830
- // "quote_ccy": "USDT",
831
- // "quote_ccy_precision": 6,
832
- // "taker_fee_rate": "0.003"
833
- // },
833
+ // "is_margin_available": true,
834
+ // "is_pre_trading_available": true,
835
+ // "is_api_trading_available": true
836
+ // }
834
837
  // ],
835
838
  // "message": "OK"
836
839
  // }
@@ -856,11 +859,11 @@ export default class coinex extends Exchange {
856
859
  'settleId': undefined,
857
860
  'type': 'spot',
858
861
  'spot': true,
859
- 'margin': undefined,
862
+ 'margin': this.safeBool(market, 'is_margin_available'),
860
863
  'swap': false,
861
864
  'future': false,
862
865
  'option': false,
863
- 'active': undefined,
866
+ 'active': this.safeBool(market, 'is_api_trading_available'),
864
867
  'contract': false,
865
868
  'linear': undefined,
866
869
  'inverse': undefined,
@@ -366,68 +366,45 @@ export default class cryptomus extends Exchange {
366
366
  // }
367
367
  //
368
368
  const coins = this.safeList(response, 'result');
369
+ const groupedById = this.groupBy(coins, 'currency_code');
370
+ const keys = Object.keys(groupedById);
369
371
  const result = {};
370
- for (let i = 0; i < coins.length; i++) {
371
- const networkEntry = coins[i];
372
- const currencyId = this.safeString(networkEntry, 'currency_code');
373
- const code = this.safeCurrencyCode(currencyId);
374
- if (!(code in result)) {
375
- result[code] = {
376
- 'id': currencyId,
377
- 'code': code,
378
- 'precision': undefined,
379
- 'type': undefined,
380
- 'name': undefined,
381
- 'active': undefined,
382
- 'deposit': undefined,
383
- 'withdraw': undefined,
384
- 'fee': undefined,
372
+ for (let i = 0; i < keys.length; i++) {
373
+ const id = keys[i];
374
+ const code = this.safeCurrencyCode(id);
375
+ const networks = {};
376
+ const networkEntries = groupedById[id];
377
+ for (let j = 0; j < networkEntries.length; j++) {
378
+ const networkEntry = networkEntries[j];
379
+ const networkId = this.safeString(networkEntry, 'network_code');
380
+ const networkCode = this.networkIdToCode(networkId);
381
+ networks[networkCode] = {
382
+ 'id': networkId,
383
+ 'network': networkCode,
385
384
  'limits': {
386
385
  'withdraw': {
387
- 'min': undefined,
388
- 'max': undefined,
386
+ 'min': this.safeNumber(networkEntry, 'min_withdraw'),
387
+ 'max': this.safeNumber(networkEntry, 'max_withdraw'),
389
388
  },
390
389
  'deposit': {
391
- 'min': undefined,
392
- 'max': undefined,
390
+ 'min': this.safeNumber(networkEntry, 'min_deposit'),
391
+ 'max': this.safeNumber(networkEntry, 'max_deposit'),
393
392
  },
394
393
  },
395
- 'networks': {},
396
- 'info': {},
394
+ 'active': undefined,
395
+ 'deposit': this.safeBool(networkEntry, 'can_withdraw'),
396
+ 'withdraw': this.safeBool(networkEntry, 'can_deposit'),
397
+ 'fee': undefined,
398
+ 'precision': undefined,
399
+ 'info': networkEntry,
397
400
  };
398
401
  }
399
- const networkId = this.safeString(networkEntry, 'network_code');
400
- const networkCode = this.networkIdToCode(networkId);
401
- result[code]['networks'][networkCode] = {
402
- 'id': networkId,
403
- 'network': networkCode,
404
- 'limits': {
405
- 'withdraw': {
406
- 'min': this.safeNumber(networkEntry, 'min_withdraw'),
407
- 'max': this.safeNumber(networkEntry, 'max_withdraw'),
408
- },
409
- 'deposit': {
410
- 'min': this.safeNumber(networkEntry, 'min_deposit'),
411
- 'max': this.safeNumber(networkEntry, 'max_deposit'),
412
- },
413
- },
414
- 'active': undefined,
415
- 'deposit': this.safeBool(networkEntry, 'can_withdraw'),
416
- 'withdraw': this.safeBool(networkEntry, 'can_deposit'),
417
- 'fee': undefined,
418
- 'precision': undefined,
419
- 'info': networkEntry,
420
- };
421
- // add entry in info
422
- const info = this.safeList(result[code], 'info', []);
423
- info.push(networkEntry);
424
- result[code]['info'] = info;
425
- }
426
- // only after all entries are formed in currencies, restructure each entry
427
- const allKeys = Object.keys(result);
428
- for (let i = 0; i < allKeys.length; i++) {
429
- const code = allKeys[i];
430
- result[code] = this.safeCurrencyStructure(result[code]); // this is needed after adding network entry
402
+ result[code] = this.safeCurrencyStructure({
403
+ 'id': id,
404
+ 'code': code,
405
+ 'networks': networks,
406
+ 'info': networkEntries,
407
+ });
431
408
  }
432
409
  return result;
433
410
  }
package/js/src/deribit.js CHANGED
@@ -2694,21 +2694,21 @@ export default class deribit extends Exchange {
2694
2694
  const unrealizedPnl = this.safeString(position, 'floating_profit_loss');
2695
2695
  const initialMarginString = this.safeString(position, 'initial_margin');
2696
2696
  const notionalString = this.safeString(position, 'size_currency');
2697
+ const notionalStringAbs = Precise.stringAbs(notionalString);
2697
2698
  const maintenanceMarginString = this.safeString(position, 'maintenance_margin');
2698
- const currentTime = this.milliseconds();
2699
2699
  return this.safePosition({
2700
2700
  'info': position,
2701
2701
  'id': undefined,
2702
2702
  'symbol': this.safeString(market, 'symbol'),
2703
- 'timestamp': currentTime,
2704
- 'datetime': this.iso8601(currentTime),
2703
+ 'timestamp': undefined,
2704
+ 'datetime': undefined,
2705
2705
  'lastUpdateTimestamp': undefined,
2706
2706
  'initialMargin': this.parseNumber(initialMarginString),
2707
- 'initialMarginPercentage': this.parseNumber(Precise.stringMul(Precise.stringDiv(initialMarginString, notionalString), '100')),
2707
+ 'initialMarginPercentage': this.parseNumber(Precise.stringMul(Precise.stringDiv(initialMarginString, notionalStringAbs), '100')),
2708
2708
  'maintenanceMargin': this.parseNumber(maintenanceMarginString),
2709
- 'maintenanceMarginPercentage': this.parseNumber(Precise.stringMul(Precise.stringDiv(maintenanceMarginString, notionalString), '100')),
2709
+ 'maintenanceMarginPercentage': this.parseNumber(Precise.stringMul(Precise.stringDiv(maintenanceMarginString, notionalStringAbs), '100')),
2710
2710
  'entryPrice': this.safeNumber(position, 'average_price'),
2711
- 'notional': this.parseNumber(notionalString),
2711
+ 'notional': this.parseNumber(notionalStringAbs),
2712
2712
  'leverage': this.safeInteger(position, 'leverage'),
2713
2713
  'unrealizedPnl': this.parseNumber(unrealizedPnl),
2714
2714
  'contracts': undefined,