def _setup_dataProviderService(userConfig): dataProviderName = userConfig.projectConfig.dataProviderName if dataProviderName == DataProviderName.TD: userConfigDataProvider = UserConfig.get_config('TD') elif dataProviderName == DataProviderName.IB: userConfigDataProvider = UserConfig.get_config('IB') elif dataProviderName == DataProviderName.ROBINHOOD: userConfigDataProvider = UserConfig.get_config('ROBINHOOD') elif dataProviderName in [ DataProviderName.RANDOM, DataProviderName.LOCAL_FILE ]: userConfigDataProvider = UserConfig.get_config('LOCAL') else: raise RuntimeError( 'cannot handle userConfig.projectConfig.dataProviderName=%s' % (dataProviderName, )) userConfigDataProvider.projectConfig.logLevel = LogLevel.ERROR userConfigDataProvider.projectConfig.dataProviderName = dataProviderName # Do NOT delete. This is not necessary because settings.py is applied but just make sure it is effective userConfigDataProvider.brokerClientFactory = userConfig.brokerClientFactory # userConfig.brokerClientFactory is used as a singleton manager so that userConfigDataProvider will not create extra copy of brokerClients userConfigDataProvider.timeGeneratorFactory = userConfig.timeGeneratorFactory # make sure timeGenerator is singleton userConfigDataProvider = setup_services(userConfigDataProvider, None) userConfigDataProvider.dataProviderService.setAsDataProviderService( ) # set brokerService instance as a dataProviderService instance userConfigDataProvider.dataProviderService.getBrokerClient( ).setAsDataProviderClient() userConfig.trader.dataProviderService = userConfigDataProvider.dataProviderService # use the created dataProviderService as the dataProviderService of the trader userConfig.dataProviderService = userConfigDataProvider.dataProviderService # use the created dataProviderService as the dataProviderService of the main userConfig return userConfig
def run_me(fileName, userManualInput, userConfig=None, autoReconnectPremium=False): restart = None autoReconnectPremium = autoReconnectPremium while True: try: if not userConfig or restart: userConfig = UserConfig.get_config('IB') userConfig = _build_config(userConfig, userManualInput, fileName) if userConfig.projectConfig.brokerServiceName != userConfig.projectConfig.dataProviderName: print( '!!! Data provider is %s but the broker service is %s. They are NOT same. !!!' % (userConfig.projectConfig.dataProviderName, userConfig.projectConfig.brokerServiceName)) userConfig = _setup_dataProviderService(userConfig) autoReconnectPremium = userConfig.projectConfig.autoReconnectPremium finally_run(userConfig, LiveBacktest.LIVE) break except CustomError as e: if e.error_code in [509, 504, 502, 10141] and autoReconnectPremium: print('IBridgePy will sleep 10 seconds and reconnect again.') restart = True time.sleep(10) else: raise e
def build_active_IBridgePy_plus(accountCode=None): userConfig = UserConfig().get_config('IBinsync') if accountCode: userConfig.projectConfig.accountCode = accountCode userConfig.projectConfig.logLevel = 'INFO' userConfig = _build_config(userConfig) userConfig.trader.display_all() return userConfig.trader
def build_active_TD_trader(accountCode=None): userConfig = UserConfig.get_config('TD') userConfig.projectConfig.logLevel = 'INFO' if accountCode: userConfig.projectConfig.accountCode = accountCode userConfig = _build_config(userConfig) userConfig.trader.connect() return userConfig.trader
def run_me_at_HFT(fileName, userManualInput): userConfig = UserConfig.get_config('HFT') userConfig.traderConfig.runMode = TraderRunMode.HFT # Prevent that runMode is overridden by settings.py _helper(userConfig, userManualInput, fileName)
def run_me_at_td_ameritrade(fileName, userManualInput, userConfig=None): if not userConfig: userConfig = UserConfig.get_config('TD') _helper(userConfig, userManualInput, fileName)
def run_me_at_robinhood(fileName, userManualInput, userConfig=None): if not userConfig: userConfig = UserConfig.get_config('ROBINHOOD') _helper(userConfig, userManualInput, fileName)
def test_me(fileName, userManualInput, userConfig=None): if not userConfig: userConfig = UserConfig.get_config('BACKTEST') # print(__name__ + '::test_me: id of userConfig=%s' % (id(userConfig),)) userConfig = _build_config(userConfig, userManualInput, fileName) finally_run(userConfig, LiveBacktest.BACKTEST)