def connect(self, host, port, clientId, timeout=2): """ Connect to TWS/IBG at given host and port and with a clientId that is not in use elsewhere. When timeout is not zero, asyncio.TimeoutError is raised if the connection is not established within the timeout period. """ util.syncAwait(self.connectAsync(host, port, clientId, timeout))
def run(*awaitables: List[Awaitable]): """ By default run the event loop forever. When awaitables (like Tasks, Futures or coroutines) are given then run the event loop until each has completed and return their results. """ loop = asyncio.get_event_loop() if not awaitables: result = loop.run_forever() else: if len(awaitables) == 1: future = awaitables[0] else: future = asyncio.gather(*awaitables) result = util.syncAwait(future) return result
def terminate(self): """ Terminate TWS/IBG. """ util.syncAwait(self.terminateAsync())
def stop(self): """ Cleanly shutdown TWS/IBG. """ util.syncAwait(self.stopAsync())
def start(self): """ Launch TWS/IBG. """ util.syncAwait(self.startAsync())
def __init__(self, *args, **kwargs): Object.__init__(self, *args, **kwargs) self._proc = None self._logger = logging.getLogger('ib_insync.IBController') util.syncAwait(self.start()) asyncio.ensure_future(self.monitor())