from ibapi.client import EClient
from ibapi.wrapper import EWrapper
from ibapi.contract import Contract
from ibapi.order import *
import threading
import time
class IBapi(EWrapper, EClient):
def __init__(self):
EClient.__init__(self, self)
def openOrder(self, orderId, contract, order, orderState):
print('openOrder id:', orderId, contract.symbol, contract.secType, '@', contract.exchange,
':', order.action, order.orderType, order.totalQuantity, orderState.status)
def run_loop():
app.run()
app = IBapi()
app.connect('127.0.0.1', 7497, 123)
# Start the socket in a thread
api_thread = threading.Thread(target=run_loop, daemon=True)
api_thread.start()
time.sleep(3)
app.disconnect()
Here is my code to request all the open orders in my account. But I could only get back the selling order but not the buying order in my output. There are buying orders record from my trader station. So, I wonder is it because only selling order could be requested, if not, how could I request all the orders I have made including sell and buy orders by api.
Ref: https://interactivebrokers.github.io/tws-api/index.html