gpt4 book ai didi

python - IB TWS API - reqHistoricalData - keepUpToDate

转载 作者:行者123 更新时间:2023-12-05 06:14:42 33 4
gpt4 key购买 nike

我正在使用一个程序,通过 IB TWS API 检索给定合约的历史数据。我面临的问题是,当我希望将“keepUpToDate”从 False 更改为 True 以便我继续接收最新数据时,程序无法运行。

代码如下:

from ibapi.client import EClient
from ibapi.wrapper import EWrapper
from ibapi.contract import Contract
from ibapi.common import BarData
import datetime


class MyWrapper(EWrapper):

def nextValidId(self, orderId:int):
print("Setting nextValidOrderId: %d", orderId)
self.nextValidOrderId = orderId
self.start()

def historicalData(self, reqId:int, bar: BarData):
print("HistoricalData. ReqId:", reqId, "BarData.", bar)

def historicalDataEnd(self, reqId: int, start: str, end: str):
print("HistoricalDataEnd. ReqId:", reqId, "from", start, "to", end)
app.disconnect()
print("Finished")

def historicalDataUpdate(self, reqId: int, bar: BarData):
print("HistoricalDataUpdate. ReqId:", reqId, "BarData.", bar)

def error(self, reqId, errorCode, errorString):
print("Error. Id: " , reqId, " Code: " , errorCode , " Msg: " , errorString)

def start(self):
queryTime = (datetime.datetime.today() - datetime.timedelta(days=0)).strftime("%Y%m%d %H:%M:%S")

contract = Contract()
contract.secType = "STK"
contract.symbol = "CBLI"
contract.currency = "USD"
contract.exchange = "SMART"

app.reqHistoricalData(1, contract, queryTime, "2 D", "15 mins", "TRADES", 0, 1, False, [])

app = EClient(MyWrapper())
app.connect("127.0.0.1", 7496, clientId=123)
app.run()

我正在尝试将第 38 行的值从 False 更改为 True。我也认为问题可能出在第 30 行,因为文档指出“如果为 True,则无法指定 endDateTime。”

https://interactivebrokers.github.io/tws-api/historical_bars.html

如有任何意见,我们将不胜感激。

最佳答案

如果您想使用 keepUpToDate,则不能声明结束时间。我不使用 Python,所以 null 可能是 None 或 ""之类的其他东西,我不确定语法是什么。

改变:

app.reqHistoricalData(1, contract, queryTime, "2 D", "15 mins", "TRADES", 0, 1, False, [])

到:

app.reqHistoricalData(1, contract, null, "2 D", "15 mins", "TRADES", 0, 1, True, [])

关于python - IB TWS API - reqHistoricalData - keepUpToDate,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62755152/

33 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com