1
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

sys cheng
  • 39
  • 1
  • 10
  • The buy orders must have been filled, 'open'Order means ones that haven't been filled. Try reqExecutions for filled orders. – brian Jul 16 '21 at 15:11
  • How could I use this function? I have included in the IBapi class, but there is no record about buy orders. – sys cheng Jul 19 '21 at 09:37
  • https://interactivebrokers.github.io/tws-api/executions_commissions.html – brian Jul 19 '21 at 15:01

0 Answers0