mirror of
https://gitlab.com/simple-stock-bots/simple-telegram-stock-bot.git
synced 2025-06-16 15:06:53 +00:00
Close #66
This commit is contained in:
parent
610dbc3492
commit
f9b8921ba8
@ -55,10 +55,12 @@ class IEX_Symbol:
|
|||||||
) -> Optional[Tuple[pd.DataFrame, datetime]]:
|
) -> Optional[Tuple[pd.DataFrame, datetime]]:
|
||||||
|
|
||||||
reg_symbols = r.get(
|
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()
|
).json()
|
||||||
otc_symbols = r.get(
|
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()
|
).json()
|
||||||
|
|
||||||
reg = pd.DataFrame(data=reg_symbols)
|
reg = pd.DataFrame(data=reg_symbols)
|
||||||
@ -83,7 +85,10 @@ class IEX_Symbol:
|
|||||||
str
|
str
|
||||||
Human readable text on status of IEX API
|
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:
|
if resp.status_code == 200:
|
||||||
status = resp.json()["status"]
|
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}"
|
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:
|
if response.status_code == 200:
|
||||||
IEXData = response.json()
|
IEXData = response.json()
|
||||||
|
|
||||||
@ -226,7 +234,10 @@ class IEX_Symbol:
|
|||||||
return "OTC stocks do not currently support any commands."
|
return "OTC stocks do not currently support any commands."
|
||||||
|
|
||||||
IEXurl = f"https://cloud.iexapis.com/stable/stock/{symbol}/dividends/next?token={self.IEX_TOKEN}"
|
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():
|
if response.status_code == 200 and response.json():
|
||||||
IEXData = response.json()[0]
|
IEXData = response.json()[0]
|
||||||
keys = (
|
keys = (
|
||||||
@ -288,7 +299,10 @@ class IEX_Symbol:
|
|||||||
return "OTC stocks do not currently support any commands."
|
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}"
|
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:
|
if response.status_code == 200:
|
||||||
data = response.json()
|
data = response.json()
|
||||||
if data:
|
if data:
|
||||||
@ -324,7 +338,10 @@ class IEX_Symbol:
|
|||||||
return "OTC stocks do not currently support any commands."
|
return "OTC stocks do not currently support any commands."
|
||||||
|
|
||||||
IEXurl = f"https://cloud.iexapis.com/stable/stock/{symbol}/company?token={self.IEX_TOKEN}"
|
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:
|
if response.status_code == 200:
|
||||||
data = response.json()
|
data = response.json()
|
||||||
@ -352,7 +369,10 @@ class IEX_Symbol:
|
|||||||
return "OTC stocks do not currently support any commands."
|
return "OTC stocks do not currently support any commands."
|
||||||
|
|
||||||
IEXurl = f"https://cloud.iexapis.com/stable/stock/{symbol}/stats?token={self.IEX_TOKEN}"
|
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:
|
if response.status_code == 200:
|
||||||
data = response.json()
|
data = response.json()
|
||||||
@ -399,7 +419,10 @@ class IEX_Symbol:
|
|||||||
return pd.DataFrame()
|
return pd.DataFrame()
|
||||||
|
|
||||||
IEXurl = f"https://cloud.iexapis.com/stable/stock/{symbol}/intraday-prices?token={self.IEX_TOKEN}"
|
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:
|
if response.status_code == 200:
|
||||||
df = pd.DataFrame(response.json())
|
df = pd.DataFrame(response.json())
|
||||||
df.dropna(inplace=True, subset=["date", "minute", "high", "low", "volume"])
|
df.dropna(inplace=True, subset=["date", "minute", "high", "low", "volume"])
|
||||||
@ -437,7 +460,8 @@ class IEX_Symbol:
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
response = r.get(
|
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:
|
if response.status_code == 200:
|
||||||
@ -460,7 +484,8 @@ class IEX_Symbol:
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
stocks = r.get(
|
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()
|
).json()
|
||||||
|
|
||||||
return [f"${s['symbol']}: {s['companyName']}" for s in stocks]
|
return [f"${s['symbol']}: {s['companyName']}" for s in stocks]
|
||||||
|
35
cg_Crypto.py
35
cg_Crypto.py
@ -44,7 +44,10 @@ class cg_Crypto:
|
|||||||
self, return_df=False
|
self, return_df=False
|
||||||
) -> Optional[Tuple[pd.DataFrame, datetime]]:
|
) -> Optional[Tuple[pd.DataFrame, datetime]]:
|
||||||
|
|
||||||
raw_symbols = r.get("https://api.coingecko.com/api/v3/coins/list").json()
|
raw_symbols = r.get(
|
||||||
|
"https://api.coingecko.com/api/v3/coins/list",
|
||||||
|
timeout=5,
|
||||||
|
).json()
|
||||||
symbols = pd.DataFrame(data=raw_symbols)
|
symbols = pd.DataFrame(data=raw_symbols)
|
||||||
|
|
||||||
symbols["description"] = "$$" + symbols["symbol"] + ": " + symbols["name"]
|
symbols["description"] = "$$" + symbols["symbol"] + ": " + symbols["name"]
|
||||||
@ -62,7 +65,10 @@ class cg_Crypto:
|
|||||||
str
|
str
|
||||||
Human readable text on status of CoinGecko API
|
Human readable text on status of CoinGecko API
|
||||||
"""
|
"""
|
||||||
status = r.get("https://api.coingecko.com/api/v3/ping")
|
status = r.get(
|
||||||
|
"https://api.coingecko.com/api/v3/ping",
|
||||||
|
timeout=5,
|
||||||
|
)
|
||||||
|
|
||||||
if status.status_code == 200:
|
if status.status_code == 200:
|
||||||
return f"CoinGecko API responded that it was OK in {status.elapsed.total_seconds()} Seconds."
|
return f"CoinGecko API responded that it was OK in {status.elapsed.total_seconds()} Seconds."
|
||||||
@ -124,7 +130,8 @@ class cg_Crypto:
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
response = r.get(
|
response = r.get(
|
||||||
f"https://api.coingecko.com/api/v3/coins/{symbol.id}?localization=false"
|
f"https://api.coingecko.com/api/v3/coins/{symbol.id}?localization=false",
|
||||||
|
timeout=5,
|
||||||
)
|
)
|
||||||
if response.status_code == 200:
|
if response.status_code == 200:
|
||||||
data = response.json()
|
data = response.json()
|
||||||
@ -167,7 +174,8 @@ class cg_Crypto:
|
|||||||
Returns a timeseries dataframe with high, low, and volume data if its available. Otherwise returns empty pd.DataFrame.
|
Returns a timeseries dataframe with high, low, and volume data if its available. Otherwise returns empty pd.DataFrame.
|
||||||
"""
|
"""
|
||||||
response = r.get(
|
response = r.get(
|
||||||
f"https://api.coingecko.com/api/v3/coins/{symbol.id}/ohlc?vs_currency=usd&days=1"
|
f"https://api.coingecko.com/api/v3/coins/{symbol.id}/ohlc?vs_currency=usd&days=1",
|
||||||
|
timeout=5,
|
||||||
)
|
)
|
||||||
if response.status_code == 200:
|
if response.status_code == 200:
|
||||||
df = pd.DataFrame(
|
df = pd.DataFrame(
|
||||||
@ -194,7 +202,8 @@ class cg_Crypto:
|
|||||||
Returns a timeseries dataframe with high, low, and volume data if its available. Otherwise returns empty pd.DataFrame.
|
Returns a timeseries dataframe with high, low, and volume data if its available. Otherwise returns empty pd.DataFrame.
|
||||||
"""
|
"""
|
||||||
response = r.get(
|
response = r.get(
|
||||||
f"https://api.coingecko.com/api/v3/coins/{symbol.id}/ohlc?vs_currency=usd&days=30"
|
f"https://api.coingecko.com/api/v3/coins/{symbol.id}/ohlc?vs_currency=usd&days=30",
|
||||||
|
timeout=5,
|
||||||
)
|
)
|
||||||
|
|
||||||
if response.status_code == 200:
|
if response.status_code == 200:
|
||||||
@ -221,7 +230,8 @@ class cg_Crypto:
|
|||||||
Each symbol passed in is a key with its value being a human readable formatted string of the symbols statistics.
|
Each symbol passed in is a key with its value being a human readable formatted string of the symbols statistics.
|
||||||
"""
|
"""
|
||||||
response = r.get(
|
response = r.get(
|
||||||
f"https://api.coingecko.com/api/v3/coins/{symbol.id}?localization=false"
|
f"https://api.coingecko.com/api/v3/coins/{symbol.id}?localization=false",
|
||||||
|
timeout=5,
|
||||||
)
|
)
|
||||||
if response.status_code == 200:
|
if response.status_code == 200:
|
||||||
data = response.json()
|
data = response.json()
|
||||||
@ -253,7 +263,8 @@ class cg_Crypto:
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
response = r.get(
|
response = r.get(
|
||||||
f"https://api.coingecko.com/api/v3/coins/{symbol.id}?localization=false"
|
f"https://api.coingecko.com/api/v3/coins/{symbol.id}?localization=false",
|
||||||
|
timeout=5,
|
||||||
)
|
)
|
||||||
if response.status_code == 200:
|
if response.status_code == 200:
|
||||||
data = response.json()
|
data = response.json()
|
||||||
@ -273,9 +284,10 @@ class cg_Crypto:
|
|||||||
list of $$ID: NAME
|
list of $$ID: NAME
|
||||||
"""
|
"""
|
||||||
|
|
||||||
coins = r.get("https://api.coingecko.com/api/v3/search/trending").json()[
|
coins = r.get(
|
||||||
"coins"
|
"https://api.coingecko.com/api/v3/search/trending",
|
||||||
]
|
timeout=5,
|
||||||
|
).json()["coins"]
|
||||||
|
|
||||||
return [f"$${c['item']['symbol'].upper()}: {c['item']['name']}" for c in coins]
|
return [f"$${c['item']['symbol'].upper()}: {c['item']['name']}" for c in coins]
|
||||||
|
|
||||||
@ -283,7 +295,8 @@ class cg_Crypto:
|
|||||||
query = ",".join([c.id for c in coins])
|
query = ",".join([c.id for c in coins])
|
||||||
|
|
||||||
prices = r.get(
|
prices = r.get(
|
||||||
f"https://api.coingecko.com/api/v3/simple/price?ids={query}&vs_currencies=usd&include_24hr_change=true"
|
f"https://api.coingecko.com/api/v3/simple/price?ids={query}&vs_currencies=usd&include_24hr_change=true",
|
||||||
|
timeout=5,
|
||||||
).json()
|
).json()
|
||||||
|
|
||||||
replies = []
|
replies = []
|
||||||
|
Loading…
x
Reference in New Issue
Block a user