Created
November 3, 2017 01:56
-
-
Save KMConner/f76b5e7d709af3db7159bd5164bc53c7 to your computer and use it in GitHub Desktop.
Downloads bitcoin chart history from waif.jp
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
""" | |
With this script, we can download BitCoin chart history from zaif. | |
""" | |
import time | |
import requests | |
import json | |
ONE_MONTH_SECONDS = 3600 * 24 * 30 | |
if __name__ == "__main__": | |
time_stamp = int(time.time()) | |
csv_str = "" | |
for i in range(24): | |
tmp = "" | |
json_str: str = requests.get( | |
"https://zaif.jp/zaif_chart_api/v1/history?symbol=BTC_JPY&resolution=1&from=" + str( | |
time_stamp - ONE_MONTH_SECONDS) + "&to=" + str(time_stamp)).text | |
time_stamp -= ONE_MONTH_SECONDS | |
json_str = json_str.replace("\\", "") | |
array_data: list = json.loads(json_str[1:-1])["ohlc_data"] | |
# time, volume, average, high, low, close, open | |
for d in array_data: | |
tmp += str(d["time"]) + "," + str(d["volume"]) + "," + str(d["average"]) + "," + str( | |
d["high"]) + "," + str(d["low"]) + "," + str(d["close"]) + "," + str(d["open"]) + "\r\n" | |
csv_str = tmp + csv_str | |
print(i) | |
file = open("./out.csv", "w") | |
file.write(csv_str) | |
file.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment