ccxt 4.2.81 → 4.2.82

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.
package/js/src/okx.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import Exchange from './abstract/okx.js';
2
- import type { TransferEntry, Int, OrderSide, OrderType, Trade, OHLCV, Order, FundingRateHistory, OrderRequest, FundingHistory, Str, Transaction, Ticker, OrderBook, Balances, Tickers, Market, Greeks, Strings, MarketInterface, Currency, Leverage, Num, Account } from './base/types.js';
2
+ import type { TransferEntry, Int, OrderSide, OrderType, Trade, OHLCV, Order, FundingRateHistory, OrderRequest, FundingHistory, Str, Transaction, Ticker, OrderBook, Balances, Tickers, Market, Greeks, Strings, MarketInterface, Currency, Leverage, Num, Account, OptionChain, Option } from './base/types.js';
3
3
  /**
4
4
  * @class okx
5
5
  * @augments Exchange
@@ -315,5 +315,26 @@ export default class okx extends Exchange {
315
315
  info: any;
316
316
  };
317
317
  closePosition(symbol: string, side?: OrderSide, params?: {}): Promise<Order>;
318
+ fetchOption(symbol: string, params?: {}): Promise<Option>;
319
+ fetchOptionChain(code: string, params?: {}): Promise<OptionChain>;
320
+ parseOption(chain: any, currency?: Currency, market?: Market): {
321
+ info: any;
322
+ currency: any;
323
+ symbol: string;
324
+ timestamp: number;
325
+ datetime: string;
326
+ impliedVolatility: any;
327
+ openInterest: any;
328
+ bidPrice: number;
329
+ askPrice: number;
330
+ midPrice: any;
331
+ markPrice: any;
332
+ lastPrice: number;
333
+ underlyingPrice: any;
334
+ change: any;
335
+ percentage: any;
336
+ baseVolume: number;
337
+ quoteVolume: any;
338
+ };
318
339
  handleErrors(httpCode: any, reason: any, url: any, method: any, headers: any, body: any, response: any, requestHeaders: any, requestBody: any): any;
319
340
  }
package/js/src/okx.js CHANGED
@@ -97,6 +97,8 @@ export default class okx extends Exchange {
97
97
  'fetchOpenInterestHistory': true,
98
98
  'fetchOpenOrder': undefined,
99
99
  'fetchOpenOrders': true,
100
+ 'fetchOption': true,
101
+ 'fetchOptionChain': true,
100
102
  'fetchOrder': true,
101
103
  'fetchOrderBook': true,
102
104
  'fetchOrderBooks': false,
@@ -7413,6 +7415,143 @@ export default class okx extends Exchange {
7413
7415
  const order = this.safeValue(data, 0);
7414
7416
  return this.parseOrder(order, market);
7415
7417
  }
7418
+ async fetchOption(symbol, params = {}) {
7419
+ /**
7420
+ * @method
7421
+ * @name okx#fetchOption
7422
+ * @description fetches option data that is commonly found in an option chain
7423
+ * @see https://www.okx.com/docs-v5/en/#order-book-trading-market-data-get-ticker
7424
+ * @param {string} symbol unified market symbol
7425
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
7426
+ * @returns {object} an [option chain structure]{@link https://docs.ccxt.com/#/?id=option-chain-structure}
7427
+ */
7428
+ await this.loadMarkets();
7429
+ const market = this.market(symbol);
7430
+ const request = {
7431
+ 'instId': market['id'],
7432
+ };
7433
+ const response = await this.publicGetMarketTicker(this.extend(request, params));
7434
+ //
7435
+ // {
7436
+ // "code": "0",
7437
+ // "msg": "",
7438
+ // "data": [
7439
+ // {
7440
+ // "instType": "OPTION",
7441
+ // "instId": "BTC-USD-241227-60000-P",
7442
+ // "last": "",
7443
+ // "lastSz": "0",
7444
+ // "askPx": "",
7445
+ // "askSz": "0",
7446
+ // "bidPx": "",
7447
+ // "bidSz": "0",
7448
+ // "open24h": "",
7449
+ // "high24h": "",
7450
+ // "low24h": "",
7451
+ // "volCcy24h": "0",
7452
+ // "vol24h": "0",
7453
+ // "ts": "1711176035035",
7454
+ // "sodUtc0": "",
7455
+ // "sodUtc8": ""
7456
+ // }
7457
+ // ]
7458
+ // }
7459
+ //
7460
+ const result = this.safeList(response, 'data', []);
7461
+ const chain = this.safeDict(result, 0, {});
7462
+ return this.parseOption(chain, undefined, market);
7463
+ }
7464
+ async fetchOptionChain(code, params = {}) {
7465
+ /**
7466
+ * @method
7467
+ * @name okx#fetchOptionChain
7468
+ * @description fetches data for an underlying asset that is commonly found in an option chain
7469
+ * @see https://www.okx.com/docs-v5/en/#order-book-trading-market-data-get-tickers
7470
+ * @param {string} currency base currency to fetch an option chain for
7471
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
7472
+ * @param {string} [params.uly] the underlying asset, can be obtained from fetchUnderlyingAssets ()
7473
+ * @returns {object} a list of [option chain structures]{@link https://docs.ccxt.com/#/?id=option-chain-structure}
7474
+ */
7475
+ await this.loadMarkets();
7476
+ const currency = this.currency(code);
7477
+ const request = {
7478
+ 'uly': currency['code'] + '-USD',
7479
+ 'instType': 'OPTION',
7480
+ };
7481
+ const response = await this.publicGetMarketTickers(this.extend(request, params));
7482
+ //
7483
+ // {
7484
+ // "code": "0",
7485
+ // "msg": "",
7486
+ // "data": [
7487
+ // {
7488
+ // "instType": "OPTION",
7489
+ // "instId": "BTC-USD-240323-52000-C",
7490
+ // "last": "",
7491
+ // "lastSz": "0",
7492
+ // "askPx": "",
7493
+ // "askSz": "0",
7494
+ // "bidPx": "",
7495
+ // "bidSz": "0",
7496
+ // "open24h": "",
7497
+ // "high24h": "",
7498
+ // "low24h": "",
7499
+ // "volCcy24h": "0",
7500
+ // "vol24h": "0",
7501
+ // "ts": "1711176207008",
7502
+ // "sodUtc0": "",
7503
+ // "sodUtc8": ""
7504
+ // },
7505
+ // ]
7506
+ // }
7507
+ //
7508
+ const result = this.safeList(response, 'data', []);
7509
+ return this.parseOptionChain(result, undefined, 'instId');
7510
+ }
7511
+ parseOption(chain, currency = undefined, market = undefined) {
7512
+ //
7513
+ // {
7514
+ // "instType": "OPTION",
7515
+ // "instId": "BTC-USD-241227-60000-P",
7516
+ // "last": "",
7517
+ // "lastSz": "0",
7518
+ // "askPx": "",
7519
+ // "askSz": "0",
7520
+ // "bidPx": "",
7521
+ // "bidSz": "0",
7522
+ // "open24h": "",
7523
+ // "high24h": "",
7524
+ // "low24h": "",
7525
+ // "volCcy24h": "0",
7526
+ // "vol24h": "0",
7527
+ // "ts": "1711176035035",
7528
+ // "sodUtc0": "",
7529
+ // "sodUtc8": ""
7530
+ // }
7531
+ //
7532
+ const marketId = this.safeString(chain, 'instId');
7533
+ market = this.safeMarket(marketId, market);
7534
+ const timestamp = this.safeInteger(chain, 'ts');
7535
+ return {
7536
+ 'info': chain,
7537
+ 'currency': undefined,
7538
+ 'symbol': market['symbol'],
7539
+ 'timestamp': timestamp,
7540
+ 'datetime': this.iso8601(timestamp),
7541
+ 'impliedVolatility': undefined,
7542
+ 'openInterest': undefined,
7543
+ 'bidPrice': this.safeNumber(chain, 'bidPx'),
7544
+ 'askPrice': this.safeNumber(chain, 'askPx'),
7545
+ 'midPrice': undefined,
7546
+ 'markPrice': undefined,
7547
+ 'lastPrice': this.safeNumber(chain, 'last'),
7548
+ 'underlyingPrice': undefined,
7549
+ 'change': undefined,
7550
+ 'percentage': undefined,
7551
+ 'baseVolume': this.safeNumber(chain, 'volCcy24h'),
7552
+ 'quoteVolume': undefined,
7553
+ };
7554
+ }
7416
7555
  handleErrors(httpCode, reason, url, method, headers, body, response, requestHeaders, requestBody) {
7417
7556
  if (!response) {
7418
7557
  return undefined; // fallback to default error handler
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ccxt",
3
- "version": "4.2.81",
3
+ "version": "4.2.82",
4
4
  "description": "A JavaScript / TypeScript / Python / C# / PHP cryptocurrency trading library with support for 100+ exchanges",
5
5
  "unpkg": "dist/ccxt.browser.js",
6
6
  "type": "module",