我必须循环执行此功能。
我想传递x。 x,表示循环应执行多少次。
关于我的数据越来越长:
def get_data(x):
ts = round(time.time())
url = 'https://api.bitfinex.com/v2/candles/trade:'
timeframe = '1h:'
symbol = 'tBTCUSD'
period = 120 * 3600 # max. 120
start = '/hist?start=' + str((ts - period) * 1000)
end = '&end=' + str(ts * 1000)
string = url + timeframe + symbol + start + end
response = requests.get(string)
data = response.json()
time.sleep(1)
period2 = x * period
start = '/hist?start=' + str((ts - period2 - 3600) * 1000)
end = '&end=' + str((ts - period - 3600) * 1000)
string = url + timeframe + symbol + start + end
response = requests.get(string)
data1 = response.json()
data.extend(data1)
time.sleep(1)
return data
我如何完成此任务?