mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-22 23:05:15 +00:00
Merge pull request #557 from narumiruna/fix-attribute
python: fix attribute, modify annotations and add test cases
This commit is contained in:
commit
36ff360cfc
|
@ -18,16 +18,16 @@ from .ticker import Ticker
|
|||
from .trade import Trade
|
||||
|
||||
|
||||
class Event:
|
||||
pass
|
||||
|
||||
|
||||
@dataclass
|
||||
class UserDataEvent(Event):
|
||||
class Event:
|
||||
session: str
|
||||
exchange: str
|
||||
channel_type: ChannelType
|
||||
event_type: EventType
|
||||
|
||||
|
||||
@dataclass
|
||||
class UserDataEvent(Event):
|
||||
balances: List[Balance] = None
|
||||
trades: List[Trade] = None
|
||||
orders: List[Order] = None
|
||||
|
@ -47,11 +47,7 @@ class UserDataEvent(Event):
|
|||
|
||||
@dataclass
|
||||
class MarketDataEvent(Event):
|
||||
session: str
|
||||
exchange: str
|
||||
symbol: str
|
||||
channel_type: ChannelType
|
||||
event_type: EventType
|
||||
subscribed_at: datetime
|
||||
error: ErrorMessage
|
||||
depth: Depth = None
|
||||
|
|
|
@ -30,7 +30,7 @@ class Trade:
|
|||
session=obj.session,
|
||||
exchange=obj.exchange,
|
||||
symbol=obj.symbol,
|
||||
id=obj.id,
|
||||
trade_id=obj.id,
|
||||
price=parse_float(obj.price),
|
||||
quantity=parse_float(obj.quantity),
|
||||
created_at=parse_time(obj.created_at),
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
from ..data import Event
|
||||
from ..data import UserDataEvent
|
||||
from ..enums import ChannelType
|
||||
from ..enums import EventType
|
||||
from .handler import Handler
|
||||
|
@ -6,7 +6,7 @@ from .handler import Handler
|
|||
|
||||
class BalanceHandler(Handler):
|
||||
|
||||
def __call__(self, event: Event) -> None:
|
||||
def __call__(self, event: UserDataEvent) -> None:
|
||||
if event.channel_type != ChannelType.BALANCE:
|
||||
return
|
||||
|
||||
|
@ -15,7 +15,7 @@ class BalanceHandler(Handler):
|
|||
|
||||
class BalanceSnapshotHandler(BalanceHandler):
|
||||
|
||||
def __call__(self, event: Event) -> None:
|
||||
def __call__(self, event: UserDataEvent) -> None:
|
||||
if event.event_type != EventType.SNAPSHOT:
|
||||
return
|
||||
|
||||
|
@ -24,7 +24,7 @@ class BalanceSnapshotHandler(BalanceHandler):
|
|||
|
||||
class BalanceUpdateHandler(BalanceHandler):
|
||||
|
||||
def __call__(self, event: Event) -> None:
|
||||
def __call__(self, event: UserDataEvent) -> None:
|
||||
if event.event_type != EventType.UPDATE:
|
||||
return
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
from ..data import Event
|
||||
from ..data import MarketDataEvent
|
||||
from ..enums import ChannelType
|
||||
from ..enums import EventType
|
||||
from .handler import Handler
|
||||
|
@ -6,7 +6,7 @@ from .handler import Handler
|
|||
|
||||
class BookHandler(Handler):
|
||||
|
||||
def __call__(self, event: Event) -> None:
|
||||
def __call__(self, event: MarketDataEvent) -> None:
|
||||
if event.channel_type != ChannelType.BOOK:
|
||||
return
|
||||
|
||||
|
@ -15,7 +15,7 @@ class BookHandler(Handler):
|
|||
|
||||
class BookSnapshotHandler(BookHandler):
|
||||
|
||||
def __call__(self, event: Event) -> None:
|
||||
def __call__(self, event: MarketDataEvent) -> None:
|
||||
if event.event_type != EventType.SNAPSHOT:
|
||||
return
|
||||
|
||||
|
@ -24,7 +24,7 @@ class BookSnapshotHandler(BookHandler):
|
|||
|
||||
class BookUpdateHandler(BookHandler):
|
||||
|
||||
def __call__(self, event: Event) -> None:
|
||||
def __call__(self, event: MarketDataEvent) -> None:
|
||||
if event.event_type != EventType.UPDATE:
|
||||
return
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
from ..data import Event
|
||||
from ..data import MarketDataEvent
|
||||
from ..enums import ChannelType
|
||||
from ..enums import EventType
|
||||
from .handler import Handler
|
||||
|
@ -6,7 +6,7 @@ from .handler import Handler
|
|||
|
||||
class KLineHandler(Handler):
|
||||
|
||||
def __call__(self, event: Event) -> None:
|
||||
def __call__(self, event: MarketDataEvent) -> None:
|
||||
if event.channel_type != ChannelType.KLINE:
|
||||
return
|
||||
|
||||
|
@ -15,7 +15,7 @@ class KLineHandler(Handler):
|
|||
|
||||
class KLineSnapshotHandler(KLineHandler):
|
||||
|
||||
def __call__(self, event: Event) -> None:
|
||||
def __call__(self, event: MarketDataEvent) -> None:
|
||||
if event.event_type != EventType.SNAPSHOT:
|
||||
return
|
||||
|
||||
|
@ -24,7 +24,7 @@ class KLineSnapshotHandler(KLineHandler):
|
|||
|
||||
class KLineUpdateHandler(KLineHandler):
|
||||
|
||||
def __call__(self, event: Event) -> None:
|
||||
def __call__(self, event: MarketDataEvent) -> None:
|
||||
if event.event_type != EventType.UPDATE:
|
||||
return
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
from ..data import Event
|
||||
from ..data import UserDataEvent
|
||||
from ..enums import ChannelType
|
||||
from ..enums import EventType
|
||||
from .handler import Handler
|
||||
|
@ -6,7 +6,7 @@ from .handler import Handler
|
|||
|
||||
class OrderHandler(Handler):
|
||||
|
||||
def __call__(self, event: Event) -> None:
|
||||
def __call__(self, event: UserDataEvent) -> None:
|
||||
if event.channel_type != ChannelType.ORDER:
|
||||
return
|
||||
|
||||
|
@ -15,7 +15,7 @@ class OrderHandler(Handler):
|
|||
|
||||
class OrderSnapshotHandler(OrderHandler):
|
||||
|
||||
def __call__(self, event: Event) -> None:
|
||||
def __call__(self, event: UserDataEvent) -> None:
|
||||
if event.event_type != EventType.SNAPSHOT:
|
||||
return
|
||||
|
||||
|
@ -24,7 +24,7 @@ class OrderSnapshotHandler(OrderHandler):
|
|||
|
||||
class OrderUpdateHandler(OrderHandler):
|
||||
|
||||
def __call__(self, event: Event) -> None:
|
||||
def __call__(self, event: UserDataEvent) -> None:
|
||||
if event.event_type != EventType.UPDATE:
|
||||
return
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
from ..data import Event
|
||||
from ..data import MarketDataEvent
|
||||
from ..enums import ChannelType
|
||||
from ..enums import EventType
|
||||
from .handler import Handler
|
||||
|
@ -6,7 +6,7 @@ from .handler import Handler
|
|||
|
||||
class TickerHandler(Handler):
|
||||
|
||||
def __call__(self, event: Event) -> None:
|
||||
def __call__(self, event: MarketDataEvent) -> None:
|
||||
if event.channel_type != ChannelType.TICKER:
|
||||
return
|
||||
|
||||
|
@ -15,7 +15,7 @@ class TickerHandler(Handler):
|
|||
|
||||
class TickerSnapshotHandler(TickerHandler):
|
||||
|
||||
def __call__(self, event: Event) -> None:
|
||||
def __call__(self, event: MarketDataEvent) -> None:
|
||||
if event.event_type != EventType.SNAPSHOT:
|
||||
return
|
||||
|
||||
|
@ -24,7 +24,7 @@ class TickerSnapshotHandler(TickerHandler):
|
|||
|
||||
class TickerUpdateHandler(TickerHandler):
|
||||
|
||||
def __call__(self, event: Event) -> None:
|
||||
def __call__(self, event: MarketDataEvent) -> None:
|
||||
if event.event_type != EventType.UPDATE:
|
||||
return
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
[tool.poetry]
|
||||
name = "bbgo"
|
||||
version = "0.1.5"
|
||||
version = "0.1.8"
|
||||
description = ""
|
||||
authors = ["なるみ <weaper@gmail.com>"]
|
||||
packages = [
|
||||
|
|
18
python/tests/test_utils.py
Normal file
18
python/tests/test_utils.py
Normal file
|
@ -0,0 +1,18 @@
|
|||
from bbgo.utils import parse_float
|
||||
from bbgo.utils import parse_time
|
||||
|
||||
|
||||
def test_parse_time():
|
||||
t = 1650610080000
|
||||
d = parse_time(t)
|
||||
|
||||
assert d.timestamp() == t / 1000
|
||||
|
||||
|
||||
def test_parse_float():
|
||||
assert parse_float(None) == 0
|
||||
assert parse_float("") == 0
|
||||
|
||||
s = "3.14159265358979"
|
||||
f = 3.14159265358979
|
||||
assert parse_float(s) == f
|
Loading…
Reference in New Issue
Block a user