Skip to content

Instantly share code, notes, and snippets.

@KMConner
Created November 3, 2017 01:56
Show Gist options
  • Save KMConner/f76b5e7d709af3db7159bd5164bc53c7 to your computer and use it in GitHub Desktop.
Save KMConner/f76b5e7d709af3db7159bd5164bc53c7 to your computer and use it in GitHub Desktop.
Downloads bitcoin chart history from waif.jp
"""
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