erdewit / ib_insync

Python sync/async framework for Interactive Brokers API
BSD 2-Clause "Simplified" License
2.8k stars 743 forks source link

Trade.remaning() will fail, confused int and string #602

Closed piotrgolawski closed 1 year ago

piotrgolawski commented 1 year ago

Yo. As in title print('trade.remaining()', trade.remaining()) File "/home/p/.cache/pypoetry/virtualenvs/trader-QSw8Zroc-py3.10/lib/python3.10/site-packages/ib_insync/order.py", line 327, in remaining return self.order.totalQuantity - self.filled() TypeError: unsupported operand type(s) for -: 'str' and 'int'

You are casting it somewhere probably, so def remaining(self): """Number of shares remaining to be filled.""" return int(self.order.totalQuantity) - int(self.filled())

BTW. can you share a suggestion how to make sell function to wait untill filledEvent will be finished? Just to make this stuff synchronous.

Thanks

erdewit commented 1 year ago

Probably you're specifying totalQuantity as a str. It must be int or float.

piotrgolawski commented 1 year ago

Are you totally sure?

At first I was not setting totalQuantity at all, just quantity as a integer.

When I setup totalQuantity also as a integer (just number 2), the problem was still there.

Have you checked that?

erdewit commented 1 year ago

Pretty sure yes. I see that you're using a very old version of ib_insync and it would be wise to update it.

piotrgolawski commented 1 year ago

Oh, I will then, thank you