[英]Get permID within an list in Interactive Brokers using Python
This code: 这段代码:
open_trades = ib.trades() #Interactive Brokers function
for i in range(0,len(open_trades)):
print(open_trades[i].orderStatus
prints OrderStatus(status='Submitted', remaining=1000.0, permId =1036207528, clientId=1) 打印OrderStatus(状态='已提交',剩余= 1000.0, permId = 1036207528,clientId = 1)
Now how do I get the permID ? 现在如何获得permID ?
The answer should look something like this (I tried many other things too): 答案应该看起来像这样(我也尝试了许多其他事情):
open_trades[i].orderStatus.permID #no attribute error
open_trades[i].orderStatus.OrderStatus.permID #no attribute error
open_trades[i].orderStatus[0].permID #gets error 'OrderStatus' object does not support indexing
The last attempt is most likely the closest answer which gets the error: 最后一次尝试最有可能是得到错误的最接近答案:
'OrderStatus' object does not support indexing 'OrderStatus'对象不支持索引
The issue that you are struggling with is related to __str__
implementation for objects in Python (see this question ). 您正在努力解决的问题与Python中对象的__str__
实现有关(请参阅此问题 )。
Object can implement a custom __str__
method therefore printing a string representation of the object. 对象可以实现自定义__str__
方法,因此可以打印对象的字符串表示形式 。 However, it can be confusing, as it does not necessarily corresponds to the structure of the object (and its properties). 但是,这可能会造成混淆,因为它不一定对应于对象的结构(及其属性)。
Not knowing what libraries you use ( MCVE would be handy here) I suggest checking the available methods and object variables under debugger and then using them to access the properties you want. 不知道您使用什么库(在这里MCVE会很方便)我建议检查调试器下的可用方法和对象变量,然后使用它们访问所需的属性。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.