循环之后不会继续

发布于 2025-01-20 12:31:15 字数 1900 浏览 1 评论 0原文

我有一段时间的循环循环。他们都按照预期的方式单独工作,但在第一次迭代循环之后,for循环的合并不会持续。

我无法弄清楚我的错误在哪里,因此我被卡住了。

import ccxt
from datetime import datetime
import pandas as pd
import numpy as np

exchange = ccxt.binance({ 'enableRateLimit': True })
now = int(round(datetime.timestamp(datetime.now())*1000))

data = []
symbols = ['ETH/USDT', 'BTC/USDT', 'LTC/USDT']
date = 1649196000000
for symbol in symbols:
    while date <= now:
        ohlcv = exchange.fetch_ohlcv(symbol, '1d', date, 20)
        data.append(ohlcv[0])
        # print symbol to check which symbol has been fetched
        print(symbol)
        # print date to view table
        print(data)
        # update date variable with date from last record
        date = data[-1][0]
        # increase date with one day to fetch new record
        date += 86400000

提前


ETH/USDT
[[1649203200000, 3407.0, 3407.5, 3162.39, 3168.51, 736273.1047]]
ETH/USDT
[[1649203200000, 3407.0, 3407.5, 3162.39, 3168.51, 736273.1047], [1649289600000, 3168.52, 3268.98, 3143.15, 3227.19, 458179.3272]]
ETH/USDT
[[1649203200000, 3407.0, 3407.5, 3162.39, 3168.51, 736273.1047], [1649289600000, 3168.52, 3268.98, 3143.15, 3227.19, 458179.3272], [1649376000000, 3227.2, 3314.02, 3173.52, 3192.39, 502422.5048]]
ETH/USDT
[[1649203200000, 3407.0, 3407.5, 3162.39, 3168.51, 736273.1047], [1649289600000, 3168.52, 3268.98, 3143.15, 3227.19, 458179.3272], [1649376000000, 3227.2, 3314.02, 3173.52, 3192.39, 502422.5048], [1649462400000, 3192.39, 3228.23, 3181.28, 3220.46, 110418.446]]
            date     open     high      low    close       volume
0  1649203200000  3407.00  3407.50  3162.39  3168.51  736273.1047
1  1649289600000  3168.52  3268.98  3143.15  3227.19  458179.3272
2  1649376000000  3227.20  3314.02  3173.52  3192.39  502422.5048
3  1649462400000  3192.39  3228.23  3181.28  3220.46  110418.4460

谢谢你

I have a while loop inside a for loop. Individually they both work as expected but combined the for loop does not continue after the first iteration of the while loop.

I am stuck getting this to work as I can not figure out where my mistake is.

import ccxt
from datetime import datetime
import pandas as pd
import numpy as np

exchange = ccxt.binance({ 'enableRateLimit': True })
now = int(round(datetime.timestamp(datetime.now())*1000))

data = []
symbols = ['ETH/USDT', 'BTC/USDT', 'LTC/USDT']
date = 1649196000000
for symbol in symbols:
    while date <= now:
        ohlcv = exchange.fetch_ohlcv(symbol, '1d', date, 20)
        data.append(ohlcv[0])
        # print symbol to check which symbol has been fetched
        print(symbol)
        # print date to view table
        print(data)
        # update date variable with date from last record
        date = data[-1][0]
        # increase date with one day to fetch new record
        date += 86400000

Output


ETH/USDT
[[1649203200000, 3407.0, 3407.5, 3162.39, 3168.51, 736273.1047]]
ETH/USDT
[[1649203200000, 3407.0, 3407.5, 3162.39, 3168.51, 736273.1047], [1649289600000, 3168.52, 3268.98, 3143.15, 3227.19, 458179.3272]]
ETH/USDT
[[1649203200000, 3407.0, 3407.5, 3162.39, 3168.51, 736273.1047], [1649289600000, 3168.52, 3268.98, 3143.15, 3227.19, 458179.3272], [1649376000000, 3227.2, 3314.02, 3173.52, 3192.39, 502422.5048]]
ETH/USDT
[[1649203200000, 3407.0, 3407.5, 3162.39, 3168.51, 736273.1047], [1649289600000, 3168.52, 3268.98, 3143.15, 3227.19, 458179.3272], [1649376000000, 3227.2, 3314.02, 3173.52, 3192.39, 502422.5048], [1649462400000, 3192.39, 3228.23, 3181.28, 3220.46, 110418.446]]
            date     open     high      low    close       volume
0  1649203200000  3407.00  3407.50  3162.39  3168.51  736273.1047
1  1649289600000  3168.52  3268.98  3143.15  3227.19  458179.3272
2  1649376000000  3227.20  3314.02  3173.52  3192.39  502422.5048
3  1649462400000  3192.39  3228.23  3181.28  3220.46  110418.4460

Thank you in advance

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

自此以后,行同陌路 2025-01-27 12:31:15

第一个循环运行直到date&gt;现在

然后开始循环的的下一个迭代开始。 <代码>循环被跳过,因为date&gt;现在

The first while loop runs until date > now.

Then the next iteration of the for loop starts. The while loop is skipped because date > now.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文