-
-
Notifications
You must be signed in to change notification settings - Fork 7.3k
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
How to get OHLCV until a date #392
Comments
Hi!
The fetchOHLCV method doesn't have an "until" argument, but it has a "limit" argument instead, that is the number of candles you want back. The "limit" argument is more common than "until", because most of exchanges accept a number of candles, not the end date of the range. Example A So, let's say, you are fetching 2 days of 5m timeframe:
Therefore we need a limit of 576 candles. As of ccxt v1.9.252, you can do this: # datetimes are UTC
import ccxt
poloniex = ccxt.poloniex()
ohlcv = poloniex.fetch_ohlcv("ETH/BTC", '5m', poloniex.parse8601('2017-01-15 00:00:00'), 576)
for entry in ohlcv:
print('Example A', poloniex.iso8601(entry[0]), entry[1:5]) This will give you exactly the amount of candles starting from 2017-01-15 00:00:00 to 2017-01-17 00:00:00, inclusively. Example B An alternative way, that does work with earlier versions of ccxt as well is to pass the extra import ccxt
poloniex = ccxt.poloniex()
start = poloniex.parse8601('2017-01-15 00:00:00')
end = poloniex.parse8601('2017-01-17 00:00:00') # inclusive
ohlcv = poloniex.fetch_ohlcv("ETH/BTC", '5m', start, None, { 'end': int(end/1000)})
for entry in ohlcv:
print('Example B', poloniex.iso8601(entry[0]), entry[1:5]) Both of the above examples should output the same result. Don't forget to upgrade to the most recent version of the library. Thx! P.S Let us know if it helped you or not, plz. |
If I use the first example it gives me the correct candles, but the second example (the one for earlier versions of ccxt) wasn't working and it gave me candles since the date until today. But anyway, the first example works perfectly so I'm fine with that :) thanks!! (by the way, do you sleep some day?? The speed of answering questions and development of this project is insane!) |
Hi, I'm trying to get data not only with a starting date, but also with a finish date. I mean, something like this:
I know that fetch_ohlcv doesn't allow "until" parameter, and I wonder if its planned to be implemented, or what would be the suggested way to get a range. I wouldn't want to get a full range, from some date until today, but I'd want to get data for specific moments in time, like in my example (a month from the past year, or a day in the past or something like that)
I found the ticket #215 but after checking the provided example, I'm not sure that it is doing the correct result. In the example, I changed the initial data with this:
But then when I print "data", the results are not in that range:
I'm not sure to understand how to do this...
The text was updated successfully, but these errors were encountered: