Keyboard Shortcuts
Likes
Search
Multiple symbol request speed
Hello i new here i try get data for multiple symbol,
about 580 +-, but it take allot time and not always finish this. this how i try make this.
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Try to obtain the data asynchronically
Example from ib-ruby Source-code: Documentation: https://ib-ruby.github.io/ib-doc/market_price.html i.e. > market_data = ["BMY", "CAT","DE","FL","GE","IBM","K","KO","T","VZ"].map{|y| IB::Stock.new( symbol: y).verify.first} > market_data.map{|c| c.market_price(thread: true)}.join > puts market_data.sort_by( &:symbol).map{|c| [c.symbol, c.misc.to_f].join " -> "? }.join "\n" BMY -> 54.05 CAT -> 129.99 DE -> 147.87 FL -> 50.88 GE -> 8.02 IBM -> 121.7 K -> 61.98 KO -> 50.3 RH -> 113.2 T -> 30.32 VZ -> 60.23 ?=> nil > It takes about 10 sec. to obtain the results. have fun. |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
How long does a successful run take? I am wondering whether your loop exceeds the acceptable rate of requests (50 requests per second) and that your client gets penalized for that. In that case I can think of two approaches you could try: First you could try the PACEAPI connection option. This option exists since TWS API 974 and makes TWS pace your requests for you. Here the release notes description: Better Pacing: API messages sent at a higher rate than 50/second can now be paced by TWS at the 50/second rate instead of potentially causing a disconnection. This is now done automatically by the RTD Server API and can be done with other API technologies by invoking SetConnectOptions("+PACEAPI") prior to eConnect. You could also add pacing code to your client code, meaning you could sleep for a small amount of time before each call to reqHistoricalTicks (say 50ms to 100ms) or larger amount after 10 or 20 calls. Hope this helps. ´³¨¹°ù²µ±ð²Ô PS: Using sleep calls is generally a bad idea when waiting for events or results in an asynchronous API such as TWS API. In fact you should remove the Sleep calls before requests for pacing is acceptable and sometimes necessary. |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
I was able to do a little better than 50 symbols per 300 seconds with our Java framework, but I think there is an IBKR policy enforced limit of about 2 seconds per request once you go beyond +/-10 symbols. Please keep in mind that IBKR is a brokerage and not a data provider. Also, the TWS API won't allow for operations that TWS does not need. And Bid/Ask information for 500 symbols is not needed for TWS. [Just to make sure. I do not work for or with IBKR in any capacity] Your question intrigued the researcher in me and I tried a few things such as:
No matter what I did I ended up at about one result per 2 seconds. Or 100 seconds for 50 requests and 1,000 seconds for 500 requests. Attached a couple charts. ´³¨¹°ù²µ±ð²Ô On Sun, Oct 24, 2021 at 06:34 PM, <danndann4488@...> wrote:On Mon, Oct 25, 2021 at 01:23 AM, ´³¨¹°ù²µ±ð²Ô Reinold wrote: |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
¿ªÔÆÌåÓý
"You
could also add pacing code to your client code, meaning you could sleep for a small amount of time?before?each
call to reqHistoricalTicks (say 50ms to 100ms) or larger amount after 10 or 20 calls."
I made a simple Java helper class to handle that.? I attached the code, same as pasted below.? It simply keeps track of when requests are made and then blocks long
enough to avoid a pacing violation.? I call it right before calls to?reqMktData().? Seems to allow the code to run faster than the +PACEAPI.
import java.util.LinkedList;
import java.util.Queue;
public class PaceMaker {
private int maxrequests;
private Queue<Long> requesttimes;
public PaceMaker(int maxrequestspersecond) {
this.maxrequests = maxrequestspersecond;
this.requesttimes = new LinkedList<Long>();
}
//blocks to stay under max requests per second
public void submitRequest() {
requesttimes.add(System.currentTimeMillis());
while(!processQueue()) {
try {
Thread.sleep(2);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
private boolean processQueue() {
long freetime = System.currentTimeMillis() - 1000;
while(!requesttimes.isEmpty() && requesttimes.peek() < freetime) {
requesttimes.poll();
}
return requesttimes.size() < maxrequests;
}
}From: [email protected] <[email protected]> on behalf of ´³¨¹°ù²µ±ð²Ô Reinold via groups.io <TwsApiOnGroupsIo@...>
Sent: Sunday, October 24, 2021 3:23 PM To: [email protected] <[email protected]> Subject: Re: [TWS API] Multiple symbol request speed ?
How long does a successful run take? I am wondering whether your loop exceeds the acceptable rate of requests (50 requests per second) and that your client gets penalized for that. In that case I can think of two approaches you could try: First you could try the PACEAPI connection option. This option exists since TWS API 974 and makes TWS pace your requests for you. Here the release notes description: Better Pacing: API messages sent at a higher rate than 50/second can now be paced by TWS at the 50/second rate instead of potentially causing a disconnection. This is now done automatically by the RTD Server API and can be done with other API technologies by invoking SetConnectOptions("+PACEAPI") prior to eConnect. You could also add pacing code to your client code, meaning you could sleep for a small amount of time before each call to reqHistoricalTicks (say 50ms to 100ms) or larger amount after 10 or 20 calls. Hope this helps. ´³¨¹°ù²µ±ð²Ô PS: Using sleep calls is generally a bad idea when waiting for events or results in an asynchronous API such as TWS API. In fact you should remove the
Sleep calls before requests for pacing is acceptable and sometimes necessary. |