fixing the stock function. the old provider colsed off their api. New api not as feature rich but it works
This commit is contained in:
parent
93ba9bb359
commit
aec1193d5d
19
app/stock.py
19
app/stock.py
@ -1,4 +1,6 @@
|
|||||||
|
from datetime import date
|
||||||
import requests
|
import requests
|
||||||
|
import os
|
||||||
|
|
||||||
def parse_share(msg):
|
def parse_share(msg):
|
||||||
if len(msg.split()) > 1:
|
if len(msg.split()) > 1:
|
||||||
@ -12,15 +14,10 @@ def parse_share(msg):
|
|||||||
return '```Please input at least one valid share: !stock [share_name]```'
|
return '```Please input at least one valid share: !stock [share_name]```'
|
||||||
|
|
||||||
def get_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]
|
||||||
|
|
||||||
request = requests.get("https://api.iextrading.com/1.0/stock/{}/quote".format(share_name)).json()
|
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'])
|
||||||
|
|
||||||
return '```Company Name: {}\nSymbol: {}\nSector: {}\n\nOpen: ${}\nCurrently: ${}\nChange: ${}\nChange percent {}%```'.format(
|
|
||||||
request['companyName'],
|
|
||||||
request['symbol'],
|
|
||||||
request['sector'],
|
|
||||||
request['open'],
|
|
||||||
request['latestPrice'],
|
|
||||||
request['change'],
|
|
||||||
request['changePercent']
|
|
||||||
)
|
|
Loading…
x
Reference in New Issue
Block a user