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

add option to raise on sync failures on connect #626

Merged
merged 1 commit into from
Aug 29, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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