Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Returning wrong historical data during runtime app #64

Open
rkawa01 opened this issue Jun 13, 2023 · 4 comments
Open

Returning wrong historical data during runtime app #64

rkawa01 opened this issue Jun 13, 2023 · 4 comments

Comments

@rkawa01
Copy link

rkawa01 commented Jun 13, 2023

I encountered recently issue with getting historical data during runtime app, for example Pyqt5 or even
running it on jupyter notebook. Here is example data:

Time now: 2023-06-13 12:07:23.156518
Time of data: 2023-06-13 02:09:00

{'time': 1686614940,
 'high': 25901.76,
 'low': 25894.92,
 'open': 25895.07,
 'volumefrom': 4.707,
 'volumeto': 121916.59,
 'close': 25901.42,
 'conversionType': 'direct',
 'conversionSymbol': ''}

The reason of that difference of time is because i ran kernel at night.

It always returns the data from the time kernel was started, so to get the real time data i would have to restart the kernel.
The same thing happens when using application in Pyqt5. However using cryptocompare.get_price(...) it always returns the newest value. Somewhere i read that it could be caching mechanism implemented in the library I am not sure if it was meant to be like this. Is there any solution to overcome this problem? Maybe it's only at my side and just can't address the issue.

@lagerfeuer
Copy link
Owner

Hi @Thyen-Radek,
I'm not sure I understand what you're trying to communicate. Could get_historical_price be what you're looking for?

@rkawa01
Copy link
Author

rkawa01 commented Jun 21, 2023

Hi @lagerfeuer
Here is snippet of a code:

historical_minute = \
    cryptocompare.get_historical_price_minute(
        "BTC",
        "USD",
        limit=10,
        exchange="CCCAGG"
   )

So technically there i am getting 10 or 11 newest prices of BTC, at least i should right ?
Imagine i have python application that is running for some hours.
There is some loop with sleep(300) and snippet code of above.
So it is retrieving prices every 5 minutes but i will not get the newest prices. Instead of this i will get prices from the time
the python application was started.
I think to perfectly understand me you should check it yourself.

Same happens in jupyter notebook, whenever i run cell i won't get the newest historical prices but technically
it should be the newest prices taken from api right?

i am not sure how to explain but in above example i showed latest BTC price with using get_historical_price and
printing it out: print(datetime.datetime.fromtimestamp(historical_minute[-1]['time'])) with it's own time and also i printed out the time it was executed (real time on my computer) but times were not close at all as you could see.

Well in the end i am pretty sure the time in that historical_prices is not updating and other stuff too.
I hope that i provided it more clearly. Maybe you could address the issue because i can't notice.

@rkawa01
Copy link
Author

rkawa01 commented Jun 22, 2023

Well i found the issue in library method:

def get_historical_price_minute(
    coin: str,
    currency: str = CURRENCY,
    limit: int = LIMIT,
    exchange: str = "CCCAGG",
    toTs: Timestamp = time.time(),
) -> Optional[List[Dict]]:

So i need to pass to the function toTs = datetime.datetime.now() to achieve the newest prices ?
Since library is imported at the start of the python app, the toTs stays always the same because it is initialized when starting the app.

I am pretty sure it should be more clear in library or at least timeStamp should be always passed to achieve what we want.
Or in function get_historical_price_minute when passing arguments it could be changed:

toTs: Timestamp = None

in function:

if toTs is None:
   toTs = time.time()

@lagerfeuer
Copy link
Owner

@Thyen-Radek Thanks for the detailed explanation. You are indeed right, it's a bug. And you already outlined the solution. Feel free to open a PR, not sure when I'll get to it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants