mirror of
https://gitlab.com/simple-stock-bots/simple-telegram-stock-bot.git
synced 2025-06-16 15:06:53 +00:00
#31 just need to fix bugs from Main
This commit is contained in:
parent
e1ed5fbf57
commit
6ab7f2c25d
@ -10,7 +10,7 @@ import schedule
|
|||||||
from fuzzywuzzy import fuzz
|
from fuzzywuzzy import fuzz
|
||||||
import os
|
import os
|
||||||
|
|
||||||
from symbol_router import Stock
|
from Symbol import Stock
|
||||||
|
|
||||||
|
|
||||||
class IEX_Symbol:
|
class IEX_Symbol:
|
||||||
|
10
Symbol.py
10
Symbol.py
@ -1,5 +1,4 @@
|
|||||||
import requests as r
|
import requests as r
|
||||||
from cg_Crypto import cg_Crypto
|
|
||||||
|
|
||||||
|
|
||||||
class Symbol:
|
class Symbol:
|
||||||
@ -28,10 +27,11 @@ class Stock(Symbol):
|
|||||||
def __init__(self, symbol: str) -> None:
|
def __init__(self, symbol: str) -> None:
|
||||||
self.symbol = symbol
|
self.symbol = symbol
|
||||||
self.id = symbol
|
self.id = symbol
|
||||||
|
self.name = "$" + symbol.upper()
|
||||||
|
|
||||||
|
|
||||||
# This is so every Coin instance doesnt have to download entire list of coin symbols and id's
|
# Used by Coin to change symbols for ids
|
||||||
cg = cg_Crypto()
|
coins = r.get("https://api.coingecko.com/api/v3/coins/list").json()
|
||||||
|
|
||||||
|
|
||||||
class Coin(Symbol):
|
class Coin(Symbol):
|
||||||
@ -40,7 +40,9 @@ class Coin(Symbol):
|
|||||||
self.get_data()
|
self.get_data()
|
||||||
|
|
||||||
def get_data(self) -> None:
|
def get_data(self) -> None:
|
||||||
self.id = cg.symbol_id(self.symbol)
|
self.id = list(filter(lambda coin: coin["symbol"] == self.symbol, coins))[0][
|
||||||
|
"id"
|
||||||
|
]
|
||||||
data = r.get("https://api.coingecko.com/api/v3/coins/" + self.id).json()
|
data = r.get("https://api.coingecko.com/api/v3/coins/" + self.id).json()
|
||||||
self.data = data
|
self.data = data
|
||||||
|
|
||||||
|
11
bot.py
11
bot.py
@ -260,7 +260,7 @@ def intra(update: Update, context: CallbackContext):
|
|||||||
mpf.plot(
|
mpf.plot(
|
||||||
df,
|
df,
|
||||||
type="renko",
|
type="renko",
|
||||||
title=f"\n${symbol.name}",
|
title=f"\n{symbol.name}",
|
||||||
volume="volume" in df.keys(),
|
volume="volume" in df.keys(),
|
||||||
style="yahoo",
|
style="yahoo",
|
||||||
mav=20,
|
mav=20,
|
||||||
@ -270,7 +270,7 @@ def intra(update: Update, context: CallbackContext):
|
|||||||
|
|
||||||
update.message.reply_photo(
|
update.message.reply_photo(
|
||||||
photo=buf,
|
photo=buf,
|
||||||
caption=f"\nIntraday chart for ${symbol.name} from {df.first_valid_index().strftime('%I:%M')} to"
|
caption=f"\nIntraday chart for {symbol.name} from {df.first_valid_index().strftime('%I:%M')} to"
|
||||||
+ f" {df.last_valid_index().strftime('%I:%M')} ET on"
|
+ f" {df.last_valid_index().strftime('%I:%M')} ET on"
|
||||||
+ f" {datetime.date.today().strftime('%d, %b %Y')}\n\n{s.price_reply([symbol])[0]}",
|
+ f" {datetime.date.today().strftime('%d, %b %Y')}\n\n{s.price_reply([symbol])[0]}",
|
||||||
parse_mode=telegram.ParseMode.MARKDOWN,
|
parse_mode=telegram.ParseMode.MARKDOWN,
|
||||||
@ -298,7 +298,6 @@ def chart(update: Update, context: CallbackContext):
|
|||||||
parse_mode=telegram.ParseMode.MARKDOWN,
|
parse_mode=telegram.ParseMode.MARKDOWN,
|
||||||
)
|
)
|
||||||
return
|
return
|
||||||
|
|
||||||
context.bot.send_chat_action(
|
context.bot.send_chat_action(
|
||||||
chat_id=chat_id, action=telegram.ChatAction.UPLOAD_PHOTO
|
chat_id=chat_id, action=telegram.ChatAction.UPLOAD_PHOTO
|
||||||
)
|
)
|
||||||
@ -307,7 +306,7 @@ def chart(update: Update, context: CallbackContext):
|
|||||||
mpf.plot(
|
mpf.plot(
|
||||||
df,
|
df,
|
||||||
type="candle",
|
type="candle",
|
||||||
title=f"\n${symbol.name}",
|
title=f"\n{symbol.name}",
|
||||||
volume="volume" in df.keys(),
|
volume="volume" in df.keys(),
|
||||||
style="yahoo",
|
style="yahoo",
|
||||||
savefig=dict(fname=buf, dpi=400, bbox_inches="tight"),
|
savefig=dict(fname=buf, dpi=400, bbox_inches="tight"),
|
||||||
@ -316,7 +315,7 @@ def chart(update: Update, context: CallbackContext):
|
|||||||
|
|
||||||
update.message.reply_photo(
|
update.message.reply_photo(
|
||||||
photo=buf,
|
photo=buf,
|
||||||
caption=f"\n1 Month chart for ${symbol.name} from {df.first_valid_index().strftime('%d, %b %Y')}"
|
caption=f"\n1 Month chart for {symbol.name} from {df.first_valid_index().strftime('%d, %b %Y')}"
|
||||||
+ f" to {df.last_valid_index().strftime('%d, %b %Y')}\n\n{s.price_reply([symbol])[0]}",
|
+ f" to {df.last_valid_index().strftime('%d, %b %Y')}\n\n{s.price_reply([symbol])[0]}",
|
||||||
parse_mode=telegram.ParseMode.MARKDOWN,
|
parse_mode=telegram.ParseMode.MARKDOWN,
|
||||||
)
|
)
|
||||||
@ -406,8 +405,6 @@ def error(update: Update, context: CallbackContext):
|
|||||||
# Finally, send the message
|
# Finally, send the message
|
||||||
update.message.reply_text(text=message, parse_mode=telegram.ParseMode.HTML)
|
update.message.reply_text(text=message, parse_mode=telegram.ParseMode.HTML)
|
||||||
update.message.reply_text(text="Please inform the bot admin of this issue.")
|
update.message.reply_text(text="Please inform the bot admin of this issue.")
|
||||||
print("-" * 50)
|
|
||||||
print(tb_string)
|
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
|
14
cg_Crypto.py
14
cg_Crypto.py
@ -9,7 +9,7 @@ import requests as r
|
|||||||
import schedule
|
import schedule
|
||||||
from fuzzywuzzy import fuzz
|
from fuzzywuzzy import fuzz
|
||||||
from markdownify import markdownify
|
from markdownify import markdownify
|
||||||
from symbol_router import Coin
|
from Symbol import Coin
|
||||||
|
|
||||||
|
|
||||||
class cg_Crypto:
|
class cg_Crypto:
|
||||||
@ -163,7 +163,7 @@ 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(
|
||||||
"https://api.coingecko.com/api/v3/coins/{symbol}/ohlc?vs_currency=usd&days=1"
|
f"https://api.coingecko.com/api/v3/coins/{symbol.id}/ohlc?vs_currency=usd&days=1"
|
||||||
)
|
)
|
||||||
if response.status_code == 200:
|
if response.status_code == 200:
|
||||||
df = pd.DataFrame(
|
df = pd.DataFrame(
|
||||||
@ -190,9 +190,9 @@ 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(
|
||||||
"https://api.coingecko.com/api/v3/coins/{symbol}/ohlc?vs_currency=usd&days=30"
|
f"https://api.coingecko.com/api/v3/coins/{symbol.id}/ohlc?vs_currency=usd&days=30"
|
||||||
)
|
)
|
||||||
print(response.status_code)
|
|
||||||
if response.status_code == 200:
|
if response.status_code == 200:
|
||||||
df = pd.DataFrame(
|
df = pd.DataFrame(
|
||||||
response.json(), columns=["Date", "Open", "High", "Low", "Close"]
|
response.json(), columns=["Date", "Open", "High", "Low", "Close"]
|
||||||
@ -217,7 +217,7 @@ 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}?localization=false"
|
f"https://api.coingecko.com/api/v3/coins/{symbol.id}?localization=false"
|
||||||
)
|
)
|
||||||
if response.status_code == 200:
|
if response.status_code == 200:
|
||||||
data = response.json()
|
data = response.json()
|
||||||
@ -249,12 +249,12 @@ class cg_Crypto:
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
response = r.get(
|
response = r.get(
|
||||||
f"https://api.coingecko.com/api/v3/coins/{symbol}?localization=false"
|
f"https://api.coingecko.com/api/v3/coins/{symbol.id}?localization=false"
|
||||||
)
|
)
|
||||||
if response.status_code == 200:
|
if response.status_code == 200:
|
||||||
data = response.json()
|
data = response.json()
|
||||||
try:
|
try:
|
||||||
return markdownify(data["description"])
|
return markdownify(data["description"]["en"])
|
||||||
except KeyError:
|
except KeyError:
|
||||||
return f"{symbol} does not have a description available."
|
return f"{symbol} does not have a description available."
|
||||||
|
|
||||||
|
@ -51,7 +51,7 @@ class Router:
|
|||||||
symbols.append(Coin(coin.lower()))
|
symbols.append(Coin(coin.lower()))
|
||||||
else:
|
else:
|
||||||
print(f"{coin} is not in list of coins")
|
print(f"{coin} is not in list of coins")
|
||||||
|
print(symbols)
|
||||||
return symbols
|
return symbols
|
||||||
|
|
||||||
def status(self) -> str:
|
def status(self) -> str:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user