-
Notifications
You must be signed in to change notification settings - Fork 390
/
pennapps.py
55 lines (42 loc) · 1.66 KB
/
pennapps.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
'''
import requests
import json
client_id = r''
client_secret = r''
auth_data = {
'grant_type' : 'client_credentials',
'client_id' : client_id,
'client_secret' : client_secret,
'scope' : 'read_content read_financial_data read_product_data read_user_profile'
}
# create session instance
session = requests.Session()
# make a POST to retrieve access_token
auth_request = session.post('https://idfs.gs.com/as/token.oauth2', data = auth_data)
access_token_dict = json.loads(auth_request.text)
access_token = access_token_dict['access_token']
# update session headers
session.headers.update({'Authorization':'Bearer '+ access_token})
# test API connectivity
request_url = 'https://api.marquee.gs.com/v1/users/self'
request = session.get(url=request_url)
print(request.text)
'''
from datetime import date
from gs_quant.data import Dataset
from gs_quant.markets.securities import SecurityMaster, AssetIdentifier
from gs_quant.session import GsSession
client_id = 'cf8dea63e6e5446380ca2f64304cd21d'
client_secret = '0b5ed460f1891ba61eee18c194809b3a48aa46c988866e77e9ed9f85021a5865'
scopes = GsSession.Scopes.get_default()
GsSession.use(client_id=client_id, client_secret=client_secret, scopes=scopes)
ds = Dataset('USCANFPP_MINI')
print (ds)
gsids = ds.get_coverage()['gsid'].values.tolist()
df = ds.get_data(date(2012, 7, 2), date(2017, 6, 30), gsid=gsids[0:5])
print (df)
for idx, row in df.iterrows():
marqueeAssetId = row['assetId']
asset = SecurityMaster.get_asset(marqueeAssetId, AssetIdentifier.MARQUEE_ID)
df.loc[df['assetId'] == marqueeAssetId, 'assetName'] = asset.name
print (df)