I am trying to get historical data from IBPY. I get it, but the volume is extremely low to the point it's useless. I would like to know how to get the correct historical volume estimation.
I'm executing the following code:
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()
and this is the output:
<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>
The data arrives, but the volumes of each row are impossibly low (~22 for hourly bars).
On their website: https://interactivebrokers.github.io/tws-api/historical_bars.html#hd_what_to_show
it is stated that:
Note: IB's historical data feed is filtered for some types of trades which generally occur away from the NBBO such as combos, block trades, and derivatives. For that reason the historical data volume will be lower than an unfiltered historical data feed
However, the retrieved volumes are so low they are useless.
I suppose I'm not the first to need historical volume data, and there is probably a way to get it. Can you please tell me how? Thanks!
Volume is reported in hundreds. For example 22 is 2,200 shares.
For a reference see the Trader Workstation API Reference Guide or online here.