【问题标题】:reqHistoricalData() returning empty value using IBpy?reqHistoricalData() 使用 IBpy 返回空值?
【发布时间】:2015-05-08 18:23:38
【问题描述】:

我正在尝试使用 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())

知道可能出了什么问题吗?

【问题讨论】:

    标签: python ibrokers interactive-brokers ibpy


    【解决方案1】:

    您需要注册历史数据消息。

    con.register(my_hist_data_handler, message.historicalData)

    然后定义你想用它做什么

    def my_hist_data_handler(msg): print(msg)

    另请注意 MSFT(或 QQQ)是股票

    qqqq.m_secType = "STK" #cash is for forex
    qqqq.m_symbol = "MSFT" #use less confusing var name
    qqqq.m_currency = "USD" 
    qqqq.m_exchange = "SMART" #for stocks usually
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-05-22
      • 1970-01-01
      • 1970-01-01
      • 2021-07-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多