Keyboard Shortcuts
Likes
- Twsapi
- Messages
Search
reqMktData subscription is not continuous
Trying to subscribe to live Bid / Ask prices for ES futures using "reqMktData".?
?
var contract = new Contract { Symbol = "ES", Exchange = "CME", ConId = 495512563, LastTradeDateOrContractMonth = "20251219" };
_client.TickPrice += o => Console.WriteLine(JsonSerializer.Serialize(o));
_client.ClientSocket.reqMktData(id, contract, string.Empty, false, false, null); ?
As a result, I receive one round of messages below, and then notifications stop.??
?
{"Attribs":{"CanAutoExecute":true,"PastLimit":true,"PreOpen":false,"Unreported":false,"BidPastLow":false,"AskPastHigh":false},"Value":5801,"Data":5801,"RequestId":3,"Field":1}
{"Attribs":null,"Value":1,"Data":1,"RequestId":3,"Field":0} {"Attribs":{"CanAutoExecute":true,"PastLimit":false,"PreOpen":false,"Unreported":false,"BidPastLow":false,"AskPastHigh":false},"Value":6300,"Data":6300,"RequestId":3,"Field":2} {"Attribs":null,"Value":1,"Data":1,"RequestId":3,"Field":3} {"Attribs":null,"Value":1,"Data":1,"RequestId":3,"Field":0} {"Attribs":null,"Value":1,"Data":1,"RequestId":3,"Field":3} {"Attribs":null,"Value":0,"Data":0,"RequestId":3,"Field":5} {"Attribs":{"CanAutoExecute":false,"PastLimit":false,"PreOpen":false,"Unreported":false,"BidPastLow":false,"AskPastHigh":false},"Value":6274,"Data":6274,"RequestId":3,"Field":9} {"Attribs":{"CanAutoExecute":false,"PastLimit":false,"PreOpen":false,"Unreported":false,"BidPastLow":false,"AskPastHigh":false},"Value":6050.5,"Data":6050.5,"RequestId":3,"Field":14} ?
Are there any settings, like "Return only snapshots instead of continuous subscriptions"??
Why notifications stop after receiving only one quote?? |
Re: reqMktData callbacks are missing data with gateway 10.30 and 10.31 sporadically, works fine with 10.19 and older gateways/TWS
I still believe there is no bug or anything wrong with reqMktData real time feeds. And snapshots are probably what you are looking for in the first place. TWS API documentation says about reqMktData snapshots that: ... it is possible to request a snapshot of the current state of the market once instead of requesting a stream of updates continuously as market values change. What you experience is likely that, at times, not all of the market values you are interested in change during the 20 seconds you are looking at the market. You could easily verify that yourselves by downloading TickByTick historical data for the time periods that fail your test. I took a quick look at the "missing" BID price for MTDR on 20241217:
I don't have enough data about your 10.19 vs 10.30+ comparisons to explain the differences your are seeing. It may very well be that IBGW/TWS 10.19, upon subscription, send some "recent historical values" and 10.30+ are now cleaner and send "only market values that changed". But that is just a guess and there may be other explanations. 闯ü谤驳别苍 ? ? ?
On Thu, Dec 19, 2024 at 11:56 AM, ajn wrote:
|
Re: Entry that triggers OCO with TP and SL
Got it On Sat, Dec 21, 2024 at 12:27?PM Richard L King via <rlking=[email protected]> wrote:
|
Re: reqMktData callbacks are missing data with gateway 10.30 and 10.31 sporadically, works fine with 10.19 and older gateways/TWS
On Mon, Dec 23, 2024 at 10:31 PM, 闯ü谤驳别苍 Reinold wrote:
Twenty seconds seems to be a pretty long time (see attached). How long do you think we should wait before crossing over from thinking this is a "feature" to "bug"? Ah... good old Sorites paradox, never fails to amuse :-) |
Re: reqMktData callbacks are missing data with gateway 10.30 and 10.31 sporadically, works fine with 10.19 and older gateways/TWS
On Tue, Dec 24, 2024 at 06:53 AM, 闯ü谤驳别苍 Reinold wrote:
Well, for practical purposes, whether it's a "bug" or not is a moot point. But, just as you wouldn't call it a bug, I wouldn't necessarily call it a great improvement either ;-) That said, I understand your viewpoint, and would simply remind future readers that it's wise to distinguish between so-called "hard" vs "soft" real-time requirements when building these types of programs. |
Re: reqMktData callbacks are missing data with gateway 10.30 and 10.31 sporadically, works fine with 10.19 and older gateways/TWS
We are talking about entirely different cases
The first case smells like a bug (as long as data should be available), while the second case is simply a change in systemic behavior. Even if that behavior change, in the eyes of the user, is a degradation and causes previously working timeouts to now fail. That is the crux with timeouts - they are always too long until they are suddenly not long enough. During my due diligence before switching from V9 TWS/IBGW to the first stable V10 (probably around TWS 10.10) I found that timing for certain operations had changed. Some for the better and some for the worse. So it is not unreasonable to assume that something similar happened between 10.19 and 10.30+. To quickly check that hypothesis I went back to my records and compared all reqMkt() subscriptions for SPY ETF in December 2023 (when I used stable TWS/IBGW 10.19) with those from MTD December 2024 (with stable TWS/IBGW 10.30). And guess what:
Small things other than the TWS version have changed on my side since December 2023, but I cannot imagine that any of those changes could cause the longer time to first tick. But I will run tests with 10.19 to confirm when the markets are closed later in the week. Attached a quick xlsx with the raw results. I still would not call this a bug (though this change of behavior may have not been intended by the developers) 闯ü谤驳别苍 ?
On Mon, Dec 23, 2024 at 09:40 PM, buddy wrote:
|
Re: reqMktData callbacks are missing data with gateway 10.30 and 10.31 sporadically, works fine with 10.19 and older gateways/TWS
On Tue, Dec 24, 2024 at 03:40 AM, buddy wrote:
Of course, what's also interesting, is this could actually be a bug w/ 10.19 instead. That is, 10.19 might be providing bad data in a timely manner instead of timing out. Unfortunately, it's difficult to be certain without digging much much deeper into the IBKR infra and the TWS/IBGW code. |
Re: reqMktData callbacks are missing data with gateway 10.30 and 10.31 sporadically, works fine with 10.19 and older gateways/TWS
On Mon, Dec 23, 2024 at 10:31 PM, 闯ü谤驳别苍 Reinold wrote:
Even if it did, that wouldn't explain why it arrives in time when using 10.19. If you run the test case as prescribed, and compare the results of 10.19 vs 10.30+, you'll probably see what I mean. I suppose it could be classified as "not a bug" if IBKR wants to intentionally degrade the service they once provided. And, as a skeptic, I wouldn't put that past them. Nevertheless, from a technical user's perspective, this is at best a [massive] shortcoming IMHO. After all, without any SLA they could just hold data back completely, or provide the same QOS for DELAYED and REALTIME. It's an absurd proposition so I'm leaning toward "this is a bug (full stop)". Playing that much faster and looser w/ their specifications would leave a bad taste in an engineer's mouth... although a lawyer might love it. :-/ |
Re: reqMktData callbacks are missing data with gateway 10.30 and 10.31 sporadically, works fine with 10.19 and older gateways/TWS
Rarely is lack of "last hop" bandwidth the root cause for network issues. In my experience it is pretty much always latency. That is latency from processing, end-to-end "flight time", congestion along the route, traffic shaping games played by the ISP, or packet loss and retransmission. But since you can reproduce what you are seeing with a t3.2xlarge AWS instance, I am pretty sure that network issues are not the root cause of what you are seeing. Having said that, latency (or changes of latency) could very well make your experience better or worse. I am still not convinced that there is a "bug" here and I was wondering, whether you have tried (or could try) some runs without timeouts. At least the Python code currently gives up and cancels the subscription after 20 seconds, right? Maybe it just takes that long occasionally when you send massive numbers of subscriptions and cancellations. There are a few reasons why that may be the case:
Just curious whether the data eventually arrives if you give it enough time. 闯ü谤驳别苍 PS. Just as an FYI attached recent latency and packet loss measurements for the IBKR entry points as experienced by a server outside of Chicago. ?
?
On Fri, Dec 20, 2024 at 10:10 AM, ajn wrote:
|
Re: reqIds hangs when recereating IBClient - EWrapper
Each time when you connect you apparently use client ID zero: eConnect(Host, Port, 0). When you disconnect this client you must allow IBKR time to close all processes related to this client on their side. According to an undocumented recommendation from IBKR do you need to wait approximately one minute before you try to connect again to the same client ID number (zero, in your case). Your post does not mention how long you are waiting after closing before trying to reconnect to that client.
If you can't wait one minute before reconnecting then you should simply use a different client ID number. Any integer number can be used, there are no rules for this. So you could use for example a randomly generated ID, or a timestamp as ID (e.g. hhmmss). It is documented that you can have a maximum of 32 clients connected at the same time. |
reqIds hangs when recereating IBClient - EWrapper
I have IBClient that implements EWrapper that I copied from C# samples from official TWS repository.?
When some event happens, I would like to destroy existing client and create new instance.?
This is the method I use to create this client.?
?
void Create()
{ ? var signal = new EReaderMonitorSignal(); ? _client = new IBClient(signal);
? _client.ClientSocket.SetConnectOptions("+PACEAPI"); ? _client.ClientSocket.eConnect(Host, Port, 0); ? var reader = new EReader(_client.ClientSocket, signal);
? var process = new Thread(() =>
? { ? ? while (_client.ClientSocket.IsConnected()) ? ? { ? ? ? signal.waitForSignal(); ? ? ? reader.processMsgs(); ? ? } ? }); ? process.Start();
? reader.Start(); } ?
After that, I'm waiting for the next valid ID.
?
async Task Register()
{ ? var source = new TaskCompletionSource(); ? void subscribe(int o)
? { ? ? _client.NextValidId -= subscribe; ? ? source.TrySetResult(); ? } ? _client.NextValidId += subscribe;
? _client.ClientSocket.reqIds(-1); ? await source.Task;
} ?
Then use method to destroy client.?
?
void Destroy()
{ ? _client?.ClientSocket?.eDisconnect(); } ?
The first time everything works fine.
When I try to call these 3 methods next time, "reqIds" hangs and I never receive response for "NextValidId".?
Is it some known limitation that only one client can connect to TWS only once or am I missing something??
|
Re: Entry that triggers OCO with TP and SL
开云体育This is not correct: all three orders must have unique order ids. But the TP and SL orders must have “ParentId” set to the “OrderId” of the main order. ? ? From: [email protected] <[email protected]> On Behalf Of Andy Sanders via groups.io
Sent: 19 December 2024 05:28 To: [email protected] Subject: Re: [TWS API] Entry that triggers OCO with TP and SL ? Create 3 separate orders. TP and SL orders will have property "OrderId" that should be the same as the main order ID.? The first two orders will have property "Transmit" set to false, the last one is true.? ? |
Re: Entry that triggers OCO with TP and SL
Thank you.? I will try this. On Thu, Dec 19, 2024 at 12:28?AM Andy Sanders via <arteinvolo=[email protected]> wrote:
|
Re: IB's New automated trading system questionnaire
Thanks to everyone for their suggestions.? I flailed around for longer than I would like to admit before finding a send email solution that works for me. 1) I found out gmail offers something called an "app password" that requires you to use 2-factor authentication and then you can create a password that works with SMTP over port 465. 2) I installed MSVC 2010, changed my email program to use the new password and rebuilt.? (It was easier to use MSVC 2010 than to build with MSVC 2019 which had various complaints.) Voila, I'm once again able to send emails.? The only ongoing cost will be dealing with gmail's two factor log ins. Frank |
Re: No definition for SPX option using LocalSymbol
For the future readers.
I was using data coming from Schwab and each SPX contract had two dates, "LastTradingDate" and "ExpirationDate". I was trying to use option contract expiring the same day to place order in IB but it was rejected because even though contract is expiring today, the last trading day for that contract was yesterday.? |
Re: reqMktData callbacks are missing data with gateway 10.30 and 10.31 sporadically, works fine with 10.19 and older gateways/TWS
Uh, my sanity is restored :)
?
As for your comment about the network, yes my dev setup is in EU (yet its 250Mbit up/down fiber, typically no issues here with Internet otherwise, but of course anything can happen :) and again switching back and forth between 10.19 and 10.30 all the time, where 10.19 does't have issues) However, I can reproduce it from my test site in US just as well. Test site is in AWS with pretty biffy setup on the East Coast? (us-east-1, i..e supposed to be closest to IB servers, ?t3.2xlarge instance aws claims 5gbit network, ok it is probably less in reality but itis not likelly a bottleneck even it is "just" 500Mbit to the Internet ).? |
Re: IB's New automated trading system questionnaire
?
Once you've set up the appropriate Telegram bot on your Telegram account, sending a message programmatically is pretty easy. ?Here's my (redacted) code for that:
?
#!/usr/bin/env python3 |
Re: IB's New automated trading system questionnaire
开云体育Another option is Telegram. I wouldn't trust too much on email as it's very difficult these days to have your mail accepted by the receiving end as non-spam or not get blocked.For instant notification, Telegram has been a great option for me. It has? good api documentation. Start here: Greetings, Raoul On 18-12-2024 18:10, 闯ü谤驳别苍 Reinold via
groups.io wrote:
|