Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
mock__process_order_package,
mock__process_close_market,
):
mock_events = [
events.MarketCatalogueEvent(None),
events.MarketBookEvent(None),
events.RawDataEvent(None),
events.CurrentOrdersEvent(None),
BaseOrderPackage(None, "1.123", [], "12", None),
events.ClearedMarketsEvent(None),
events.ClearedOrdersEvent(None),
events.CloseMarketEvent(None),
events.StrategyResetEvent(None),
events.CustomEvent(None),
events.NewDayEvent(None),
events.EventType.TERMINATOR,
]
for i in mock_events:
self.flumine.handler_queue.put(i)
self.flumine.run()
mock__process_market_books.assert_called_with(mock_events[1])
mock__process_raw_data.assert_called_with(mock_events[2])
mock__process_market_catalogues.assert_called_with(mock_events[0])
mock__process_end_flumine.assert_called_with()
mock__process_current_orders.assert_called_with(mock_events[3])
mock__process_order_package.assert_called_with(mock_events[4])
mock__process_close_market.assert_called_with(mock_events[7])
EVENT_TYPE = EventType.RAW_DATA
QUEUE_TYPE = QueueType.HANDLER
class CurrentOrdersEvent(BaseEvent):
EVENT_TYPE = EventType.CURRENT_ORDERS
QUEUE_TYPE = QueueType.HANDLER
class ClearedMarketsEvent(BaseEvent):
EVENT_TYPE = EventType.CLEARED_MARKETS
QUEUE_TYPE = QueueType.HANDLER
class ClearedOrdersEvent(BaseEvent):
EVENT_TYPE = EventType.CLEARED_ORDERS
QUEUE_TYPE = QueueType.HANDLER
class CloseMarketEvent(BaseEvent):
EVENT_TYPE = EventType.CLOSE_MARKET
QUEUE_TYPE = QueueType.HANDLER
class StrategyResetEvent(BaseEvent):
EVENT_TYPE = EventType.STRATEGY_RESET
QUEUE_TYPE = QueueType.HANDLER
class CustomEvent(BaseEvent):
EVENT_TYPE = EventType.CUSTOM_EVENT
QUEUE_TYPE = QueueType.HANDLER
def run(self) -> None:
"""
Main run thread
"""
with self:
while True:
event = self.handler_queue.get()
if event.EVENT_TYPE == EventType.TERMINATOR:
self._process_end_flumine()
break
elif event.EVENT_TYPE == EventType.MARKET_CATALOGUE:
self._process_market_catalogues(event)
elif event.EVENT_TYPE == EventType.MARKET_BOOK:
self._process_market_books(event)
elif event.EVENT_TYPE == EventType.RAW_DATA:
self._process_raw_data(event)
elif event.EVENT_TYPE == EventType.CURRENT_ORDERS:
self._process_current_orders(event)
elif event.EVENT_TYPE == EventType.ORDER_PACKAGE:
EVENT_TYPE = EventType.CURRENT_ORDERS
QUEUE_TYPE = QueueType.HANDLER
class ClearedMarketsEvent(BaseEvent):
EVENT_TYPE = EventType.CLEARED_MARKETS
QUEUE_TYPE = QueueType.HANDLER
class ClearedOrdersEvent(BaseEvent):
EVENT_TYPE = EventType.CLEARED_ORDERS
QUEUE_TYPE = QueueType.HANDLER
class CloseMarketEvent(BaseEvent):
EVENT_TYPE = EventType.CLOSE_MARKET
QUEUE_TYPE = QueueType.HANDLER
class StrategyResetEvent(BaseEvent):
EVENT_TYPE = EventType.STRATEGY_RESET
QUEUE_TYPE = QueueType.HANDLER
class CustomEvent(BaseEvent):
EVENT_TYPE = EventType.CUSTOM_EVENT
QUEUE_TYPE = QueueType.HANDLER
class NewDayEvent(BaseEvent):
EVENT_TYPE = EventType.NEW_DAY
QUEUE_TYPE = QueueType.HANDLER
EVENT_TYPE = EventType.CLEARED_MARKETS
QUEUE_TYPE = QueueType.HANDLER
class ClearedOrdersEvent(BaseEvent):
EVENT_TYPE = EventType.CLEARED_ORDERS
QUEUE_TYPE = QueueType.HANDLER
class CloseMarketEvent(BaseEvent):
EVENT_TYPE = EventType.CLOSE_MARKET
QUEUE_TYPE = QueueType.HANDLER
class StrategyResetEvent(BaseEvent):
EVENT_TYPE = EventType.STRATEGY_RESET
QUEUE_TYPE = QueueType.HANDLER
class CustomEvent(BaseEvent):
EVENT_TYPE = EventType.CUSTOM_EVENT
QUEUE_TYPE = QueueType.HANDLER
class NewDayEvent(BaseEvent):
EVENT_TYPE = EventType.NEW_DAY
QUEUE_TYPE = QueueType.HANDLER
EVENT_TYPE = EventType.MARKET_CATALOGUE
QUEUE_TYPE = QueueType.HANDLER
class MarketBookEvent(BaseEvent):
EVENT_TYPE = EventType.MARKET_BOOK
QUEUE_TYPE = QueueType.HANDLER
class RawDataEvent(BaseEvent):
EVENT_TYPE = EventType.RAW_DATA
QUEUE_TYPE = QueueType.HANDLER
class CurrentOrdersEvent(BaseEvent):
EVENT_TYPE = EventType.CURRENT_ORDERS
QUEUE_TYPE = QueueType.HANDLER
class ClearedMarketsEvent(BaseEvent):
EVENT_TYPE = EventType.CLEARED_MARKETS
QUEUE_TYPE = QueueType.HANDLER
class ClearedOrdersEvent(BaseEvent):
EVENT_TYPE = EventType.CLEARED_ORDERS
QUEUE_TYPE = QueueType.HANDLER
class CloseMarketEvent(BaseEvent):
EVENT_TYPE = EventType.CLOSE_MARKET
QUEUE_TYPE = QueueType.HANDLER
@property
def elapsed_seconds(self):
return (datetime.datetime.utcnow() - self._time_created).total_seconds()
def __str__(self):
return "<{0} [{1}]>".format(self.EVENT_TYPE.name, self.QUEUE_TYPE.name)
class MarketCatalogueEvent(BaseEvent):
EVENT_TYPE = EventType.MARKET_CATALOGUE
QUEUE_TYPE = QueueType.HANDLER
class MarketBookEvent(BaseEvent):
EVENT_TYPE = EventType.MARKET_BOOK
QUEUE_TYPE = QueueType.HANDLER
class RawDataEvent(BaseEvent):
EVENT_TYPE = EventType.RAW_DATA
QUEUE_TYPE = QueueType.HANDLER
class CurrentOrdersEvent(BaseEvent):
EVENT_TYPE = EventType.CURRENT_ORDERS
QUEUE_TYPE = QueueType.HANDLER
class ClearedMarketsEvent(BaseEvent):
EVENT_TYPE = EventType.CLEARED_MARKETS
QUEUE_TYPE = QueueType.HANDLER
PLACE = "Place"
CANCEL = "Cancel"
REPLACE = "Replace"
UPDATE = "Update"
class BaseOrderPackage(BaseEvent):
"""
Data structure for multiple orders,
temporary to allow execution
"""
# todo client/retry
EVENT_TYPE = EventType.ORDER_PACKAGE
QUEUE_TYPE = QueueType.HANDLER
EXCHANGE = None
def __init__(
self,
client,
market_id: str,
orders: list,
package_type: OrderPackageType,
market,
async_: bool = False,
):
super(BaseOrderPackage, self).__init__(None)
self.id = uuid.uuid1()
self.client = client
self.market_id = market_id
EVENT_TYPE = EventType.CLOSE_MARKET
QUEUE_TYPE = QueueType.HANDLER
class StrategyResetEvent(BaseEvent):
EVENT_TYPE = EventType.STRATEGY_RESET
QUEUE_TYPE = QueueType.HANDLER
class CustomEvent(BaseEvent):
EVENT_TYPE = EventType.CUSTOM_EVENT
QUEUE_TYPE = QueueType.HANDLER
class NewDayEvent(BaseEvent):
EVENT_TYPE = EventType.NEW_DAY
QUEUE_TYPE = QueueType.HANDLER
QUEUE_TYPE = None
def __init__(self, event):
self._time_created = datetime.datetime.utcnow()
self.event = event
@property
def elapsed_seconds(self):
return (datetime.datetime.utcnow() - self._time_created).total_seconds()
def __str__(self):
return "<{0} [{1}]>".format(self.EVENT_TYPE.name, self.QUEUE_TYPE.name)
class MarketCatalogueEvent(BaseEvent):
EVENT_TYPE = EventType.MARKET_CATALOGUE
QUEUE_TYPE = QueueType.HANDLER
class MarketBookEvent(BaseEvent):
EVENT_TYPE = EventType.MARKET_BOOK
QUEUE_TYPE = QueueType.HANDLER
class RawDataEvent(BaseEvent):
EVENT_TYPE = EventType.RAW_DATA
QUEUE_TYPE = QueueType.HANDLER
class CurrentOrdersEvent(BaseEvent):
EVENT_TYPE = EventType.CURRENT_ORDERS
QUEUE_TYPE = QueueType.HANDLER