这是我的代码:
from threading import Timer
from ibapi.client import EClient
from ibapi.wrapper import EWrapper
from ibapi.contract import Contract
from ibapi.order import *
class TestApp(EWrapper, EClient):
def __init__(self):
EClient.__init__(self, self)
def Error(self, reqID, errorCode, errorString):
print('Error :', reqID, '', errorCode,'', errorString)
def contractDetails(self, reqID, contractDetails):
print('Contract Details :', reqID, '', contractDetails)
def nextValidId(self, orderId):
self.nextOrderID = orderId
self.run()
def orderStatus(self, orderId, status, filled, remaining, avgFillPrice, permID, lastFillprice, cliendId, whyHeld, mktCapPrice):
print('Orderstatus Id. ', orderId, 'Status: ', status, 'Filled: ', 'Remaining: ', remaining, 'Last Fill Price: ', lastFillprice)
def openOrderEnd(self, orderId, contract, order, orderState):
print('Open Order ID. ', orderId, contract.symbol, contract.secType, '@', contract.exchange, ': ', order.action, order.orderType, order.totalQuantity, orderState.status)
def execDetails(self, reqId, contract, execution):
print('Exec Details. ', reqId, contract.symbol, contract.secType, contract.currency, execution.execId, execution.orderId, execution.shares, execution.lastLiquidity)
def accountSummary(self, reqId, account, tag, value, currency):
print('Account Summary. ', reqId, account, tag, value, currency)
def start(self):
contract = Contract()
contract.symbol = 'NFLX'
contract.secType = 'STK'
contract.exchange = 'SMART'
contract.currency = 'USD'
contract.primaryExchange = 'NASDAQ'
order = Order()
order.action = 'BUY'
order.totalQuantity = 2
order.orderType = 'LMT'
order.lmtPrice = 539.50
self.placeOrder(self.nextOrderID, contract, order)
def stop(self):
self.done = True
self.disconnect()
def main():
app = TestApp()
app.nextOrderID = 0
app.connect('127.0.0.1', 7497, 0)
Timer(3, app.stop).start()
app.run()
if __name__ == '__main__':
main()
执行此代码时,我只是收到基本消息:
错误 -1 2104 市场数据农场连接正常:hfarm 错误 -1 2104 市场数据农场连接正常:usfarm.nj 错误 -1 2104 市场数据农场连接正常:usfuture 错误 -1 2104 市场数据农场连接正常:jfarm错误 -1 2104 市场数据农场连接正常:eufarm 错误 -1 2104 市场数据农场连接正常:cashfarm 错误 -1 2104 市场数据农场连接正常:usfarm 错误 -1 2106 HMDS 数据农场连接正常:euhmds 错误 - 1 2106 HMDS 数据场连接正常:fundfarm ERROR -1 2106 HMDS 数据场连接正常:ushmds ERROR -1 2158 Sec-def 数据场连接正常:secdefnj
我从 IBKR 在线视频中复制了代码。我不知道我做错了什么。我将不胜感激任何帮助。