client terminating earlier in IbPy

283 views Asked by At

I am trying to run an IBpy in my linux server machine, I am using IBgateway to connect my api code to IB.
I am ordering a limit order, the problem is that the IBgateway is terminating my client connection.
As soon as it places the order the connection will be closed, making me unable to get the order status.
(This same code works perfectly when I run it in the Windows machine.)

The code I am using to place order:

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)
1

There are 1 answers

0
Qishen Ha On

I think you should just add

time.sleep(10)

after placed the order to see the order status. And of course you should register a handler for those response message.