-
-
Save kandy/89e5f11fe8e5059551433fc2019d8706 to your computer and use it in GitHub Desktop.
Crawl Some Data from Bloomberg
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import requests | |
import json | |
Req = [ | |
"KOSPI2:IND", | |
"NIFTY:IND", | |
"SX5E:IND", | |
"UKX:IND", | |
"NDX:IND" | |
] | |
Data = {} | |
for stock in Req: | |
Link = "https://www.bloomberg.com/markets/api/bulk-time-series/price/"+stock.replace("\\:","%3A")+"?timeFrame=1_MONTH" | |
Page = requests.get(Link) | |
RawData = json.loads(Page.text) | |
for each in RawData[0]["price"]: | |
if each["date"] in Data.keys(): | |
Data[each["date"]][stock.replace("\\:",":")] = str(each["value"]) | |
else: | |
Data[each["date"]] = {} | |
Data[each["date"]][stock.replace("\\:",":")] = str(each["value"]) | |
print("", end="\t") | |
print("\t".join(Req)) | |
for date in Data: | |
print(date, end="\t") | |
for stockNum in range(len(Req)): | |
if stockNum == len(Req)-1: | |
if Req[stockNum] not in Data[date]: | |
print("-") | |
else: | |
print (Data[date][Req[stockNum].replace("\\:",":")]) | |
else: | |
if Req[stockNum] not in Data[date]: | |
print("-", end="\t") | |
else: | |
print (Data[date][Req[stockNum].replace("\\:",":")], end="\t") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment