-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbackend.py
76 lines (59 loc) · 3.09 KB
/
backend.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
from urllib.request import urlopen
import requests
import json, csv, os, test
from os import name, path
import datetime
import yfinance
def filecheck(f):
if path.exists("./data/"+f)==False:
with open(os.path.join("./data", f), 'w') as fp:
print("File created: "+f)
pass
else:
print("File already exist: "+f)
""" ---------------------------------------------------Stock Details------------------------------------------------------------------"""
def daily_o_c(name, date):
url = test.daily_o_c_api(name,date)
# remove above line and add
# url = "https://api.polygon.io/v1/open-close/"+name+"/"+ str(date)+"?adjusted=true&apiKey=<YOUR_API_KEY>"
response = urlopen(url)
data_json = json.loads(response.read())
return data_json
""" ----------------------------------------------------------------------------------------------------------------------------------"""
""" ---------------------------------------------------Stock Listing------------------------------------------------------------------"""
def refresh():
filecheck("stock.csv")
file = open("./data/stock.csv")
csvread = csv.reader(file)
data = []
for row in csvread:
data.append(row)
return data
""" ----------------------------------------------------------------------------------------------------------------------------------"""
""" ---------------------------------------------------Crypto Details------------------------------------------------------------------"""
def crypto_daily_o_c(name, date):
url = test.crypto_daily_o_c_api(name,date)
# remove above line and add
# url = "https://api.polygon.io/v1/open-close/"+name+"/"+ str(date)+"?adjusted=true&apiKey=<YOUR_API_KEY>"
response = urlopen(url)
data_json = json.loads(response.read())
return data_json
""" ----------------------------------------------------------------------------------------------------------------------------------"""
""" ---------------------------------------------------Crypto Listing------------------------------------------------------------------"""
def crypto_refresh():
file = open("./data/cryptocurrencies.json")
data_json = json.loads(file.read())
data = []
for key in data_json:
data.append([key,data_json[key]])
return data
""" ----------------------------------------------------------------------------------------------------------------------------------"""
""" ---------------------------------------------------Stocks Aggregate Bars------------------------------------------------------------------"""
def stocks_aggregate(from_date, to_date, ticker):
url = test.stocks_aggregate_api(from_date,to_date,ticker)
# remove above line and add
# url = "https://api.polygon.io/v2/aggs/ticker/AAPL/range/1/day/2020-07-22/2021-07-22?adjusted=true&sort=asc&limit=120&apiKey=<YOUR_API_KEY>"
response = urlopen(url)
data_json = json.loads(response.read())
return data_json
""" ----------------------------------------------------------------------------------------------------------------------------------"""