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