mirror of
https://gitlab.com/simple-stock-bots/simple-telegram-stock-bot.git
synced 2025-06-16 06:56:46 +00:00
Resolve "Remove binance-peg crypto"
This commit is contained in:
parent
2bb825d721
commit
ccc44bfa21
44
Symbol.py
44
Symbol.py
@ -1,6 +1,5 @@
|
||||
import functools
|
||||
|
||||
import requests as r
|
||||
import pandas as pd
|
||||
import logging
|
||||
|
||||
|
||||
class Symbol:
|
||||
@ -30,33 +29,26 @@ class Symbol:
|
||||
class Stock(Symbol):
|
||||
"""Stock Market Object. Gets data from IEX Cloud"""
|
||||
|
||||
def __init__(self, symbol: str) -> None:
|
||||
self.symbol = symbol
|
||||
self.id = symbol
|
||||
self.name = "$" + symbol.upper()
|
||||
self.tag = "$" + symbol.upper()
|
||||
def __init__(self, symbol: pd.DataFrame) -> None:
|
||||
if len(symbol) > 1:
|
||||
logging.info(f"Crypto with shared id:\n\t{symbol.id}")
|
||||
symbol = symbol.head(1)
|
||||
|
||||
|
||||
# Used by Coin to change symbols for ids
|
||||
coins = r.get("https://api.coingecko.com/api/v3/coins/list").json()
|
||||
self.symbol = symbol.symbol.values[0]
|
||||
self.id = symbol.id.values[0]
|
||||
self.name = symbol.name.values[0]
|
||||
self.tag = symbol.type_id.values[0].upper()
|
||||
|
||||
|
||||
class Coin(Symbol):
|
||||
"""Cryptocurrency Object. Gets data from CoinGecko."""
|
||||
|
||||
@functools.cache
|
||||
def __init__(self, symbol: str) -> None:
|
||||
self.symbol = symbol
|
||||
self.tag = "$$" + symbol.upper()
|
||||
self.get_data()
|
||||
def __init__(self, symbol: pd.DataFrame) -> None:
|
||||
if len(symbol) > 1:
|
||||
logging.info(f"Crypto with shared id:\n\t{symbol.id}")
|
||||
symbol = symbol.head(1)
|
||||
|
||||
def get_data(self) -> None:
|
||||
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()
|
||||
self.data = data
|
||||
|
||||
self.name = data["name"]
|
||||
self.description = data["description"]
|
||||
# self.price = data["market_data"]["current_price"][self.currency]
|
||||
self.symbol = symbol.symbol.values[0]
|
||||
self.id = symbol.id.values[0]
|
||||
self.name = symbol.name.values[0]
|
||||
self.tag = symbol.type_id.values[0].upper()
|
||||
|
21
T_info.py
21
T_info.py
@ -73,24 +73,3 @@ trending - Trending Stocks and Cryptos. 💬
|
||||
intra - $[symbol] Plot since the last market open. 📈
|
||||
chart - $[chart] Plot of the past month. 📊
|
||||
""" # Not used by the bot but for updaing commands with BotFather
|
||||
|
||||
|
||||
tests = """
|
||||
/info $tsla
|
||||
/info $$btc
|
||||
/news $tsla
|
||||
/news $$btc
|
||||
/stat $tsla
|
||||
/stat $$btc
|
||||
/cap $tsla
|
||||
/cap $$btc
|
||||
/dividend $tsla
|
||||
/dividend $msft
|
||||
/dividend $$btc
|
||||
/intra $tsla
|
||||
/intra $$btc
|
||||
/chart $tsla
|
||||
/chart $$btc
|
||||
/help
|
||||
/trending
|
||||
"""
|
||||
|
@ -69,6 +69,9 @@ class cg_Crypto:
|
||||
raw_symbols = self.get("/coins/list")
|
||||
symbols = pd.DataFrame(data=raw_symbols)
|
||||
|
||||
# Removes all binance-peg symbols
|
||||
symbols = symbols[~symbols["id"].str.contains("binance-peg")]
|
||||
|
||||
symbols["description"] = (
|
||||
"$$" + symbols["symbol"].str.upper() + ": " + symbols["name"]
|
||||
)
|
||||
|
@ -2,6 +2,7 @@
|
||||
"""
|
||||
|
||||
import datetime
|
||||
import logging
|
||||
import random
|
||||
import re
|
||||
from logging import critical, debug, error, info, warning
|
||||
@ -63,18 +64,26 @@ class Router:
|
||||
symbols = []
|
||||
stocks = set(re.findall(self.STOCK_REGEX, text))
|
||||
for stock in stocks:
|
||||
if stock.upper() in self.stock.symbol_list["symbol"].values:
|
||||
symbols.append(Stock(stock))
|
||||
sym = self.stock.symbol_list[
|
||||
self.stock.symbol_list["symbol"].str.fullmatch(stock, case=False)
|
||||
]
|
||||
if ~sym.empty:
|
||||
print(sym)
|
||||
symbols.append(Stock(sym))
|
||||
else:
|
||||
info(f"{stock} is not in list of stocks")
|
||||
|
||||
coins = set(re.findall(self.CRYPTO_REGEX, text))
|
||||
for coin in coins:
|
||||
if coin.lower() in self.crypto.symbol_list["symbol"].values:
|
||||
symbols.append(Coin(coin.lower()))
|
||||
sym = self.crypto.symbol_list[
|
||||
self.crypto.symbol_list["symbol"].str.fullmatch(
|
||||
coin.lower(), case=False
|
||||
)
|
||||
]
|
||||
if ~sym.empty:
|
||||
symbols.append(Coin(sym))
|
||||
else:
|
||||
info(f"{coin} is not in list of coins")
|
||||
|
||||
if symbols:
|
||||
info(symbols)
|
||||
for symbol in symbols:
|
||||
|
33
tests.py
Normal file
33
tests.py
Normal file
@ -0,0 +1,33 @@
|
||||
import keyboard
|
||||
import time
|
||||
|
||||
|
||||
tests = """$$xno
|
||||
/info $tsla
|
||||
/info $$btc
|
||||
/news $tsla
|
||||
/news $$btc
|
||||
/stat $tsla
|
||||
/stat $$btc
|
||||
/cap $tsla
|
||||
/cap $$btc
|
||||
/dividend $tsla
|
||||
/dividend $msft
|
||||
/dividend $$btc
|
||||
/intra $tsla
|
||||
/intra $$btc
|
||||
/chart $tsla
|
||||
/chart $$btc
|
||||
/help
|
||||
/trending""".split(
|
||||
"\n"
|
||||
)
|
||||
|
||||
print("press enter to start")
|
||||
keyboard.wait("enter")
|
||||
|
||||
for test in tests:
|
||||
print(test)
|
||||
keyboard.write(test)
|
||||
time.sleep(1)
|
||||
keyboard.press_and_release("enter")
|
Loading…
x
Reference in New Issue
Block a user