Beispiel #1
0
    def on_event(self, order: OrderEvent):
        print(f'已将{order.symbol}计入到资产组合')
        trade = TradeEvent(order.symbol, order.price, order.amount)

        print('还可以继续执行')
        bus.get().cancel_delivery(order)
        bus.get().post(trade)
        bus.get().unregister(self)
Beispiel #2
0
def run():
    import random
    import string
    current_bus = bus.get()
    salt = ''.join(random.sample(string.ascii_letters + string.digits, 8))
    setattr(current_bus, 'context_str', f'random_{salt}')

    TestSubscriber()
    SubscriberA()
    SubscriberB()
    SubscriberC()

    bus.get().post_sticky(StickyConfigEvent('模拟配置数据'))

    StickySubscriber()
    StickyNewSubscriber()

    bus.get().post(QuoteEvent({
        'open': 10,
        'high': 100,
        'low': 3,
        'close': 60
    }))
Beispiel #3
0
 def __init__(self):
     bus.get().register(self)
Beispiel #4
0
 def on_event(self, event: OrderEvent):
     print(f'以价格{event.price}购买{event.symbol}共计{event.amount}')
     print(bus.get().subscriptions_by_event_type.get(OrderEvent, []))
     if len(bus.get().subscriptions_by_event_type.get(OrderEvent, [])) == 1:
         bus.get().stop()
Beispiel #5
0
 def __init__(self):
     print('StickyNewSubscriber will be registered ')
     bus.get().register(self)
Beispiel #6
0
 def call_by_sticky_event(self, event: StickyConfigEvent):
     print("粘滞事件配置: ", event.config)
     bus.get().remove_sticky_event(event)
     print('已移除粘滞事件')
Beispiel #7
0
 def on_event(self, event: QuoteEvent):
     print("开盘价: ", event.open)
     bus.get().post(OrderEvent('HUOBI.ETHUSDT', event.close, 200))
Beispiel #8
0
 def on_event(self, event: TradeEvent):
     print(f"已撮合该交易: {event.symbol}-{event.price}-{event.amount}")
     order = OrderEvent(event.symbol, event.price, event.amount)
     bus.get().post(order)
Beispiel #9
0
 def __init__(self):
     # print(f'in subscriber c: {bus.get()}')
     bus.get().register(self)