21:25:10,085 root INFO Waiting for Gateway connection 21:25:10,085 ib_insync.IBC INFO Starting 21:25:15,099 root INFO Waiting for Gateway connection 21:25:20,115 root INFO Waiting for Gateway connection 21:25:25,129 root INFO Waiting for Gateway connection 21:25:30,129 root INFO Waiting for Gateway connection 21:25:35,129 root INFO Waiting for Gateway connection 21:25:40,084 ib_insync.client INFO Connecting to 127.0.0.1:4002 with clientId 1. ') while ib.isConnected() = False: ('Waiting for Gateway connection') ib.sleep(5) ntract = Forex('EURUSD') ib.qualifåontracts(ntract) ('Requesting historical live bars') hlbars = ib.reqHistoricalData(ntract, endDateTime='', durationStr='10800 S', barSizeSetting='1 min', whatToShow='MIDPOINT', useRTH=False, formatDate=1, keepUpToDate=True) ('starting timerange loop') for t in IB.timeRange(startdatetime, stopdatetime, 60): self.time = t hlbarsdf = self.get_latest_bars(hlbars) lastbar = hlbarsdf.tail(1) (lastbar) def get_latest_bars(self, hlbars): hlbarsdf = util.df(hlbars).set_index('date') hlbarsdf = hlbarsdf hlbarsdf = hlbarsdf.loc] return hlbarsdf if _name_ = '_main_': logfile = 'logging.txt' startdatetime = () stopdatetime = startdatetime + datetime.timedelta(hours = 23) logging.basicConfig( level=logging.INFO, format='%(asctime)s %(name)s %(levelname)s %(message)s', handlers=) (logfile) t_event_loop(asyncio.ProactorEventLoop()) # needed util.patchAsyncio() util.allowCtrlC() ('Instantiate IBC') ibc = IBC(twsVersion=972, gateway=True) ('Instantiate IB') ib = IB() ('Instantiate Watchdog') WD = Watchdog(ibc, ib, port=4002) ('Start Watchdog') WD.start() ('Instantiate Main') main = Main() main.resume() ('Run IB') WD.stop() Log - 21:25:10,080 root INFO logging.txt 21:25:10,085 root INFO Instantiate IBC 21:25:10,085 root INFO Instantiate IB 21:25:10,085 root INFO Instantiate Watchdog 21:25:10,085 root INFO Start Watchdog 21:25:10,085 ib_insync.Watchdog INFO Starting 21:25:10,085 root INFO Instantiate Main 21:25:10,085 root INFO Initialise connectedEvent callback 21:25:10,085 root INFO Initialise execDetailsEvent callback 21:25:10,085 root INFO Initialise commissionReportEvent callback 21:25:10,085 root INFO RESUME. I am attaching my code and log - from ib_insync import * import logging import sys import asyncio import datetime import os import numpy as np import pandas as pd import math class Main(): def _init_(self): super()._init_() # INITIALISE EVENTS ('Initialise connectedEvent callback') ib.connectedEvent += self.onConnected ('Initialise execDetailsEvent callback') ib.execDetailsEvent += self.onExecDetails ('Initialise commissionReportEvent callback') ib.commissionReportEvent += self.onCommissionReport def onExecDetails(self, trade, fill): self.update_positions_from_fill(fill) self.update_holdings_from_fill(fill) def onCommissionReport(self, trade, fill, commissionreport): pass def update_positions_from_fill(self, fill): pass def update_holdings_from_fill(self, fill): pass def onConnected(self): ('Connection event triggered') self.resume() def resume(self): ('RESUME. Could you please help? I am running this on windows platform. I am sure I am missing some aspect of make it work correctly. However, when I get error 1100 or manually close the gateway, watchdog doesnt kill the existing gateway session / restart gateway and the program goes dead but continues the IB.timerange loop with stale data. I am using watchdog to restart gateway on error 1100 and resubscribe to historical live bars. Hi Ewald, This weekend I updated to ib_insync version 0.9.43 ( and TWSAPI to 9.74 as a result).
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |