-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathyahoo.py
More file actions
29 lines (23 loc) · 771 Bytes
/
yahoo.py
File metadata and controls
29 lines (23 loc) · 771 Bytes
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
import sys
from yahoo_finance_api2 import share
from yahoo_finance_api2.exceptions import YahooFinanceError
def fetch_yahoo():
my_share = share.Share('^HSI')
symbol_data = None
try:
symbol_data = my_share.get_historical(share.PERIOD_TYPE_DAY,
0,
share.FREQUENCY_TYPE_DAY,
5)
except YahooFinanceError as e:
print(e.message)
sys.exit(1)
new_x = {
'Open': [],
'High': [],
'Low': []
}
new_x['Open'].append(symbol_data.get('open')[0])
new_x['High'].append(symbol_data.get('high')[0])
new_x['Low'].append(symbol_data.get('low')[0])
return new_x