Keyboard Shortcuts
Likes
- Twsapi
- Messages
Search
Re: Order Id in error messages
When I first encountered it a couple of days ago, I have raised a ticket with IB, so this is the exact quote from their reply after analyzing the logs they requested:
"the way error callback operates for the order rejection is by utilizing the reqID of the last request made via the API. For more details on how the error callbacks handles reqID, you may explore the given link below: " Likewise, I have found out about ibkrcampus from them. As soon as I excluded reqPnLSingle from my code everything was back to normal. I have tested it several times turning it back on and forth off. Unfortunately, I did not save the initial chat with IB support that contained pieces of evidence. If I have a moment I will try to protocol what's happening. |
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:
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:
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 position11: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
´³¨¹°ù²µ±ð²Ô 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: |
questions on bracket and hege orders
Three questions:
1. Suppose I send a bracket order to buy. Once the parent buy order executes, two sell orders go out. One is at a higher price and is? a limit order, and the other is a stop order that gets activated at a lower price. After the main order fills, but before the two sell orders fill, is it possible to cancel the two sell orders? Or will I get an error because all three are a package deal? 2. What is the difference between bracket orders and hedging orders? The conditional orders execute only after the parent order is filled, that is the same. Also, both make use of the .transmit flag. However, the bracket order examples seem to have more legs, and when non parent id orders are filled, that fill cancels the others. Is that the only difference? 3. Can I construct "bracket/hedge" orders that are more general and have more legs? Will the behavior always be a.) child orders are only sent after the parent order goes out, and b.) only one child order can fill? |
Re: Order Id in error messages
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: This is what I would expect, but the point is exactly it does not work this way. EWrapper.error(reqId:?int. The request identifier corresponding to the most recent reqId that maintained the error stream. (source:?) |
Re: IB Gateway crash
Not sure I understand how an IGB crash may impact your keyboard.Also I don't see how IBG may impact the OS so deep that you need a Hard reset. This look more an issue at OS level. If you use a remote desktop or a VNC like KVM that also could be a culprit, Some dislike very fast scrolling display like a log burst on a window. |
IB Gateway crash
Today, 2023.10.23 21:12:12 UTC IBG crashed and did not restart. This happened on two machines. One hosts my trading application and a realtime IBG, the other only a paper IBG.
Subsequently, the keyboard was dead and I had to hard reset to recover. Does anyone had a similar experience or has a clue? |
Re: Correlate orders and fills from the API to those in Flex Report
I never had the need for Flex Reports but recently started a low-priority project to make an XML schema for automatic ingestion of Flex XML data. The test data I had collected for that does show some line-up between TWS API and Flex XML:
toggle quoted message
Show quoted text
There may be others, but at least in my test data, "permId" does not line up with "ibOrderID". You might have to select the Flex Query option "Include Audit Trail Fields" to see those fields in the Flex XML. ´³¨¹°ù²µ±ð²Ô On Mon, Oct 30, 2023 at 10:19 AM, Little Trader wrote:
|
Re: C++ reqHistoricalData() closing connection
From my experience a connection closed trough exception happens when your submit to GTW or TWS a message that was build in EClient.cpp but contains a non valid value. From that perspective, the area that maybe an issue is what is inside your "Contract" object, ? |
Re: Order Id in error messages
Well, your characterization is not correct. The id parameter for callbacks always identifies the message the error relates to:
toggle quoted message
Show quoted text
Between requestIds and orderIds, numeric values for orderIds have to follow strict requirements possibly for very long periods of time (as in forever or until you reset the sequence in TWS/IBGW) while requestIds are ephemeral and can be reused as soon as the last request they have been used for is complete. Therefore, you simple design a numeric assignment strategy for your client that makes sure that, at any point in time, the id value of an error callback can be uniquely related to a recent request or an order. There are may ways you can do that, but a simple approach, that worked well for us for years is this:
Your error callback can uniquely be related to requests or order. ´³¨¹°ù²µ±ð²Ô On Mon, Oct 30, 2023 at 05:19 AM, bespalex wrote: This one thing has almost blown my mind recently, so I guess the 'discovery' may be helpful for others. |
Order Id in error messages
This one thing has almost blown my mind recently, so I guess the 'discovery' may be helpful for others.
Normally, when you handle errors, you would expect to get an order id the callback, but it actually does not work this way. You only get the order id as a reqId if the last thing you did was placing an order, but if you requested something else requiring reqId, like reqPnLSingle for example, you would be getting this reqId back in the errors callback. Yes, I know this is mentioned in the documentation, but still come to think about it, this can really mess up your algo, if you are not careful enough! |
Re: Does IB really limit you 1 session at a time with SSO?
Oh ok I see. I just verified that you can't have multiple users under your demo account, so I guess only for the demo I have to deal with this 1 session for the entire account problem... I will be sure to create a second user in my live account though. Thanks!
|
Re: Does IB really limit you 1 session at a time with SSO?
The limitation is one session for each user name at any point in time. But you can create a second user name for your live account through the Client Portal. That second user can have the same or fewer permissions. For example you could disable trading permissions for the second user if you are concerned about accidental mobile "butt trading". ´³¨¹°ù²µ±ð²Ô For me it is impossible to do the following which I can do with any other brokers with APIs. |
Re: updateMktDepthL2 missing data points
IDK how much more of this you want to read about. But, I'll just try to bolster the crux of ´³¨¹°ù²µ±ð²Ô's reply by referring you to Wikipedia regarding the . I'll also add that the "first approach" they describe (re-entrancy, local store, immutable objs) is often the approach people tend to overlook. This may happen because one doesn't need extra tools for the first approach, it's basically a "style". And, I suspect if you show someone a "thing" (mutex, semaphore, etc) they remember it more than if you describe a "way" (don't share data, put everything on the stack, etc). Well, I'm not an educator so that's all conjecture. The second approach, otoh, can't be avoided in some cases... often when dealing with physical resources. Anyway, you should choose the approach which suits your given circumstances. Only experience and judgement will help you know which. I'd err toward the first approach if there are any doubts. But again, the first approach doesn't often come naturally until it's practiced a bit... and sometimes it's not worth the extra mental gymnastics. As usual, YMMV. |
Does IB really limit you 1 session at a time with SSO?
For me it is impossible to do the following which I can do with any other brokers with APIs.
With IB, I have this weird limitation where
Is this really IB's limitation? It's impossible for you to run your trading system and login to their client app to check your own account? |
C++ reqHistoricalData() closing connection
Hi, Whenever I call reqHistoricalData() the connectionClosed callback is hit in my Client Class. I am trying to get real time bar updates. Below is what I am passing into reqHistoricalData(): |
Re: updateMktDepthL2 missing data points
my design is pretty the same, except much feature-less than what ´³¨¹°ù²µ±ð²Ô and his buddies implemented.
if i should write it as simple as i can, the design is this:
|
Re: Placing an order using the Gateway API to the demo account results in 401 Unauthorised
Hi Jurgen,
Thanks for helping out again. The maintenance was the issue. I tried placing the order this morning, and the order was successfully placed with PreSubmitted status. However, it is now stuck in PreSubmitted and not actually getting submitted. Is this because today is Sunday, and markets are closed? Or am I missing something in my API call? Response from place order request [
{
"order_id": "1172085515",
"order_status": "PreSubmitted",
"encrypt_message": "1"
}
]
Response from order status request {
"sub_type": null,
"request_id": "759",
"server_id": "496",
"order_id": 1172085515,
"conidex": "586139726@CME",
"conid": 586139726,
"symbol": "MES",
"side": "B",
"contract_description_1": "MES DEC23 (5)",
"listing_exchange": "CME",
"option_acct": "c",
"company_name": "Micro E-Mini S&P 500 Stock Price Index",
"size": "5.0",
"total_size": "5.0",
"currency": "USD",
"account": "DU8021006",
"order_type": "MARKET",
"cum_fill": "0.0",
"order_status": "PreSubmitted",
"order_ccp_status": "0",
"order_status_description": "Order Submitted",
"tif": "GTC",
"fg_color": "#FFFFFF",
"bg_color": "#0000CC",
"order_not_editable": false,
"editable_fields":"",
"cannot_cancel_order": false,
"deactivate_order": false,
"sec_type": "FUT",
"available_chart_periods": "#R|1",
"order_description": "Buy 5 Market, GTC",
"order_description_with_contract": "Buy 5 MES DEC'23 Market, GTC",
"alert_active": 1,
"child_order_type": "3",
"order_clearing_account": "DU8021006",
"size_and_fills": "0/5",
"exit_strategy_display_price": "4136.50",
"exit_strategy_chart_description": "Buy 5 Market, GTC",
"exit_strategy_tool_availability": "1",
"allowed_duplicate_opposite": true,
"order_time": "231029050317"
}
|