Skip to content
This repository has been archived by the owner on Mar 14, 2024. It is now read-only.

Commit

Permalink
Merge pull request #626 from onursatici/os/sync-failures
Browse files Browse the repository at this point in the history
add option to raise on sync failures on connect
  • Loading branch information
erdewit authored Aug 29, 2023
2 parents 0d94ccd + 30be0e9 commit f278ec1
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions ib_insync/ib.py
Original file line number Diff line number Diff line change
Expand Up @@ -1772,7 +1772,7 @@ def reqUserInfo(self) -> str:
async def connectAsync(
self, host: str = '127.0.0.1', port: int = 7497,
clientId: int = 1, timeout: Optional[float] = 4,
readonly: bool = False, account: str = ''):
readonly: bool = False, account: str = '', bailOnSyncFailure=False):
clientId = int(clientId)
self.wrapper.clientId = clientId
timeout = timeout or None
Expand Down Expand Up @@ -1806,22 +1806,30 @@ async def connectAsync(
tasks = [
asyncio.wait_for(req, timeout)
for req in reqs.values()]
failures = []
resps = await asyncio.gather(*tasks, return_exceptions=True)
for name, resp in zip(reqs, resps):
if isinstance(resp, asyncio.TimeoutError):
self._logger.error(f'{name} request timed out')
if isinstance(resp, Exception):
failures.append(resp)


# the request for executions must come after all orders are in
try:
await asyncio.wait_for(self.reqExecutionsAsync(), timeout)
except asyncio.TimeoutError:
except asyncio.TimeoutError as e:
self._logger.error('executions request timed out')
failures.append(e)

# final check if socket is still ready
if not self.client.isReady():
raise ConnectionError(
'Socket connection broken while connecting')

if bailOnSyncFailure and len(failures) > 0:
raise ConnectionError(failures)

self._logger.info('Synchronization complete')
self.connectedEvent.emit()
except BaseException:
Expand Down

0 comments on commit f278ec1

Please sign in to comment.