-
Notifications
You must be signed in to change notification settings - Fork 1
/
executor.py
35 lines (23 loc) · 853 Bytes
/
executor.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
from queue import Queue
from threading import Thread
from config import logger
class Executor:
def __init__(self):
self.order_queue = Queue()
self._executor_thread = Thread(target=self.execute, daemon=True)
self._executor_thread.start()
def add_to_execution_queue(self, order):
"""Add order to the queue
:type order: MarketOrder
:param order: Order to add to the execution queue
"""
logger.info(f"Adding order[{order}] to queue...")
self.order_queue.put(order)
def execute(self):
"""Get next order from the queue and execute"""
while True:
order = self.order_queue.get()
logger.info(f"Executing order[{order}]...")
order.execute_order()
self.order_queue.task_done()
order_executor = Executor()