drop pydantic to match master
parent
f55f56a29f
commit
9073fbc317
|
@ -24,7 +24,8 @@ import pendulum
|
||||||
import asks
|
import asks
|
||||||
from fuzzywuzzy import process as fuzzy
|
from fuzzywuzzy import process as fuzzy
|
||||||
import numpy as np
|
import numpy as np
|
||||||
from pydantic import BaseModel
|
|
||||||
|
from piker.data.types import Struct
|
||||||
|
|
||||||
from .._util import resproc
|
from .._util import resproc
|
||||||
|
|
||||||
|
@ -33,10 +34,6 @@ from piker.log import get_logger
|
||||||
|
|
||||||
from cryptofeed.symbols import Symbol
|
from cryptofeed.symbols import Symbol
|
||||||
|
|
||||||
_spawn_kwargs = {
|
|
||||||
'infect_asyncio': True,
|
|
||||||
}
|
|
||||||
|
|
||||||
log = get_logger(__name__)
|
log = get_logger(__name__)
|
||||||
|
|
||||||
|
|
||||||
|
@ -56,7 +53,7 @@ _ohlc_dtype = [
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
class JSONRPCResult(BaseModel):
|
class JSONRPCResult(Struct):
|
||||||
jsonrpc: str = '2.0'
|
jsonrpc: str = '2.0'
|
||||||
result: dict
|
result: dict
|
||||||
usIn: int
|
usIn: int
|
||||||
|
@ -65,7 +62,7 @@ class JSONRPCResult(BaseModel):
|
||||||
testnet: bool
|
testnet: bool
|
||||||
|
|
||||||
|
|
||||||
class KLinesResult(BaseModel):
|
class KLinesResult(Struct):
|
||||||
close: List[float]
|
close: List[float]
|
||||||
cost: List[float]
|
cost: List[float]
|
||||||
high: List[float]
|
high: List[float]
|
||||||
|
@ -75,12 +72,7 @@ class KLinesResult(BaseModel):
|
||||||
ticks: List[int]
|
ticks: List[int]
|
||||||
volume: List[float]
|
volume: List[float]
|
||||||
|
|
||||||
|
class Trade(Struct):
|
||||||
class KLines(JSONRPCResult):
|
|
||||||
result: KLinesResult
|
|
||||||
|
|
||||||
|
|
||||||
class Trade(BaseModel):
|
|
||||||
trade_seq: int
|
trade_seq: int
|
||||||
trade_id: str
|
trade_id: str
|
||||||
timestamp: int
|
timestamp: int
|
||||||
|
@ -93,13 +85,10 @@ class Trade(BaseModel):
|
||||||
direction: str
|
direction: str
|
||||||
amount: float
|
amount: float
|
||||||
|
|
||||||
class LastTradesResult(BaseModel):
|
class LastTradesResult(Struct):
|
||||||
trades: List[Trade]
|
trades: List[Trade]
|
||||||
has_more: bool
|
has_more: bool
|
||||||
|
|
||||||
class LastTrades(JSONRPCResult):
|
|
||||||
result: LastTradesResult
|
|
||||||
|
|
||||||
|
|
||||||
# convert datetime obj timestamp to unixtime in milliseconds
|
# convert datetime obj timestamp to unixtime in milliseconds
|
||||||
def deribit_timestamp(when):
|
def deribit_timestamp(when):
|
||||||
|
@ -216,9 +205,9 @@ class Client:
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
klines = KLines(**response)
|
klines = JSONRPCResult(**response)
|
||||||
|
|
||||||
result = klines.result
|
result = KLinesResult(**klines.result)
|
||||||
new_bars = []
|
new_bars = []
|
||||||
for i in range(len(result.close)):
|
for i in range(len(result.close)):
|
||||||
|
|
||||||
|
@ -256,7 +245,7 @@ class Client:
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
return LastTrades(**response)
|
return LastTradesResult(**(JSONRPCResult(**response).result))
|
||||||
|
|
||||||
|
|
||||||
@acm
|
@acm
|
||||||
|
|
|
@ -47,7 +47,7 @@ from cryptofeed.defines import (
|
||||||
)
|
)
|
||||||
from cryptofeed.symbols import Symbol
|
from cryptofeed.symbols import Symbol
|
||||||
|
|
||||||
from .api import Client
|
from .api import Client, Trade
|
||||||
|
|
||||||
_spawn_kwargs = {
|
_spawn_kwargs = {
|
||||||
'infect_asyncio': True,
|
'infect_asyncio': True,
|
||||||
|
@ -65,8 +65,10 @@ def get_config() -> dict[str, Any]:
|
||||||
return {}
|
return {}
|
||||||
|
|
||||||
conf['log'] = {}
|
conf['log'] = {}
|
||||||
conf['log']['filename'] = '/tmp/feedhandler.log'
|
conf['log']['disabled'] = True
|
||||||
conf['log']['level'] = 'WARNING'
|
|
||||||
|
# conf['log']['filename'] = '/tmp/feedhandler.log'
|
||||||
|
# conf['log']['level'] = 'WARNING'
|
||||||
|
|
||||||
return conf
|
return conf
|
||||||
|
|
||||||
|
@ -299,8 +301,8 @@ async def stream_quotes(
|
||||||
# keep client cached for real-time section
|
# keep client cached for real-time section
|
||||||
cache = await client.cache_symbols()
|
cache = await client.cache_symbols()
|
||||||
|
|
||||||
last_trade = (await client.last_trades(
|
last_trade = Trade(**(await client.last_trades(
|
||||||
cb_sym_to_deribit_inst(nsym), count=1)).result.trades[0]
|
cb_sym_to_deribit_inst(nsym), count=1)).trades[0])
|
||||||
|
|
||||||
first_quote = {
|
first_quote = {
|
||||||
'symbol': sym,
|
'symbol': sym,
|
||||||
|
|
Loading…
Reference in New Issue