Deribit api key changes introduce:
- `get_timestamp_int`: added this is the hack, so we can aboid use the custom deribit date format. - `get_currencies`: added so we could get all deribit's available currencies. - Also a couple of format fixes.deribit_fix
parent
a4954393f9
commit
d475347e53
|
@ -52,12 +52,14 @@ from cryptofeed import FeedHandler
|
||||||
from cryptofeed.defines import (
|
from cryptofeed.defines import (
|
||||||
DERIBIT,
|
DERIBIT,
|
||||||
L1_BOOK, TRADES,
|
L1_BOOK, TRADES,
|
||||||
OPTION, CALL, PUT
|
OPTION, CALL, PUT,
|
||||||
|
OPEN_INTEREST,
|
||||||
)
|
)
|
||||||
from cryptofeed.symbols import Symbol
|
from cryptofeed.symbols import Symbol
|
||||||
from cryptofeed.types import (
|
from cryptofeed.types import (
|
||||||
L1Book,
|
L1Book,
|
||||||
Trade,
|
Trade,
|
||||||
|
OpenInterest,
|
||||||
)
|
)
|
||||||
from piker.brokers import SymbolNotFound
|
from piker.brokers import SymbolNotFound
|
||||||
from .venues import (
|
from .venues import (
|
||||||
|
@ -110,6 +112,10 @@ def deribit_timestamp(when: datetime) -> int:
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def get_timestamp_int(expiry_date: str) -> int:
|
||||||
|
return int(time.mktime(time.strptime(expiry_date, '%d%b%y')))
|
||||||
|
|
||||||
|
|
||||||
def str_to_cb_sym(name: str) -> Symbol:
|
def str_to_cb_sym(name: str) -> Symbol:
|
||||||
base, strike_price, expiry_date, option_type = name.split('-')
|
base, strike_price, expiry_date, option_type = name.split('-')
|
||||||
|
|
||||||
|
@ -122,8 +128,9 @@ def str_to_cb_sym(name: str) -> Symbol:
|
||||||
else:
|
else:
|
||||||
raise Exception("Couldn\'t parse option type")
|
raise Exception("Couldn\'t parse option type")
|
||||||
|
|
||||||
new_expiry_date = get_values_from_cb_normalized_date(expiry_date)
|
new_expiry_date: int = get_timestamp_int(
|
||||||
|
get_values_from_cb_normalized_date(expiry_date)
|
||||||
|
)
|
||||||
return Symbol(
|
return Symbol(
|
||||||
base=base,
|
base=base,
|
||||||
quote=quote,
|
quote=quote,
|
||||||
|
@ -143,11 +150,12 @@ def piker_sym_to_cb_sym(name: str) -> Symbol:
|
||||||
)= tuple(
|
)= tuple(
|
||||||
name.upper().split('-'))
|
name.upper().split('-'))
|
||||||
|
|
||||||
|
new_expiry_date = get_timestamp_int(expiry_date)
|
||||||
quote: str = base
|
quote: str = base
|
||||||
|
|
||||||
if option_type == 'P':
|
if option_type == 'P' or option_type == 'PUT':
|
||||||
option_type = PUT
|
option_type = PUT
|
||||||
elif option_type == 'C':
|
elif option_type == 'C' or option_type == 'CALL':
|
||||||
option_type = CALL
|
option_type = CALL
|
||||||
else:
|
else:
|
||||||
raise Exception("Couldn\'t parse option type")
|
raise Exception("Couldn\'t parse option type")
|
||||||
|
@ -158,7 +166,7 @@ def piker_sym_to_cb_sym(name: str) -> Symbol:
|
||||||
type=OPTION,
|
type=OPTION,
|
||||||
strike_price=strike_price,
|
strike_price=strike_price,
|
||||||
option_type=option_type,
|
option_type=option_type,
|
||||||
expiry_date=expiry_date
|
expiry_date=new_expiry_date
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@ -226,16 +234,18 @@ def get_config() -> dict[str, Any]:
|
||||||
)
|
)
|
||||||
|
|
||||||
conf_option = section.get('option', {})
|
conf_option = section.get('option', {})
|
||||||
section.clear # clear the dict to reuse it
|
conf_log = conf_option.get('log', {})
|
||||||
section['deribit'] = {}
|
return {
|
||||||
section['deribit']['key_id'] = conf_option.get('api_key')
|
'deribit': {
|
||||||
section['deribit']['key_secret'] = conf_option.get('api_secret')
|
'key_id': conf_option['key_id'],
|
||||||
|
'key_secret': conf_option['key_secret'],
|
||||||
section['log'] = {}
|
},
|
||||||
section['log']['filename'] = 'feedhandler.log'
|
'log': {
|
||||||
section['log']['level'] = 'DEBUG'
|
'filename': conf_log['filename'],
|
||||||
|
'level': conf_log['level'],
|
||||||
return section
|
'disabled': conf_log['disabled'],
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
class Client:
|
class Client:
|
||||||
|
@ -311,6 +321,20 @@ class Client:
|
||||||
|
|
||||||
return balances
|
return balances
|
||||||
|
|
||||||
|
async def get_currencies(
|
||||||
|
self,
|
||||||
|
|
||||||
|
) -> list[dict]:
|
||||||
|
'''
|
||||||
|
Return the set of currencies for deribit.
|
||||||
|
'''
|
||||||
|
assets = {}
|
||||||
|
resp = await self._json_rpc_auth_wrapper(
|
||||||
|
'public/get_currencies',
|
||||||
|
params={}
|
||||||
|
)
|
||||||
|
return resp.result
|
||||||
|
|
||||||
async def get_assets(
|
async def get_assets(
|
||||||
self,
|
self,
|
||||||
venue: str | None = None,
|
venue: str | None = None,
|
||||||
|
@ -323,11 +347,7 @@ class Client:
|
||||||
|
|
||||||
'''
|
'''
|
||||||
assets = {}
|
assets = {}
|
||||||
resp = await self._json_rpc_auth_wrapper(
|
currencies = await self.get_currencies()
|
||||||
'public/get_currencies',
|
|
||||||
params={}
|
|
||||||
)
|
|
||||||
currencies: list[dict] = resp.result
|
|
||||||
for currency in currencies:
|
for currency in currencies:
|
||||||
name: str = currency['currency']
|
name: str = currency['currency']
|
||||||
tx_tick: Decimal = digits_to_dec(currency['fee_precision'])
|
tx_tick: Decimal = digits_to_dec(currency['fee_precision'])
|
||||||
|
|
Loading…
Reference in New Issue