Getting BSE Stock Price by Market Data API

January 28th, 2010 by Kevin | Posted under programs.

In my post Using Python to get BSE price, I had mentioned a second way of getting the data from the Stock Market Data API

Unfortunately, I am unable to get the proper output even though the status code returned is 200 OK. Maybe I am using the API in a wrong way. So I have asked the guys at Stock Market Data API for some help.

The SMD Get Quote API follows simple HTTP GET syntax: start with a base URL and then add arguments and values after a question mark (?). For the most recent snapshot feed, you need to provide SMDAPIId, MarketId, SymbolId and Format parameters:

http://smdapi.co.cc/api/get_quote?apiid=APIId&market=MarketId&symbol=SymbolId&format=Format

Here is my Python code:

import httplib2

def get_bse(code):
     """Retrieve the BSE information based on the BSE Company Code entered"""

     APIId = "de8290b371"
     MarketId = "BSE"
     Format = "JSON"
     url_string = "http://smdapi.co.cc/api/get_quote?apiid=" + APIId + "&market=" + MarketId +
                   "&symbol=" + str(code) + "&format=" + Format
     print(url_string)
     referer = "http://kevinrodrigues.com"

     h = httplib2.Http(".cache")
     resp, content = h.request(url_string, "GET", headers={'Referer': referer})

     print(resp.status)
     print(content)

     with open('stock.json', 'w', encoding='utf8') as f:
          str_content = str(content)
          f.write(str_content)

if __name__ == '__main__':
     get_bse(500180)   #Get the stock information for HDFCBANK with code 500180

Could any of you help me get this right?

 

Related Posts:

Tags:

Do you have any comments on Getting BSE Stock Price by Market Data API ?

Spam protection by WP Captcha-Free