我正在尝试使用 IBpy 从某些仪器返回历史数据,但是当我尝试文档中的代码时,我得到一个空结果。
我设法使用 R Ibroker 使它工作,但我真的更希望它使用 Python API 工作。
这是我正在测试的代码。
from time import sleep, strftime
from time import sleep
from ib.ext.Contract import Contract
from ib.opt import ibConnection, message
def my_account_handler(msg):
print(msg)
def my_tick_handler(msg):
print(msg)
if __name__ == '__main__':
con = ibConnection()
con.register(my_account_handler, 'UpdateAccountValue')
con.register(my_tick_handler, message.tickSize, message.tickPrice)
con.connect()
def inner():
qqqq = Contract()
qqqq.m_secType = "CASH"
qqqq.m_symbol = "MSFT"
qqqq.m_currency = "USD"
qqqq.m_exchange = "IDEALPRO"
endtime = strftime('%Y%m%d %H:%M:%S')
con.reqHistoricalData(1,qqqq,endtime,"5 D","1 hour","MIDPOINT",1,1)
sleep(10)
inner()
sleep(5)
print('disconnected', con.disconnect())
知道可能出了什么问题吗?