【问题标题】:client terminating earlier in IbPy客户端在 IbPy 中提前终止
【发布时间】:2014-12-16 13:50:45
【问题描述】:

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

【问题讨论】:

    标签: python tws ibpy


    【解决方案1】:

    我认为你应该添加

    time.sleep(10)
    

    下单后查看订单状态。当然,您应该为这些响应消息注册一个处理程序。

    【讨论】:

      猜你喜欢
      • 2018-05-08
      • 2019-04-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-06-21
      • 1970-01-01
      • 2021-06-27
      相关资源
      最近更新 更多