0
$\begingroup$

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

Jupyter Output

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)

$\endgroup$
7
  • $\begingroup$ The terminal will not allow you to get such data - Bloomberg is quite good when it comes to restricting access to these things. $\endgroup$ Feb 24 at 18:41
  • $\begingroup$ @rubikscube09 does that mean that any faster data from Bloomberg would be past a massive pay wall? If so, are there other finance APIs that are similar at all? $\endgroup$ Feb 24 at 19:07
  • $\begingroup$ What frequency do you require? Minute level ? Seconds? Tick level? $\endgroup$ Feb 24 at 19:39
  • $\begingroup$ @ColeMcMahon-Gioeli most likely yes. There are quite a few ticker data providers out there, at a variety of frequencies. $\endgroup$ Feb 24 at 21:01
  • $\begingroup$ @Kermittfrog I need at least minute level, but preferably second level. I don't need anything sub-second level. What ticker data providers would you recommend? $\endgroup$ Feb 25 at 0:45
0
$\begingroup$

Hi you can use Alphavantage and inquire a student offer, that gives you more calls per minute and more calls per month. You only have to have a student mail account and confirm the purposes of your endeavour.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.