Пример #1
0
class Exchange:
    def __init__(self, ws):
        self.q = Queue()  # set size?
        self.output = Queue()
        self.ws = ws
        self.simulator = TraderSimulator()

    def producer(self):
        self.simulator.start(self.q)

    def consumer(self):
        order_matcher = OrderMatcher(self.output)
        order_matcher.start(self.q)

    def output_writer(self):
        print("running output_writer")
        while True:
            message = self.output.get()
            if message == POISON_PILL:
                break
            msg_string = message.encode('utf8')
            self.ws.sendMessage(msg_string)

    def start_exchange(self):
        prod = Thread(target=self.producer)
        prod.start()
        cons = Thread(target=self.consumer)
        cons.start()
        output_thread = Thread(target=self.output_writer)
        output_thread.start()

    def kill(self):
        print("Dying...")
        self.output.put(POISON_PILL)
        self.q.put(POISON_PILL)
        self.simulator.kill()
        print("Dead.")
Пример #2
0
 def __init__(self, ws):
     self.q = Queue()  # set size?
     self.output = Queue()
     self.ws = ws
     self.simulator = TraderSimulator()