我正在尝试从IBPY获取历史数据。 我知道了,但是音量极低,无法使用。 我想知道如何获得正确的历史交易量估算值。
我正在执行以下代码:
from ib.opt import Connection, message
from ib.ext.Contract import Contract
from ib.ext.Order import Order
from time import sleep, strftime
def historical_data_handler(msg):
print(msg)
connection = Connection.create(port=7496, clientId=999)
connection.register(historical_data_handler, message.historicalData)
connection.connect()
req = Contract()
req.m_secType = "STK"
req.m_symbol = "TSLA"
req.m_currency = "USD"
req.m_exchange = "AMEX"
endtime = strftime('%Y%m%d %H:%M:%S')
connection.reqHistoricalData(1,req,endtime,"1 D","1 hour","TRADES",1,1)
sleep(5)
connection.disconnect()
这是输出:
<historicalData reqId=1, date=20181123 16:30:00, open=333.21, high=333.33, low=331.04, close=332.92, volume=22, count=21, WAP=332.233, hasGaps=False>
<historicalData reqId=1, date=20181123 16:30:00, open=333.21, high=333.33, low=331.04, close=332.92, volume=22, count=21, WAP=332.233, hasGaps=False>
<historicalData reqId=1, date=20181123 17:00:00, open=332.93, high=334.2, low=327.0, close=328.2, volume=42, count=39, WAP=329.755, hasGaps=False>
<historicalData reqId=1, date=20181123 17:00:00, open=332.93, high=334.2, low=327.0, close=328.2, volume=42, count=39, WAP=329.755, hasGaps=False>
<historicalData reqId=1, date=20181123 18:00:00, open=329.0, high=330.37, low=327.96, close=327.96, volume=17, count=17, WAP=329.375, hasGaps=False>
<historicalData reqId=1, date=20181123 18:00:00, open=329.0, high=330.37, low=327.96, close=327.96, volume=17, count=17, WAP=329.375, hasGaps=False>
<historicalData reqId=1, date=20181123 19:00:00, open=328.5, high=328.6, low=326.07, close=326.07, volume=25, count=25, WAP=327.498, hasGaps=False>
<historicalData reqId=1, date=20181123 19:00:00, open=328.5, high=328.6, low=326.07, close=326.07, volume=25, count=25, WAP=327.498, hasGaps=False>
数据到达了,但是每一行的容量都不可能太低(每小时柱形约为22)。
在他们的网站上: https://interactivebrokers.github.io/tws-api/historical_bars.html#hd_what_to_show
据说:
注意:IB的历史数据供稿已针对某些类型的交易进行了过滤 通常发生在NBBO之外,例如连击,大宗交易, 和衍生品。因此,历史数据量为 低于未过滤的历史数据供稿
但是,检索到的卷是如此之低以至无用。
我想我不是第一个需要历史体积数据的人,并且可能有一种获取它的方法。 你能告诉我如何吗? 谢谢!