using yet another stock provider, this one has slightly more info
This commit is contained in:
parent
667e06bea3
commit
317334798a
21
app/stock.py
21
app/stock.py
@ -12,11 +12,18 @@ def parse_share(msg):
|
||||
return res
|
||||
return '```Please input at least one valid share: !stock [share_name]```'
|
||||
|
||||
def get_stock(share_name):
|
||||
token = os.getenv('stock_api_key')
|
||||
request_string="https://www.alphavantage.co/query?function=TIME_SERIES_DAILY&symbol={}&interval=5min&apikey={}".format(share_name, token)
|
||||
request = requests.get(request_string).json()
|
||||
target_date = request['Meta Data']['3. Last Refreshed']
|
||||
blob = request['Time Series (Daily)'][target_date]
|
||||
|
||||
return "```Symbol: {}\nOpen: {}\nClose: {}\nHigh: {}\nLow: {}\nVolume: {}```".format(share_name.upper(), blob['1. open'], blob['4. close'], blob['2. high'], blob['3. low'], blob['5. volume'])
|
||||
def get_stock(share_name):
|
||||
share_name = share_name.upper()
|
||||
token = os.getenv('stock_api_key')
|
||||
request_string = "https://fmpcloud.io/api/v3/quote/%s?apikey=%s" % (share_name, token)
|
||||
request = requests.get(request_string).json()[0]
|
||||
|
||||
previous_close = request['previousClose']
|
||||
opening_price = request['open']
|
||||
current_price = request['price']
|
||||
change = request['change']
|
||||
day_low = request['dayLow']
|
||||
day_high = request['dayHigh']
|
||||
|
||||
return "```Current price: $%s\nOpen: $%s\nPrevious close: $%s\nChange: $%s\nDay low: $%s\nDay High: $%s```" % (current_price, opening_price, previous_close, change, day_low, day_high)
|
Loading…
x
Reference in New Issue
Block a user