I need to compile stock price data for ADR and ORD pairs (and the currency between them) into a Pandas dataframe. My initial plan was use Python's requests library and a free Rapid API account to get data from the Bloomberg API, the code for which I've attached below. The issue with this is that the time intervals seem to be 5 minutes at the fastest, and I need much faster. (The "MY RAPID API KEY" is removed because you must create a free account to get a key. I'm already near the limit of requests my account can make for the month so I can't give it out, sorry for the inconvenience)
import requests
import pandas as pd
import numpy as np
import datetime
def extract_ticks(interval="d1"):
url="https://bloomberg-market-and-financial-news.p.rapidapi.com/market/get-chart"
querystring = {"interval":interval,"id":"dge:ln"}
headers = {
'x-rapidapi-host': "bloomberg-market-and-financial-news.p.rapidapi.com",
'x-rapidapi-key': "MY RAPID API KEY"
}
response = requests.request("GET", url, headers=headers, params=querystring)
json_d = response.json()
return json_d
#Get year to date data ytd
json_d = extract_ticks()
print(json_d)
# Write the data to json file
import json
with open("dge_ytd.json","w") as fp:
json.dump(json_d,fp)
import pandas as pd
import datetime
with open("dge_ytd.json","r") as fp:
json_d = json.load(fp)
ticks_d = json_d['result']['DGE:LN']['ticks']
df = pd.DataFrame(ticks_d)
df['Close'] = df['close']
df['Date'] = df['time'].apply(lambda x:datetime.datetime.fromtimestamp(x))
df = df.set_index('time')
data = df.sort_index(ascending=True, axis=0)
data
#creating a separate dataset
new_data = data[['Date','Close']]
index = range(0,len(new_data))
new_data['index']=index
new_data=new_data.set_index('index')
new_data['Date'] = pd.to_datetime(new_data.Date,format='%Y-%m-%d')
new_data
This code does great work for the formatting I need and storage of the Dataframe, and the Bloomberg API is very easy to use. My school has a Bloomberg Terminal, which I've never used before. Can I get faster time intervals using the Terminal license, or will I need to find a different data source? If so, what data sources can I use that I can get for very cheap and how can I get the data into a pandas df?
Thanks in advance, and let me know if there's any clarifying information I can provide in the comments; this is my first question so I'm hoping I followed the correct formatting procedure (I couldn't copy in Jupyter output without columns getting mangled together)