ccxt 4.2.79__py2.py3-none-any.whl → 4.2.81__py2.py3-none-any.whl
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.
Potentially problematic release.
This version of ccxt might be problematic. Click here for more details.
- ccxt/__init__.py +1 -1
- ccxt/abstract/upbit.py +1 -0
- ccxt/async_support/__init__.py +1 -1
- ccxt/async_support/base/exchange.py +10 -1
- ccxt/async_support/binance.py +92 -4
- ccxt/async_support/bybit.py +174 -1
- ccxt/async_support/deribit.py +152 -1
- ccxt/async_support/gate.py +193 -6
- ccxt/async_support/hyperliquid.py +42 -9
- ccxt/async_support/mexc.py +2 -2
- ccxt/async_support/okx.py +17 -34
- ccxt/async_support/upbit.py +2 -0
- ccxt/base/exchange.py +34 -5
- ccxt/base/types.py +23 -0
- ccxt/binance.py +92 -4
- ccxt/bybit.py +174 -1
- ccxt/deribit.py +152 -1
- ccxt/gate.py +193 -6
- ccxt/hyperliquid.py +42 -9
- ccxt/mexc.py +2 -2
- ccxt/okx.py +17 -34
- ccxt/pro/__init__.py +1 -1
- ccxt/pro/binance.py +5 -5
- ccxt/pro/bitopro.py +2 -1
- ccxt/pro/gemini.py +4 -3
- ccxt/pro/phemex.py +6 -1
- ccxt/test/base/test_ohlcv.py +3 -2
- ccxt/test/base/test_shared_methods.py +8 -0
- ccxt/test/base/test_ticker.py +7 -1
- ccxt/test/test_async.py +26 -25
- ccxt/test/test_sync.py +26 -25
- ccxt/upbit.py +2 -0
- {ccxt-4.2.79.dist-info → ccxt-4.2.81.dist-info}/METADATA +4 -4
- {ccxt-4.2.79.dist-info → ccxt-4.2.81.dist-info}/RECORD +36 -36
- {ccxt-4.2.79.dist-info → ccxt-4.2.81.dist-info}/WHEEL +0 -0
- {ccxt-4.2.79.dist-info → ccxt-4.2.81.dist-info}/top_level.txt +0 -0
ccxt/binance.py
CHANGED
@@ -7,7 +7,7 @@ from ccxt.base.exchange import Exchange
|
|
7
7
|
from ccxt.abstract.binance import ImplicitAPI
|
8
8
|
import hashlib
|
9
9
|
import json
|
10
|
-
from ccxt.base.types import Balances, Currency, Greeks, Int, Leverage, Leverages, MarginMode, MarginModes, Market, MarketInterface, Num, Order, OrderBook, OrderRequest, OrderSide, OrderType, Str, Strings, Ticker, Tickers, Trade, Transaction, TransferEntry
|
10
|
+
from ccxt.base.types import Balances, Currency, Greeks, Int, Leverage, Leverages, MarginMode, MarginModes, Market, MarketInterface, Num, Option, Order, OrderBook, OrderRequest, OrderSide, OrderType, Str, Strings, Ticker, Tickers, Trade, Transaction, TransferEntry
|
11
11
|
from typing import List
|
12
12
|
from ccxt.base.errors import ExchangeError
|
13
13
|
from ccxt.base.errors import PermissionDenied
|
@@ -133,6 +133,8 @@ class binance(Exchange, ImplicitAPI):
|
|
133
133
|
'fetchOpenInterestHistory': True,
|
134
134
|
'fetchOpenOrder': True,
|
135
135
|
'fetchOpenOrders': True,
|
136
|
+
'fetchOption': True,
|
137
|
+
'fetchOptionChain': False,
|
136
138
|
'fetchOrder': True,
|
137
139
|
'fetchOrderBook': True,
|
138
140
|
'fetchOrderBooks': False,
|
@@ -2422,13 +2424,13 @@ class binance(Exchange, ImplicitAPI):
|
|
2422
2424
|
},
|
2423
2425
|
})
|
2424
2426
|
|
2425
|
-
def is_inverse(self, type, subType=None) -> bool:
|
2427
|
+
def is_inverse(self, type: str, subType: Str = None) -> bool:
|
2426
2428
|
if subType is None:
|
2427
|
-
return
|
2429
|
+
return(type == 'delivery')
|
2428
2430
|
else:
|
2429
2431
|
return subType == 'inverse'
|
2430
2432
|
|
2431
|
-
def is_linear(self, type, subType=None) -> bool:
|
2433
|
+
def is_linear(self, type: str, subType: Str = None) -> bool:
|
2432
2434
|
if subType is None:
|
2433
2435
|
return(type == 'future') or (type == 'swap')
|
2434
2436
|
else:
|
@@ -11410,3 +11412,89 @@ class binance(Exchange, ImplicitAPI):
|
|
11410
11412
|
'symbol': market['symbol'],
|
11411
11413
|
'marginMode': 'isolated' if isIsolated else 'cross',
|
11412
11414
|
}
|
11415
|
+
|
11416
|
+
def fetch_option(self, symbol: str, params={}) -> Option:
|
11417
|
+
"""
|
11418
|
+
fetches option data that is commonly found in an option chain
|
11419
|
+
:see: https://binance-docs.github.io/apidocs/voptions/en/#24hr-ticker-price-change-statistics
|
11420
|
+
:param str symbol: unified market symbol
|
11421
|
+
:param dict [params]: extra parameters specific to the exchange API endpoint
|
11422
|
+
:returns dict: an `option chain structure <https://docs.ccxt.com/#/?id=option-chain-structure>`
|
11423
|
+
"""
|
11424
|
+
self.load_markets()
|
11425
|
+
market = self.market(symbol)
|
11426
|
+
request = {
|
11427
|
+
'symbol': market['id'],
|
11428
|
+
}
|
11429
|
+
response = self.eapiPublicGetTicker(self.extend(request, params))
|
11430
|
+
#
|
11431
|
+
# [
|
11432
|
+
# {
|
11433
|
+
# "symbol": "BTC-241227-80000-C",
|
11434
|
+
# "priceChange": "0",
|
11435
|
+
# "priceChangePercent": "0",
|
11436
|
+
# "lastPrice": "2750",
|
11437
|
+
# "lastQty": "0",
|
11438
|
+
# "open": "2750",
|
11439
|
+
# "high": "2750",
|
11440
|
+
# "low": "2750",
|
11441
|
+
# "volume": "0",
|
11442
|
+
# "amount": "0",
|
11443
|
+
# "bidPrice": "4880",
|
11444
|
+
# "askPrice": "0",
|
11445
|
+
# "openTime": 0,
|
11446
|
+
# "closeTime": 0,
|
11447
|
+
# "firstTradeId": 0,
|
11448
|
+
# "tradeCount": 0,
|
11449
|
+
# "strikePrice": "80000",
|
11450
|
+
# "exercisePrice": "63944.09893617"
|
11451
|
+
# }
|
11452
|
+
# ]
|
11453
|
+
#
|
11454
|
+
chain = self.safe_dict(response, 0, {})
|
11455
|
+
return self.parse_option(chain, None, market)
|
11456
|
+
|
11457
|
+
def parse_option(self, chain, currency: Currency = None, market: Market = None):
|
11458
|
+
#
|
11459
|
+
# {
|
11460
|
+
# "symbol": "BTC-241227-80000-C",
|
11461
|
+
# "priceChange": "0",
|
11462
|
+
# "priceChangePercent": "0",
|
11463
|
+
# "lastPrice": "2750",
|
11464
|
+
# "lastQty": "0",
|
11465
|
+
# "open": "2750",
|
11466
|
+
# "high": "2750",
|
11467
|
+
# "low": "2750",
|
11468
|
+
# "volume": "0",
|
11469
|
+
# "amount": "0",
|
11470
|
+
# "bidPrice": "4880",
|
11471
|
+
# "askPrice": "0",
|
11472
|
+
# "openTime": 0,
|
11473
|
+
# "closeTime": 0,
|
11474
|
+
# "firstTradeId": 0,
|
11475
|
+
# "tradeCount": 0,
|
11476
|
+
# "strikePrice": "80000",
|
11477
|
+
# "exercisePrice": "63944.09893617"
|
11478
|
+
# }
|
11479
|
+
#
|
11480
|
+
marketId = self.safe_string(chain, 'symbol')
|
11481
|
+
market = self.safe_market(marketId, market)
|
11482
|
+
return {
|
11483
|
+
'info': chain,
|
11484
|
+
'currency': None,
|
11485
|
+
'symbol': market['symbol'],
|
11486
|
+
'timestamp': None,
|
11487
|
+
'datetime': None,
|
11488
|
+
'impliedVolatility': None,
|
11489
|
+
'openInterest': None,
|
11490
|
+
'bidPrice': self.safe_number(chain, 'bidPrice'),
|
11491
|
+
'askPrice': self.safe_number(chain, 'askPrice'),
|
11492
|
+
'midPrice': None,
|
11493
|
+
'markPrice': None,
|
11494
|
+
'lastPrice': self.safe_number(chain, 'lastPrice'),
|
11495
|
+
'underlyingPrice': self.safe_number(chain, 'exercisePrice'),
|
11496
|
+
'change': self.safe_number(chain, 'priceChange'),
|
11497
|
+
'percentage': self.safe_number(chain, 'priceChangePercent'),
|
11498
|
+
'baseVolume': self.safe_number(chain, 'volume'),
|
11499
|
+
'quoteVolume': None,
|
11500
|
+
}
|
ccxt/bybit.py
CHANGED
@@ -6,7 +6,7 @@
|
|
6
6
|
from ccxt.base.exchange import Exchange
|
7
7
|
from ccxt.abstract.bybit import ImplicitAPI
|
8
8
|
import hashlib
|
9
|
-
from ccxt.base.types import Balances, Currency, Greeks, Int, Leverage, Market, MarketInterface, Num, Order, OrderBook, OrderRequest, OrderSide, OrderType, Str, Strings, Ticker, Tickers, Trade, Transaction, TransferEntry
|
9
|
+
from ccxt.base.types import Balances, Currency, Greeks, Int, Leverage, Market, MarketInterface, Num, Option, OptionChain, Order, OrderBook, OrderRequest, OrderSide, OrderType, Str, Strings, Ticker, Tickers, Trade, Transaction, TransferEntry
|
10
10
|
from typing import List
|
11
11
|
from ccxt.base.errors import ExchangeError
|
12
12
|
from ccxt.base.errors import PermissionDenied
|
@@ -106,6 +106,8 @@ class bybit(Exchange, ImplicitAPI):
|
|
106
106
|
'fetchOpenInterestHistory': True,
|
107
107
|
'fetchOpenOrder': True,
|
108
108
|
'fetchOpenOrders': True,
|
109
|
+
'fetchOption': True,
|
110
|
+
'fetchOptionChain': True,
|
109
111
|
'fetchOrder': False,
|
110
112
|
'fetchOrderBook': True,
|
111
113
|
'fetchOrders': False,
|
@@ -7631,6 +7633,177 @@ class bybit(Exchange, ImplicitAPI):
|
|
7631
7633
|
'rate': self.safe_number(income, 'feeRate'),
|
7632
7634
|
}
|
7633
7635
|
|
7636
|
+
def fetch_option(self, symbol: str, params={}) -> Option:
|
7637
|
+
"""
|
7638
|
+
fetches option data that is commonly found in an option chain
|
7639
|
+
:see: https://bybit-exchange.github.io/docs/v5/market/tickers
|
7640
|
+
:param str symbol: unified market symbol
|
7641
|
+
:param dict [params]: extra parameters specific to the exchange API endpoint
|
7642
|
+
:returns dict: an `option chain structure <https://docs.ccxt.com/#/?id=option-chain-structure>`
|
7643
|
+
"""
|
7644
|
+
self.load_markets()
|
7645
|
+
market = self.market(symbol)
|
7646
|
+
request = {
|
7647
|
+
'category': 'option',
|
7648
|
+
'symbol': market['id'],
|
7649
|
+
}
|
7650
|
+
response = self.publicGetV5MarketTickers(self.extend(request, params))
|
7651
|
+
#
|
7652
|
+
# {
|
7653
|
+
# "retCode": 0,
|
7654
|
+
# "retMsg": "SUCCESS",
|
7655
|
+
# "result": {
|
7656
|
+
# "category": "option",
|
7657
|
+
# "list": [
|
7658
|
+
# {
|
7659
|
+
# "symbol": "BTC-27DEC24-55000-P",
|
7660
|
+
# "bid1Price": "0",
|
7661
|
+
# "bid1Size": "0",
|
7662
|
+
# "bid1Iv": "0",
|
7663
|
+
# "ask1Price": "0",
|
7664
|
+
# "ask1Size": "0",
|
7665
|
+
# "ask1Iv": "0",
|
7666
|
+
# "lastPrice": "10980",
|
7667
|
+
# "highPrice24h": "0",
|
7668
|
+
# "lowPrice24h": "0",
|
7669
|
+
# "markPrice": "11814.66756236",
|
7670
|
+
# "indexPrice": "63838.92",
|
7671
|
+
# "markIv": "0.8866",
|
7672
|
+
# "underlyingPrice": "71690.55303594",
|
7673
|
+
# "openInterest": "0.01",
|
7674
|
+
# "turnover24h": "0",
|
7675
|
+
# "volume24h": "0",
|
7676
|
+
# "totalVolume": "2",
|
7677
|
+
# "totalTurnover": "78719",
|
7678
|
+
# "delta": "-0.23284954",
|
7679
|
+
# "gamma": "0.0000055",
|
7680
|
+
# "vega": "191.70757975",
|
7681
|
+
# "theta": "-30.43617927",
|
7682
|
+
# "predictedDeliveryPrice": "0",
|
7683
|
+
# "change24h": "0"
|
7684
|
+
# }
|
7685
|
+
# ]
|
7686
|
+
# },
|
7687
|
+
# "retExtInfo": {},
|
7688
|
+
# "time": 1711162003672
|
7689
|
+
# }
|
7690
|
+
#
|
7691
|
+
result = self.safe_dict(response, 'result', {})
|
7692
|
+
resultList = self.safe_list(result, 'list', [])
|
7693
|
+
chain = self.safe_dict(resultList, 0, {})
|
7694
|
+
return self.parse_option(chain, None, market)
|
7695
|
+
|
7696
|
+
def fetch_option_chain(self, code: str, params={}) -> OptionChain:
|
7697
|
+
"""
|
7698
|
+
fetches data for an underlying asset that is commonly found in an option chain
|
7699
|
+
:see: https://bybit-exchange.github.io/docs/v5/market/tickers
|
7700
|
+
:param str currency: base currency to fetch an option chain for
|
7701
|
+
:param dict [params]: extra parameters specific to the exchange API endpoint
|
7702
|
+
:returns dict: a list of `option chain structures <https://docs.ccxt.com/#/?id=option-chain-structure>`
|
7703
|
+
"""
|
7704
|
+
self.load_markets()
|
7705
|
+
currency = self.currency(code)
|
7706
|
+
request = {
|
7707
|
+
'category': 'option',
|
7708
|
+
'baseCoin': currency['id'],
|
7709
|
+
}
|
7710
|
+
response = self.publicGetV5MarketTickers(self.extend(request, params))
|
7711
|
+
#
|
7712
|
+
# {
|
7713
|
+
# "retCode": 0,
|
7714
|
+
# "retMsg": "SUCCESS",
|
7715
|
+
# "result": {
|
7716
|
+
# "category": "option",
|
7717
|
+
# "list": [
|
7718
|
+
# {
|
7719
|
+
# "symbol": "BTC-27DEC24-55000-P",
|
7720
|
+
# "bid1Price": "0",
|
7721
|
+
# "bid1Size": "0",
|
7722
|
+
# "bid1Iv": "0",
|
7723
|
+
# "ask1Price": "0",
|
7724
|
+
# "ask1Size": "0",
|
7725
|
+
# "ask1Iv": "0",
|
7726
|
+
# "lastPrice": "10980",
|
7727
|
+
# "highPrice24h": "0",
|
7728
|
+
# "lowPrice24h": "0",
|
7729
|
+
# "markPrice": "11814.66756236",
|
7730
|
+
# "indexPrice": "63838.92",
|
7731
|
+
# "markIv": "0.8866",
|
7732
|
+
# "underlyingPrice": "71690.55303594",
|
7733
|
+
# "openInterest": "0.01",
|
7734
|
+
# "turnover24h": "0",
|
7735
|
+
# "volume24h": "0",
|
7736
|
+
# "totalVolume": "2",
|
7737
|
+
# "totalTurnover": "78719",
|
7738
|
+
# "delta": "-0.23284954",
|
7739
|
+
# "gamma": "0.0000055",
|
7740
|
+
# "vega": "191.70757975",
|
7741
|
+
# "theta": "-30.43617927",
|
7742
|
+
# "predictedDeliveryPrice": "0",
|
7743
|
+
# "change24h": "0"
|
7744
|
+
# },
|
7745
|
+
# ]
|
7746
|
+
# },
|
7747
|
+
# "retExtInfo": {},
|
7748
|
+
# "time": 1711162003672
|
7749
|
+
# }
|
7750
|
+
#
|
7751
|
+
result = self.safe_dict(response, 'result', {})
|
7752
|
+
resultList = self.safe_list(result, 'list', [])
|
7753
|
+
return self.parse_option_chain(resultList, None, 'symbol')
|
7754
|
+
|
7755
|
+
def parse_option(self, chain, currency: Currency = None, market: Market = None):
|
7756
|
+
#
|
7757
|
+
# {
|
7758
|
+
# "symbol": "BTC-27DEC24-55000-P",
|
7759
|
+
# "bid1Price": "0",
|
7760
|
+
# "bid1Size": "0",
|
7761
|
+
# "bid1Iv": "0",
|
7762
|
+
# "ask1Price": "0",
|
7763
|
+
# "ask1Size": "0",
|
7764
|
+
# "ask1Iv": "0",
|
7765
|
+
# "lastPrice": "10980",
|
7766
|
+
# "highPrice24h": "0",
|
7767
|
+
# "lowPrice24h": "0",
|
7768
|
+
# "markPrice": "11814.66756236",
|
7769
|
+
# "indexPrice": "63838.92",
|
7770
|
+
# "markIv": "0.8866",
|
7771
|
+
# "underlyingPrice": "71690.55303594",
|
7772
|
+
# "openInterest": "0.01",
|
7773
|
+
# "turnover24h": "0",
|
7774
|
+
# "volume24h": "0",
|
7775
|
+
# "totalVolume": "2",
|
7776
|
+
# "totalTurnover": "78719",
|
7777
|
+
# "delta": "-0.23284954",
|
7778
|
+
# "gamma": "0.0000055",
|
7779
|
+
# "vega": "191.70757975",
|
7780
|
+
# "theta": "-30.43617927",
|
7781
|
+
# "predictedDeliveryPrice": "0",
|
7782
|
+
# "change24h": "0"
|
7783
|
+
# }
|
7784
|
+
#
|
7785
|
+
marketId = self.safe_string(chain, 'symbol')
|
7786
|
+
market = self.safe_market(marketId, market)
|
7787
|
+
return {
|
7788
|
+
'info': chain,
|
7789
|
+
'currency': None,
|
7790
|
+
'symbol': market['symbol'],
|
7791
|
+
'timestamp': None,
|
7792
|
+
'datetime': None,
|
7793
|
+
'impliedVolatility': self.safe_number(chain, 'markIv'),
|
7794
|
+
'openInterest': self.safe_number(chain, 'openInterest'),
|
7795
|
+
'bidPrice': self.safe_number(chain, 'bid1Price'),
|
7796
|
+
'askPrice': self.safe_number(chain, 'ask1Price'),
|
7797
|
+
'midPrice': None,
|
7798
|
+
'markPrice': self.safe_number(chain, 'markPrice'),
|
7799
|
+
'lastPrice': self.safe_number(chain, 'lastPrice'),
|
7800
|
+
'underlyingPrice': self.safe_number(chain, 'underlyingPrice'),
|
7801
|
+
'change': self.safe_number(chain, 'change24h'),
|
7802
|
+
'percentage': None,
|
7803
|
+
'baseVolume': self.safe_number(chain, 'totalVolume'),
|
7804
|
+
'quoteVolume': None,
|
7805
|
+
}
|
7806
|
+
|
7634
7807
|
def sign(self, path, api='public', method='GET', params={}, headers=None, body=None):
|
7635
7808
|
url = self.implode_hostname(self.urls['api'][api]) + '/' + path
|
7636
7809
|
if api == 'public':
|
ccxt/deribit.py
CHANGED
@@ -6,7 +6,7 @@
|
|
6
6
|
from ccxt.base.exchange import Exchange
|
7
7
|
from ccxt.abstract.deribit import ImplicitAPI
|
8
8
|
import hashlib
|
9
|
-
from ccxt.base.types import Account, Balances, Currency, Greeks, Int, Market, MarketInterface, Num, Order, OrderBook, OrderSide, OrderType, Str, Strings, Ticker, Tickers, Trade, Transaction, TransferEntry
|
9
|
+
from ccxt.base.types import Account, Balances, Currency, Greeks, Int, Market, MarketInterface, Num, Option, OptionChain, Order, OrderBook, OrderSide, OrderType, Str, Strings, Ticker, Tickers, Trade, Transaction, TransferEntry
|
10
10
|
from typing import List
|
11
11
|
from ccxt.base.errors import ExchangeError
|
12
12
|
from ccxt.base.errors import PermissionDenied
|
@@ -83,6 +83,8 @@ class deribit(Exchange, ImplicitAPI):
|
|
83
83
|
'fetchMyTrades': True,
|
84
84
|
'fetchOHLCV': True,
|
85
85
|
'fetchOpenOrders': True,
|
86
|
+
'fetchOption': True,
|
87
|
+
'fetchOptionChain': True,
|
86
88
|
'fetchOrder': True,
|
87
89
|
'fetchOrderBook': True,
|
88
90
|
'fetchOrders': False,
|
@@ -3270,6 +3272,155 @@ class deribit(Exchange, ImplicitAPI):
|
|
3270
3272
|
'info': greeks,
|
3271
3273
|
}
|
3272
3274
|
|
3275
|
+
def fetch_option(self, symbol: str, params={}) -> Option:
|
3276
|
+
"""
|
3277
|
+
fetches option data that is commonly found in an option chain
|
3278
|
+
:see: https://docs.deribit.com/#public-get_book_summary_by_instrument
|
3279
|
+
:param str symbol: unified market symbol
|
3280
|
+
:param dict [params]: extra parameters specific to the exchange API endpoint
|
3281
|
+
:returns dict: an `option chain structure <https://docs.ccxt.com/#/?id=option-chain-structure>`
|
3282
|
+
"""
|
3283
|
+
self.load_markets()
|
3284
|
+
market = self.market(symbol)
|
3285
|
+
request = {
|
3286
|
+
'instrument_name': market['id'],
|
3287
|
+
}
|
3288
|
+
response = self.publicGetGetBookSummaryByInstrument(self.extend(request, params))
|
3289
|
+
#
|
3290
|
+
# {
|
3291
|
+
# "jsonrpc": "2.0",
|
3292
|
+
# "result": [
|
3293
|
+
# {
|
3294
|
+
# "mid_price": 0.04025,
|
3295
|
+
# "volume_usd": 11045.12,
|
3296
|
+
# "quote_currency": "BTC",
|
3297
|
+
# "estimated_delivery_price": 65444.72,
|
3298
|
+
# "creation_timestamp": 1711100949273,
|
3299
|
+
# "base_currency": "BTC",
|
3300
|
+
# "underlying_index": "BTC-27DEC24",
|
3301
|
+
# "underlying_price": 73742.14,
|
3302
|
+
# "volume": 4.0,
|
3303
|
+
# "interest_rate": 0.0,
|
3304
|
+
# "price_change": -6.9767,
|
3305
|
+
# "open_interest": 274.2,
|
3306
|
+
# "ask_price": 0.042,
|
3307
|
+
# "bid_price": 0.0385,
|
3308
|
+
# "instrument_name": "BTC-27DEC24-240000-C",
|
3309
|
+
# "mark_price": 0.04007735,
|
3310
|
+
# "last": 0.04,
|
3311
|
+
# "low": 0.04,
|
3312
|
+
# "high": 0.043
|
3313
|
+
# }
|
3314
|
+
# ],
|
3315
|
+
# "usIn": 1711100949273223,
|
3316
|
+
# "usOut": 1711100949273580,
|
3317
|
+
# "usDiff": 357,
|
3318
|
+
# "testnet": False
|
3319
|
+
# }
|
3320
|
+
#
|
3321
|
+
result = self.safe_list(response, 'result', [])
|
3322
|
+
chain = self.safe_dict(result, 0, {})
|
3323
|
+
return self.parse_option(chain, None, market)
|
3324
|
+
|
3325
|
+
def fetch_option_chain(self, code: str, params={}) -> OptionChain:
|
3326
|
+
"""
|
3327
|
+
fetches data for an underlying asset that is commonly found in an option chain
|
3328
|
+
:see: https://docs.deribit.com/#public-get_book_summary_by_currency
|
3329
|
+
:param str currency: base currency to fetch an option chain for
|
3330
|
+
:param dict [params]: extra parameters specific to the exchange API endpoint
|
3331
|
+
:returns dict: a list of `option chain structures <https://docs.ccxt.com/#/?id=option-chain-structure>`
|
3332
|
+
"""
|
3333
|
+
self.load_markets()
|
3334
|
+
currency = self.currency(code)
|
3335
|
+
request = {
|
3336
|
+
'currency': currency['id'],
|
3337
|
+
'kind': 'option',
|
3338
|
+
}
|
3339
|
+
response = self.publicGetGetBookSummaryByCurrency(self.extend(request, params))
|
3340
|
+
#
|
3341
|
+
# {
|
3342
|
+
# "jsonrpc": "2.0",
|
3343
|
+
# "result": [
|
3344
|
+
# {
|
3345
|
+
# "mid_price": 0.4075,
|
3346
|
+
# "volume_usd": 2836.83,
|
3347
|
+
# "quote_currency": "BTC",
|
3348
|
+
# "estimated_delivery_price": 65479.26,
|
3349
|
+
# "creation_timestamp": 1711101594477,
|
3350
|
+
# "base_currency": "BTC",
|
3351
|
+
# "underlying_index": "BTC-28JUN24",
|
3352
|
+
# "underlying_price": 68827.27,
|
3353
|
+
# "volume": 0.1,
|
3354
|
+
# "interest_rate": 0.0,
|
3355
|
+
# "price_change": 0.0,
|
3356
|
+
# "open_interest": 364.1,
|
3357
|
+
# "ask_price": 0.411,
|
3358
|
+
# "bid_price": 0.404,
|
3359
|
+
# "instrument_name": "BTC-28JUN24-42000-C",
|
3360
|
+
# "mark_price": 0.40752052,
|
3361
|
+
# "last": 0.423,
|
3362
|
+
# "low": 0.423,
|
3363
|
+
# "high": 0.423
|
3364
|
+
# }
|
3365
|
+
# ],
|
3366
|
+
# "usIn": 1711101594456388,
|
3367
|
+
# "usOut": 1711101594484065,
|
3368
|
+
# "usDiff": 27677,
|
3369
|
+
# "testnet": False
|
3370
|
+
# }
|
3371
|
+
#
|
3372
|
+
result = self.safe_list(response, 'result', [])
|
3373
|
+
return self.parse_option_chain(result, 'base_currency', 'instrument_name')
|
3374
|
+
|
3375
|
+
def parse_option(self, chain, currency: Currency = None, market: Market = None):
|
3376
|
+
#
|
3377
|
+
# {
|
3378
|
+
# "mid_price": 0.04025,
|
3379
|
+
# "volume_usd": 11045.12,
|
3380
|
+
# "quote_currency": "BTC",
|
3381
|
+
# "estimated_delivery_price": 65444.72,
|
3382
|
+
# "creation_timestamp": 1711100949273,
|
3383
|
+
# "base_currency": "BTC",
|
3384
|
+
# "underlying_index": "BTC-27DEC24",
|
3385
|
+
# "underlying_price": 73742.14,
|
3386
|
+
# "volume": 4.0,
|
3387
|
+
# "interest_rate": 0.0,
|
3388
|
+
# "price_change": -6.9767,
|
3389
|
+
# "open_interest": 274.2,
|
3390
|
+
# "ask_price": 0.042,
|
3391
|
+
# "bid_price": 0.0385,
|
3392
|
+
# "instrument_name": "BTC-27DEC24-240000-C",
|
3393
|
+
# "mark_price": 0.04007735,
|
3394
|
+
# "last": 0.04,
|
3395
|
+
# "low": 0.04,
|
3396
|
+
# "high": 0.043
|
3397
|
+
# }
|
3398
|
+
#
|
3399
|
+
marketId = self.safe_string(chain, 'instrument_name')
|
3400
|
+
market = self.safe_market(marketId, market)
|
3401
|
+
currencyId = self.safe_string(chain, 'base_currency')
|
3402
|
+
code = self.safe_currency_code(currencyId, currency)
|
3403
|
+
timestamp = self.safe_integer(chain, 'timestamp')
|
3404
|
+
return {
|
3405
|
+
'info': chain,
|
3406
|
+
'currency': code['code'],
|
3407
|
+
'symbol': market['symbol'],
|
3408
|
+
'timestamp': timestamp,
|
3409
|
+
'datetime': self.iso8601(timestamp),
|
3410
|
+
'impliedVolatility': None,
|
3411
|
+
'openInterest': self.safe_number(chain, 'open_interest'),
|
3412
|
+
'bidPrice': self.safe_number(chain, 'bid_price'),
|
3413
|
+
'askPrice': self.safe_number(chain, 'ask_price'),
|
3414
|
+
'midPrice': self.safe_number(chain, 'mid_price'),
|
3415
|
+
'markPrice': self.safe_number(chain, 'mark_price'),
|
3416
|
+
'lastPrice': self.safe_number(chain, 'last'),
|
3417
|
+
'underlyingPrice': self.safe_number(chain, 'underlying_price'),
|
3418
|
+
'change': None,
|
3419
|
+
'percentage': self.safe_number(chain, 'price_change'),
|
3420
|
+
'baseVolume': self.safe_number(chain, 'volume'),
|
3421
|
+
'quoteVolume': self.safe_number(chain, 'volume_usd'),
|
3422
|
+
}
|
3423
|
+
|
3273
3424
|
def nonce(self):
|
3274
3425
|
return self.milliseconds()
|
3275
3426
|
|