ib_async icon indicating copy to clipboard operation
ib_async copied to clipboard

Price History Download

Open vvu1980 opened this issue 1 year ago • 3 comments

Hello!

This issue I found a while ago, using ib_insync library. Today I found ib_async and decided to check, how it handle the process of historical market data download. As I understand it is almost the same, as with previous library. But the issue is still the same:

I am downloading the market data for ES and NQ futures contracts with 5 minute itteration to catch the changes in 5 min timeframe. On the example below you will see the difference in market data for the same timestamp, but downloaded with the difference of 5 min.

Please check the row 259 (or 22:35:00 ) for the symbol_1 symbol_2 data comparisson. Below you can see that the data is the different. It looks it is recalcalculated and appened another value.

The question is simple, on which site this problem occures: broker or on my end? And how could it be solved ?

TimeNow:  2024-04-24 22:35:05+03:00
2024-04-24 22:35:06.623634
0.3022572994232178
0.6002254486083984
                   date  symbol_1  symbol_2    spread     ratio    zScore
257 2024-04-24 22:25:00   5109.25   17669.5  12560.25  3.458335  1.133683
258 2024-04-24 22:30:00   5108.75   17669.5  12560.75  3.458674  1.276354
259 2024-04-24 22:35:00   5109.00   17670.5  12561.50  3.458700  1.062281
TimeNow:  2024-04-24 22:40:06+03:00
2024-04-24 22:40:07.307414
0.3034403324127197
0.6038002967834473
                   date  symbol_1  symbol_2    spread     ratio    zScore
258 2024-04-24 22:30:00   5108.75  17669.50  12560.75  3.458674  1.276354
259 2024-04-24 22:35:00   5107.00  17665.50  12558.50  3.459076  1.394353
260 2024-04-24 22:40:00   5107.00  17666.75  12559.75  3.459321  1.388979

For the downloading the data I am using:

            market_data = pd.DataFrame(
            ib.reqHistoricalData(
                symbol_1,
                endDateTime='',
                durationStr='1 D',
                barSizeSetting='5 mins',
                whatToShow="TRADES",
                useRTH=False,
                formatDate=1,
                keepUpToDate=False
           ))

vvu1980 avatar Apr 24 '24 19:04 vvu1980

Is the question about why the price is the same for multiple rows?

Both /ES and /NQ operate in $0.25 increments, so they can easily have the same values over multiple reported checks.

The data looks logical here unless something else was expected.

mattsta avatar Apr 28 '24 00:04 mattsta

@vvu1980 you didn't mention what price you have written as symbol_1 and symbol_2. If the price is the closing price, it's normal that you'll find different values over different time because it's not consolidated. It's not related to any library issues, because the 5 minute bars is consolidated after 5 minutes, therefore at 22:40:00 you can use High, Low and Close price of that bar.
At 22:35:00 you can only use the Open price of that current bar.
If you look at prior bars, for example 22:30:00 it has same values because was already consolidated when you downloaded its values at 22:35:05.

nalon99 avatar May 06 '24 14:05 nalon99

@vvu1980 you didn't mention what price you have written as symbol_1 and symbol_2. If the price is the closing price, it's normal that you'll find different values over different time because it's not consolidated. It's not related to any library issues, because the 5 minute bars is consolidated after 5 minutes, therefore at 22:40:00 you can use High, Low and Close price of that bar. At 22:35:00 you can only use the Open price of that current bar. If you look at prior bars, for example 22:30:00 it has same values because was already consolidated when you downloaded its values at 22:35:05.

Thanks a lot for your comment!

I already understood that the time marks the begining of the candle, not the end of it. This is why I was confused about the changes of the same value of the same candle!

vvu1980 avatar May 06 '24 14:05 vvu1980