Keyboard Shortcuts
Likes
- Twsapi
- Messages
Search
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). ´³¨¹°ù²µ±ð²Ô
|
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. 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. ? 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, |
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: 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:
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:
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()); |
Re: Market depth data has been RESET. Error Code: 317, C++ Program
Yes I mean flushing local order book. |
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. |
Re: Multiple users Read only access
Nothing easy popup to my mind. |