0

I initialize a date variable and a now variable. While date is smaller than now the code loops.

import ccxt
import datetime
exchange = ccxt.binance({ 'enableRateLimit': True })

date = 1502928000
now = int(round(datetime.datetime.timestamp(now)))

while date <= now:
    ohlcv = exchange.fetch_ohlcv('BTC/USDT', '1d', date, 1)
    print(ohlcv)
    date += 86400
    print(date)

At then end of the loop I update the date with one day, this works because I print the date and confirm the date changed.

But, the date within the request stays the same value. The response is always:

[[1502928000000, 4261.48, 4485.39, 4200.74, 4285.08, 795.150377]]
[[1502928000000, 4261.48, 4485.39, 4200.74, 4285.08, 795.150377]]
[[1502928000000, 4261.48, 4485.39, 4200.74, 4285.08, 795.150377]]
[[1502928000000, 4261.48, 4485.39, 4200.74, 4285.08, 795.150377]]
...

How do I update the date variable within the request?

Thank you

FObersteiner
  • 22,500
  • 8
  • 42
  • 72
timmy
  • 468
  • 1
  • 6
  • 21
  • @FObersteiner Sorry about that, I have added the missing lines. Now it is comnplete. – timmy Apr 08 '22 at 13:34
  • 1
    Thanks, I see. I think this answers your question? [CCXT binance fetch\_ohlcv function](https://stackoverflow.com/questions/68045470/ccxt-binance-fetch-ohlcv-function) - just make the timestamps milliseconds since the epoch, not seconds. – FObersteiner Apr 08 '22 at 14:26
  • Oh yes, this solved it. Thank you! Please add another comment and I upvote it. Is mistakenly clicked the button twice... – timmy Apr 08 '22 at 15:34
  • 1
    no worries ^^ don't know if you can dupe-flag you own question but I'd leave it here in case others come a cross this issue (don't know how clear the docs are). – FObersteiner Apr 08 '22 at 16:54

0 Answers0