0

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)

Now how do I get the 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

sophros
  • 14,672
  • 11
  • 46
  • 75
chess master1
  • 55
  • 1
  • 9
  • Ok. I will try to simplify it without the loop and ask again. I thought this was going to be an easy solutiion, but I guess not. – chess master1 Jul 08 '19 at 16:01

1 Answers1

1

The issue that you are struggling with is related to __str__ implementation for objects in Python (see this question).

Object can implement a custom __str__ method therefore printing a string representation of the object. 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.

sophros
  • 14,672
  • 11
  • 46
  • 75