循环之后不会继续
我有一段时间的循环循环。他们都按照预期的方式单独工作,但在第一次迭代循环之后,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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
第一个
循环运行直到
date&gt;现在
。然后开始循环的
的下一个迭代开始。 <代码>
循环被跳过,因为date&gt;现在
。The first
while
loop runs untildate > now
.Then the next iteration of the
for
loop starts. Thewhile
loop is skipped becausedate > now
.