我正在尝试从 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 之外的某些类型的交易进行过滤,例如组合交易、大宗交易和衍生品。因此,历史数据量将低于未过滤的历史数据馈送
但是,检索到的卷太少了,它们毫无用处。
我想我不是第一个需要历史成交量数据的人,而且可能有办法获得它。你能告诉我怎么做吗?谢谢!