Merge pull request #549 from narumiruna/python/handlers

python: add event&channel handlers
This commit is contained in:
Yo-An Lin 2022-04-20 15:18:36 +08:00 committed by GitHub
commit 1cb4b312fc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 254 additions and 37 deletions

View File

@ -1,4 +1,5 @@
from . import enums
from . import handlers
from . import utils
from .services import MarketService
from .services import TradingService

View File

@ -1,3 +1,21 @@
from .balance import BalanceHandler
from .balance import BalanceSnapshotHandler
from .balance import BalanceUpdateHandler
from .book import BookSnapshotHandler
from .book import BookUpdateHandler
from .error import ErrorHandler
from .handler import Handler
from .kline import KLineHandler
from .kline import KLineSnapshotHandler
from .kline import KLineUpdateHandler
from .order import OrderHandler
from .order import OrderSnapshotHandler
from .order import OrderUpdateHandler
from .snapshot import SnapshotHandler
from .ticker import TickerHandler
from .ticker import TickerSnapshotHandler
from .ticker import TickerUpdateHandler
from .trade import TradeHandler
from .trade import TradeSnapshotHandler
from .trade import TradeUpdateHandler
from .update import UpdateHandler

View File

@ -0,0 +1,31 @@
from ..data import Event
from ..enums import ChannelType
from ..enums import EventType
from .handler import Handler
class BalanceHandler(Handler):
def __call__(self, event: Event) -> None:
if event.channel_type != ChannelType.BALANCE:
return
super(BalanceHandler, self).__call__(event)
class BalanceSnapshotHandler(BalanceHandler):
def __call__(self, event: Event) -> None:
if event.event_type != EventType.SNAPSHOT:
return
super(BalanceSnapshotHandler, self).__call__(event)
class BalanceUpdateHandler(BalanceHandler):
def __call__(self, event: Event) -> None:
if event.event_type != EventType.UPDATE:
return
super(BalanceUpdateHandler, self).__call__(event)

View File

@ -0,0 +1,31 @@
from ..data import Event
from ..enums import ChannelType
from ..enums import EventType
from .handler import Handler
class BookHandler(Handler):
def __call__(self, event: Event) -> None:
if event.channel_type != ChannelType.BOOK:
return
super(BookHandler, self).__call__(event)
class BookSnapshotHandler(BookHandler):
def __call__(self, event: Event) -> None:
if event.event_type != EventType.SNAPSHOT:
return
super(BookSnapshotHandler, self).__call__(event)
class BookUpdateHandler(BookHandler):
def __call__(self, event: Event) -> None:
if event.event_type != EventType.UPDATE:
return
super(BookUpdateHandler, self).__call__(event)

View File

@ -0,0 +1,31 @@
from ..data import Event
from ..enums import ChannelType
from ..enums import EventType
from .handler import Handler
class KLineHandler(Handler):
def __call__(self, event: Event) -> None:
if event.channel_type != ChannelType.KLINE:
return
super(KLineHandler, self).__call__(event)
class KLineSnapshotHandler(KLineHandler):
def __call__(self, event: Event) -> None:
if event.event_type != EventType.SNAPSHOT:
return
super(KLineSnapshotHandler, self).__call__(event)
class KLineUpdateHandler(KLineHandler):
def __call__(self, event: Event) -> None:
if event.event_type != EventType.UPDATE:
return
super(KLineUpdateHandler, self).__call__(event)

View File

@ -0,0 +1,31 @@
from ..data import Event
from ..enums import ChannelType
from ..enums import EventType
from .handler import Handler
class OrderHandler(Handler):
def __call__(self, event: Event) -> None:
if event.channel_type != ChannelType.ORDER:
return
super(OrderHandler, self).__call__(event)
class OrderSnapshotHandler(OrderHandler):
def __call__(self, event: Event) -> None:
if event.event_type != EventType.SNAPSHOT:
return
super(OrderSnapshotHandler, self).__call__(event)
class OrderUpdateHandler(OrderHandler):
def __call__(self, event: Event) -> None:
if event.event_type != EventType.UPDATE:
return
super(OrderUpdateHandler, self).__call__(event)

View File

@ -0,0 +1,12 @@
from ..data import Event
from ..enums import EventType
from .handler import Handler
class SnapshotHandler(Handler):
def __call__(self, event: Event) -> None:
if event.event_type != EventType.SNAPSHOT:
return
super(SnapshotHandler, self).__call__(event)

View File

@ -0,0 +1,31 @@
from ..data import Event
from ..enums import ChannelType
from ..enums import EventType
from .handler import Handler
class TickerHandler(Handler):
def __call__(self, event: Event) -> None:
if event.channel_type != ChannelType.TICKER:
return
super(TickerHandler, self).__call__(event)
class TickerSnapshotHandler(TickerHandler):
def __call__(self, event: Event) -> None:
if event.event_type != EventType.SNAPSHOT:
return
super(TickerSnapshotHandler, self).__call__(event)
class TickerUpdateHandler(TickerHandler):
def __call__(self, event: Event) -> None:
if event.event_type != EventType.UPDATE:
return
super(TickerUpdateHandler, self).__call__(event)

View File

@ -0,0 +1,31 @@
from ..data import Event
from ..enums import ChannelType
from ..enums import EventType
from .handler import Handler
class TradeHandler(Handler):
def __call__(self, event: Event) -> None:
if event.channel_type != ChannelType.TRADE:
return
super(TradeHandler, self).__call__(event)
class TradeSnapshotHandler(TradeHandler):
def __call__(self, event: Event) -> None:
if event.event_type != EventType.SNAPSHOT:
return
super(TradeSnapshotHandler, self).__call__(event)
class TradeUpdateHandler(TradeHandler):
def __call__(self, event: Event) -> None:
if event.event_type != EventType.UPDATE:
return
super(TradeUpdateHandler, self).__call__(event)

File diff suppressed because one or more lines are too long

View File

@ -1,6 +1,6 @@
[tool.poetry]
name = "bbgo"
version = "0.1.0"
version = "0.1.1"
description = ""
authors = ["なるみ <weaper@gmail.com>"]
packages = [