Пример #1
0
class TableHandler(EventHandler):
    onData = None  # type: ignore
    onHalt = None  # type: ignore
    onContinue = None  # type: ignore
    onError = None  # type: ignore
    onStart = None  # type: ignore
    onExit = None  # type: ignore

    def __init__(self) -> None:
        self._trades = Table(Trade.schema(), index="timestamp")
        self._orders = Table(Order.schema(), index="id")

    def installTables(self, manager: Any) -> None:
        manager.host_table("trades", self._trades)
        manager.host_table("orders", self._orders)

    def tables(self) -> Tuple[Table, Table]:
        return self._trades, self._orders

    async def onTrade(self, event: Event) -> None:
        """onTrade"""
        trade: Trade = event.target  # type: ignore
        self._trades.update([trade.json()])

    async def onOpen(self, event: Event) -> None:
        """onOpen"""
        order: Order = event.target  # type: ignore
        self._orders.update([order.json()])

    async def onCancel(self, event: Event) -> None:
        """onCancel"""
        order: Order = event.target  # type: ignore
        self._orders.remove([order.id])

    async def onChange(self, event: Event) -> None:
        """onChange"""
        order: Order = event.target  # type: ignore
        self._orders.update([order.json()])

    async def onFill(self, event: Event) -> None:
        """onFill"""
        order: Order = event.target  # type: ignore
        self._orders.remove([order.id])
Пример #2
0
class TableHandler(EventHandler):
    onData = None  # type: ignore
    onHalt = None  # type: ignore
    onContinue = None  # type: ignore
    onError = None  # type: ignore
    onStart = None  # type: ignore
    onExit = None  # type: ignore

    def __init__(self):
        self._trades = Table(Trade.perspectiveSchema(), index="timestamp")
        self._orders = Table(Order.perspectiveSchema(), index="id")

    def installTables(self, manager) -> None:
        manager.host_table("trades", self._trades)
        manager.host_table("orders", self._orders)

    def tables(self) -> Tuple[Table, Table]:
        return self._trades, self._orders

    def onTrade(self, event: Event):
        '''onTrade'''
        self._trades.update([event.target.to_json()])

    def onOpen(self, event: Event):
        '''onOpen'''
        self._orders.update([event.target.to_json()])

    def onCancel(self, event: Event):
        '''onCancel'''
        self._orders.remove([event.target.id])

    def onChange(self, event: Event):
        '''onChange'''
        self._orders.update([event.target.to_json()])

    def onFill(self, event: Event):
        '''onFill'''
        self._orders.remove([event.target.id])