6262class TradingEngine (Application ):
6363 """A configureable trading application"""
6464
65- name = "AAT"
66- description = "async algorithmic trading engine"
65+ name = "AAT" # type: ignore
66+ description = "async algorithmic trading engine" # type: ignore
6767
6868 # Configureable parameters
69- verbose = Bool (default_value = True )
70- api = Bool (default_value = False )
71- port = Unicode (default_value = "8080" , help = "Port to run on" ).tag (config = True )
72- event_loop = Instance (klass = asyncio .events .AbstractEventLoop )
73- executor = Instance (klass = ThreadPoolExecutor , args = (4 ,), kwargs = {})
69+ verbose = Bool (default_value = True ) # type: ignore
70+ api = Bool (default_value = False ) # type: ignore
71+ port = Unicode (default_value = "8080" , help = "Port to run on" ).tag (config = True ) # type: ignore
72+ event_loop = Instance (klass = asyncio .events .AbstractEventLoop ) # type: ignore
73+ executor = Instance (klass = ThreadPoolExecutor , args = (4 ,), kwargs = {}) # type: ignore
7474
7575 # Core components
76- trading_type = Instance (klass = TradingType , default_value = TradingType .SIMULATION )
77- order_manager = Instance (OrderManager , args = (), kwargs = {})
78- risk_manager = Instance (RiskManager , args = (), kwargs = {})
79- portfolio_manager = Instance (PortfolioManager , args = (), kwargs = {})
80- exchanges = List (trait = Instance (klass = Exchange ))
81- event_handlers = List (trait = Instance (EventHandler ), default_value = [])
82- strategies = List (trait = Instance (Strategy ), default_value = [])
76+ trading_type = Instance (klass = TradingType , default_value = TradingType .SIMULATION ) # type: ignore
77+ order_manager = Instance (OrderManager , args = (), kwargs = {}) # type: ignore
78+ risk_manager = Instance (RiskManager , args = (), kwargs = {}) # type: ignore
79+ portfolio_manager = Instance (PortfolioManager , args = (), kwargs = {}) # type: ignore
80+ exchanges = List (trait = Instance (klass = Exchange )) # type: ignore
81+ event_handlers = List (trait = Instance (EventHandler ), default_value = []) # type: ignore
82+ strategies = List (trait = Instance (Strategy ), default_value = []) # type: ignore
8383
8484 # API application
85- api_application = Instance (klass = TornadoApplication )
86- api_handlers = List (default_value = [])
85+ api_application = Instance (klass = TornadoApplication ) # type: ignore
86+ api_handlers = List (default_value = []) # type: ignore
8787
88- table_manager = Instance (
88+ table_manager = Instance ( # type: ignore
8989 klass = PerspectiveManager or object , args = (), kwargs = {}
9090 ) # failover to object
9191
9292 aliases = {"port" : "AAT.port" , "trading_type" : "AAT.trading_type" }
9393
94- @validate ("trading_type" )
94+ @validate ("trading_type" ) # type: ignore
9595 def _validate_trading_type (self , proposal : dict ) -> TradingType :
9696 if proposal ["value" ] not in (
9797 TradingType .LIVE ,
@@ -102,7 +102,7 @@ def _validate_trading_type(self, proposal: dict) -> TradingType:
102102 raise TraitError (f'Invalid trading type: { proposal ["value" ]} ' )
103103 return proposal ["value" ]
104104
105- @validate ("exchanges" )
105+ @validate ("exchanges" ) # type: ignore
106106 def _validate_exchanges (self , proposal : dict ) -> ListType [Exchange ]:
107107 for exch in proposal ["value" ]:
108108 if not isinstance (exch , Exchange ):
@@ -148,7 +148,7 @@ def __init__(self, **config: dict) -> None:
148148
149149 # setup subscriptions
150150 self ._handler_subscriptions : Dict [EventType , List ] = {
151- m : [] for m in EventType .__members__ .values ()
151+ m : [] for m in EventType .__members__ .values () # type: ignore
152152 }
153153
154154 # setup `now` handler for backtest
@@ -311,10 +311,10 @@ def registerCallback(
311311 Returns:
312312 value (bool): True if registered (new), else False
313313 """
314- if (callback , handler ) not in self ._handler_subscriptions [event_type ]:
314+ if (callback , handler ) not in self ._handler_subscriptions [event_type ]: # type: ignore
315315 if not asyncio .iscoroutinefunction (callback ):
316316 callback = self ._make_async (callback )
317- self ._handler_subscriptions [event_type ].append ((callback , handler ))
317+ self ._handler_subscriptions [event_type ].append ((callback , handler )) # type: ignore
318318 return True
319319 return False
320320
@@ -449,19 +449,23 @@ async def processEvent(self, event: Event, strategy: Strategy = None) -> None:
449449 # ignore heartbeat
450450 return
451451
452- for callback , handler in self ._handler_subscriptions [event .type ]:
452+ for callback , handler in self ._handler_subscriptions [event .type ]: # type: ignore
453453 # TODO make cleaner? move to somewhere not in critical path?
454454 if strategy is not None and (handler not in (strategy , self .manager )):
455455 continue
456456
457457 # TODO make cleaner? move to somewhere not in critical path?
458- if event .type in (
459- EventType .TRADE ,
460- EventType .OPEN ,
461- EventType .CHANGE ,
462- EventType .CANCEL ,
463- EventType .DATA ,
464- ) and not self .manager .dataSubscriptions (handler , event ):
458+ if (
459+ event .type
460+ in (
461+ EventType .TRADE ,
462+ EventType .OPEN ,
463+ EventType .CHANGE ,
464+ EventType .CANCEL ,
465+ EventType .DATA ,
466+ )
467+ and not self .manager .dataSubscriptions (handler , event )
468+ ):
465469 continue
466470
467471 try :
0 commit comments