ccxt 4.2.79 → 4.2.81

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 (43) hide show
  1. package/README.md +3 -3
  2. package/build.sh +1 -1
  3. package/dist/ccxt.browser.js +752 -73
  4. package/dist/ccxt.browser.min.js +3 -3
  5. package/dist/cjs/ccxt.js +1 -1
  6. package/dist/cjs/src/base/Exchange.js +35 -3
  7. package/dist/cjs/src/binance.js +91 -1
  8. package/dist/cjs/src/bybit.js +178 -1
  9. package/dist/cjs/src/deribit.js +155 -0
  10. package/dist/cjs/src/gate.js +200 -5
  11. package/dist/cjs/src/hyperliquid.js +54 -10
  12. package/dist/cjs/src/okx.js +19 -42
  13. package/dist/cjs/src/pro/binance.js +5 -5
  14. package/dist/cjs/src/pro/bitopro.js +2 -1
  15. package/dist/cjs/src/pro/gemini.js +3 -2
  16. package/dist/cjs/src/pro/phemex.js +7 -2
  17. package/dist/cjs/src/upbit.js +2 -0
  18. package/js/ccxt.d.ts +3 -3
  19. package/js/ccxt.js +1 -1
  20. package/js/src/abstract/upbit.d.ts +1 -0
  21. package/js/src/base/Exchange.d.ts +14 -5
  22. package/js/src/base/Exchange.js +35 -3
  23. package/js/src/base/types.d.ts +21 -0
  24. package/js/src/binance.d.ts +23 -3
  25. package/js/src/binance.js +91 -1
  26. package/js/src/bybit.d.ts +22 -1
  27. package/js/src/bybit.js +178 -1
  28. package/js/src/deribit.d.ts +22 -1
  29. package/js/src/deribit.js +155 -0
  30. package/js/src/gate.d.ts +22 -1
  31. package/js/src/gate.js +200 -5
  32. package/js/src/hyperliquid.d.ts +1 -0
  33. package/js/src/hyperliquid.js +54 -10
  34. package/js/src/okx.d.ts +0 -1
  35. package/js/src/okx.js +19 -42
  36. package/js/src/pro/binance.js +5 -5
  37. package/js/src/pro/bitopro.js +2 -1
  38. package/js/src/pro/gemini.d.ts +2 -2
  39. package/js/src/pro/gemini.js +3 -2
  40. package/js/src/pro/phemex.js +7 -2
  41. package/js/src/upbit.js +2 -0
  42. package/package.json +1 -1
  43. package/skip-tests.json +7 -2
package/dist/cjs/ccxt.js CHANGED
@@ -181,7 +181,7 @@ var woo$1 = require('./src/pro/woo.js');
181
181
 
182
182
  //-----------------------------------------------------------------------------
183
183
  // this is updated by vss.js when building
184
- const version = '4.2.79';
184
+ const version = '4.2.81';
185
185
  Exchange["default"].ccxtVersion = version;
186
186
  const exchanges = {
187
187
  'ace': ace,
@@ -468,6 +468,8 @@ class Exchange {
468
468
  'fetchOpenOrder': undefined,
469
469
  'fetchOpenOrders': undefined,
470
470
  'fetchOpenOrdersWs': undefined,
471
+ 'fetchOption': undefined,
472
+ 'fetchOptionChain': undefined,
471
473
  'fetchOrder': undefined,
472
474
  'fetchOrderBook': true,
473
475
  'fetchOrderBooks': undefined,
@@ -1437,6 +1439,12 @@ class Exchange {
1437
1439
  intToBase16(elem) {
1438
1440
  return elem.toString(16);
1439
1441
  }
1442
+ extendExchangeOptions(newOptions) {
1443
+ this.options = this.extend(this.options, newOptions);
1444
+ }
1445
+ createSafeDictionary() {
1446
+ return {};
1447
+ }
1440
1448
  /* eslint-enable */
1441
1449
  // ------------------------------------------------------------------------
1442
1450
  // ########################################################################
@@ -3137,7 +3145,7 @@ class Exchange {
3137
3145
  throw new errors.BadResponse(errorMessage);
3138
3146
  }
3139
3147
  }
3140
- marketIds(symbols) {
3148
+ marketIds(symbols = undefined) {
3141
3149
  if (symbols === undefined) {
3142
3150
  return symbols;
3143
3151
  }
@@ -3147,7 +3155,7 @@ class Exchange {
3147
3155
  }
3148
3156
  return result;
3149
3157
  }
3150
- marketSymbols(symbols, type = undefined, allowEmpty = true, sameTypeOnly = false, sameSubTypeOnly = false) {
3158
+ marketSymbols(symbols = undefined, type = undefined, allowEmpty = true, sameTypeOnly = false, sameSubTypeOnly = false) {
3151
3159
  if (symbols === undefined) {
3152
3160
  if (!allowEmpty) {
3153
3161
  throw new errors.ArgumentsRequired(this.id + ' empty list of symbols is not supported');
@@ -3188,7 +3196,7 @@ class Exchange {
3188
3196
  }
3189
3197
  return result;
3190
3198
  }
3191
- marketCodes(codes) {
3199
+ marketCodes(codes = undefined) {
3192
3200
  if (codes === undefined) {
3193
3201
  return codes;
3194
3202
  }
@@ -4128,6 +4136,9 @@ class Exchange {
4128
4136
  async fetchOrderBooks(symbols = undefined, limit = undefined, params = {}) {
4129
4137
  throw new errors.NotSupported(this.id + ' fetchOrderBooks() is not supported yet');
4130
4138
  }
4139
+ async watchBidsAsks(symbols = undefined, params = {}) {
4140
+ throw new errors.NotSupported(this.id + ' watchBidsAsks() is not supported yet');
4141
+ }
4131
4142
  async watchTickers(symbols = undefined, params = {}) {
4132
4143
  throw new errors.NotSupported(this.id + ' watchTickers() is not supported yet');
4133
4144
  }
@@ -4480,6 +4491,12 @@ class Exchange {
4480
4491
  async fetchGreeks(symbol, params = {}) {
4481
4492
  throw new errors.NotSupported(this.id + ' fetchGreeks() is not supported yet');
4482
4493
  }
4494
+ async fetchOptionChain(code, params = {}) {
4495
+ throw new errors.NotSupported(this.id + ' fetchOptionChain() is not supported yet');
4496
+ }
4497
+ async fetchOption(symbol, params = {}) {
4498
+ throw new errors.NotSupported(this.id + ' fetchOption() is not supported yet');
4499
+ }
4483
4500
  async fetchDepositsWithdrawals(code = undefined, since = undefined, limit = undefined, params = {}) {
4484
4501
  /**
4485
4502
  * @method
@@ -5658,6 +5675,21 @@ class Exchange {
5658
5675
  parseGreeks(greeks, market = undefined) {
5659
5676
  throw new errors.NotSupported(this.id + ' parseGreeks () is not supported yet');
5660
5677
  }
5678
+ parseOption(chain, currency = undefined, market = undefined) {
5679
+ throw new errors.NotSupported(this.id + ' parseOption () is not supported yet');
5680
+ }
5681
+ parseOptionChain(response, currencyKey = undefined, symbolKey = undefined) {
5682
+ const optionStructures = {};
5683
+ for (let i = 0; i < response.length; i++) {
5684
+ const info = response[i];
5685
+ const currencyId = this.safeString(info, currencyKey);
5686
+ const currency = this.safeCurrency(currencyId);
5687
+ const marketId = this.safeString(info, symbolKey);
5688
+ const market = this.safeMarket(marketId, undefined, undefined, 'option');
5689
+ optionStructures[market['symbol']] = this.parseOption(info, currency, market);
5690
+ }
5691
+ return optionStructures;
5692
+ }
5661
5693
  parseMarginModes(response, symbols = undefined, symbolKey = undefined, marketType = undefined) {
5662
5694
  const marginModeStructures = {};
5663
5695
  for (let i = 0; i < response.length; i++) {
@@ -111,6 +111,8 @@ class binance extends binance$1 {
111
111
  'fetchOpenInterestHistory': true,
112
112
  'fetchOpenOrder': true,
113
113
  'fetchOpenOrders': true,
114
+ 'fetchOption': true,
115
+ 'fetchOptionChain': false,
114
116
  'fetchOrder': true,
115
117
  'fetchOrderBook': true,
116
118
  'fetchOrderBooks': false,
@@ -2402,7 +2404,7 @@ class binance extends binance$1 {
2402
2404
  }
2403
2405
  isInverse(type, subType = undefined) {
2404
2406
  if (subType === undefined) {
2405
- return type === 'delivery';
2407
+ return (type === 'delivery');
2406
2408
  }
2407
2409
  else {
2408
2410
  return subType === 'inverse';
@@ -12408,6 +12410,94 @@ class binance extends binance$1 {
12408
12410
  'marginMode': isIsolated ? 'isolated' : 'cross',
12409
12411
  };
12410
12412
  }
12413
+ async fetchOption(symbol, params = {}) {
12414
+ /**
12415
+ * @method
12416
+ * @name binance#fetchOption
12417
+ * @description fetches option data that is commonly found in an option chain
12418
+ * @see https://binance-docs.github.io/apidocs/voptions/en/#24hr-ticker-price-change-statistics
12419
+ * @param {string} symbol unified market symbol
12420
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
12421
+ * @returns {object} an [option chain structure]{@link https://docs.ccxt.com/#/?id=option-chain-structure}
12422
+ */
12423
+ await this.loadMarkets();
12424
+ const market = this.market(symbol);
12425
+ const request = {
12426
+ 'symbol': market['id'],
12427
+ };
12428
+ const response = await this.eapiPublicGetTicker(this.extend(request, params));
12429
+ //
12430
+ // [
12431
+ // {
12432
+ // "symbol": "BTC-241227-80000-C",
12433
+ // "priceChange": "0",
12434
+ // "priceChangePercent": "0",
12435
+ // "lastPrice": "2750",
12436
+ // "lastQty": "0",
12437
+ // "open": "2750",
12438
+ // "high": "2750",
12439
+ // "low": "2750",
12440
+ // "volume": "0",
12441
+ // "amount": "0",
12442
+ // "bidPrice": "4880",
12443
+ // "askPrice": "0",
12444
+ // "openTime": 0,
12445
+ // "closeTime": 0,
12446
+ // "firstTradeId": 0,
12447
+ // "tradeCount": 0,
12448
+ // "strikePrice": "80000",
12449
+ // "exercisePrice": "63944.09893617"
12450
+ // }
12451
+ // ]
12452
+ //
12453
+ const chain = this.safeDict(response, 0, {});
12454
+ return this.parseOption(chain, undefined, market);
12455
+ }
12456
+ parseOption(chain, currency = undefined, market = undefined) {
12457
+ //
12458
+ // {
12459
+ // "symbol": "BTC-241227-80000-C",
12460
+ // "priceChange": "0",
12461
+ // "priceChangePercent": "0",
12462
+ // "lastPrice": "2750",
12463
+ // "lastQty": "0",
12464
+ // "open": "2750",
12465
+ // "high": "2750",
12466
+ // "low": "2750",
12467
+ // "volume": "0",
12468
+ // "amount": "0",
12469
+ // "bidPrice": "4880",
12470
+ // "askPrice": "0",
12471
+ // "openTime": 0,
12472
+ // "closeTime": 0,
12473
+ // "firstTradeId": 0,
12474
+ // "tradeCount": 0,
12475
+ // "strikePrice": "80000",
12476
+ // "exercisePrice": "63944.09893617"
12477
+ // }
12478
+ //
12479
+ const marketId = this.safeString(chain, 'symbol');
12480
+ market = this.safeMarket(marketId, market);
12481
+ return {
12482
+ 'info': chain,
12483
+ 'currency': undefined,
12484
+ 'symbol': market['symbol'],
12485
+ 'timestamp': undefined,
12486
+ 'datetime': undefined,
12487
+ 'impliedVolatility': undefined,
12488
+ 'openInterest': undefined,
12489
+ 'bidPrice': this.safeNumber(chain, 'bidPrice'),
12490
+ 'askPrice': this.safeNumber(chain, 'askPrice'),
12491
+ 'midPrice': undefined,
12492
+ 'markPrice': undefined,
12493
+ 'lastPrice': this.safeNumber(chain, 'lastPrice'),
12494
+ 'underlyingPrice': this.safeNumber(chain, 'exercisePrice'),
12495
+ 'change': this.safeNumber(chain, 'priceChange'),
12496
+ 'percentage': this.safeNumber(chain, 'priceChangePercent'),
12497
+ 'baseVolume': this.safeNumber(chain, 'volume'),
12498
+ 'quoteVolume': undefined,
12499
+ };
12500
+ }
12411
12501
  }
12412
12502
 
12413
12503
  module.exports = binance;
@@ -70,6 +70,7 @@ class bybit extends bybit$1 {
70
70
  'fetchDeposits': true,
71
71
  'fetchDepositWithdrawFee': 'emulated',
72
72
  'fetchDepositWithdrawFees': true,
73
+ 'fetchFundingHistory': true,
73
74
  'fetchFundingRate': true,
74
75
  'fetchFundingRateHistory': true,
75
76
  'fetchFundingRates': true,
@@ -91,6 +92,8 @@ class bybit extends bybit$1 {
91
92
  'fetchOpenInterestHistory': true,
92
93
  'fetchOpenOrder': true,
93
94
  'fetchOpenOrders': true,
95
+ 'fetchOption': true,
96
+ 'fetchOptionChain': true,
94
97
  'fetchOrder': false,
95
98
  'fetchOrderBook': true,
96
99
  'fetchOrders': false,
@@ -110,7 +113,6 @@ class bybit extends bybit$1 {
110
113
  'fetchUnderlyingAssets': false,
111
114
  'fetchVolatilityHistory': true,
112
115
  'fetchWithdrawals': true,
113
- 'fetchFundingHistory': true,
114
116
  'repayCrossMargin': true,
115
117
  'setLeverage': true,
116
118
  'setMarginMode': true,
@@ -8207,6 +8209,181 @@ class bybit extends bybit$1 {
8207
8209
  'rate': this.safeNumber(income, 'feeRate'),
8208
8210
  };
8209
8211
  }
8212
+ async fetchOption(symbol, params = {}) {
8213
+ /**
8214
+ * @method
8215
+ * @name bybit#fetchOption
8216
+ * @description fetches option data that is commonly found in an option chain
8217
+ * @see https://bybit-exchange.github.io/docs/v5/market/tickers
8218
+ * @param {string} symbol unified market symbol
8219
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
8220
+ * @returns {object} an [option chain structure]{@link https://docs.ccxt.com/#/?id=option-chain-structure}
8221
+ */
8222
+ await this.loadMarkets();
8223
+ const market = this.market(symbol);
8224
+ const request = {
8225
+ 'category': 'option',
8226
+ 'symbol': market['id'],
8227
+ };
8228
+ const response = await this.publicGetV5MarketTickers(this.extend(request, params));
8229
+ //
8230
+ // {
8231
+ // "retCode": 0,
8232
+ // "retMsg": "SUCCESS",
8233
+ // "result": {
8234
+ // "category": "option",
8235
+ // "list": [
8236
+ // {
8237
+ // "symbol": "BTC-27DEC24-55000-P",
8238
+ // "bid1Price": "0",
8239
+ // "bid1Size": "0",
8240
+ // "bid1Iv": "0",
8241
+ // "ask1Price": "0",
8242
+ // "ask1Size": "0",
8243
+ // "ask1Iv": "0",
8244
+ // "lastPrice": "10980",
8245
+ // "highPrice24h": "0",
8246
+ // "lowPrice24h": "0",
8247
+ // "markPrice": "11814.66756236",
8248
+ // "indexPrice": "63838.92",
8249
+ // "markIv": "0.8866",
8250
+ // "underlyingPrice": "71690.55303594",
8251
+ // "openInterest": "0.01",
8252
+ // "turnover24h": "0",
8253
+ // "volume24h": "0",
8254
+ // "totalVolume": "2",
8255
+ // "totalTurnover": "78719",
8256
+ // "delta": "-0.23284954",
8257
+ // "gamma": "0.0000055",
8258
+ // "vega": "191.70757975",
8259
+ // "theta": "-30.43617927",
8260
+ // "predictedDeliveryPrice": "0",
8261
+ // "change24h": "0"
8262
+ // }
8263
+ // ]
8264
+ // },
8265
+ // "retExtInfo": {},
8266
+ // "time": 1711162003672
8267
+ // }
8268
+ //
8269
+ const result = this.safeDict(response, 'result', {});
8270
+ const resultList = this.safeList(result, 'list', []);
8271
+ const chain = this.safeDict(resultList, 0, {});
8272
+ return this.parseOption(chain, undefined, market);
8273
+ }
8274
+ async fetchOptionChain(code, params = {}) {
8275
+ /**
8276
+ * @method
8277
+ * @name bybit#fetchOptionChain
8278
+ * @description fetches data for an underlying asset that is commonly found in an option chain
8279
+ * @see https://bybit-exchange.github.io/docs/v5/market/tickers
8280
+ * @param {string} currency base currency to fetch an option chain for
8281
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
8282
+ * @returns {object} a list of [option chain structures]{@link https://docs.ccxt.com/#/?id=option-chain-structure}
8283
+ */
8284
+ await this.loadMarkets();
8285
+ const currency = this.currency(code);
8286
+ const request = {
8287
+ 'category': 'option',
8288
+ 'baseCoin': currency['id'],
8289
+ };
8290
+ const response = await this.publicGetV5MarketTickers(this.extend(request, params));
8291
+ //
8292
+ // {
8293
+ // "retCode": 0,
8294
+ // "retMsg": "SUCCESS",
8295
+ // "result": {
8296
+ // "category": "option",
8297
+ // "list": [
8298
+ // {
8299
+ // "symbol": "BTC-27DEC24-55000-P",
8300
+ // "bid1Price": "0",
8301
+ // "bid1Size": "0",
8302
+ // "bid1Iv": "0",
8303
+ // "ask1Price": "0",
8304
+ // "ask1Size": "0",
8305
+ // "ask1Iv": "0",
8306
+ // "lastPrice": "10980",
8307
+ // "highPrice24h": "0",
8308
+ // "lowPrice24h": "0",
8309
+ // "markPrice": "11814.66756236",
8310
+ // "indexPrice": "63838.92",
8311
+ // "markIv": "0.8866",
8312
+ // "underlyingPrice": "71690.55303594",
8313
+ // "openInterest": "0.01",
8314
+ // "turnover24h": "0",
8315
+ // "volume24h": "0",
8316
+ // "totalVolume": "2",
8317
+ // "totalTurnover": "78719",
8318
+ // "delta": "-0.23284954",
8319
+ // "gamma": "0.0000055",
8320
+ // "vega": "191.70757975",
8321
+ // "theta": "-30.43617927",
8322
+ // "predictedDeliveryPrice": "0",
8323
+ // "change24h": "0"
8324
+ // },
8325
+ // ]
8326
+ // },
8327
+ // "retExtInfo": {},
8328
+ // "time": 1711162003672
8329
+ // }
8330
+ //
8331
+ const result = this.safeDict(response, 'result', {});
8332
+ const resultList = this.safeList(result, 'list', []);
8333
+ return this.parseOptionChain(resultList, undefined, 'symbol');
8334
+ }
8335
+ parseOption(chain, currency = undefined, market = undefined) {
8336
+ //
8337
+ // {
8338
+ // "symbol": "BTC-27DEC24-55000-P",
8339
+ // "bid1Price": "0",
8340
+ // "bid1Size": "0",
8341
+ // "bid1Iv": "0",
8342
+ // "ask1Price": "0",
8343
+ // "ask1Size": "0",
8344
+ // "ask1Iv": "0",
8345
+ // "lastPrice": "10980",
8346
+ // "highPrice24h": "0",
8347
+ // "lowPrice24h": "0",
8348
+ // "markPrice": "11814.66756236",
8349
+ // "indexPrice": "63838.92",
8350
+ // "markIv": "0.8866",
8351
+ // "underlyingPrice": "71690.55303594",
8352
+ // "openInterest": "0.01",
8353
+ // "turnover24h": "0",
8354
+ // "volume24h": "0",
8355
+ // "totalVolume": "2",
8356
+ // "totalTurnover": "78719",
8357
+ // "delta": "-0.23284954",
8358
+ // "gamma": "0.0000055",
8359
+ // "vega": "191.70757975",
8360
+ // "theta": "-30.43617927",
8361
+ // "predictedDeliveryPrice": "0",
8362
+ // "change24h": "0"
8363
+ // }
8364
+ //
8365
+ const marketId = this.safeString(chain, 'symbol');
8366
+ market = this.safeMarket(marketId, market);
8367
+ return {
8368
+ 'info': chain,
8369
+ 'currency': undefined,
8370
+ 'symbol': market['symbol'],
8371
+ 'timestamp': undefined,
8372
+ 'datetime': undefined,
8373
+ 'impliedVolatility': this.safeNumber(chain, 'markIv'),
8374
+ 'openInterest': this.safeNumber(chain, 'openInterest'),
8375
+ 'bidPrice': this.safeNumber(chain, 'bid1Price'),
8376
+ 'askPrice': this.safeNumber(chain, 'ask1Price'),
8377
+ 'midPrice': undefined,
8378
+ 'markPrice': this.safeNumber(chain, 'markPrice'),
8379
+ 'lastPrice': this.safeNumber(chain, 'lastPrice'),
8380
+ 'underlyingPrice': this.safeNumber(chain, 'underlyingPrice'),
8381
+ 'change': this.safeNumber(chain, 'change24h'),
8382
+ 'percentage': undefined,
8383
+ 'baseVolume': this.safeNumber(chain, 'totalVolume'),
8384
+ 'quoteVolume': undefined,
8385
+ };
8386
+ }
8210
8387
  sign(path, api = 'public', method = 'GET', params = {}, headers = undefined, body = undefined) {
8211
8388
  let url = this.implodeHostname(this.urls['api'][api]) + '/' + path;
8212
8389
  if (api === 'public') {
@@ -70,6 +70,8 @@ class deribit extends deribit$1 {
70
70
  'fetchMyTrades': true,
71
71
  'fetchOHLCV': true,
72
72
  'fetchOpenOrders': true,
73
+ 'fetchOption': true,
74
+ 'fetchOptionChain': true,
73
75
  'fetchOrder': true,
74
76
  'fetchOrderBook': true,
75
77
  'fetchOrders': false,
@@ -3456,6 +3458,159 @@ class deribit extends deribit$1 {
3456
3458
  'info': greeks,
3457
3459
  };
3458
3460
  }
3461
+ async fetchOption(symbol, params = {}) {
3462
+ /**
3463
+ * @method
3464
+ * @name deribit#fetchOption
3465
+ * @description fetches option data that is commonly found in an option chain
3466
+ * @see https://docs.deribit.com/#public-get_book_summary_by_instrument
3467
+ * @param {string} symbol unified market symbol
3468
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
3469
+ * @returns {object} an [option chain structure]{@link https://docs.ccxt.com/#/?id=option-chain-structure}
3470
+ */
3471
+ await this.loadMarkets();
3472
+ const market = this.market(symbol);
3473
+ const request = {
3474
+ 'instrument_name': market['id'],
3475
+ };
3476
+ const response = await this.publicGetGetBookSummaryByInstrument(this.extend(request, params));
3477
+ //
3478
+ // {
3479
+ // "jsonrpc": "2.0",
3480
+ // "result": [
3481
+ // {
3482
+ // "mid_price": 0.04025,
3483
+ // "volume_usd": 11045.12,
3484
+ // "quote_currency": "BTC",
3485
+ // "estimated_delivery_price": 65444.72,
3486
+ // "creation_timestamp": 1711100949273,
3487
+ // "base_currency": "BTC",
3488
+ // "underlying_index": "BTC-27DEC24",
3489
+ // "underlying_price": 73742.14,
3490
+ // "volume": 4.0,
3491
+ // "interest_rate": 0.0,
3492
+ // "price_change": -6.9767,
3493
+ // "open_interest": 274.2,
3494
+ // "ask_price": 0.042,
3495
+ // "bid_price": 0.0385,
3496
+ // "instrument_name": "BTC-27DEC24-240000-C",
3497
+ // "mark_price": 0.04007735,
3498
+ // "last": 0.04,
3499
+ // "low": 0.04,
3500
+ // "high": 0.043
3501
+ // }
3502
+ // ],
3503
+ // "usIn": 1711100949273223,
3504
+ // "usOut": 1711100949273580,
3505
+ // "usDiff": 357,
3506
+ // "testnet": false
3507
+ // }
3508
+ //
3509
+ const result = this.safeList(response, 'result', []);
3510
+ const chain = this.safeDict(result, 0, {});
3511
+ return this.parseOption(chain, undefined, market);
3512
+ }
3513
+ async fetchOptionChain(code, params = {}) {
3514
+ /**
3515
+ * @method
3516
+ * @name deribit#fetchOptionChain
3517
+ * @description fetches data for an underlying asset that is commonly found in an option chain
3518
+ * @see https://docs.deribit.com/#public-get_book_summary_by_currency
3519
+ * @param {string} currency base currency to fetch an option chain for
3520
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
3521
+ * @returns {object} a list of [option chain structures]{@link https://docs.ccxt.com/#/?id=option-chain-structure}
3522
+ */
3523
+ await this.loadMarkets();
3524
+ const currency = this.currency(code);
3525
+ const request = {
3526
+ 'currency': currency['id'],
3527
+ 'kind': 'option',
3528
+ };
3529
+ const response = await this.publicGetGetBookSummaryByCurrency(this.extend(request, params));
3530
+ //
3531
+ // {
3532
+ // "jsonrpc": "2.0",
3533
+ // "result": [
3534
+ // {
3535
+ // "mid_price": 0.4075,
3536
+ // "volume_usd": 2836.83,
3537
+ // "quote_currency": "BTC",
3538
+ // "estimated_delivery_price": 65479.26,
3539
+ // "creation_timestamp": 1711101594477,
3540
+ // "base_currency": "BTC",
3541
+ // "underlying_index": "BTC-28JUN24",
3542
+ // "underlying_price": 68827.27,
3543
+ // "volume": 0.1,
3544
+ // "interest_rate": 0.0,
3545
+ // "price_change": 0.0,
3546
+ // "open_interest": 364.1,
3547
+ // "ask_price": 0.411,
3548
+ // "bid_price": 0.404,
3549
+ // "instrument_name": "BTC-28JUN24-42000-C",
3550
+ // "mark_price": 0.40752052,
3551
+ // "last": 0.423,
3552
+ // "low": 0.423,
3553
+ // "high": 0.423
3554
+ // }
3555
+ // ],
3556
+ // "usIn": 1711101594456388,
3557
+ // "usOut": 1711101594484065,
3558
+ // "usDiff": 27677,
3559
+ // "testnet": false
3560
+ // }
3561
+ //
3562
+ const result = this.safeList(response, 'result', []);
3563
+ return this.parseOptionChain(result, 'base_currency', 'instrument_name');
3564
+ }
3565
+ parseOption(chain, currency = undefined, market = undefined) {
3566
+ //
3567
+ // {
3568
+ // "mid_price": 0.04025,
3569
+ // "volume_usd": 11045.12,
3570
+ // "quote_currency": "BTC",
3571
+ // "estimated_delivery_price": 65444.72,
3572
+ // "creation_timestamp": 1711100949273,
3573
+ // "base_currency": "BTC",
3574
+ // "underlying_index": "BTC-27DEC24",
3575
+ // "underlying_price": 73742.14,
3576
+ // "volume": 4.0,
3577
+ // "interest_rate": 0.0,
3578
+ // "price_change": -6.9767,
3579
+ // "open_interest": 274.2,
3580
+ // "ask_price": 0.042,
3581
+ // "bid_price": 0.0385,
3582
+ // "instrument_name": "BTC-27DEC24-240000-C",
3583
+ // "mark_price": 0.04007735,
3584
+ // "last": 0.04,
3585
+ // "low": 0.04,
3586
+ // "high": 0.043
3587
+ // }
3588
+ //
3589
+ const marketId = this.safeString(chain, 'instrument_name');
3590
+ market = this.safeMarket(marketId, market);
3591
+ const currencyId = this.safeString(chain, 'base_currency');
3592
+ const code = this.safeCurrencyCode(currencyId, currency);
3593
+ const timestamp = this.safeInteger(chain, 'timestamp');
3594
+ return {
3595
+ 'info': chain,
3596
+ 'currency': code['code'],
3597
+ 'symbol': market['symbol'],
3598
+ 'timestamp': timestamp,
3599
+ 'datetime': this.iso8601(timestamp),
3600
+ 'impliedVolatility': undefined,
3601
+ 'openInterest': this.safeNumber(chain, 'open_interest'),
3602
+ 'bidPrice': this.safeNumber(chain, 'bid_price'),
3603
+ 'askPrice': this.safeNumber(chain, 'ask_price'),
3604
+ 'midPrice': this.safeNumber(chain, 'mid_price'),
3605
+ 'markPrice': this.safeNumber(chain, 'mark_price'),
3606
+ 'lastPrice': this.safeNumber(chain, 'last'),
3607
+ 'underlyingPrice': this.safeNumber(chain, 'underlying_price'),
3608
+ 'change': undefined,
3609
+ 'percentage': this.safeNumber(chain, 'price_change'),
3610
+ 'baseVolume': this.safeNumber(chain, 'volume'),
3611
+ 'quoteVolume': this.safeNumber(chain, 'volume_usd'),
3612
+ };
3613
+ }
3459
3614
  nonce() {
3460
3615
  return this.milliseconds();
3461
3616
  }