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 pandas as pd
|
||||||
|
import logging
|
||||||
import requests as r
|
|
||||||
|
|
||||||
|
|
||||||
class Symbol:
|
class Symbol:
|
||||||
@ -30,33 +29,26 @@ class Symbol:
|
|||||||
class Stock(Symbol):
|
class Stock(Symbol):
|
||||||
"""Stock Market Object. Gets data from IEX Cloud"""
|
"""Stock Market Object. Gets data from IEX Cloud"""
|
||||||
|
|
||||||
def __init__(self, symbol: str) -> None:
|
def __init__(self, symbol: pd.DataFrame) -> None:
|
||||||
self.symbol = symbol
|
if len(symbol) > 1:
|
||||||
self.id = symbol
|
logging.info(f"Crypto with shared id:\n\t{symbol.id}")
|
||||||
self.name = "$" + symbol.upper()
|
symbol = symbol.head(1)
|
||||||
self.tag = "$" + symbol.upper()
|
|
||||||
|
|
||||||
|
self.symbol = symbol.symbol.values[0]
|
||||||
# Used by Coin to change symbols for ids
|
self.id = symbol.id.values[0]
|
||||||
coins = r.get("https://api.coingecko.com/api/v3/coins/list").json()
|
self.name = symbol.name.values[0]
|
||||||
|
self.tag = symbol.type_id.values[0].upper()
|
||||||
|
|
||||||
|
|
||||||
class Coin(Symbol):
|
class Coin(Symbol):
|
||||||
"""Cryptocurrency Object. Gets data from CoinGecko."""
|
"""Cryptocurrency Object. Gets data from CoinGecko."""
|
||||||
|
|
||||||
@functools.cache
|
def __init__(self, symbol: pd.DataFrame) -> None:
|
||||||
def __init__(self, symbol: str) -> None:
|
if len(symbol) > 1:
|
||||||
self.symbol = symbol
|
logging.info(f"Crypto with shared id:\n\t{symbol.id}")
|
||||||
self.tag = "$$" + symbol.upper()
|
symbol = symbol.head(1)
|
||||||
self.get_data()
|
|
||||||
|
|
||||||
def get_data(self) -> None:
|
self.symbol = symbol.symbol.values[0]
|
||||||
self.id = list(filter(lambda coin: coin["symbol"] == self.symbol, coins))[0][
|
self.id = symbol.id.values[0]
|
||||||
"id"
|
self.name = symbol.name.values[0]
|
||||||
]
|
self.tag = symbol.type_id.values[0].upper()
|
||||||
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]
|
|
||||||
|
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. 📈
|
intra - $[symbol] Plot since the last market open. 📈
|
||||||
chart - $[chart] Plot of the past month. 📊
|
chart - $[chart] Plot of the past month. 📊
|
||||||
""" # Not used by the bot but for updaing commands with BotFather
|
""" # 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")
|
raw_symbols = self.get("/coins/list")
|
||||||
symbols = pd.DataFrame(data=raw_symbols)
|
symbols = pd.DataFrame(data=raw_symbols)
|
||||||
|
|
||||||
|
# Removes all binance-peg symbols
|
||||||
|
symbols = symbols[~symbols["id"].str.contains("binance-peg")]
|
||||||
|
|
||||||
symbols["description"] = (
|
symbols["description"] = (
|
||||||
"$$" + symbols["symbol"].str.upper() + ": " + symbols["name"]
|
"$$" + symbols["symbol"].str.upper() + ": " + symbols["name"]
|
||||||
)
|
)
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
import datetime
|
import datetime
|
||||||
|
import logging
|
||||||
import random
|
import random
|
||||||
import re
|
import re
|
||||||
from logging import critical, debug, error, info, warning
|
from logging import critical, debug, error, info, warning
|
||||||
@ -63,18 +64,26 @@ class Router:
|
|||||||
symbols = []
|
symbols = []
|
||||||
stocks = set(re.findall(self.STOCK_REGEX, text))
|
stocks = set(re.findall(self.STOCK_REGEX, text))
|
||||||
for stock in stocks:
|
for stock in stocks:
|
||||||
if stock.upper() in self.stock.symbol_list["symbol"].values:
|
sym = self.stock.symbol_list[
|
||||||
symbols.append(Stock(stock))
|
self.stock.symbol_list["symbol"].str.fullmatch(stock, case=False)
|
||||||
|
]
|
||||||
|
if ~sym.empty:
|
||||||
|
print(sym)
|
||||||
|
symbols.append(Stock(sym))
|
||||||
else:
|
else:
|
||||||
info(f"{stock} is not in list of stocks")
|
info(f"{stock} is not in list of stocks")
|
||||||
|
|
||||||
coins = set(re.findall(self.CRYPTO_REGEX, text))
|
coins = set(re.findall(self.CRYPTO_REGEX, text))
|
||||||
for coin in coins:
|
for coin in coins:
|
||||||
if coin.lower() in self.crypto.symbol_list["symbol"].values:
|
sym = self.crypto.symbol_list[
|
||||||
symbols.append(Coin(coin.lower()))
|
self.crypto.symbol_list["symbol"].str.fullmatch(
|
||||||
|
coin.lower(), case=False
|
||||||
|
)
|
||||||
|
]
|
||||||
|
if ~sym.empty:
|
||||||
|
symbols.append(Coin(sym))
|
||||||
else:
|
else:
|
||||||
info(f"{coin} is not in list of coins")
|
info(f"{coin} is not in list of coins")
|
||||||
|
|
||||||
if symbols:
|
if symbols:
|
||||||
info(symbols)
|
info(symbols)
|
||||||
for symbol in 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