¿ªÔÆÌåÓý

ctrl + shift + ? for shortcuts
© 2025 Groups.io

Re: Order Id in error messages


 

Just tried this and I cannot reproduce what you describe. Maybe you can provide an example of the failure you experience.

Before I describe what I did, let me address the document you cite. I was not aware of this IBKR Campus course (is that the correct term ?). I generally like it since it gives newcomers to TWS API a nice overview of how various pieces fit together. Having said that, I consider it "second hand" information about TWS API. Better than "I read that on Facebook" but not authoritative. When in doubt, I look at sources in this order for authoritative information:
  • Reading the TWS API source code and TWS/IBGW logs
  • Reading the TWS API Guide at that is written and maintained by the TWS API developers and peer reviewed/corrected by a large group of TWS API practitioners

The IBKR Campus document seems to be pretty new (Oct 9 this year?) so it may still have some V1.00 errors. I do not know what an "error stream" is when they describe the error callback parameter reqId with "The request identifier corresponding to the most recent reqId that maintained the error stream".

Also, the first parameter for the error callback is called "id" and not "reqid" in the source code and the official TWS API Guide.

Anyway. Here is what I tried:
  • I made a small client that makes native TWS API calls and does not use any of the higher level ApiController and framework functions I'd usually use
  • The client side Java TWS API had version 10.17.1 and it connected to a paper account through the currently "stable" TWS 10.19.2e
  • To trigger an order related error, I placed a market order for an expired ES future (ESH3, orderId = 10)
  • Immediately followed by a reqPnlSingle( reqid=12345678, conid=495512552 ESZ3)
For the first test the account did not have an active ESZ3 position so reqPnlSingle would not generate any callbacks. Several runs had the same result in that the correct error message was returned with the correct orderId as the id parameter

Error. Id: 10, Code: 200, Msg: No security definition has been found for the request

I then created an ESZ3 position in the paper account for a second set of tests. Again, the client received the correct error message with the correct orderId as id parameter followed by pnl() callbacks for the ESZ3 position
11:26:30.420 [Thread-2] INFO? Error. Id: 10, Code: 200, Msg: No security definition has been found for the request?? ????
11:26:30.783 [Thread-2] INFO? Daily PnL Single. Req Id: 12345678, pos: 1, daily PnL: -14.5, unrealizedPnL: -14.5, realizedPnL: , value: 209300
11:26:31.671 [Thread-2] INFO? Daily PnL Single. Req Id: 12345678, pos: 1, daily PnL: -10.3, unrealizedPnL: -10.30, realizedPnL: , value: 209304

11:26:32.673 [Thread-2] INFO? Daily PnL Single. Req Id: 12345678, pos: 1, daily PnL: -2, unrealizedPnL: -2, realizedPnL: , value: 209312.5

Below is the TWS API log for the second test as recorded by TWS (the first test looked exactly the same)
  • The first few messages relate to the connection setup and "welcome" handshake
  • TWS received the placeOrder and pnlSingle requests within the same millisecond 30.291
  • Order processing and order rejection took 314ms and the error message clearly indicates orderId 10
  • The first pnl callback was sent 332ms later
From all we have seen in the last few years and this quick test, I'd say there is no id parameter confusion in error callbacks, But then, my test may not be exactly what you have done.

´³¨¹°ù²µ±ð²Ô

API log taken by TWS for the second test. The first looke exactly the same just without pnl() callbacks:

11:26:30:129 -> ---9-1-1-
11:26:30:131 -> ---15-1-DUxxxxxx-
11:26:30:132 -> ---4-2--1-2104-Market data farm connection is OK:usfuture.nj--
11:26:30:133 -> ---94-2--1-2104-Market data farm connection is OK:usfarm.nj--
11:26:30:138 -> ---84-2--1-2104-Market data farm connection is OK:usfuture--
11:26:30:139 -> ---64-2--1-2104-Market data farm connection is OK:eufarm--
11:26:30:139 -> ---84-2--1-2104-Market data farm connection is OK:cashfarm--
11:26:30:139 -> ---64-2--1-2104-Market data farm connection is OK:usfarm--
11:26:30:139 -> ---44-2--1-2106-HMDS data farm connection is OK:euhmds--
11:26:30:139 -> ---74-2--1-2106-HMDS data farm connection is OK:ushmds.nj--
11:26:30:139 -> ---44-2--1-2106-HMDS data farm connection is OK:ushmds--
11:26:30:139 -> ---94-2--1-2158-Sec-def data farm connection is OK:secdefnj--

11:26:30:291 <- 3-10-0-ES-FUT--0.0---CME---ESH3----BUY-1-MKT---GTC---- ...
11:26:30:291 <- 94-12345678-DUxxxxxx--495512552-

11:26:30:305 -> ---4-2-10-200-No security definition has been found for the request--

11:26:30:637 -> ---95-12345678-1--14.5--14.5-1.7976931348623157E308-209300.0-
11:26:31:557 -> ---95-12345678-1--10.30078125--10.30078125-1.7976931348623157E308-209304.19921875-
11:26:32:557 -> ---95-12345678-1--2.0--2.0-1.7976931348623157E308-209312.5-
11:26:35:559 -> ---95-12345678-1-10.5-10.5-1.7976931348623157E308-209325.0-
11:26:36:559 -> ---95-12345678-1-23.0-23.0-1.7976931348623157E308-209337.5-
11:26:38:560 -> ---95-12345678-1-35.5-35.5-1.7976931348623157E308-209350.0-





On Tue, Oct 31, 2023 at 06:19 AM, bespalex wrote:
On Mon, Oct 30, 2023 at 09:35 AM, ´³¨¹°ù²µ±ð²Ô Reinold wrote:
Well, your characterization is not correct. The id parameter for callbacks always identifies the message the error relates to:
  • If the error relates to a request, id will have the numerical value of that requestId
  • If the error relates to an order, id will have the numerical value of the orderId

This is what I would expect, but the point is exactly it does not work this way.
For example, if you place an order, and make a reqPnLSingle request with your preferable reqId immediately after that, but before you got an order error, the next error message will come with that reqId, even if it relates to the order.
Indeed, this is confirmed by the documentation:

EWrapper.error(

reqId:?int. The request identifier corresponding to the most recent reqId that maintained the error stream.
This does not pertain to the orderId from placeOrder, but whatever the most recent requestId is.

(source:?)

So it's the most recent reqId, and not necessarily the one relating to the order.
You can easily recreate the condition and check.

One of the workarounds that comes to mind is whenever you need to make a request before handling your next error message pertaining to an order, the request must be made with an orderId in place of a reqId in that request. Or it can be any offset from an orderId, as you suggested, but in any case one needs to expect that reqId in the error callback, which does not necessarily equals the orderId.

Join [email protected] to automatically receive all group messages.