¿ªÔÆÌåÓý

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

Source of the ticks timestamps

 

Hi all.

This must be a very noob question...
I was trying to track the delay of real time data I get. I use the ib_insync Python module which makes things much easier in Python.

First of all, ping to? takes about 27ms.

For real-time bars I take my current system timestamp and then subtract?the bar time minus 5 seconds (bar size). That gives me 500-1000ms.

For market data ticks, I subscribe using?reqMktData and the difference between time in the ticker (including all ticks in it - they have the same timestamp) and system time when I get them is only about?0.2ms (that's it - 200 microseconds). Now, that makes me think that ticker timestamp produced through?reqMktData subscription is actually generated in TWS (or IB Gateway which is what I use) and not on IBRK servers. Right? Thus, there is no way to say when those ticks were really produced. Is there?

I haven't looked at TickByTick yet but I see that it has a very low limit on simultaneous subscriptions (3) so won't be useful for as many contracts as I need.

Also, could someone point me on how exactly IBRK samples or aggregates ticks for?reqMktData? Do I every time just get aggregated ticks by type and price since the last update?

Thanks,
Alex


Downloading Large Amounts of Historical Data

 

My strategy requires access to large amounts of historical data - ~1000 symbols at 10 min bar resolution for 3 years that I save locally in csv.? I am pulling data through the reqHistoricalData method in 1 year batches and concatenating the resulting queries. Periodically I get "ERROR 1 322 Error processing request.-'bT' : cause - Duplicate ticker ID for API historical data query", because my script is moving to the next data request before the current one is complete.?

What approach can be taken to ensure the script waits until the current request is complete before moving to the next?

app.reqHistoricalData(ticker_id, contract, query_end_iteration.strftime('%Y%m%d %H:%M:%S') + ' EST', query_period,
bar_size, "MIDPOINT", 1, 2, False, []) # returns lol of data

while not app.data: # pauses until data is return from server.
time.sleep(0.5)

time.sleep(3) # once out of loop, give it time to load all the data before writing to pd


C# Positions

 

Trying to get current position (#'s of contracts) into a textbox. Working in c#.

Added this to Form1.cs? "ibClient.ClientSocket.reqPositions();"
Added this to EWrapperImpl.cs in the position method code "myform.AddTextBoxItemPosition(pos);"
Added this to Form1.cs - public void AddTextBoxItem(double pos)
? ? ? ? {
? ? ? ? ? ? if (this.tbConNumber.InvokeRequired)
? ? ? ? ? ? {
? ? ? ? ? ? ? ? SetTextCallback d = new SetTextCallback(AddTextBoxItem);
? ? ? ? ? ? ? ? this.Invoke(d, new object[] { pos });
? ? ? ? ? ? }
? ? ? ? ? ? else
? ? ? ? ? ? ? ? Convert.ToInt32(pos);
? ? ? ? ? ? {
? ? ? ? ? ? ? ? this.tbConNumber.Text = pos;
? ? ? ? ? ? }
? ? ? ? }
?Obviously I don't know what I am doing, I have somehow managed to get a connection, data, place orders but without the "positions" I am stuck.
Any help is appreciated.
Thanks


Re: trouble requesting trade data *and* quote data for three futures tickers

 

A simple yet effective rate limiter (if you end up needing here) would be to push requests into a FIFO queue and have a thread pull them out and send them rate limited by a Leaky Bucket Rate Limiter.? Very simple algo.

On Sat, Feb 6, 2021 at 10:39 AM Dmitry Shevkoplyas <shevkoplyas@...> wrote:
Taylor,

[no sleep... ever]
Inside your processMessages() I see "sleep for 15 seconds". What does the rest of the code doing during that blocking sleep() call? Right - nothing. Any incoming quotes, order updates, etc. Nothing will be processed, just filling?up buffers (or probably overfilling them, since you will sleep 3 times by 15 seconds) while you decided to sleep in the middle of the busy working day!-)
I guess you need to re-think your implementation so that the sleep() is neer used anywhere. Also you don't need to?

[tick-by-tick is s stream]
You mentioned "no more than 1 tick-by-tick request can be made for the same instrument within 15 seconds". Why do you want to send?reqTickByTickData() request for the same instrument >1 time?? One time is enough to subscribe for stream of updates (which will be delivered to you in form of the documented callbacks) until?you decide to cancelTickByTickData. If you don't cancel - it will keep you "subscribed" for that instrument?stream for the whole day.

[outgoing request rate control]
You probably want to avoid sending >50 requests to IB in any given second. If you're interested?only in those 3 contracts, no need to worry about outgoing request rate control, just send them all 3 asap (once only). For more serious application where you might have implemented some scanners and potentially tons of contract details requests and subscribing/cancelling other types of IB data, you might want to keep an eye on the rate of the outgoing requests, but even if you see it is getting close to 50 in current second interval, you do not block your program, but merely skipping sending request until it is safe to do so. For this you probably want to implement some "outbox" queue (in form of some container) with your requests objects and then you only allow "shoveler" to process that queue with a limited rate. Even more: for some requests there are special request limits (like for historical data requests), then you probably will need to implement different queue for those and different shoveling rules (own rate) for that queue.

Cheers,
Dmitry Shevkoplyas


On Fri, Feb 5, 2021 at 4:10 PM Nick <news1000@...> wrote:

The default is 100 concurrent reqMktData streams but only 3 reqTickByTick streams. Also, market depth is limited to 3 concurrent.

If you are getting the error for more than one request per 15 seconds that's probably what is happening. IB does screw up sometimes but usually it's a problem on the client side.

It would be useful to log all your activity or enable API logging so you can see what is actually being received by TWS.


On 2/5/2021 3:45 PM, tbrown122387@... wrote:
I also read "[b]y default, every user has a maxTicker Limit of 100 market data lines and as such can obtain the real time market data of up to 100 instruments simultaneously." 3 instruments is less than 100, and 6 (=3x2) requests is less than 100, so I think I'm good there.


IB's Stop Price Vs Trailing Amount

 

Any ideas on these two items¡¯ accurate/exact meanings ?

Could i use the?Stop Price as a profit taking order ?


Re: Fx data

 

I have not worked with FX instruments, but the reqHeadTimestamp() API call should give you an idea of the earliest data you can expect (according to the documentation).

But don't expect to get data all the way back to what reqHeadTimestamp() indicates. I always read it as the "you will never get data older than that" timestamp. Some instruments reach back that far and some don't.


Re: Fx data

 

There probably isn't data available any further back,?at least not in a form that you can easily grab. For most things, IB only goes back to around then. You could also buy historical fx data and similar from several sources, but?probably won't get any earlier than around 2005, either.? Historical data for the particular symbol I'm most concerned with only goes back to 2008, although it's been traded a lot longer than that.?


On Mon, Feb 15, 2021 at 8:48 AM <ghelie@...> wrote:
Hi,

I was trying to pull historical fx data yesterday and I was wondering if the data does not go back further than 2005 or if I did something incorrectly. I tried to pull all the fx data for around 7 currency pairs,
and for each of them, the gateway stopped returning bars around 2005.

Thanks


Fx data

 

Hi,

I was trying to pull historical fx data yesterday and I was wondering if the data does not go back further than 2005 or if I did something incorrectly. I tried to pull all the fx data for around 7 currency pairs,
and for each of them, the gateway stopped returning bars around 2005.

Thanks


Re: Long position in TSCO mysteriously shortened this morning

 

I may be mistaken as to the ticker so do double check this.
I'm also very dubious about Yahoo finance's data, it's generally deadly to rely upon it. The prices they serve may or may not be the intended series even if the ticker is correct.

If the stock is adjusted for split then that would explain the historic adjustment, you'd see different price series depending on whether you pulled the data before or after the adjusted price was flushed back.
It could also be a quirk of the paper trading system failing to allocate the split, it's an under developed version of the live system, so it does fall short sometimes. That might be worth a chat with a support person, they could tell you how the paper accoutn handles splits.

Best wishes,

M


On Mon, 15 Feb 2021 at 11:19, Graham Bygrave <graham@...> wrote:
Thanks.

That'll likely be it.? I can see the split clearly in Yahoo. Looking at
Google, there's no indication of the split - the price always appears
as diluted, which would just imply they'd back adjusted it, which is
fine.

However, in my record of prices from last week, I have OHLC for TSCO.L
at 244.20125223614,245.00123372173,237.99176624583,238.76299288089.
And it wouldn't have been adjusted at that point.? So I'm struggling to
understand Yahoo's figures.

On Thursday last week, Yahoo had the OHLC at
246.10001,247.922,243.52499,244.5,244.5.

If there's been a 15 -> 19 split and the previous price was at ~304
then all is well and IB have just failed to allocate me the additional
stock, they've just diluted my holding, which is an error by my
reckoning (otherwise I'd surely just be able to short pending splits
and profit).

But that doesn't explain why my price history doesn't show > 300
anywhere for last week.

Cheers,
G.




On Mon, 15 Feb 2021 10:45:40 +0000
"mark collins" <mark.collins@...> wrote:

> A bit more grubbing around shows a 15:19 split...
>
> M
>
> On Mon, 15 Feb 2021 at 10:44, mark collins via
> <mark.collins= [email protected]> wrote:
>
> > I attached a png of the series I thought you were speaking of. It
> > closed on the 12th north of 300, opened far lower.
> > I'm still not certain whether you are reporting position or P&L,
> > what was the P&L on the trade?
> >
> > M
> >
> >
> >
> > On Mon, 15 Feb 2021 at 10:09, Graham Bygrave <graham@...>
> > wrote:
> >> Hey,
> >>
> >> Not sure where you're seeing that fall.? My price stream shows me
> >> the close on Friday being around 239.3/245.2 and the open today
> >> being around 243.15/243.53.
> >>
> >> In any case, I didn't trade, so the position shouldn't have
> >> changed. Why would the position change?? I'm miles away from being
> >> called.
> >>
> >> Cheers,
> >> G.
> >>
> >>
> >> On Mon, 15 Feb 2021 09:59:15 +0000
> >> "mark collins" <mark.collins@...> wrote:
> >>?
> >> > A quick Google showed a large fall over the weekend. Could it be
> >> > that you are seeing the p&l change?
> >> >
> >> > M
> >> >
> >> > On Mon, 15 Feb 2021, 09:01 Graham Bygrave, <graham@...>
> >> > wrote:
> >> > > I held 2143 of TSCO.L last night (paper trading account) at the
> >> > > close. This morning on the open I have 1691 with the shortfall
> >> > > being booked in P&L as a loss (i.e. as though I'd just given
> >> > > them away).
> >> > >
> >> > > What's that about?
> >> > >
> >> > > Thanks,
> >> > > G.
> >> > >
> >> > >
> >> > >
> >> > >
> >> > >
> >> > >?
> >> >
> >> >
> >> >
> >> >
> >> >?
> >>
> >>
> >>
> >>
> >>
> >>
> >>?
> >
> > --
> > +44 (0) 7528 551604?
> > Gulfstream Software - Winner Risk Management Awards 2010
> > This message is subject to :
> >
> >
> >
> >?
>








--
+44 (0) 7528 551604?
Gulfstream Software - Winner Risk Management Awards 2010
This message is subject to :


Re: Long position in TSCO mysteriously shortened this morning

 

Thanks.

That'll likely be it. I can see the split clearly in Yahoo. Looking at
Google, there's no indication of the split - the price always appears
as diluted, which would just imply they'd back adjusted it, which is
fine.

However, in my record of prices from last week, I have OHLC for TSCO.L
at 244.20125223614,245.00123372173,237.99176624583,238.76299288089.
And it wouldn't have been adjusted at that point. So I'm struggling to
understand Yahoo's figures.

On Thursday last week, Yahoo had the OHLC at
246.10001,247.922,243.52499,244.5,244.5.

If there's been a 15 -> 19 split and the previous price was at ~304
then all is well and IB have just failed to allocate me the additional
stock, they've just diluted my holding, which is an error by my
reckoning (otherwise I'd surely just be able to short pending splits
and profit).

But that doesn't explain why my price history doesn't show > 300
anywhere for last week.

Cheers,
G.




On Mon, 15 Feb 2021 10:45:40 +0000
"mark collins" <mark.collins@...> wrote:

A bit more grubbing around shows a 15:19 split...

M

On Mon, 15 Feb 2021 at 10:44, mark collins via groups.io
<mark.collins= [email protected]> wrote:

I attached a png of the series I thought you were speaking of. It
closed on the 12th north of 300, opened far lower.
I'm still not certain whether you are reporting position or P&L,
what was the P&L on the trade?

M



On Mon, 15 Feb 2021 at 10:09, Graham Bygrave <graham@...>
wrote:
Hey,

Not sure where you're seeing that fall. My price stream shows me
the close on Friday being around 239.3/245.2 and the open today
being around 243.15/243.53.

In any case, I didn't trade, so the position shouldn't have
changed. Why would the position change? I'm miles away from being
called.

Cheers,
G.


On Mon, 15 Feb 2021 09:59:15 +0000
"mark collins" <mark.collins@...> wrote:

A quick Google showed a large fall over the weekend. Could it be
that you are seeing the p&l change?

M

On Mon, 15 Feb 2021, 09:01 Graham Bygrave, <graham@...>
wrote:
I held 2143 of TSCO.L last night (paper trading account) at the
close. This morning on the open I have 1691 with the shortfall
being booked in P&L as a loss (i.e. as though I'd just given
them away).

What's that about?

Thanks,
G.













--
+44 (0) 7528 551604 gulfstream-software.com
Gulfstream Software - Winner Risk Management Awards 2010
This message is subject to :




Understanding placeOrder and its relation with used client ID

 

After some struggling, I think I finally understood why my orders weren't being updated with placeOrder:

- If the order was initially created with a different software using a certain client id (e.g. 11), I will be able to modify it if I use a connection with the same client id.
- If I use a different client id, the order is not modified at all.
- If I use the master client id, same behavior: order not modified
- If the order was created manually at TWS, a new order is created, and then updated in next iterations, but the manually created order persists without changes.

So, these are my questions:
- Is it impossible to modify or cancel an order manually created at TWS from the API?
- Is it impossible to modify or cancel orders initially created through the API but with a different client ID?
- Is it impossible to keep two different connections using the same client ID? (almost sure that this is not possible, but just checking)


Re: Long position in TSCO mysteriously shortened this morning

 

A bit more grubbing around shows a 15:19 split...

M

On Mon, 15 Feb 2021 at 10:44, mark collins via <mark.collins=[email protected]> wrote:

I attached a png of the series I thought you were speaking of. It closed on the 12th north of 300, opened far lower.
I'm still not certain whether you are reporting position or P&L, what was the P&L on the trade?

M



On Mon, 15 Feb 2021 at 10:09, Graham Bygrave <graham@...> wrote:
Hey,

Not sure where you're seeing that fall.? My price stream shows me the
close on Friday being around 239.3/245.2 and the open today being
around 243.15/243.53.

In any case, I didn't trade, so the position shouldn't have changed.
Why would the position change?? I'm miles away from being called.

Cheers,
G.


On Mon, 15 Feb 2021 09:59:15 +0000
"mark collins" <mark.collins@...> wrote:

> A quick Google showed a large fall over the weekend. Could it be that
> you are seeing the p&l change?
>
> M
>
> On Mon, 15 Feb 2021, 09:01 Graham Bygrave, <graham@...> wrote:
>
> > I held 2143 of TSCO.L last night (paper trading account) at the
> > close. This morning on the open I have 1691 with the shortfall
> > being booked in P&L as a loss (i.e. as though I'd just given them
> > away).
> >
> > What's that about?
> >
> > Thanks,
> > G.
> >
> >
> >
> >
> >
> >?
>
>
>
>
>








--
+44 (0) 7528 551604?
Gulfstream Software - Winner Risk Management Awards 2010
This message is subject to :



--
+44 (0) 7528 551604?
Gulfstream Software - Winner Risk Management Awards 2010
This message is subject to :


Re: Long position in TSCO mysteriously shortened this morning

 

I attached a png of the series I thought you were speaking of. It closed on the 12th north of 300, opened far lower.
I'm still not certain whether you are reporting position or P&L, what was the P&L on the trade?

M



On Mon, 15 Feb 2021 at 10:09, Graham Bygrave <graham@...> wrote:
Hey,

Not sure where you're seeing that fall.? My price stream shows me the
close on Friday being around 239.3/245.2 and the open today being
around 243.15/243.53.

In any case, I didn't trade, so the position shouldn't have changed.
Why would the position change?? I'm miles away from being called.

Cheers,
G.


On Mon, 15 Feb 2021 09:59:15 +0000
"mark collins" <mark.collins@...> wrote:

> A quick Google showed a large fall over the weekend. Could it be that
> you are seeing the p&l change?
>
> M
>
> On Mon, 15 Feb 2021, 09:01 Graham Bygrave, <graham@...> wrote:
>
> > I held 2143 of TSCO.L last night (paper trading account) at the
> > close. This morning on the open I have 1691 with the shortfall
> > being booked in P&L as a loss (i.e. as though I'd just given them
> > away).
> >
> > What's that about?
> >
> > Thanks,
> > G.
> >
> >
> >
> >
> >
> >?
>
>
>
>
>








--
+44 (0) 7528 551604?
Gulfstream Software - Winner Risk Management Awards 2010
This message is subject to :


Re: Long position in TSCO mysteriously shortened this morning

 

Hey,

Not sure where you're seeing that fall. My price stream shows me the
close on Friday being around 239.3/245.2 and the open today being
around 243.15/243.53.

In any case, I didn't trade, so the position shouldn't have changed.
Why would the position change? I'm miles away from being called.

Cheers,
G.


On Mon, 15 Feb 2021 09:59:15 +0000
"mark collins" <mark.collins@...> wrote:

A quick Google showed a large fall over the weekend. Could it be that
you are seeing the p&l change?

M

On Mon, 15 Feb 2021, 09:01 Graham Bygrave, <graham@...> wrote:

I held 2143 of TSCO.L last night (paper trading account) at the
close. This morning on the open I have 1691 with the shortfall
being booked in P&L as a loss (i.e. as though I'd just given them
away).

What's that about?

Thanks,
G.









Re: Long position in TSCO mysteriously shortened this morning

 

A quick Google showed a large fall over the weekend. Could it be that you are seeing the p&l change?

M

On Mon, 15 Feb 2021, 09:01 Graham Bygrave, <graham@...> wrote:
I held 2143 of TSCO.L last night (paper trading account) at the close.
This morning on the open I have 1691 with the shortfall being booked in
P&L as a loss (i.e. as though I'd just given them away).

What's that about?

Thanks,
G.






Re: Long position in TSCO mysteriously shortened this morning

 

Can you provide any more details?

Best wishes,

M

On Mon, 15 Feb 2021, 09:01 Graham Bygrave, <graham@...> wrote:
I held 2143 of TSCO.L last night (paper trading account) at the close.
This morning on the open I have 1691 with the shortfall being booked in
P&L as a loss (i.e. as though I'd just given them away).

What's that about?

Thanks,
G.






Long position in TSCO mysteriously shortened this morning

 

I held 2143 of TSCO.L last night (paper trading account) at the close.
This morning on the open I have 1691 with the shortfall being booked in
P&L as a loss (i.e. as though I'd just given them away).

What's that about?

Thanks,
G.


Re: bad volume numbers using in history

 

If you want to capture most historical data available from ibkr make sure you specify SMART for the exchange in the contract object in you request. If you need to specify the exchange as part of the intrinsic definition of the contract, use its primary exchange field additionally.

§á§ß, 15 §æ§Ö§Ó§â. 2021 §Ô., 02:57 Hany Danial <shdtech@...>:

i'm working TWS API, trying to get get historical data of a stock using:

date_time_obj = datetime.datetime.strptime('14/11/19', '%d/%m/%y')
queryTime0 = date_time_obj.strftime("%Y%m%d %H:%M:%S")
reqHistoricalData(id, contract, queryTime0, "52 W", "1 day", "TRADES", 1, 1, False, [])

example:

self.reqHistoricalData(id, contract, queryTime0, "3 D", "1 day", "TRADES", 1, 1, False, [])
HistoricalData. ReqId: 1   DNN BarData. Date: 20191112, Open: 0.450100, High: 0.450100, Low: 0.450100, Close: 0.450100, Volume: 5, Average: 0.450100, BarCount: 3

comparing the volume to yahoo chart, the volume in that day is more than 300k shares, it doesn't make any sense, even if i multiply it by 100. some dates will not return data for specified date by using TRADES, only if i used MIDPOINT. is there another api to use or am i using it incorrectly ?


List of error codes not documented?

 

Hello,

This is the third error that I come across which is not documented in API documentation. Has anyone collected or listed these undocumented error codes somewhere?

Following error code shows with three different descriptions. At least the first one makes sense to me but the second and third are still ambigous.

Error Code: 10189, Msg: Failed to request tick-by-tick data:No historical market data for EUR/CASH@FXSUBPIP Last 0
Error Code: 10189, Msg: Failed to request tick-by-tick data.Trading TWS session is connected from a different IP address
Error Code: 10189, Msg: Failed to request tick-by-tick data.No market data permissions for NYSE STK

More undocumented codes from this group:
Error Code 10187:?/g/twsapi/message/44164?p=,,,20,0,0,0::Created,,undocumented+error,20,2,0,6076358
Error Code 505:?/g/twsapi/topic/4040516#4368

Thanks,


bad volume numbers using in history

 

i'm working TWS API, trying to get get historical data of a stock using:

date_time_obj = datetime.datetime.strptime('14/11/19', '%d/%m/%y')
queryTime0 = date_time_obj.strftime("%Y%m%d %H:%M:%S")
reqHistoricalData(id, contract, queryTime0, "52 W", "1 day", "TRADES", 1, 1, False, [])

example:

self.reqHistoricalData(id, contract, queryTime0, "3 D", "1 day", "TRADES", 1, 1, False, [])
HistoricalData. ReqId: 1   DNN BarData. Date: 20191112, Open: 0.450100, High: 0.450100, Low: 0.450100, Close: 0.450100, Volume: 5, Average: 0.450100, BarCount: 3

comparing the volume to yahoo chart, the volume in that day is more than 300k shares, it doesn't make any sense, even if i multiply it by 100. some dates will not return data for specified date by using TRADES, only if i used MIDPOINT. is there another api to use or am i using it incorrectly ?