我的代码如下,但它没有返回任何结果(没有错误,只是返回了“done”):
from ibapi.client import EClient
from ibapi.wrapper import EWrapper
from ibapi.contract import Contract
import threading
# 定义继承自EWrapper和EClient的IBapi类
class IBapi(EWrapper, EClient):
def __init__(self):
EClient.__init__(self, self)
def tickPrice(self, reqId, tickType, price, attrib):
if tickType == 2 and reqId == 1:
print('当前卖价为:', price)
def historicalData(self, reqId, bar):
print(reqId, bar.date, bar.high, bar.low, bar.volume)
# 定义循环运行函数
def run_loop():
app.run()
# 创建IBapi实例并连接至本地服务器
app = IBapi()
app.connect('127.0.0.1', 7497, 123)
api_thread = threading.Thread(target=run_loop, daemon=True)
api_thread.start()
# 创建一个期货合约对象
contract = Contract()
contract.symbol = "VIX"
contract.secType = "FUT"
contract.exchange = "CFE"
contract.currency = "USD"
contract.lastTradeDateOrContractMonth = "20240117"
contract.multiplier = "1000"
contract.includeExpired = True
# 请求历史数据
app.reqHistoricalData(1, contract, "", "1 M", "30 mins", "bid", 0, 1, False, [])
# 断开与服务器的连接
app.disconnect()
print("完成")
我记得之前我运行过非常类似的代码,当时是正常的。请问有人能告诉我现在的代码中哪里出错了吗?
非常感谢!