-
Notifications
You must be signed in to change notification settings - Fork 0
/
polygon_data.py
65 lines (52 loc) · 1.75 KB
/
polygon_data.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
import sqlite3
from polygon import RESTClient
import config
connection = sqlite3.connect(config.DB_FILE)
connection.row_factory = sqlite3.Row
cursor = connection.cursor()
cursor.execute("""
SELECT id, symbol, name from stock
""")
rows = cursor.fetchall()
symbols = []
stock_dict = {}
for row in rows:
symbol = row['symbol']
symbols.append(symbol)
stock_dict[symbol] = row['id']
# api fetch from polygon
client = RESTClient(config.POLYGON_API_KEY)
for ticker in rows:
print(f"processing symbol: {ticker['symbol']}")
stock_id = stock_dict[ticker['symbol']]
ticker_detils = client.get_ticker_details(ticker['symbol'])
ticker_symbol = ticker['symbol']
# active info
active = ticker_detils.active
# address info
addressWrapper = ticker_detils.address
if(addressWrapper):
address = addressWrapper.address1
city = addressWrapper.city
state = addressWrapper.state
else:
address = None
city = None
state = None
# branding info
branding = ticker_detils.branding
if(branding):
logo_url = branding.logo_url
else:
logo_url = None
description = ticker_detils.description
ticker_name = ticker_detils.ticker
list_date = ticker_detils.list_date
market_cap = ticker_detils.market_cap
name = ticker_detils.name
primary_exchange = ticker_detils.primary_exchange
cursor.execute("""
INSERT INTO ticker_details (stock_id, active, address, city, state, logo, description, ticker, list_date, market_cap, name, primary_exchange)
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
""", (stock_id, active, address, city, state, logo_url, description, ticker_name, list_date, market_cap, name, primary_exchange))
connection.commit()