def get_IB_historical_data(self, ibcontract, tickerid, durationStr, barSizeSetting):
historic_data_queue = finishableQueue(self.init_historicprices(tickerid))
self.reqHistoricalData(
tickerid, # tickerId,
ibcontract, # contract,
datetime.datetime.today().strftime("%Y%m%d %H:%M:%S %Z"), # endDateTime,
durationStr, # durationStr,
barSizeSetting, # barSizeSetting,
"TRADES", # whatToShow,
1, # useRTH,
1, # formatDate
False, # KeepUpToDate <<==== added for api 9.73.2
[] ## chartoptions not used
)
MAX_WAIT_SECONDS = 10
historic_data = historic_data_queue.get(timeout = MAX_WAIT_SECONDS)
if historic_data_queue.timed_out():
print("historic_data_queue.timed_out")
self.cancelHistoricalData(tickerid)
df = pd.DataFrame(historic_data)
df.columns = ['Datetime', 'Open', 'High', 'Low', 'Close', 'Volume']
return df
如果name=='main':
app = App_Class('127.0.0.1',7497, 11)
time.sleep(1234)
ibcontract = IBcontract()
ibcontract.secType = 'FUT'
ibcontract.lastTradeDateOrContractMonth = '20221129'
ibcontract.symbol = 'HSI'
ibcontract.exchange = 'HKFE'
resolved_ibcontract = app.resolve_ib_contract(ibcontract)
print(resolved_ibcontract)
df = app.get_IB_historical_data(resolved_ibcontract, 10, durationStr='30 D', barSizeSetting='1 D')
print(df)
我是初学蟒蛇的。我不知道为什么我不能打印数据帧,我已经订阅了数据。
我第一次运行程序:576501930,HSI,FUT,20221129,0.0,,50,香港期交所,,HKD,HSIX2,HSI、False,组合:错误10 320读取请求时出错。字符串索引超出范围:0历史数据队列超时错误-1 504未连接ValueError:长度不匹配:期望的轴有0个元素,新值有6个元素
我第二次运行程序时,当我重新运行时,他们说"_队列空的";
任何人都知道为什么以及如何修复它,谢谢。
''添加''ibcontract.includeExpired=True"合同详细信息">
''从''更改datetime.datetime.today((.strftime("%Y%m%d%H:%m:%S%Z"(,#endDateTime,''到''datetime.datetime.today((.strftime("%Y%m%d-%H:%m:%S"(,#endDateTime,"在定义get_IB_historical_data"中