ib-api-reloaded / ib_async

Python sync/async framework for Interactive Brokers API (replaces ib_insync)
BSD 2-Clause "Simplified" License
458 stars 72 forks source link

can not subscribing to order status #85

Closed tsauliu closed 3 weeks ago

tsauliu commented 3 weeks ago

I'm trying to subscribe to IB TWS order status through the following code. I've tried multiple times but it won't work. nothing coming back to my terminal when order is placed

from ib_async import *
ib = IB()
util.startLoop()
ib.connect('127.0.0.1', 7497, clientId=1)
print(ib.isConnected())
def orderStatusCallback(trade):
    print(f'Order Status: {trade.order.orderId}, Status: {trade.orderStatus.status}')
    print(f'Filled: {trade.orderStatus.filled}, Remaining: {trade.orderStatus.remaining}')
ib.orderStatusEvent += orderStatusCallback
ib.cancelOrderEvent += lambda trade: print(f'Order {trade.order.orderId} has been cancelled')
ib.openOrderEvent += lambda trade: print(f'Order {trade.order.orderId} has been opened')
ib.run()
tsauliu commented 3 weeks ago

problem solved, you have to use cliendid=0 to receive status for gui orders