我正在尝试在我的 linux 服务器机器上运行 IBpy,我正在使用 IBgateway 将我的 api 代码连接到 IB。
我正在订购限价单,问题是 IBgateway 正在终止我的客户端连接。
一旦下订单,连接就会关闭,使我无法获得订单状态。
(当我在 Windows 机器上运行相同的代码时,它可以完美运行。)
我用来下订单的代码:
def place_single_order(self,order_type,action,lmtprice,expiry_date,quantity,conn) :
conn=Connection.create(host='localhost', port=7496, clientId=1,receiver=ib, sender=None, dispatcher=None)
conn.connect()
conn.register(self.error_handler, 'Error')
conn.register(self.executed_order, message.execDetails)
conn.register(self.validids,message.nextValidId)
conn.register(self.my_order_status,message.orderStatus)
newContract = Contract()
newContract.m_symbol = 'ES'
newContract.m_secType = 'FUT'
newContract.m_exchange = 'GLOBEX'
newContract.m_currency = 'USD'
newContract.m_expiry = expiry_date
order = Order()
order.m_action = action
order.m_totalQuantity = quantity
order.m_transmit=True
order.m_orderType = order_type
if lmtprice != 0 and order_type=='LMT' :
order.m_lmtPrice=lmtprice
elif lmtprice != 0 and order_type=='STP' :
order.m_auxPrice=lmtprice
else :
pass
oid=self.new_orderID(conn) #this is to get the new orderid from IB by #
conn.placeOrder(oid,newContract,order)