Skip to content

Commit

Permalink
Add method to lookup stock
Browse files Browse the repository at this point in the history
Pending a bugfix to the alphavantage library being used
(see RomelTorres/alpha_vantage#329)
  • Loading branch information
ddavness committed Dec 6, 2021
1 parent d0f11f7 commit b437470
Showing 1 changed file with 19 additions and 5 deletions.
24 changes: 19 additions & 5 deletions src/AlphaVantageDriver.py
Expand Up @@ -88,7 +88,6 @@ def g(*args, **kwargs):
# Figure out the key we're looking for based on the sample
for k in dump.get(list(dump.keys())[0]).keys():
if k.startswith(key_sample):
print(k)
kw = k
break

Expand All @@ -103,10 +102,6 @@ def g(*args, **kwargs):
return meta

class AlphaVantageDriver():
fx_driver = None
cc_driver = None
mkt_driver = None

def __init__(self, apikey = "") -> None:
if apikey is None or apikey.strip() == "":
raise ValueError("No API Key provided!")
Expand All @@ -129,3 +124,22 @@ def crypto(self, symbol = "", to = "USD"):
@pack_into_dated_dict(key_sample = "4.")
def mkt(self, full_history = False, symbol = ""):
return self.mkt_driver.get_daily(symbol = symbol, outputsize = "full" if full_history else "compact")

@av_rate_limit
def search_stock(self, content):
"""
Checks whether AlphaVantage tracks the given stock/fund, and if so, it's currency denomination
"""
matches = [{
"symbol": entry.get("1. symbol"),
"name": entry.get("2. name"),
"currency": entry.get("8. currency"),
"match": float(entry.get("9. matchScore"))
} for entry in self.mkt_driver.get_symbol_search(keywords = content)[0]]

# For the sake of simplicity, we'll fail if the match score isn't a perfect 1.
for entry in matches:
if entry.get("match") == 1:
return entry

return matches

0 comments on commit b437470

Please sign in to comment.