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/dist/cjs/ccxt.js CHANGED
@@ -193,7 +193,7 @@ var xt$1 = require('./src/pro/xt.js');
193
193
 
194
194
  //-----------------------------------------------------------------------------
195
195
  // this is updated by vss.js when building
196
- const version = '4.4.91';
196
+ const version = '4.4.93';
197
197
  Exchange["default"].ccxtVersion = version;
198
198
  const exchanges = {
199
199
  'alpaca': alpaca,
@@ -1438,6 +1438,8 @@ class ascendex extends ascendex$1 {
1438
1438
  // "timestamp": 1573576916201
1439
1439
  // }
1440
1440
  //
1441
+ // & linear (fetchClosedOrders)
1442
+ //
1441
1443
  // {
1442
1444
  // "ac": "FUTURES",
1443
1445
  // "accountId": "fut2ODPhGiY71Pl4vtXnOZ00ssgD7QGn",
@@ -1445,7 +1447,7 @@ class ascendex extends ascendex$1 {
1445
1447
  // "orderId": "a17e0874ecbdU0711043490bbtcpDU5X",
1446
1448
  // "seqNum": -1,
1447
1449
  // "orderType": "Limit",
1448
- // "execInst": "NULL_VAL",
1450
+ // "execInst": "NULL_VAL", // NULL_VAL, ReduceOnly , ...
1449
1451
  // "side": "Buy",
1450
1452
  // "symbol": "BTC-PERP",
1451
1453
  // "price": "30000",
@@ -1534,14 +1536,14 @@ class ascendex extends ascendex$1 {
1534
1536
  const status = this.parseOrderStatus(this.safeString(order, 'status'));
1535
1537
  const marketId = this.safeString(order, 'symbol');
1536
1538
  const symbol = this.safeSymbol(marketId, market, '/');
1537
- let timestamp = this.safeInteger2(order, 'timestamp', 'sendingTime');
1539
+ let timestamp = this.safeIntegerN(order, ['timestamp', 'sendingTime', 'time']);
1538
1540
  const lastTradeTimestamp = this.safeInteger(order, 'lastExecTime');
1539
1541
  if (timestamp === undefined) {
1540
1542
  timestamp = lastTradeTimestamp;
1541
1543
  }
1542
1544
  const price = this.safeString(order, 'price');
1543
1545
  const amount = this.safeString(order, 'orderQty');
1544
- const average = this.safeString(order, 'avgPx');
1546
+ const average = this.safeString2(order, 'avgPx', 'avgFilledPx');
1545
1547
  const filled = this.safeStringN(order, ['cumFilledQty', 'cumQty', 'fillQty']);
1546
1548
  const id = this.safeString(order, 'orderId');
1547
1549
  let clientOrderId = this.safeString(order, 'id');
@@ -1573,12 +1575,12 @@ class ascendex extends ascendex$1 {
1573
1575
  }
1574
1576
  const triggerPrice = this.omitZero(this.safeString(order, 'stopPrice'));
1575
1577
  let reduceOnly = undefined;
1576
- const execInst = this.safeString(order, 'execInst');
1577
- if (execInst === 'reduceOnly') {
1578
+ const execInst = this.safeStringLower(order, 'execInst');
1579
+ if (execInst === 'reduceonly') {
1578
1580
  reduceOnly = true;
1579
1581
  }
1580
1582
  let postOnly = undefined;
1581
- if (execInst === 'Post') {
1583
+ if (execInst === 'post') {
1582
1584
  postOnly = true;
1583
1585
  }
1584
1586
  return this.safeOrder({
@@ -2342,8 +2344,7 @@ class ascendex extends ascendex$1 {
2342
2344
  // }
2343
2345
  //
2344
2346
  let data = this.safeList(response, 'data', []);
2345
- const isArray = Array.isArray(data);
2346
- if (!isArray) {
2347
+ if (!Array.isArray(data)) {
2347
2348
  data = this.safeList(data, 'data', []);
2348
2349
  }
2349
2350
  return this.parseOrders(data, market, since, limit);
@@ -859,6 +859,12 @@ class Exchange {
859
859
  return hexData;
860
860
  }
861
861
  }
862
+ mapToSafeMap(dict) {
863
+ return dict; // wrapper for go
864
+ }
865
+ safeMapToMap(dict) {
866
+ return dict; // wrapper for go
867
+ }
862
868
  spawn(method, ...args) {
863
869
  const future = Future.Future();
864
870
  // using setTimeout 0 to force the execution to run after the future is returned
@@ -2817,14 +2823,14 @@ class Exchange {
2817
2823
  }
2818
2824
  values.push(market);
2819
2825
  }
2820
- this.markets = this.indexBy(values, 'symbol');
2826
+ this.markets = this.mapToSafeMap(this.indexBy(values, 'symbol'));
2821
2827
  const marketsSortedBySymbol = this.keysort(this.markets);
2822
2828
  const marketsSortedById = this.keysort(this.markets_by_id);
2823
2829
  this.symbols = Object.keys(marketsSortedBySymbol);
2824
2830
  this.ids = Object.keys(marketsSortedById);
2825
2831
  if (currencies !== undefined) {
2826
2832
  // currencies is always undefined when called in constructor but not when called from loadMarkets
2827
- this.currencies = this.deepExtend(this.currencies, currencies);
2833
+ this.currencies = this.mapToSafeMap(this.deepExtend(this.currencies, currencies));
2828
2834
  }
2829
2835
  else {
2830
2836
  let baseCurrencies = [];
@@ -2854,8 +2860,8 @@ class Exchange {
2854
2860
  }
2855
2861
  baseCurrencies = this.sortBy(baseCurrencies, 'code', false, '');
2856
2862
  quoteCurrencies = this.sortBy(quoteCurrencies, 'code', false, '');
2857
- this.baseCurrencies = this.indexBy(baseCurrencies, 'code');
2858
- this.quoteCurrencies = this.indexBy(quoteCurrencies, 'code');
2863
+ this.baseCurrencies = this.mapToSafeMap(this.indexBy(baseCurrencies, 'code'));
2864
+ this.quoteCurrencies = this.mapToSafeMap(this.indexBy(quoteCurrencies, 'code'));
2859
2865
  const allCurrencies = this.arrayConcat(baseCurrencies, quoteCurrencies);
2860
2866
  const groupedCurrencies = this.groupBy(allCurrencies, 'code');
2861
2867
  const codes = Object.keys(groupedCurrencies);
@@ -2876,7 +2882,7 @@ class Exchange {
2876
2882
  resultingCurrencies.push(highestPrecisionCurrency);
2877
2883
  }
2878
2884
  const sortedCurrencies = this.sortBy(resultingCurrencies, 'code');
2879
- this.currencies = this.deepExtend(this.currencies, this.indexBy(sortedCurrencies, 'code'));
2885
+ this.currencies = this.mapToSafeMap(this.deepExtend(this.currencies, this.indexBy(sortedCurrencies, 'code')));
2880
2886
  }
2881
2887
  this.currencies_by_id = this.indexBySafe(this.currencies, 'id');
2882
2888
  const currenciesSortedByCode = this.keysort(this.currencies);
@@ -4016,7 +4022,7 @@ class Exchange {
4016
4022
  return this.filterBySinceLimit(sorted, since, limit, 0, tail);
4017
4023
  }
4018
4024
  parseLeverageTiers(response, symbols = undefined, marketIdKey = undefined) {
4019
- // marketIdKey should only be undefined when response is a dictionary
4025
+ // marketIdKey should only be undefined when response is a dictionary.
4020
4026
  symbols = this.marketSymbols(symbols);
4021
4027
  const tiers = {};
4022
4028
  let symbolsLength = 0;
@@ -5454,6 +5460,9 @@ class Exchange {
5454
5460
  async fetchGreeks(symbol, params = {}) {
5455
5461
  throw new errors.NotSupported(this.id + ' fetchGreeks() is not supported yet');
5456
5462
  }
5463
+ async fetchAllGreeks(symbols = undefined, params = {}) {
5464
+ throw new errors.NotSupported(this.id + ' fetchAllGreeks() is not supported yet');
5465
+ }
5457
5466
  async fetchOptionChain(code, params = {}) {
5458
5467
  throw new errors.NotSupported(this.id + ' fetchOptionChain() is not supported yet');
5459
5468
  }
@@ -5748,11 +5757,20 @@ class Exchange {
5748
5757
  if (precisionNumber === 0) {
5749
5758
  return '1';
5750
5759
  }
5751
- let parsedPrecision = '0.';
5752
- for (let i = 0; i < precisionNumber - 1; i++) {
5753
- parsedPrecision = parsedPrecision + '0';
5760
+ if (precisionNumber > 0) {
5761
+ let parsedPrecision = '0.';
5762
+ for (let i = 0; i < precisionNumber - 1; i++) {
5763
+ parsedPrecision = parsedPrecision + '0';
5764
+ }
5765
+ return parsedPrecision + '1';
5766
+ }
5767
+ else {
5768
+ let parsedPrecision = '1';
5769
+ for (let i = 0; i < precisionNumber * -1 - 1; i++) {
5770
+ parsedPrecision = parsedPrecision + '0';
5771
+ }
5772
+ return parsedPrecision + '0';
5754
5773
  }
5755
- return parsedPrecision + '1';
5756
5774
  }
5757
5775
  integerPrecisionToAmount(precision) {
5758
5776
  /**
@@ -6909,6 +6927,31 @@ class Exchange {
6909
6927
  parseGreeks(greeks, market = undefined) {
6910
6928
  throw new errors.NotSupported(this.id + ' parseGreeks () is not supported yet');
6911
6929
  }
6930
+ parseAllGreeks(greeks, symbols = undefined, params = {}) {
6931
+ //
6932
+ // the value of greeks is either a dict or a list
6933
+ //
6934
+ const results = [];
6935
+ if (Array.isArray(greeks)) {
6936
+ for (let i = 0; i < greeks.length; i++) {
6937
+ const parsedTicker = this.parseGreeks(greeks[i]);
6938
+ const greek = this.extend(parsedTicker, params);
6939
+ results.push(greek);
6940
+ }
6941
+ }
6942
+ else {
6943
+ const marketIds = Object.keys(greeks);
6944
+ for (let i = 0; i < marketIds.length; i++) {
6945
+ const marketId = marketIds[i];
6946
+ const market = this.safeMarket(marketId);
6947
+ const parsed = this.parseGreeks(greeks[marketId], market);
6948
+ const greek = this.extend(parsed, params);
6949
+ results.push(greek);
6950
+ }
6951
+ }
6952
+ symbols = this.marketSymbols(symbols);
6953
+ return this.filterByArray(results, 'symbol', symbols);
6954
+ }
6912
6955
  parseOption(chain, currency = undefined, market = undefined) {
6913
6956
  throw new errors.NotSupported(this.id + ' parseOption () is not supported yet');
6914
6957
  }
@@ -7049,7 +7092,7 @@ class Exchange {
7049
7092
  return reconstructedDate;
7050
7093
  }
7051
7094
  convertMarketIdExpireDate(date) {
7052
- // parse 03JAN24 to 240103
7095
+ // parse 03JAN24 to 240103.
7053
7096
  const monthMappping = {
7054
7097
  'JAN': '01',
7055
7098
  'FEB': '02',
@@ -7147,16 +7190,35 @@ class Exchange {
7147
7190
  */
7148
7191
  throw new errors.NotSupported(this.id + ' fetchTransfers () is not supported yet');
7149
7192
  }
7150
- cleanUnsubscription(client, subHash, unsubHash) {
7193
+ cleanUnsubscription(client, subHash, unsubHash, subHashIsPrefix = false) {
7151
7194
  if (unsubHash in client.subscriptions) {
7152
7195
  delete client.subscriptions[unsubHash];
7153
7196
  }
7154
- if (subHash in client.subscriptions) {
7155
- delete client.subscriptions[subHash];
7197
+ if (!subHashIsPrefix) {
7198
+ if (subHash in client.subscriptions) {
7199
+ delete client.subscriptions[subHash];
7200
+ }
7201
+ if (subHash in client.futures) {
7202
+ const error = new errors.UnsubscribeError(this.id + ' ' + subHash);
7203
+ client.reject(error, subHash);
7204
+ }
7156
7205
  }
7157
- if (subHash in client.futures) {
7158
- const error = new errors.UnsubscribeError(this.id + ' ' + subHash);
7159
- client.reject(error, subHash);
7206
+ else {
7207
+ const clientSubscriptions = Object.keys(client.subscriptions);
7208
+ for (let i = 0; i < clientSubscriptions.length; i++) {
7209
+ const sub = clientSubscriptions[i];
7210
+ if (sub.startsWith(subHash)) {
7211
+ delete client.subscriptions[sub];
7212
+ }
7213
+ }
7214
+ const clientFutures = Object.keys(client.futures);
7215
+ for (let i = 0; i < clientFutures.length; i++) {
7216
+ const future = clientFutures[i];
7217
+ if (future.startsWith(subHash)) {
7218
+ const error = new errors.UnsubscribeError(this.id + ' ' + future);
7219
+ client.reject(error, future);
7220
+ }
7221
+ }
7160
7222
  }
7161
7223
  client.resolve(true, unsubHash);
7162
7224
  }
@@ -7199,24 +7261,10 @@ class Exchange {
7199
7261
  }
7200
7262
  else {
7201
7263
  if (topic === 'myTrades' && (this.myTrades !== undefined)) {
7202
- // don't reset this.myTrades directly here
7203
- // because in c# we need to use a different object (thread-safe dict)
7204
- const keys = Object.keys(this.myTrades);
7205
- for (let i = 0; i < keys.length; i++) {
7206
- const key = keys[i];
7207
- if (key in this.myTrades) {
7208
- delete this.myTrades[key];
7209
- }
7210
- }
7264
+ this.myTrades = undefined;
7211
7265
  }
7212
7266
  else if (topic === 'orders' && (this.orders !== undefined)) {
7213
- const orderSymbols = Object.keys(this.orders);
7214
- for (let i = 0; i < orderSymbols.length; i++) {
7215
- const orderSymbol = orderSymbols[i];
7216
- if (orderSymbol in this.orders) {
7217
- delete this.orders[orderSymbol];
7218
- }
7219
- }
7267
+ this.orders = undefined;
7220
7268
  }
7221
7269
  else if (topic === 'ticker' && (this.tickers !== undefined)) {
7222
7270
  const tickerSymbols = Object.keys(this.tickers);
@@ -64,6 +64,7 @@ class binance extends binance$1 {
64
64
  'editOrder': true,
65
65
  'editOrders': true,
66
66
  'fetchAccounts': undefined,
67
+ 'fetchAllGreeks': true,
67
68
  'fetchBalance': true,
68
69
  'fetchBidsAsks': true,
69
70
  'fetchBorrowInterest': true,
@@ -11537,6 +11538,7 @@ class binance extends binance$1 {
11537
11538
  const request = {};
11538
11539
  if (symbol !== undefined) {
11539
11540
  request['symbol'] = market['id'];
11541
+ symbol = market['symbol'];
11540
11542
  }
11541
11543
  if (since !== undefined) {
11542
11544
  request['startTime'] = since;
@@ -11567,7 +11569,7 @@ class binance extends binance$1 {
11567
11569
  //
11568
11570
  const settlements = this.parseSettlements(response, market);
11569
11571
  const sorted = this.sortBy(settlements, 'timestamp');
11570
- return this.filterBySymbolSinceLimit(sorted, market['symbol'], since, limit);
11572
+ return this.filterBySymbolSinceLimit(sorted, symbol, since, limit);
11571
11573
  }
11572
11574
  parseSettlement(settlement, market) {
11573
11575
  //
@@ -13332,6 +13334,47 @@ class binance extends binance$1 {
13332
13334
  //
13333
13335
  return this.parseGreeks(response[0], market);
13334
13336
  }
13337
+ /**
13338
+ * @method
13339
+ * @name binance#fetchAllGreeks
13340
+ * @description fetches all option contracts greeks, financial metrics used to measure the factors that affect the price of an options contract
13341
+ * @see https://developers.binance.com/docs/derivatives/option/market-data/Option-Mark-Price
13342
+ * @param {string[]} [symbols] unified symbols of the markets to fetch greeks for, all markets are returned if not assigned
13343
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
13344
+ * @returns {object} a [greeks structure]{@link https://docs.ccxt.com/#/?id=greeks-structure}
13345
+ */
13346
+ async fetchAllGreeks(symbols = undefined, params = {}) {
13347
+ await this.loadMarkets();
13348
+ symbols = this.marketSymbols(symbols, undefined, true, true, true);
13349
+ const request = {};
13350
+ let market = undefined;
13351
+ if (symbols !== undefined) {
13352
+ const symbolsLength = symbols.length;
13353
+ if (symbolsLength === 1) {
13354
+ market = this.market(symbols[0]);
13355
+ request['symbol'] = market['id'];
13356
+ }
13357
+ }
13358
+ const response = await this.eapiPublicGetMark(this.extend(request, params));
13359
+ //
13360
+ // [
13361
+ // {
13362
+ // "symbol": "BTC-231229-40000-C",
13363
+ // "markPrice": "2012",
13364
+ // "bidIV": "0.60236275",
13365
+ // "askIV": "0.62267244",
13366
+ // "markIV": "0.6125176",
13367
+ // "delta": "0.39111646",
13368
+ // "theta": "-32.13948531",
13369
+ // "gamma": "0.00004656",
13370
+ // "vega": "51.70062218",
13371
+ // "highPriceLimit": "6474",
13372
+ // "lowPriceLimit": "5"
13373
+ // }
13374
+ // ]
13375
+ //
13376
+ return this.parseAllGreeks(response, symbols);
13377
+ }
13335
13378
  parseGreeks(greeks, market = undefined) {
13336
13379
  //
13337
13380
  // {
@@ -2208,6 +2208,7 @@ class bitmart extends bitmart$1 {
2208
2208
  * @param {object} [params] extra parameters specific to the exchange API endpoint
2209
2209
  * @param {int} [params.until] the latest time in ms to fetch trades for
2210
2210
  * @param {boolean} [params.marginMode] *spot* whether to fetch trades for margin orders or spot orders, defaults to spot orders (only isolated margin orders are supported)
2211
+ * @param {string} [params.stpMode] self-trade prevention only for spot, defaults to none, ['none', 'cancel_maker', 'cancel_taker', 'cancel_both']
2211
2212
  * @returns {Trade[]} a list of [trade structures]{@link https://docs.ccxt.com/#/?id=trade-structure}
2212
2213
  */
2213
2214
  async fetchMyTrades(symbol = undefined, since = undefined, limit = undefined, params = {}) {
@@ -2323,6 +2324,7 @@ class bitmart extends bitmart$1 {
2323
2324
  * @param {int} [since] the earliest time in ms to fetch trades for
2324
2325
  * @param {int} [limit] the maximum number of trades to retrieve
2325
2326
  * @param {object} [params] extra parameters specific to the exchange API endpoint
2327
+ * @param {string} [params.stpMode] self-trade prevention only for spot, defaults to none, ['none', 'cancel_maker', 'cancel_taker', 'cancel_both']
2326
2328
  * @returns {object[]} a list of [trade structures]{@link https://docs.ccxt.com/#/?id=trade-structure}
2327
2329
  */
2328
2330
  async fetchOrderTrades(id, symbol = undefined, since = undefined, limit = undefined, params = {}) {
@@ -2784,6 +2786,7 @@ class bitmart extends bitmart$1 {
2784
2786
  * @param {string} [params.stopLossPrice] *swap only* the price to trigger a stop-loss order
2785
2787
  * @param {string} [params.takeProfitPrice] *swap only* the price to trigger a take-profit order
2786
2788
  * @param {int} [params.plan_category] *swap tp/sl only* 1: tp/sl, 2: position tp/sl, default is 1
2789
+ * @param {string} [params.stpMode] self-trade prevention only for spot, defaults to none, ['none', 'cancel_maker', 'cancel_taker', 'cancel_both']
2787
2790
  * @returns {object} an [order structure]{@link https://docs.ccxt.com/#/?id=order-structure}
2788
2791
  */
2789
2792
  async createOrder(symbol, type, side, amount, price = undefined, params = {}) {
@@ -2854,6 +2857,7 @@ class bitmart extends bitmart$1 {
2854
2857
  * @see https://developer-pro.bitmart.com/en/spot/#new-batch-order-v4-signed
2855
2858
  * @param {Array} orders list of orders to create, each object should contain the parameters required by createOrder, namely symbol, type, side, amount, price and params
2856
2859
  * @param {object} [params] extra parameters specific to the exchange API endpoint
2860
+ * @param {string} [params.stpMode] self-trade prevention only for spot, defaults to none, ['none', 'cancel_maker', 'cancel_taker', 'cancel_both']
2857
2861
  * @returns {object} an [order structure]{@link https://docs.ccxt.com/#/?id=order-structure}
2858
2862
  */
2859
2863
  async createOrders(orders, params = {}) {
@@ -3438,6 +3442,7 @@ class bitmart extends bitmart$1 {
3438
3442
  * @param {string} [params.orderType] *swap only* 'limit', 'market', or 'trailing'
3439
3443
  * @param {boolean} [params.trailing] *swap only* set to true if you want to fetch trailing orders
3440
3444
  * @param {boolean} [params.trigger] *swap only* set to true if you want to fetch trigger orders
3445
+ * @param {string} [params.stpMode] self-trade prevention only for spot, defaults to none, ['none', 'cancel_maker', 'cancel_taker', 'cancel_both']
3441
3446
  * @returns {Order[]} a list of [order structures]{@link https://docs.ccxt.com/#/?id=order-structure}
3442
3447
  */
3443
3448
  async fetchOpenOrders(symbol = undefined, since = undefined, limit = undefined, params = {}) {
@@ -3564,6 +3569,7 @@ class bitmart extends bitmart$1 {
3564
3569
  * @param {object} [params] extra parameters specific to the exchange API endpoint
3565
3570
  * @param {int} [params.until] timestamp in ms of the latest entry
3566
3571
  * @param {string} [params.marginMode] *spot only* 'cross' or 'isolated', for margin trading
3572
+ * @param {string} [params.stpMode] self-trade prevention only for spot, defaults to none, ['none', 'cancel_maker', 'cancel_taker', 'cancel_both']
3567
3573
  * @returns {Order[]} a list of [order structures]{@link https://docs.ccxt.com/#/?id=order-structure}
3568
3574
  */
3569
3575
  async fetchClosedOrders(symbol = undefined, since = undefined, limit = undefined, params = {}) {
@@ -3632,6 +3638,7 @@ class bitmart extends bitmart$1 {
3632
3638
  * @param {string} [params.clientOrderId] *spot* fetch the order by client order id instead of order id
3633
3639
  * @param {string} [params.orderType] *swap only* 'limit', 'market', 'liquidate', 'bankruptcy', 'adl' or 'trailing'
3634
3640
  * @param {boolean} [params.trailing] *swap only* set to true if you want to fetch a trailing order
3641
+ * @param {string} [params.stpMode] self-trade prevention only for spot, defaults to none, ['none', 'cancel_maker', 'cancel_taker', 'cancel_both']
3635
3642
  * @returns {object} An [order structure]{@link https://docs.ccxt.com/#/?id=order-structure}
3636
3643
  */
3637
3644
  async fetchOrder(id, symbol = undefined, params = {}) {
@@ -35,7 +35,6 @@ class bitmex extends bitmex$1 {
35
35
  'swap': true,
36
36
  'future': true,
37
37
  'option': false,
38
- 'index': true,
39
38
  'addMargin': undefined,
40
39
  'cancelAllOrders': true,
41
40
  'cancelAllOrdersAfter': true,
@@ -91,6 +90,7 @@ class bitmex extends bitmex$1 {
91
90
  'fetchTransactions': 'emulated',
92
91
  'fetchTransfer': false,
93
92
  'fetchTransfers': false,
93
+ 'index': true,
94
94
  'reduceMargin': undefined,
95
95
  'sandbox': true,
96
96
  'setLeverage': true,
@@ -1987,7 +1987,7 @@ class bitmex extends bitmex$1 {
1987
1987
  * @param {float} [price] the price at which the order is to be fulfilled, in units of the quote currency, ignored in market orders
1988
1988
  * @param {object} [params] extra parameters specific to the exchange API endpoint
1989
1989
  * @param {object} [params.triggerPrice] the price at which a trigger order is triggered at
1990
- * @param {object} [params.triggerDirection] the direction whenever the trigger happens with relation to price - 'above' or 'below'
1990
+ * @param {object} [params.triggerDirection] the direction whenever the trigger happens with relation to price - 'ascending' or 'descending'
1991
1991
  * @param {float} [params.trailingAmount] the quote amount to trail away from the current market price
1992
1992
  * @returns {object} an [order structure]{@link https://github.com/ccxt/ccxt/wiki/Manual#order-structure}
1993
1993
  */
@@ -2017,7 +2017,7 @@ class bitmex extends bitmex$1 {
2017
2017
  const isTrailingAmountOrder = trailingAmount !== undefined;
2018
2018
  if (isTriggerOrder || isTrailingAmountOrder) {
2019
2019
  const triggerDirection = this.safeString(params, 'triggerDirection');
2020
- const triggerAbove = (triggerDirection === 'above');
2020
+ const triggerAbove = ((triggerDirection === 'ascending') || (triggerDirection === 'above'));
2021
2021
  if ((type === 'limit') || (type === 'market')) {
2022
2022
  this.checkRequiredArgument('createOrder', triggerDirection, 'triggerDirection', ['above', 'below']);
2023
2023
  }
@@ -2074,7 +2074,7 @@ class bitmex extends bitmex$1 {
2074
2074
  const isTrailingAmountOrder = trailingAmount !== undefined;
2075
2075
  if (isTrailingAmountOrder) {
2076
2076
  const triggerDirection = this.safeString(params, 'triggerDirection');
2077
- const triggerAbove = (triggerDirection === 'above');
2077
+ const triggerAbove = ((triggerDirection === 'ascending') || (triggerDirection === 'above'));
2078
2078
  if ((type === 'limit') || (type === 'market')) {
2079
2079
  this.checkRequiredArgument('createOrder', triggerDirection, 'triggerDirection', ['above', 'below']);
2080
2080
  }
@@ -653,7 +653,7 @@ class bitvavo extends bitvavo$1 {
653
653
  });
654
654
  }
655
655
  // set currencies here to avoid calling publicGetAssets twice
656
- this.currencies = this.deepExtend(this.currencies, result);
656
+ this.currencies = this.mapToSafeMap(this.deepExtend(this.currencies, result));
657
657
  return result;
658
658
  }
659
659
  /**
@@ -1225,6 +1225,9 @@ class bitvavo extends bitvavo$1 {
1225
1225
  if (operatorId !== undefined) {
1226
1226
  request['operatorId'] = this.parseToInt(operatorId);
1227
1227
  }
1228
+ else {
1229
+ throw new errors.ArgumentsRequired(this.id + ' createOrder() requires an operatorId in params or options, eg: exchange.options[\'operatorId\'] = 1234567890');
1230
+ }
1228
1231
  return this.extend(request, params);
1229
1232
  }
1230
1233
  /**
@@ -1329,6 +1332,9 @@ class bitvavo extends bitvavo$1 {
1329
1332
  if (operatorId !== undefined) {
1330
1333
  request['operatorId'] = this.parseToInt(operatorId);
1331
1334
  }
1335
+ else {
1336
+ throw new errors.ArgumentsRequired(this.id + ' editOrder() requires an operatorId in params or options, eg: exchange.options[\'operatorId\'] = 1234567890');
1337
+ }
1332
1338
  request['market'] = market['id'];
1333
1339
  return request;
1334
1340
  }
@@ -1370,6 +1376,9 @@ class bitvavo extends bitvavo$1 {
1370
1376
  if (operatorId !== undefined) {
1371
1377
  request['operatorId'] = this.parseToInt(operatorId);
1372
1378
  }
1379
+ else {
1380
+ throw new errors.ArgumentsRequired(this.id + ' cancelOrder() requires an operatorId in params or options, eg: exchange.options[\'operatorId\'] = 1234567890');
1381
+ }
1373
1382
  return this.extend(request, params);
1374
1383
  }
1375
1384
  /**
@@ -57,6 +57,7 @@ class bybit extends bybit$1 {
57
57
  'createTriggerOrder': true,
58
58
  'editOrder': true,
59
59
  'editOrders': true,
60
+ 'fetchAllGreeks': true,
60
61
  'fetchBalance': true,
61
62
  'fetchBidsAsks': 'emulated',
62
63
  'fetchBorrowInterest': false,
@@ -1155,6 +1156,7 @@ class bybit extends bybit$1 {
1155
1156
  '4h': '4h',
1156
1157
  '1d': '1d',
1157
1158
  },
1159
+ 'useMarkPriceForPositionCollateral': false, // use mark price for position collateral
1158
1160
  },
1159
1161
  'features': {
1160
1162
  'default': {
@@ -3884,7 +3886,7 @@ class bybit extends bybit$1 {
3884
3886
  * @param {int} [params.isLeverage] *unified spot only* false then spot trading true then margin trading
3885
3887
  * @param {string} [params.tpslMode] *contract only* 'full' or 'partial'
3886
3888
  * @param {string} [params.mmp] *option only* market maker protection
3887
- * @param {string} [params.triggerDirection] *contract only* the direction for trigger orders, 'above' or 'below'
3889
+ * @param {string} [params.triggerDirection] *contract only* the direction for trigger orders, 'ascending' or 'descending'
3888
3890
  * @param {float} [params.triggerPrice] The price at which a trigger order is triggered at
3889
3891
  * @param {float} [params.stopLossPrice] The price at which a stop loss order is triggered at
3890
3892
  * @param {float} [params.takeProfitPrice] The price at which a take profit order is triggered at
@@ -4139,9 +4141,9 @@ class bybit extends bybit$1 {
4139
4141
  }
4140
4142
  else {
4141
4143
  if (triggerDirection === undefined) {
4142
- throw new errors.ArgumentsRequired(this.id + ' stop/trigger orders require a triggerDirection parameter, either "above" or "below" to determine the direction of the trigger.');
4144
+ throw new errors.ArgumentsRequired(this.id + ' stop/trigger orders require a triggerDirection parameter, either "ascending" or "descending" to determine the direction of the trigger.');
4143
4145
  }
4144
- const isAsending = ((triggerDirection === 'above') || (triggerDirection === '1'));
4146
+ const isAsending = ((triggerDirection === 'ascending') || (triggerDirection === 'above') || (triggerDirection === '1'));
4145
4147
  request['triggerDirection'] = isAsending ? 1 : 2;
4146
4148
  }
4147
4149
  request['triggerPrice'] = this.getPrice(symbol, triggerPrice);
@@ -6553,12 +6555,14 @@ class bybit extends bybit$1 {
6553
6555
  }
6554
6556
  let collateralString = this.safeString(position, 'positionBalance');
6555
6557
  const entryPrice = this.omitZero(this.safeStringN(position, ['entryPrice', 'avgPrice', 'avgEntryPrice']));
6558
+ const markPrice = this.safeString(position, 'markPrice');
6556
6559
  const liquidationPrice = this.omitZero(this.safeString(position, 'liqPrice'));
6557
6560
  const leverage = this.safeString(position, 'leverage');
6558
6561
  if (liquidationPrice !== undefined) {
6559
6562
  if (market['settle'] === 'USDC') {
6560
6563
  // (Entry price - Liq price) * Contracts + Maintenance Margin + (unrealised pnl) = Collateral
6561
- const difference = Precise["default"].stringAbs(Precise["default"].stringSub(entryPrice, liquidationPrice));
6564
+ const price = this.safeBool(this.options, 'useMarkPriceForPositionCollateral', false) ? markPrice : entryPrice;
6565
+ const difference = Precise["default"].stringAbs(Precise["default"].stringSub(price, liquidationPrice));
6562
6566
  collateralString = Precise["default"].stringAdd(Precise["default"].stringAdd(Precise["default"].stringMul(difference, size), maintenanceMarginString), unrealisedPnl);
6563
6567
  }
6564
6568
  else {
@@ -6614,7 +6618,7 @@ class bybit extends bybit$1 {
6614
6618
  'contractSize': this.safeNumber(market, 'contractSize'),
6615
6619
  'marginRatio': this.parseNumber(marginRatio),
6616
6620
  'liquidationPrice': this.parseNumber(liquidationPrice),
6617
- 'markPrice': this.safeNumber(position, 'markPrice'),
6621
+ 'markPrice': this.parseNumber(markPrice),
6618
6622
  'lastPrice': this.safeNumber(position, 'avgExitPrice'),
6619
6623
  'collateral': this.parseNumber(collateralString),
6620
6624
  'marginMode': marginMode,
@@ -8030,6 +8034,77 @@ class bybit extends bybit$1 {
8030
8034
  'datetime': this.iso8601(timestamp),
8031
8035
  });
8032
8036
  }
8037
+ /**
8038
+ * @method
8039
+ * @name bybit#fetchAllGreeks
8040
+ * @description fetches all option contracts greeks, financial metrics used to measure the factors that affect the price of an options contract
8041
+ * @see https://bybit-exchange.github.io/docs/api-explorer/v5/market/tickers
8042
+ * @param {string[]} [symbols] unified symbols of the markets to fetch greeks for, all markets are returned if not assigned
8043
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
8044
+ * @param {string} [params.baseCoin] the baseCoin of the symbol, default is BTC
8045
+ * @returns {object} a [greeks structure]{@link https://docs.ccxt.com/#/?id=greeks-structure}
8046
+ */
8047
+ async fetchAllGreeks(symbols = undefined, params = {}) {
8048
+ await this.loadMarkets();
8049
+ symbols = this.marketSymbols(symbols, undefined, true, true, true);
8050
+ const baseCoin = this.safeString(params, 'baseCoin', 'BTC');
8051
+ const request = {
8052
+ 'category': 'option',
8053
+ 'baseCoin': baseCoin,
8054
+ };
8055
+ let market = undefined;
8056
+ if (symbols !== undefined) {
8057
+ const symbolsLength = symbols.length;
8058
+ if (symbolsLength === 1) {
8059
+ market = this.market(symbols[0]);
8060
+ request['symbol'] = market['id'];
8061
+ }
8062
+ }
8063
+ const response = await this.publicGetV5MarketTickers(this.extend(request, params));
8064
+ //
8065
+ // {
8066
+ // "retCode": 0,
8067
+ // "retMsg": "SUCCESS",
8068
+ // "result": {
8069
+ // "category": "option",
8070
+ // "list": [
8071
+ // {
8072
+ // "symbol": "BTC-26JAN24-39000-C",
8073
+ // "bid1Price": "3205",
8074
+ // "bid1Size": "7.1",
8075
+ // "bid1Iv": "0.5478",
8076
+ // "ask1Price": "3315",
8077
+ // "ask1Size": "1.98",
8078
+ // "ask1Iv": "0.5638",
8079
+ // "lastPrice": "3230",
8080
+ // "highPrice24h": "3255",
8081
+ // "lowPrice24h": "3200",
8082
+ // "markPrice": "3273.02263032",
8083
+ // "indexPrice": "36790.96",
8084
+ // "markIv": "0.5577",
8085
+ // "underlyingPrice": "37649.67254894",
8086
+ // "openInterest": "19.67",
8087
+ // "turnover24h": "170140.33875912",
8088
+ // "volume24h": "4.56",
8089
+ // "totalVolume": "22",
8090
+ // "totalTurnover": "789305",
8091
+ // "delta": "0.49640971",
8092
+ // "gamma": "0.00004131",
8093
+ // "vega": "69.08651675",
8094
+ // "theta": "-24.9443226",
8095
+ // "predictedDeliveryPrice": "0",
8096
+ // "change24h": "0.18532111"
8097
+ // }
8098
+ // ]
8099
+ // },
8100
+ // "retExtInfo": {},
8101
+ // "time": 1699584008326
8102
+ // }
8103
+ //
8104
+ const result = this.safeDict(response, 'result', {});
8105
+ const data = this.safeList(result, 'list', []);
8106
+ return this.parseAllGreeks(data, symbols);
8107
+ }
8033
8108
  parseGreeks(greeks, market = undefined) {
8034
8109
  //
8035
8110
  // {
@@ -9175,7 +9250,7 @@ class bybit extends bybit$1 {
9175
9250
  }
9176
9251
  else {
9177
9252
  authFull = auth_base + queryEncoded;
9178
- url += '?' + this.rawencode(query);
9253
+ url += '?' + queryEncoded;
9179
9254
  }
9180
9255
  let signature = undefined;
9181
9256
  if (this.secret.indexOf('PRIVATE KEY') > -1) {
@@ -9193,7 +9268,7 @@ class bybit extends bybit$1 {
9193
9268
  'timestamp': timestamp,
9194
9269
  });
9195
9270
  const sortedQuery = this.keysort(query);
9196
- const auth = this.rawencode(sortedQuery);
9271
+ const auth = this.rawencode(sortedQuery, true);
9197
9272
  let signature = undefined;
9198
9273
  if (this.secret.indexOf('PRIVATE KEY') > -1) {
9199
9274
  signature = rsa.rsa(auth, this.secret, sha256.sha256);
@@ -9220,7 +9295,7 @@ class bybit extends bybit$1 {
9220
9295
  }
9221
9296
  }
9222
9297
  else {
9223
- url += '?' + this.rawencode(sortedQuery);
9298
+ url += '?' + this.rawencode(sortedQuery, true);
9224
9299
  url += '&sign=' + signature;
9225
9300
  }
9226
9301
  }