Keyboard Shortcuts
Likes
- Twsapi
- Messages
Search
Re: Get movers in the last 1 (say) minute
Hi Gordon,
thanks for your reply. A) Yes, actually the examples you gave are normalized according to IB.
So what I want is essentially is hot contracts by price but over say 1, or (5, 10 min) etc. scaled by their expected volatility over respective time period. B) Thanks, that how i will proceed. Will start with 'Hot contracts by price' and then go from there, at least it is normalized by volatility already. |
||||
Re: goodAfterTime attribute not supported for combo orders
You could try a instead.
toggle quoted message
Show quoted text
´³¨¹°ù²µ±ð²Ô On Fri, Oct 13, 2023 at 06:13 PM, Ace wrote:
HI, |
||||
goodAfterTime attribute not supported for combo orders
HI,
I want to attach a?"Good After" market order to an option combo order to close the position at a predeterrmined time using this attibute: time_order.goodAfterTime = expiration_day +?' '?+?'15:40:00 US/Eastern' But I get this error message: 349 Generic combo does not support "Good After" attribute. Is it just not possible to do it for a combo or there is another way? Thank you! |
||||
Re: Get movers in the last 1 (say) minute
A>> Can you give a definition of "biggest movers" ? |
||||
Re: questions about the two thread design (TWS c++ api)
It proves that callbacks CANNOT be process anywhere else. |
||||
Re: questions about the two thread design (TWS c++ api)
Yes, I was able to find those callback invocations in all?EDecoder.cpp as well. However, this just proves that calling *is* done in the main thread, not that it *isn't done in the other thread*. Apologies for being pedantic.
The reasons I ask are? a.) some threads on this forum mention calls can be done from either thread, and b.) it's difficult to grep every single callback of my EWrapper implementation in the source code. I only grepped the ones I'm interested in and indeed they're all *only* being called in EDecoder.cpp, so you're probably right. |
||||
How does IB calculate option prices when ex-dividend date is during the lifetime of the option?
I have a specific query about how the TWS API adjusts option price calculations in the presence of an ex-dividend date. Below is the full context and what I've tried so far. IB offers as part of the API Black scholes doesn't take early exercise or the impact of dividends causing a price drop into account, so this requires so modifications to the calculations. There's a couple of ways to account for the dividend price drop but none of them seem to match up with the TWS API calculations. Approaches that I've tried:
There was a third approach that I tried but can't find the details of it in my notes. When I messaged the TWS API team, they got back saying it was the TWS team proper that was responsible for the calculations. And then after following up with the other team I still didn't get any response. I'm hoping someone here has insight into IB's methods. So, to the experts in this group, do you have any insights into how IB modifies their option price calculations when an ex-dividend date is within the lifetime of the option? |
||||
Re: TWS api multiple similar orders submission delays
On Thu, Oct 5, 2023 at 01:47 PM, @tomaszk wrote:
I do not wait for anything, the only thing I do is my order send function is synchronized:Does that mean you do not send your second Limit order till you get a status update for the first order? If so, this will delay your entire process of placing multiple Limit orders. If I understand your prints correctly, you are measuring delay between each print and not when the real execution happens on the server? I am not sure if there's a good way of measuring delay between when you place an order and when the exchange server gets it. The "execDetails" callback's 'execution.time' tells a little about the server side (liely the IB server and not the exchange server) execution time but unfortunately only has seconds granularity. Also, this time cannot be really compared with your computer time, as they are not in sync. It's somewhat difficult to know where exactly the delay might be occurring. The OS we typically use (Windows, MAC, Linux) are not real-time systems and may have it's own delays. I make sure to not run any other programs when running TWS and limit my background tasks, but delays could be introduced at several other places along the way:?TWS UI/gateway delays, internet delays reaching IB server (if you are east coast vs west coast vs out of country will also affect this), IB server delays, IB server sending order to exchange server delay and round trip delay back to your computer for printing status. |
||||
Re: questions about the two thread design (TWS c++ api)
To add to Gordon's answer: One thread does I/O, parsing of network messages and formatting of network messages.? The other thread gets callbacks, does your application logic and makes requests to the API. Hunter
On Tuesday, October 10, 2023 at 12:11:09 PM PDT, Gordon Eldest via groups.io <hymagik@...> wrote:
No |
||||
Re: questions about the two thread design (TWS c++ api)
No |
||||
Re: questions about the two thread design (TWS c++ api)
Thank you for following up because I actually did *not* understand.
so to confirm: callbacks like execDetails and orderStatus and tickByTickLast can get called by a separate thread, possibly leading to race conditions, which necessitates synchronization of state variables such as current position, etc. |
||||
Re: questions about the two thread design (TWS c++ api)
You don't need to worry about contention between the message reader and sender but you do have to care about possible race conditions between your message dispatch loop and your main thread. i.e. The callbacks return data in one thread which you will likely use in your main thread. However that type of contention is related to your own app design rather than the API. On Sun, 8 Oct 2023, 22:14 , <tbrown122387@...> wrote: Oh, so I don't need to worry about race conditions at all do I? I'm just going through TestCppClient::processMessages() over and over again? Do something based on m_state, then receive information from callbacks. Got it. |
||||
Re: strange execution price for a stop loss
The data that was attached to your post seems to be for 08:32:57 US/Central, one minute later than when the STOP order happened at 08:31:57 US/Central. Prices during the STOP order second were much jumpier. Just looking at changes of Bid and Ask price does not give you a good picture of what the order book looks like and whether there is "great activity". Level II can help since it is a snapshot of the sizes for all prices in the order book at and above Ask as well as at and below Bid. At the end of the post is a snapshot for NQZ3 just after trading started at 17:00 US/Central on Sunday. If you have subscribed to Level II data for CME, you can use the TWS "Level II" window (the top window below) and the "Book Trader" (bottom window) to look at 10 levels for the buy and sell side each and your client can request the data as well:
Paper trading is a simulation, and as such, "always wrong but mostly useful". So you cannot expect that executions exactly match those that would have taken place in a live account at the same time. But as @fordfrog indicated, executions in the paper account closely follow those in the real exchange and in thin order books (such as NQZ3 at start of trading today and on the morning of October 5) even in live trading prices can briefly take place $10 or more away from Bid and Ask. I can't think of anything more you can analyze for this historical case. Going forward, you could subscribe to Level II data, record the 20 levels of order book details IBKR provides, and use them for analysis for case where you feel simulated trade prices were "too far away" from Bid/Ask. But keep in mind that not all orders make it into the order book and that some (even large) trades are not reporable or reported. So there will always be a some uncertainty. ´³¨¹°ù²µ±ð²Ô On Sun, Oct 8, 2023 at 04:57 AM, FrenchFlorent wrote:
Thank you for your answers. |
||||
Re: Avoiding time.sleep while waiting for openOrder / orderStatus callback after placeOrder
None of that invalidates anything I said about the code you posted. Hunter
On Sunday, October 8, 2023 at 06:42:57 PM PDT, Andrew Bannerman <bannerman1985@...> wrote:
threading.Event is a method to communicate between threads. I find it useful when waiting for a server to respond versus time.sleep() - when we get a server response the flag on the response is .set() (true) and the other threads waiting for it are released.? On Sun, Oct 8, 2023 at 6:50?PM Hunter C Payne via <hunterpayne2001=[email protected]> wrote:
|
||||
Re: Avoiding time.sleep while waiting for openOrder / orderStatus callback after placeOrder
threading.Event is a method to communicate between threads. I find it useful when waiting for a server to respond versus time.sleep() - when we get a server response the flag on the response is .set() (true) and the other threads waiting for it are released.? On Sun, Oct 8, 2023 at 6:50?PM Hunter C Payne via <hunterpayne2001=[email protected]> wrote:
|
||||
Re: Avoiding time.sleep while waiting for openOrder / orderStatus callback after placeOrder
In the interest of helping, Andrew's suggestion is for an interrupt style.? It also has a synchronization bug in it (the blocks of code that reads/writes the flag needs to be in a synch block, them being thread-safe isn't enough because the logic depends on multiple accesses).? And that's my point about doing this in an interrupt style way, its really (really really really) hard to get right.? As in most professional programmers don't attempt this stuff and instead use frameworks that don't require threading or give this type of work to a specialist (read old and expensive) programmer in most situations.? Just do a while loop as I suggested and if you don't want the blocking behavior, launch a thread to send the request and wait on the response (but you probably don't need to do that).? IBApi is really designed to be used in a single-threaded design. Hunter
On Sunday, October 8, 2023 at 03:33:36 PM PDT, Andrew Bannerman <bannerman1985@...> wrote:
Python if it's python your using - threading.event() module. Can assign different threads to events? as eg:? import threading # event threads event = threading.Event() hist_event = threading.Event() open_order_event = threading.Event() in the call back functions:? you may hist_event.set() ? ? def historicalDataEnd(self, reqId, start, end): ? ? ? ? super().historicalDataEnd(reqId, start, end) ? ? ? ? print("HistoricalDataEnd. ReqId:", reqId, "from", start, "to", end) ? ? ? ? hist_event.set() hist_event.clear() histData(9, FUTcontract(symbol), '3 D', '1 min') hist_event.wait() so you could do something in the ordercall back function i believe..... This is what I do at least seems to work pretty well.? I run main() in its own thread which is all my strategy logic which is a while loop? and the TradeApp() in its own thread? like this: def websocket_con(symbol): ? ? app.run() app = TradeApp() app.connect(host='127.0.0.1', port=7497, ? ? ? ? ? ? clientId=3)? # port 4002 for ib gateway paper trading/7497 for TWS paper trading con_thread = threading.Thread(target=websocket_con, args=(symbol,))? # , daemon=True con_thread.start() time.sleep(5)? # some lag added to ensure that streaming has started MainThread = threading.Thread(target=main, args=(app,)) MainThread.start() On Sun, Oct 8, 2023, 9:02 AM Lipp F. <flipp31a@...> wrote: All code?examples I can see are like this: |
||||
Re: Avoiding time.sleep while waiting for openOrder / orderStatus callback after placeOrder
Python if it's python your using - threading.event() module. Can assign different threads to events? as eg:? import threading # event threads event = threading.Event() hist_event = threading.Event() open_order_event = threading.Event() in the call back functions:? you may hist_event.set() ? ? def historicalDataEnd(self, reqId, start, end): ? ? ? ? super().historicalDataEnd(reqId, start, end) ? ? ? ? print("HistoricalDataEnd. ReqId:", reqId, "from", start, "to", end) ? ? ? ? hist_event.set() hist_event.clear() histData(9, FUTcontract(symbol), '3 D', '1 min') hist_event.wait() so you could do something in the ordercall back function i believe..... This is what I do at least seems to work pretty well.? I run main() in its own thread which is all my strategy logic which is a while loop? and the TradeApp() in its own thread? like this: def websocket_con(symbol): ? ? app.run() app = TradeApp() app.connect(host='127.0.0.1', port=7497, ? ? ? ? ? ? clientId=3)? # port 4002 for ib gateway paper trading/7497 for TWS paper trading con_thread = threading.Thread(target=websocket_con, args=(symbol,))? # , daemon=True con_thread.start() time.sleep(5)? # some lag added to ensure that streaming has started MainThread = threading.Thread(target=main, args=(app,)) MainThread.start() On Sun, Oct 8, 2023, 9:02 AM Lipp F. <flipp31a@...> wrote: All code?examples I can see are like this: |