Saturday, February 15, 2014

Python Code to Extract Bloomberg Stock Price

Leave a Comment

Latest Stock Price

To extract latest stock price data from Bloomberg website, you can use the following  piece of python code. You will need to have python installed and save this code into a .py file to run. This is a very efficient piece of code as it uses the json format and doesn't scrap from the entire webpage. Assign the 'ticker' variable below with your desired stock ticker.

import urllib
import re
import json

ticker="AAPL:US" # simply replace this with your desired stock ticker

htmltext = urllib.urlopen("http://www.bloomberg.com/markets/watchlist/recent-ticker/"+ticker)

data = json.load(htmltext)
print data['last_price']

1 minute Stock Price Data from Bloomberg

import urllib
import re
import json

ticker="AAPL:US"
htmltext = urllib.urlopen("http://www.bloomberg.com/markets/chart/data/1D/"+ticker)

data = json.load(htmltext)

datavalues=data['data_values']
for datavalue in datavalues:
    print datavalue[1]
print "number of data points" , len(datavalues)
Read More...