def setUp(self): self.journaler = Journaler() domain = ENVIRONMENTS['api'][TARGET_ENV] settings = read_settings(CONFIG_PATH_FOR_UNIT_TESTS, TARGET_ENV) self.streamer = HistoricForexPrices(domain, settings['ACCESS_TOKEN'], settings['ACCOUNT_ID'])
def test_cannot_append_self_as_consumer(self): spmc_q = QueueSPMC(Journaler()) try: spmc_q.add_consumer(spmc_q) self.fail('was able to add self as a downstream consumer q') except ValueError: pass
def setUp(self): self.prices_wiring = WireOandaPrices() self.prices_wiring.set_journaler(Journaler()) self.prices_wiring.set_target_env('practice').set_config_path( CONFIG_PATH_FOR_UNIT_TESTS) self.rates_cache_wiring = WireRateCache() self.rates_cache_wiring.set_max_tick_age(2 * 24 * 60 * 60)
def setUp(self): self.rates_q = Queue() self.prices_wiring = WireOandaPrices() self.prices_wiring.set_journaler(Journaler()) self.prices_wiring.set_target_env('practice').set_config_path( CONFIG_PATH_FOR_UNIT_TESTS) self.command_q = Queue()
def setUp(self): self.portfolio_q = Queue() self.execution_q = Queue() self.wiring = WireExecutor().set_journaler(Journaler()) self.wiring.set_target_env('practice').set_config_path( CONFIG_PATH_FOR_UNIT_TESTS) self.command_q = Queue()
def setUp(self): self.rates_q = Queue() self.forward_q = Queue() self.command_q_streamer = Queue() self.command_q_cache = Queue() self.spmc_command_q = QueueSPMC(Journaler()) self.spmc_command_q.add_consumer(self.command_q_streamer) self.spmc_command_q.add_consumer(self.command_q_cache) self.prices_wiring = WireOandaPrices() self.prices_wiring.set_journaler(Journaler()) self.prices_wiring.set_target_env('practice').set_config_path( CONFIG_PATH_FOR_UNIT_TESTS) self.rates_cache_wiring = WireRateCache() self.rates_cache_wiring.set_max_tick_age(2 * 24 * 60 * 60)
def setUp(self): self.journaler = Journaler() self.everything = WireAll() self.everything.set_max_tick_age(24 * 60 * 60).set_journaler( self.journaler) self.everything.set_target_env('practice').set_config_path( CONFIG_PATH_FOR_UNIT_TESTS) self.everything.port_wiring.set_portfolio_ccy( 'USD').set_portfolio_balance(10000) self.everything.port_wiring.set_portfolio_limit( 50).set_portfolio_limit_short(-50) self.everything.set_strategy(DummyBuyStrategy()) wire_logger() self.command_q_for_cloning = Queue() self.command_q = QueueSPMC(Journaler())
def test_wire_all_with_command_listener(self): command_q_for_cloning = Queue() command_q = QueueSPMC(Journaler()) rates_streamer, rates_command_listener, rates_cache_loop, portfolio_loop, execution_loop, strategy_loop = \ self.everything.wire(command_q=command_q, in_q=command_q_for_cloning) rates_stream_thread = Thread(target=rates_streamer.stream) rates_cache_thread = Thread(target=rates_cache_loop.start) portfolio_thread = Thread(target=portfolio_loop.start) execution_thread = Thread(target=execution_loop.start) strategy_thread = Thread(target=strategy_loop.start) rates_command_listener_thread = None t1 = None t2 = None t3 = None t4 = None try: rates_stream_thread.start() rates_cache_thread.start() portfolio_thread.start() execution_thread.start() strategy_thread.start() rates_command_listener_thread = rates_command_listener.start_thread( ) t1 = rates_cache_loop.listener.start_thread() t2 = portfolio_loop.listener.start_thread() t3 = execution_loop.listener.start_thread() t4 = strategy_loop.listener.start_thread() sleep(MAX_TIME_TO_ALLOW_SOME_EVENTS_TO_STREAM) except RuntimeError as e: self.logger.error('error starting all components', e) except: self.logger.error('error starting all components') command_q.put_nowait(COMMAND_STOP) execution_thread.join(timeout=2 * execution_loop.heartbeat) portfolio_thread.join(timeout=MAX_TIME_TO_ALLOW_SOME_EVENTS_TO_STREAM) strategy_thread.join(timeout=2 * execution_loop.heartbeat) rates_stream_thread.join( timeout=MAX_TIME_TO_ALLOW_SOME_EVENTS_TO_STREAM) rates_cache_thread.join( timeout=MAX_TIME_TO_ALLOW_SOME_EVENTS_TO_STREAM) rates_command_listener_thread.join( timeout=MAX_TIME_TO_ALLOW_SOME_EVENTS_TO_STREAM) t1.join(timeout=MAX_TIME_TO_ALLOW_SOME_EVENTS_TO_STREAM) t2.join(timeout=MAX_TIME_TO_ALLOW_SOME_EVENTS_TO_STREAM) t3.join(timeout=MAX_TIME_TO_ALLOW_SOME_EVENTS_TO_STREAM) t4.join(timeout=MAX_TIME_TO_ALLOW_SOME_EVENTS_TO_STREAM)
def setUp(self): self.journaler = Journaler() domain = ENVIRONMENTS['streaming'][TARGET_ENV] settings = read_settings(CONFIG_PATH_FOR_UNIT_TESTS, TARGET_ENV) self.events = Queue() self.heartbeat_q = Queue() self.exceptions = Queue() self.streamer = OandaEventStreamer(domain, settings['ACCESS_TOKEN'], settings['ACCOUNT_ID'], self.journaler) self.streamer.set_events_q(self.events).set_heartbeat_q( self.heartbeat_q).set_exception_q(self.exceptions) self.streamer.set_context(OANDA_CONTEXT_EVENTS) self.streaming_thread = Thread(target=self.streamer.stream, args=[]) self.streaming_thread.start()
def setUp(self): domain = ENVIRONMENTS['streaming'][TARGET_ENV] settings = read_settings(CONFIG_PATH_FOR_UNIT_TESTS, TARGET_ENV) self.streamer = OandaEventStreamer(domain, settings['ACCESS_TOKEN'], settings['ACCOUNT_ID'], Journaler()) self.streamer.set_events_q(Queue()).set_heartbeat_q( Queue()).set_exception_q(Queue()) self.streamer.set_context(OANDA_CONTEXT_EVENTS) self.streaming_thread = Thread(target=self.streamer.stream, args=[]) self.command_q = Queue() self.listener = QueueCommandListener(self.command_q, self.streamer.on_command) self.command_thread = self.listener.start_thread() self.streaming_thread.start()
def get_price_streamer(context, connection, env, token, account_id, instruments): context.last_tick = None context.last_hb = None context.response = None context.journaler = Journaler() context.events = queue.Queue() context.heartbeat_events = queue.Queue() context.exceptions = queue.Queue() domain = ENVIRONMENTS[connection][env] pricer = OandaEventStreamer(domain, token, account_id, context.journaler) pricer.set_instruments(instruments) pricer.set_events_q(context.events).set_heartbeat_q( context.heartbeat_events).set_exception_q(context.exceptions) return pricer
def setUp(self): self.starter = ThreadStarter() self.tick = parse_event_str(None, TICK_STRING) self.rates_q = Queue() self.tick_for_strategy_q = Queue() self.signal_output_q = Queue() self.strategy_wiring = WireStrategy().set_strategy( DummyBuyStrategy(), 100) command_q_strategy = Queue() self.starter.add_target(self.strategy_wiring, command_q_strategy, self.tick_for_strategy_q, self.signal_output_q) self.rates_cache_wiring = WireRateCache().set_max_tick_age( TICK_MAX_AGE) command_q_rates = Queue() self.starter.add_target(self.rates_cache_wiring, command_q_rates, self.rates_q, self.tick_for_strategy_q) self.command_q = QueueSPMC(Journaler()) self.command_q.add_consumer(command_q_rates).add_consumer( command_q_strategy)
def setUp(self): self.rates_q = Queue() self.tick_for_strategy_q = Queue() self.signal_output_q = Queue() self.strategy_wiring = WireStrategy().set_strategy(DummyBuyStrategy()) self.strategy_loop = self.strategy_wiring.wire( in_q=self.tick_for_strategy_q, out_q=self.signal_output_q) self.strategy_thread = Thread(target=self.strategy_loop.start) self.prices_wiring = WireOandaPrices() self.prices_wiring.set_journaler(Journaler()) self.prices_wiring.set_target_env('practice').set_config_path( CONFIG_PATH_FOR_UNIT_TESTS) self.streamer = self.prices_wiring.wire(out_q=self.rates_q) self.rates_cache_wiring = WireRateCache() self.rates_cache_wiring.set_max_tick_age(24 * 60 * 60) self.rates_cache_loop = self.rates_cache_wiring.wire( in_q=self.rates_q, out_q=self.tick_for_strategy_q) self.streaming_thread = Thread(target=self.streamer.stream, args=[]) self.rates_cache_thread = Thread(target=self.rates_cache_loop.start)
def step_impl(context): context.journaler = Journaler()
def setUp(self): domain = ENVIRONMENTS['api'][TARGET_ENV] settings = read_settings(CONFIG_PATH_FOR_UNIT_TESTS, TARGET_ENV) self.executor = OandaExecutionHandler(domain, settings['ACCESS_TOKEN'], settings['ACCOUNT_ID'], Journaler())
def setUp(self): self.spmc_q = QueueSPMC(Journaler()) self.consumer_queues = list() self.spmc_put_method = self.spmc_q.put_nowait