From 3e125625b1691321b915fafeea545be218717d40 Mon Sep 17 00:00:00 2001 From: Tyler Goodlet Date: Tue, 22 Mar 2022 13:14:22 -0400 Subject: [PATCH] Attempt to better handle history throttles using flag --- piker/brokers/ib.py | 40 ++++++++++++++++++++++++---------------- 1 file changed, 24 insertions(+), 16 deletions(-) diff --git a/piker/brokers/ib.py b/piker/brokers/ib.py index 3d792a9f..9a77f5fb 100644 --- a/piker/brokers/ib.py +++ b/piker/brokers/ib.py @@ -1340,20 +1340,25 @@ async def get_bars( fails = 0 bars: Optional[list] = None - for _ in range(3): + async def get(): + + bars, bars_array = await proxy.bars( + fqsn=fqsn, + end_dt=end_dt, + ) + if bars_array is None: + raise SymbolNotFound(fqsn) + + next_dt = bars[0].date + log.info(f'ib datetime {next_dt}') + + return (bars, bars_array, next_dt), fails + + in_throttle: bool = False + + for _ in range(10): try: - - bars, bars_array = await proxy.bars( - fqsn=fqsn, - end_dt=end_dt, - ) - if bars_array is None: - raise SymbolNotFound(fqsn) - - next_dt = bars[0].date - print(f'ib datetime {next_dt}') - - return (bars, bars_array, next_dt), fails + return await get() except RequestError as err: _err = err @@ -1382,7 +1387,7 @@ async def get_bars( # try to decrement start point and look further back next_dt = bars[0].date - print(f'ib datetime {next_dt}') + log.info(f'ib datetime {next_dt}') continue elif 'No market data permissions for' in err.message: @@ -1401,7 +1406,10 @@ async def get_bars( # TODO: should probably create some alert on screen # and then somehow get that to trigger an event here # that restarts/resumes this task? - await tractor.breakpoint() + if not in_throttle: + await tractor.breakpoint() + + in_throttle = True fails += 1 continue @@ -1455,7 +1463,7 @@ async def backfill_bars( # on that until we have the `marketstore` daemon in place in which # case the shm size will be driven by user config and available sys # memory. - count: int = 16, + count: int = 22, task_status: TaskStatus[trio.CancelScope] = trio.TASK_STATUS_IGNORED,