Skip to content

Commit

Permalink
Merge pull request #322 from bug-or-feature/ticker_timer
Browse files Browse the repository at this point in the history
Ticker timer
  • Loading branch information
bug-or-feature committed Jan 16, 2024
2 parents d36e435 + cc9a1dd commit a4a37a6
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions trading_ig/streamer/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,18 +44,22 @@ def stop_tick_subscription(self, epic):
subscription = self._subs.pop(epic)
self.service.unsubscribe(subscription)

def ticker(self, epic):
def ticker(self, epic, timeout_length=3):
# we won't have a ticker until at least one update is received from server,
# let's give it a few seconds
timeout = time.time() + 3
timeout = time.time() + timeout_length
while True:
logger.debug("Waiting for ticker...")
logger.info(f"Waiting for ticker for '{epic}'...")
if epic in self._tickers or time.time() > timeout:
break
time.sleep(0.25)
ticker = self._tickers[epic]
if not ticker:
raise Exception(f"No ticker found for {epic}, giving up")
try:
ticker = self._tickers[epic]
except KeyError:
raise Exception(
f"No ticker found for {epic} after "
f"waiting {timeout_length} seconds - giving up"
)
return ticker

def on_update(self, update):
Expand Down

0 comments on commit a4a37a6

Please sign in to comment.