2

I can't figure out how to capture in a dataframe the executed trades with the execDetails function from https://interactivebrokers.github.io/tws-api/executions_commissions.html

class TradingApp(EWrapper, EClient):

def __init__(self):
    EClient.__init__(self, self)
    self.orderExec_df = pd.DataFrame(columns = [
        'ReqId', 'Symbol', 'SecType', 'Currency', 'ExecId', 'Time', 'Account', 'Exchange', 'Side', 'Shares', 'Price', 'PermId', 'ClientId', 'OrderId', 'Liquidation', 'CumQty', 'AvgPrice', 'OrderRef', 'EvRule', 'EvMultiplier', 'ModelCode', 'LastLiquidity'
        ])
   

def execDetails(self, reqId, contract, execution):
    super().execDetails(reqId, contract, execution)
    print("ExecDetails. ReqId:", reqId, "Symbol:", contract.symbol, "SecType:", contract.secType, "Currency:", contract.currency, execution)
    dictionary = {"ExecDetails. ReqId:", reqId, "Symbol:", contract.symbol, "SecType:", contract.secType, "Currency:", contract.currency, execution}
    self.orderExec_df = self.orderExec_df.append(dictionary, ignore_index = 0)

orderExec_df = app.reqExecutions(10001, ExecutionFilter()) time.sleep(1) orderExec_df = app.execDetails print(orderExec_df)

printing the data works fine

I get this error message

TypeError: cannot concatenate object of type '<class 'set'>'; only Series and DataFrame objs are valid

  • your `dictionary` is actually a set. did you instead mean to do `{"ExecDetails. ReqId":reqId, "Symbol":contract.symbol, ... }` – mitoRibo Jun 29 '22 at 22:44

1 Answers1

0

I've edited the code to

def execDetails(self, reqId, contract, execution):
     super().execDetails(reqId, contract, execution)
     print("ExecDetails. ReqId:", reqId, "Symbol:", contract.symbol, "SecType:", contract.secType, "Currency:", contract.currency, execution)
     dictionary = {"ExecDetails. ReqId": reqId, "Symbol": contract.symbol, "SecType": contract.secType, "Currency": contract.currency, 'ExecId': execution.ExecId}
     self.orderExec_df = self.orderExec_df.append(dictionary, ignore_index = 0)

I call the function with

 app.reqExecutions(10001, ExecutionFilter())
 time.sleep(1)
 orderExec_df = app.execDetails

I'm still not getting a dataframe as an output. I get this message

<bound method TradingApp.execDetails of <__main__.TradingApp object at 0x0000024569D4ADF0>>