小编Ila*_*ans的帖子

IBPY 获取正确的历史成交量数据

我正在尝试从 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()
Run Code Online (Sandbox Code Playgroud)

这是输出:

<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, …
Run Code Online (Sandbox Code Playgroud)

algorithmic-trading interactive-brokers ibpy

6
推荐指数
1
解决办法
2353
查看次数