客户端在IbPy中提前终止

2024-09-30 12:23:04 发布

您现在位置:Python中文网/ 问答频道 /正文

我试图在我的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)

Tags: 代码订单self机器registermessagetypeorder

热门问题