Skip to content

Instantly share code, notes, and snippets.

@ChromoX
Created September 17, 2014 19:15
Show Gist options
  • Save ChromoX/095b81002ed8aef7b2e0 to your computer and use it in GitHub Desktop.
Save ChromoX/095b81002ed8aef7b2e0 to your computer and use it in GitHub Desktop.
CUSIP to Equity Symbol
def cusip_to_symbol(cusip):
req = requests.get("http://activequote.fidelity.com/mmnet/SymLookup.phtml?reqforlookup=REQUESTFORLOOKUP&productid=mmnet&isLoggedIn=mmnet&rows=50&for=stock&by=cusip&criteria=%s&submit=Search" % (cusip))
page_html = req.text
s_index_begin = page_html.find('<tr><td height="20" nowrap><font class="smallfont">')
s_index_end = page_html.find('</table></td></tr>', s_index_begin)
symbol_section = page_html[s_index_begin:s_index_end]
s_bracket_end = symbol_section.find('</a>')
s_bracket_begin = symbol_section.find('">', s_bracket_end - 10)
return symbol_section[s_bracket_begin + len('">'):s_bracket_end]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment