简体   繁体   中英

Capture Interactive Brokers Trade Execution details python

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

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>>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM