`IB.client.getReqId()` returns already used ID
See original GitHub issueI am using IB.client.getReqId()
to place my version of bracket orders and set parentId
in target and stop loss orders.
But I have stumbled upon an error:
Traceback (most recent call last):
(...)
File "_", line 53, in bracket_order
parent_trade: Trade = ib_client.placeOrder(contract, parent)
File "/venv/lib/python3.6/site-packages/ib_insync/ib.py", line 528, in placeOrder
assert trade.orderStatus.status not in OrderStatus.DoneStates
AssertionError
Which means that trade with such ID was found.
Parent order is created like that:
parent = MarketOrder(
action, quantity,
orderId=ib_client.client.getReqId(),
transmit=False,
conditionsIgnoreRth=False,
outsideRth=False
)
Entire bracket_order
function is copy of ib_insync.ib.IB.bracketOrder
source with parent placed as MarketOrder
instead of LimitOrder
. So all but stopLoss
are transmit=False
. Orders are placed in order:
- parent,
- target,
- stop.
Is there a problem with IB
that it start IB.client
on wrong ID or does not update it properly?
Issue Analytics
- State:
- Created 5 years ago
- Comments:23 (10 by maintainers)
Top Results From Across the Web
insync@groups.io | Wrong orderId
I have run into this issue with order id's being reused in ib_sync when orders get canceled for some reason - not sure...
Read more >Source code for ib_insync.ib
isConnected() else 'not connected') return f'<{self.__class__. ... clientId: ID number to use for this client; must be unique per connection.
Read more >Dmitry's TWS API FAQ - Trader's Notes
[Q] Client can not re-connect to TWS using the same client ID after ... Here's an example when IB API returned $2.45, while...
Read more >ibapi - Go Packages
Interactive Brokers API 9.79 pure golang, Unofficial version, smilar to the ... func (ic *IbClient) GetReqID() int64; func (ic *IbClient) HandShake() error ...
Read more >IB_insync - Sanic error after one successful order preventing ...
when I try ib.qualifyContracts() I'm seeing the same error. I swear I used to use it no problem... – needfulmeerkat41954. Apr ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I can confirm the issue seems to be fixed with 0.9.66. I started tracking for orderId collisions, but since the update I haven’t seen any. In my previous comment I was NOT on 0.9.66.
In the upcoming version of ib_insync the maximum orderId of open/completed orders is used to set the reqId sequence (see this code).
It seems the “nextValidId” from IB can’t be relied upon when TWS/gateway gets restarted.