-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
63 lines (48 loc) · 1.41 KB
/
main.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
########################
##### Dependencies #####
########################
# Stock data REST client
from polygon import RESTClient
# JSON for reading config files
import json
# Datetime for api querying
import datetime
# GCP authentication and BigQuery insertion
import GCP_module
############################
###### API Connetction #####
############################
# Get API key from config
with open('./config/api.config.JSON', 'r') as api_file:
api_key = json.load(api_file)
# Establish API connection
client = RESTClient(api_key['key'])
#############################
##### DB/GCS Connection #####
#############################
#############################
##### Ticker/Price info #####
#############################
# Load list of tickers from config file
with open('./config/ticker_list.config.JSON', 'r') as ticker_file:
tickers = json.load(ticker_file)
# Today's date for API queries
today = str(datetime.date.today())
# Query each ticker and load into DB
prices = []
for t in tickers['tickers']:
# Query API
request = client.get_daily_open_close_agg(
t,
today
)
# Append to prices list
prices.append({
'ticker' : request.symbol,
'price' : request.close,
'_date' : today
})
# DEBUG: Reach this point with no errors
print('ticker: ', request.symbol, ' close: ', request.close)
# Insert price into DB
#GCP_module.insert_price_table(prices)