def __init__(self, host='localhost', port=4001, client_id=101, is_use_gateway=False, evaluation_time_secs=20, resample_interval_secs='30s', moving_window_period=dt.timedelta(hours=1)): self.moving_window_period = moving_window_period self.chart = Chart() self.ib_util = IBUtil() # Store parameters for this model self.strategy_params = StrategyParameters(evaluation_time_secs, resample_interval_secs) self.stocks_data = {} # Dictionary storing StockData objects. self.symbols = None # List of current symbols self.account_code = "" self.prices = None # Store last prices in a DataFrame self.trade_qty = 0 self.order_id = 0 self.lock = threading.Lock() # Use ibConnection() for TWS, or create connection for API Gateway self.conn = ibConnection() if is_use_gateway else \ Connection.create(host=host, port=port, clientId=client_id) self.__register_data_handlers(self.__on_tick_event, self.__event_handler)