简体   繁体   English

捕获盈透证券交易执行详细信息 python

[英]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我无法弄清楚如何使用https://interactivebrokers.github.io/tws-api/executions_commissions.html中的 execDetails 函数在数据框中捕获已执行的交易

class TradingApp(EWrapper, EClient):类交易应用程序(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) 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'>'; TypeError: 无法连接类型为 '<class 'set'>' 的对象; only Series and DataFrame objs are valid只有 Series 和 DataFrame obj 是有效的

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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