我知道有人问过这个问题,但对我来说,没有一种解决方案有效。我正在使用模拟帐户并遇到以下问题。
from ib.opt import Connection, message
from ib.ext.Contract import Contract
from ib.ext.Order import Order
from ib.ext.CommissionReport import CommissionReport
from ib.ext.TickType import TickType as tt
def error_handler(msg):
print (msg)
def execDetails(msg):
print('ID',msg.execution.m_execId,'PRICE',msg.execution.m_price)
def commReport(msg):
print('ID',msg.commissionReport.m_execId,'COM',msg.commissionReport.m_commission)
tws = Connection.create(port=7497, clientId=999)
tws.register(execDetails, message.execDetails)
tws.register(commReport, message.commissionReport)
tws.register(error_handler, 'Error')
tws.connect()
fx = Contract()
fx.m_secType = "CASH"
fx.m_symbol = "USD"
fx.m_currency = "CAD"
fx.m_exchange = "IDEALPRO"
#tws.reqMktData(1,fx,"",False)
ord = Order()
ord.m_orderType = 'MKT'
ord.m_totalQuantity = 100000
ord.m_action = 'SELL'
tws.placeOrder(124266,fx,ord)
输出如下,但订单已执行,但未显示执行价格或佣金:
Server Version: 76
TWS Time at connection:20181214 02:00:32 Greenwich Mean Time
<error id=-1, errorCode=2104, errorMsg=Market data farm connection is OK:eufarm>
<error id=-1, errorCode=2104, errorMsg=Market data farm connection is OK:cashfarm>
<error id=-1, errorCode=2104, errorMsg=Market data farm connection is OK:usfarm>
<error id=-1, errorCode=2106, errorMsg=HMDS data farm connection is OK:njhmds>
Process finished with exit code 0