¿ªÔÆÌåÓý

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

Re: Anyone have any success modifying the trigger method?

 

¿ªÔÆÌåÓý

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

?

Please can you explain what you mean by ¡®You should be able to force any order type to be simulated by IBKR when you place the order into a One Cancels All group¡¯.

?

I don¡¯t believe placing an order in an OCA group affects the order in any way. The order is submitted to the exchange or managed by IBKR in exactly the same way as if it were not part of an OCA group. What would it even mean to simulate a Limit order? If IBKR were monitoring price to see when the limit price is hit, and only then actually submitted the limit order, the order would not be filled at least some of the time, because that delay could mean the markets may have moved by the time the limit order arrives at the exchange.

?

Perhaps I¡¯m misunderstanding what you might mean?

?

I also disagree with the statement that reqMktData data is ¡®aggregated¡¯. I know the documentation does say this somewhere, but I¡¯ve never been able to assign any meaning to it. What I would say is that the data is sampled, not aggregated ¨C and they are very different things.

?

To me, aggregation would have to mean something like creating a VWAP for prices/sizes during the aggregation interval, and I¡¯ve never seen the slightest evidence of that.

?

Sampling means that each price and size reported are genuine, but you just don¡¯t get all of them. In particular, you can miss important prices that turn out to be the high or low of whatever bar size you¡¯re constructing. ?I¡¯ve described my understanding of IBKR¡¯s data sampling algorithm in the past, and I¡¯ve never seen any reason to revise it (I¡¯ll have to see if I can find the relevant posts again in case anyone is interested).

?

?

Richard

?

?

From: [email protected] <[email protected]> On Behalf Of ´³¨¹°ù²µ±ð²Ô Reinold via groups.io
Sent: Monday, December 4, 2023 5:55 PM
To: [email protected]
Subject: Re: [TWS API] Anyone have any success modifying the trigger method?

?

Looks like your triggers should work since, according to the IBKR documents, the order types you use are no native exchange order types. Maybe the next step would be to reach out to IBKR for clarification.

What kind of tick data did you use for your analysis? ? data is aggregated and can have a delay relative to your order executions. Or did you use that should be much closer to the order fill events.

And one last thought if you are up for another test. You should be able to force any order type to be simulated by IBKR when you place the order into a group. I am not sure whether a group with just one order would work, but you could add a dummy order (maybe with a time condition so that it can never execute) into a group with the order you are really interested in. Just for testing purpose to rule out that the order types are actually native (and that the documentation is incorrect).

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


Re: Anyone have any success modifying the trigger method?

 

Looks like your triggers should work since, according to the IBKR documents, the order types you use are no native exchange order types. Maybe the next step would be to reach out to IBKR for clarification.

What kind of tick data did you use for your analysis? ? data is aggregated and can have a delay relative to your order executions. Or did you use that should be much closer to the order fill events.

And one last thought if you are up for another test. You should be able to force any order type to be simulated by IBKR when you place the order into a group. I am not sure whether a group with just one order would work, but you could add a dummy order (maybe with a time condition so that it can never execute) into a group with the order you are really interested in. Just for testing purpose to rule out that the order types are actually native (and that the documentation is incorrect).

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


On Mon, Dec 4, 2023 at 12:55 AM, @Kevin111 wrote:

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

Thanks for the reply. What I mean by "they all default to what appears to be bid/ask for buy/sell", this is based off on logging the tick data of the price, and comparing when the order was executed. The Order object after I place the order confirms that the trigger method is the one I had selected, as well as the info displayed on the trader workstation terminal.

Based on the documentation for??it seems the trigger method should be working as I am dealing with Stop Limits?andTrailing stop limits,?which are both simulated on by IB.

Some more relevant info:

I have confirmed that the Order object reflects the trigger method I chose, as well as the information provided to me from the Trader Workstation Client.
I have tested this on both paper and real accounts.
I came to this conclusion based on logging tick data sent from the API and comparing it to when my order gets executed.

?

Appreciate your help on this.


Re: Duplicate OrderID

 

I track my own open positions, so checking the max orderId before the session start seems to work just fine.


Re: Anyone have any success modifying the trigger method?

 

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

Thanks for the reply. What I mean by "they all default to what appears to be bid/ask for buy/sell", this is based off on logging the tick data of the price, and comparing when the order was executed. The Order object after I place the order confirms that the trigger method is the one I had selected, as well as the info displayed on the trader workstation terminal.

Based on the documentation for??it seems the trigger method should be working as I am dealing with Stop Limits?andTrailing stop limits,?which are both simulated on by IB.

Some more relevant info:

I have confirmed that the Order object reflects the trigger method I chose, as well as the information provided to me from the Trader Workstation Client.
I have tested this on both paper and real accounts.
I came to this conclusion based on logging tick data sent from the API and comparing it to when my order gets executed.

?

Appreciate your help on this.


Re: Anyone have any success modifying the trigger method?

 

Couple quick questions for clarification.

When you say "they all default to what appears to be bid/ask for buy/sell", does that mean the Order object you receive in the first callback after you place the order has a trigger method that is different from the one you had selected, or does that mean the actual triggers you experience look like they take place at ask/bid trigger points?

Also, have you verified that, for the instrument and exchange you are trading, the stop orders are indeed simulated by IBKR? The very last line in the documentation you point to says that trigger methods are ignored for stop-variant orders that execute natively at an exchange. You can determine whether your stop order is simulated through the "" documentation.

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

On Sun, Dec 3, 2023 at 05:57 PM, @Kevin111 wrote:

Hey all,

Been trying to modify the trigger method (),
however it doesn't seem to be working. No matter which value I set, they all default to what appears to be bid/ask for buy/sell.


Appreciate your help on this.


Anyone have any success modifying the trigger method?

 

Hey all,

Been trying to modify the trigger method (),
however it doesn't seem to be working. No matter which value I set, they all default to what appears to be bid/ask for buy/sell.


Appreciate your help on this.


Re: Why does placeOrder() require orderId when order already contains orderId?

 

The short answer to the OP's question is, that the orderId field of the Order object is irrelevant for requests. The orderId is specified only by the "id" parameter of the? request. You can see this even in the code samples IBKR provides in the section of the API documentation, where the Order.orderId field is not explicitly set.

Once the order is accepted and placed, TWS/IBGW provides you with a fully initialized Order object through the callback. That object does not only have the orderId initialized (to the "id" value of ) but also fields such as permId and several others.

From an API design, this makes a lot of sense. The "id" parameter for each API request establishes a common identifier between your client and TWS/IBGW for all subsequent exchanges related to that request. TWSAPI cannot assume that the complex objects you provide have been initialized properly (they might just contain garbage) and TWS/IBGW needs to have a fail-safe way to inform your client in case the request needs to be rejected. Any error messages related to that request will be tagged with the "id" parameter your client specified in the request.

From an application design point of view, your client should never call TWS API requests directly. So you will find yourselves making a small layer between your client and TWSAPI that hides a lot of these details. For order placement, you might want to think about a few helper functions such as "placeMarketOrder", "placeLimitOrder", or "placeBracketOrder" that handle all Order object initialization details. These functions select orderIds and call accordingly. These calls could return the selected orderId (or orderIds) to the trading logic in your client.

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


On Sun, Dec 3, 2023 at 01:21 PM, <web3ninja@...> wrote:
Did you get an answer for this ? Why are there two orderIds being sent during placeOrder ?

On Sun, May 1, 2022 at 04:30 PM, Drew Carlton wrote:
In the Python ?placeOrder(self, orderId:OrderId , contract:Contract, order:Order), the "order" argument already contains an instance variable "". So you are in fact sending two orderIds to placeOrder(). Anybody knows why? Is the "orderId" member variable in "order" even used?


Re: Why does placeOrder() require orderId when order already contains orderId?

 

Did you get an answer for this ? Why are there two orderIds being sent during placeOrder ?


Re: Market depth data has been RESET. Error Code: 317, C++ Program

 

Jurgen & Gordon,

I was also flushing my local order book each time at the end of the while loop after doing trade logic. I forgot to put that in the previous response.

Thank you


Re: Market depth data has been RESET. Error Code: 317, C++ Program

 

Jurgen,

You are correct. I was calling it at multiple points rather than treating it as a subscription. Thank you for the additional error codes I might encounter as well. To clarify, Here is my current setup:

Strategy Class -> Run() function:
while connected to TWS:
?? smartPointer_ibController->reqMktDepth();
?? smartPointer_ibController->processMessages();

The callback -> updateMktDepth() is processing each response, adding it to a public unordered_map member variable -> m_rawBook of a class called IBOrderBook(). I then do some ordering/sorting and build the bid/ask orderbook and have a pair<std:vector,std::vector> where pair.first = bids & pair.second = asks and I can get the best bid via pair.first.back() & pair.second.first.front() for best ask when accessing the new std::pair<std::vector, std::vector> public member variable m_orderBook in IBOrderBook().

Now, are you saying just call reqMktDepth() once outside the loop and just process the messages in the loop and I can avoid this error while at the same time getting a constant flow of level 2 information like so:

Strategy Class -> Run() function:

smartPointer_ibController->reqMktDepth();
while connected to TWS:
?? smartPointer_ibController->processMessages();

I was also calling reqMktDepth() right before any order entry in my loop to add more insult to injury.


Re: Market depth data has been RESET. Error Code: 317, C++ Program

 

I do not get a clear picture of what your client programs do exactly, Brendan, but I have the feeling that you need to go back to the drawing board. Gordon gave you some good pointers already, and there was a recent post titled "updateMktDepthL2 missing data points" you might want to take a look at (the second half that talks about L2 Market Book updates).

What concerns me is that, if I understand your comment correctly, your clients repeatedly call . They should not do that. Calling establishes a subscription that keeps sending you? callbacks until your client calls or disconnects from TWS/IBGW.

While the subscription is active, your client keeps two arrays (lists, maps, ...) of price-value pairs, one each for the buy side and sell side of the market book. Position (index) 0 of the buy side is the current "Bid" price/size while position 0 of the sell side is the "Ask". You would keep and update those two arrays as long as the client holds the subscription.

When the market book changes, IBKR breaks that change into a series of small incremental update indications for each of the positions that were impacted. Those indications specify the side and position that is impacted and the operation you need to perform on that position:
  • Update( side, position, price, size)
  • Delete( side, position )
  • Insert( side, position, price, size)

Occasionally, IBKR decides that it makes more sense (for whatever reason) to just discard the entire market book and to start from scratch. That is when you receive the "RESET Market Book" instruction. And while [IMHO] that would have better been implemented as a fourth operation type for the updateMktDepth callback, designers opted for an . Upon receipt of that message, your client will simply discard the two arrays and rebuild the market book from the updateMktDepth callbacks that follow right away.

While you are looking at this, you might want to keep a couple additional L2 related informational messages in mind as well:
  • Code 316 - Market depth data has been HALTED. Please re-subscribe.
  • Code 2152 - List of exchanges for Level 2 subscription

updateMktDepth sends you streams of update instructions for individual positions, but it does not tell you when the "Update Market Book" transaction is complete and when your copy of the market book is consistent again ("transaction boundaries"). For instruments with very little activity or during the middle of the night, a market book update transaction might have needed only a single updateMktDepth callback. But for heavily traded instruments or when Bid/Ask change, the transaction may take 20 or so updateMktDepth callbacks. The second half of the "updateMktDepthL2 missing data points" post discusses approaches of how you can efficiently detect when your the market book copy is consistent again.

Hope this helps,
´³¨¹°ù²µ±ð²Ô



On Sat, Dec 2, 2023 at 07:21 AM, Brendan Lydon wrote:
What do you mean by "I purge my bank, and de-facto expect to only receive types 2, or 1 only after I received a first set of new insert (0)." Mainly, "purge my bank", because I think me "flushing" the contents on my order book isn't doing what I think it is doing. Because I am actually only flushing the contents in my stored local order book. I am processing messages every time I call reqMktDepth() though, so I am not sure how my bank could be full, if those are the same thing...
On Thu, Nov 30, 2023 at 07:07 PM, Brendan Lydon wrote:
Here is my call -> reqMktDepth(reqId, m_contract, 5, false, TagValueListSPtr());
I am incrementing reqId every time I request, and the contract is for NQ e-mini expiring for december, NQZ3. My algo still gets data after this happens, & I do flush the book at most every second.


Re: Market depth data has been RESET. Error Code: 317, C++ Program

 

Yes I mean flushing local order book.

"Bank full":
By bank I mean same thing as you do I guess: the local map of entries indexed after the 'position' value.
The maximum number of entries ('position') in your local 'bank' of orders is defined in your request , can be far less on low activity instruments.
Otherwise said 'position' should not exceed your request "number of rows"-1 but also it may never reach it too.
Note:
In my implementation, if? 'position' >= nCountRowAsked, I process it as a relevant. This is limited in damages it can do in terms of memory alloc.? The complexity of what happens behind the scene make that I don't blame IB to overshoot 'position'.
Otherwise said don't do a hard memory alloc for your bank, C++ have plenty of very efficient map that are fast enough even if using dynamic alloc.

Case 317:
I no longer expect anything in-sync in term of 'position' with what will be sent trough IB call back. I expect IB to re-fill every entries ('position') without need to re-issue a request.
To exemplify in C++, in real life you may need a lock to handle sharing of resource: if (error==317) {deepthbank.erase (deepthbank.begin(),deepthbank.end());}?
This also can be diagnosed when call back run with 'operation' set as 'Insert' where position refer to an already existing one
(as in C++ the following condition should always be true on 'insert' (deepthbank.find(position) == deepthbank.end()) or equivalent using deepthbank.emplace(...).second==true),? otherwise it would means I hadn't received a 'removed' operation for it .

If you can experiment and report finding I would appreciate. Because a 317 is not something where I know a recipe to trigger it, and it should be a typical situation where this should happens if you don't .erase() your bank

Note:
I am not 100% sure that IB is fully compliant with it's own rules (like to always remove before insert)? so for cases like they forget to remove a position, (aside of 317) I default to overwrite the existing entry. Otherwise said I trust 'position'
and in case you wonder: I didn't even blip a warning as there is nothing I can do aside of de-subscribing and sending same request again, which doesn't seems a good idea in view of: delay to reprocess it, the expected high oddity of this case and the expected efficiency of this.


Re: Market depth data has been RESET. Error Code: 317, C++ Program

 

What do you mean by "I purge my bank, and de-facto expect to only receive types 2, or 1 only after I received a first set of new insert (0)." Mainly, "purge my bank", because I think me "flushing" the contents on my order book isn't doing what I think it is doing. Because I am actually only flushing the contents in my stored local order book. I am processing messages every time I call reqMktDepth() though, so I am not sure how my bank could be full, if those are the same thing...


Re: Sim Account Platform Acting Up

 

I am speaking on TWS, and I am simultaneously watching the L2 windows in my paper account. The charts too are not very accurate. The current candle in my chart will take a weird shape that doesn't reflect what data is showing in the L2. The charts will then show price action I am not seeing in the L2 and then a reset occurs and everything seemingly is back up to date and the market, i.e. level 2, will move drastically as it wasn't streaming accurate data. I think the Market Depth Reset Error Code: 317 may be causing this somehow. Maybe b/c my order book needs flushing or resetting the level 2 windows cannot get new data and in the mean time they just stream old data? Because prices still move, but data seen in my candlesticks differ greatly from that in the level 2. A theory...


Re: Duplicate OrderID

 

Yes I know but this repeated order number won't collide with the already executed order because?it's gone


El s¨¢b, 2 dic 2023 a las 8:19, J G via (<windmill_1965=[email protected]>) escribi¨®:
joanmarcel119 wrote: "If the number of the order (still open) is greater than the nextvalidId number I got at the beginning then I update it. This way the next increment is a number which won't collide with another order on the system. " I don't think that this is a foolproof solution. You only check for the highest order ID for the currently open orders. But you neglect to check for the order IDs for the orders that have already filled. It could be that an order (having order ID 120) you placed yesterday is still open, while a next order (e.g. order ID 123), placed today, has already filled.


Re: Duplicate OrderID

 

joanmarcel119 wrote: "If the number of the order (still open) is greater than the nextvalidId number I got at the beginning then I update it. This way the next increment is a number which won't collide with another order on the system. " I don't think that this is a foolproof solution. You only check for the highest order ID for the currently open orders. But you neglect to check for the order IDs for the orders that have already filled. It could be that an order (having order ID 120) you placed yesterday is still open, while a next order (e.g. order ID 123), placed today, has already filled.


Re: Sim Account Platform Acting Up

 

I have noticed very strange behavior recently. I've only been using the paper trading accounts. Specifically, on certain FX pairs, e.g. EURUSD, USDJPY, USDCAD, the balance may not be updated for up to 5 minutes after an order fills. This started last week.

Also, I have noticed that I have to cycle through the various accounts (I have FA accounts) to "force" TWS to update its positions. If I don't do this periodically, the positions page stops updating.

I'm using 10.19.


Re: Sim Account Platform Acting Up

 

Not sure I catch what you seems to imply by differentiating Paper vs Real. I don't think that Paper is less well serving LII than Real.

Some thoughts:
What do you call platform ? TWS or Gateway ?
Are you looking at LII on TWS simultaneously ?
Aside of telco contention:If TWS consider increasing the amount of RAM allocated to TWS

Suggestion too look at the "halt" status, I never seen it moving fast in real time, but it may happens that the market itself is in a stall position.
I also would wonder what is the impact of using Smart mode versus specific venue like the primary exchange or a major one.
If one venue stall maybe it stall the IB deliver process. (unlikely in my deep perception as IB should deliver RT what they have available)

Otherwise said, what you call a halt for split second need to be considered against another reference, like a Bloomberg terminal or that class of platform
Because there are real reason why market may freeze waiting for something that trigger a big move (as in: cause or consequence ?)


Re: Multiple users Read only access

 

Nothing easy popup to my mind.
50 is quit a number of users and you most probably will face a wall with the pacing violation and limitations if you use a single account
There is a concept of ClienId that allow to a certain extent to track what a proxy you have to design could do but you would have to de-consolidate a lot of trading information your self.
IB mind set is even exactly in the opposite direction, allowing a single trader to handle in single action a consolidation of accounts (customer).

So I would suggest you call IBKR direct, IBKR have cost of operation for their advanced service and here this is to deal with users that are not paying for the service in a foreseeable future.
So supporting many user for free is not really rational and they probably never considered this schooling usage in their API, hence reason to contact them and see what they can suggest.


Re: Multiple users Read only access

 

Even if someone can point me to an api spec or high level guidance would suffice. I¡¯m fairly tech savvy?