1
0
mirror of https://gitlab.com/simple-stock-bots/simple-telegram-stock-bot.git synced 2025-07-25 23:51:32 +00:00
This commit is contained in:
2021-05-21 16:50:29 -07:00
parent 610dbc3492
commit f9b8921ba8
2 changed files with 60 additions and 22 deletions

View File

@@ -55,10 +55,12 @@ class IEX_Symbol:
) -> Optional[Tuple[pd.DataFrame, datetime]]:
reg_symbols = r.get(
f"https://cloud.iexapis.com/stable/ref-data/symbols?token={self.IEX_TOKEN}"
f"https://cloud.iexapis.com/stable/ref-data/symbols?token={self.IEX_TOKEN}",
timeout=5,
).json()
otc_symbols = r.get(
f"https://cloud.iexapis.com/stable/ref-data/otc/symbols?token={self.IEX_TOKEN}"
f"https://cloud.iexapis.com/stable/ref-data/otc/symbols?token={self.IEX_TOKEN}",
timeout=5,
).json()
reg = pd.DataFrame(data=reg_symbols)
@@ -83,7 +85,10 @@ class IEX_Symbol:
str
Human readable text on status of IEX API
"""
resp = r.get("https://pjmps0c34hp7.statuspage.io/api/v2/status.json")
resp = r.get(
"https://pjmps0c34hp7.statuspage.io/api/v2/status.json",
timeout=5,
)
if resp.status_code == 200:
status = resp.json()["status"]
@@ -155,7 +160,10 @@ class IEX_Symbol:
IEXurl = f"https://cloud.iexapis.com/stable/stock/{symbol.id}/quote?token={self.IEX_TOKEN}"
response = r.get(IEXurl)
response = r.get(
IEXurl,
timeout=5,
)
if response.status_code == 200:
IEXData = response.json()
@@ -226,7 +234,10 @@ class IEX_Symbol:
return "OTC stocks do not currently support any commands."
IEXurl = f"https://cloud.iexapis.com/stable/stock/{symbol}/dividends/next?token={self.IEX_TOKEN}"
response = r.get(IEXurl)
response = r.get(
IEXurl,
timeout=5,
)
if response.status_code == 200 and response.json():
IEXData = response.json()[0]
keys = (
@@ -288,7 +299,10 @@ class IEX_Symbol:
return "OTC stocks do not currently support any commands."
IEXurl = f"https://cloud.iexapis.com/stable/stock/{symbol}/news/last/15?token={self.IEX_TOKEN}"
response = r.get(IEXurl)
response = r.get(
IEXurl,
timeout=5,
)
if response.status_code == 200:
data = response.json()
if data:
@@ -324,7 +338,10 @@ class IEX_Symbol:
return "OTC stocks do not currently support any commands."
IEXurl = f"https://cloud.iexapis.com/stable/stock/{symbol}/company?token={self.IEX_TOKEN}"
response = r.get(IEXurl)
response = r.get(
IEXurl,
timeout=5,
)
if response.status_code == 200:
data = response.json()
@@ -352,7 +369,10 @@ class IEX_Symbol:
return "OTC stocks do not currently support any commands."
IEXurl = f"https://cloud.iexapis.com/stable/stock/{symbol}/stats?token={self.IEX_TOKEN}"
response = r.get(IEXurl)
response = r.get(
IEXurl,
timeout=5,
)
if response.status_code == 200:
data = response.json()
@@ -399,7 +419,10 @@ class IEX_Symbol:
return pd.DataFrame()
IEXurl = f"https://cloud.iexapis.com/stable/stock/{symbol}/intraday-prices?token={self.IEX_TOKEN}"
response = r.get(IEXurl)
response = r.get(
IEXurl,
timeout=5,
)
if response.status_code == 200:
df = pd.DataFrame(response.json())
df.dropna(inplace=True, subset=["date", "minute", "high", "low", "volume"])
@@ -437,7 +460,8 @@ class IEX_Symbol:
pass
response = r.get(
f"https://cloud.iexapis.com/stable/stock/{symbol}/chart/1mm?token={self.IEX_TOKEN}&chartInterval=3&includeToday=false"
f"https://cloud.iexapis.com/stable/stock/{symbol}/chart/1mm?token={self.IEX_TOKEN}&chartInterval=3&includeToday=false",
timeout=5,
)
if response.status_code == 200:
@@ -460,7 +484,8 @@ class IEX_Symbol:
"""
stocks = r.get(
f"https://cloud.iexapis.com/stable/stock/market/list/mostactive?token={self.IEX_TOKEN}"
f"https://cloud.iexapis.com/stable/stock/market/list/mostactive?token={self.IEX_TOKEN}",
timeout=5,
).json()
return [f"${s['symbol']}: {s['companyName']}" for s in stocks]