Crypto backtesting
Loading...
Searching...
No Matches
alpha.py
Go to the documentation of this file.
1import requests
2import os
3
4# get api key from environment variable
5api_key = os.environ.get('ALPHAVANTAGE_API_KEY')
6token = "IBM"
7
8# replace the "demo" apikey below with your own key from https://www.alphavantage.co/support/#api-key
9url = f"https://www.alphavantage.co/query?function=TIME_SERIES_DAILY&symbol={token}&apikey={api_key}"
10r = requests.get(url)
11data = r.json()
12
13# Create directory if it doesn't exist
14path = "/tmp/tokens"
15if not os.path.exists(path):
16 os.makedirs(path)
17
18# Construct file name base on symbol
19file = f"{path}/Alpha-{token}.json"
20
21print("Writing to file: ", file)
22
23# Create file and write data to it
24with open(file, 'w') as f:
25 f.write(str(data))