【发布时间】:2023-02-18 03:53:44
【问题描述】:
我只是想获取 SPX 的历史柱数据。有没有一种方法可以“找出”合适的合同,因为我似乎做不到。
from ibapi.client import *
from ibapi.wrapper import *
class TestApp(EClient, EWrapper):
def __init__(self):
EClient.__init__(self, self)
def nextValidId(self, orderId:int):
mycontract = Contract()
mycontract.symbol = 'SPX'
mycontract.secType = 'IND'
mycontract.exchange = 'CBOE'
mycontract.currency = 'USD'
#self.reqMarketDataType(4)
self.reqHistoricalData(orderId, mycontract, "20230126-23:59:59", "1 D", "1 hour", "TRADES", 0, 1, 0, [])
#self.reqMktData(orderId, mycontract, "", 0, 0, [])
#def tickPrice(self, reqId, tickType, price, attrib):
# print(f"tickPrice reqId: {reqId}, ticktype: {TickTypeEnum.to_str(tickType)}, price: {price}, attrib: {attrib}")
#def tickSize(self, reqId, tickType, size):
# print(f"tickSize reqId: {reqId}, ticktype: {TickTypeEnum.to_str(tickType)}, size: {size}")
def historicalData(self, reqId, bar):
print(f"Historical Data: {bar}")
def historicalDataEnd(self, reqId, start, end):
print(f"End of Historical Data")
print(f"start: {start}, end: {end}")
app = TestApp()
app.connect("127.0.0.1", 7497, 1000)
app.run()
这是我最接近的结果 - 说我没有市场数据订阅。我想我不知道。有市场数据订阅的人可以确认这有效吗?
此外,是否有关于开始使用 Interactive Brokers Native Python API 的良好指南?我发现创建继承自 EClient 和 EWrapper 的应用程序非常不直观。也许这是另一个线程的主题。
【问题讨论】:
-
here 也有人问过类似的问题。
标签: python api interactive-brokers