-
Notifications
You must be signed in to change notification settings - Fork 0
/
api_handler_visual.py
60 lines (49 loc) · 1.86 KB
/
api_handler_visual.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
import requests
import json
import logging
import pandas as pd
logger = logging.getLogger(__name__)
def allocs_to_frame(json_allocations):
alloc_list = []
for json_alloc in json_allocations:
#print(json_alloc)
allocs = pd.DataFrame(json_alloc['allocations'])
allocs.set_index('ticker', inplace=True)
alloc_serie = allocs['alloc']
alloc_serie.name = json_alloc['date']
alloc_list.append(alloc_serie)
all_alloc_df = pd.concat(alloc_list, axis=1).T
return all_alloc_df
class APIBMEHandler:
def __init__(self, market):
self.url_base = 'https://miax-gateway-jog4ew3z3q-ew.a.run.app'
self.competi = 'mia_7'
self.user_key = 'AIzaSyBBKrt7mueaGfNsQ1sSwEO_-XVzLcoVRF0'
self.market = market
def get_ticker_master(self):
url = f'{self.url_base}/data/ticker_master'
params = {'competi': self.competi,
'market': self.market,
'key': self.user_key}
response = requests.get(url, params)
tk_master = response.json()
maestro_df = pd.DataFrame(tk_master['master'])
return maestro_df
def get_close_data(self):
maestro_df = self.get_ticker_master()
data_close = {}
for i, data in maestro_df.iterrows():
ticker = data.ticker
logger.info(ticker)
data_close[ticker] = self.get_close_data_ticker(ticker)
data_close = pd.DataFrame(data_close)
return data_close
def get_close_data_ticker(self, ticker):
url = f'{self.url_base}/data/time_series'
params = {'market': self.market,
'key': self.user_key,
'ticker': ticker}
response = requests.get(url, params)
tk_data = response.json()
series_data = pd.read_json(tk_data, typ='series')
return series_data