Created
September 25, 2019 19:30
-
-
Save skeller88/8dc5fd99a260acdca300dc7e357a15e3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def main(start_datetime_str: str, end_datetime_str: Optional[str], | |
base_currency: str, quote_currency: str): | |
url = f"https://api-pub.bitfinex.com/v2/candles/trade:1h:t{base_currency}{quote_currency}/hist" | |
params = { | |
"limit": 5000, | |
"sort": 1, | |
"start": datetime.datetime.strptime(start_datetime_str, strftime_days).timestamp() * 1000, | |
"end": datetime.datetime.strptime(end_datetime_str, strftime_days).timestamp() * 1000 | |
} | |
bars = requests.get(url, params=params).json() | |
with open(f'bitfinex_bars_{base_currency}{quote_currency}.csv', 'w+') as output: | |
writer = csv.writer(output) | |
writer.writerow(["timestamp", "open", "close", "high", "low", "volume_base"]) | |
while len(bars) > 0: | |
writer.writerows(bars) | |
params["start"] = bars[-1][0] | |
print('first', microsecond_timestamp_to_utc_datetime(bars[0][0]), 'last', microsecond_timestamp_to_utc_datetime(bars[-1][0])) | |
bars = requests.get(url, params=params).json() | |
if bars[0] == 'error': | |
print('done') | |
return |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment