mirror of
https://gitlab.com/simple-stock-bots/simple-discord-stock-bot.git
synced 2025-08-02 19:41:37 +00:00
updated to newest version of discord and bot files
This commit is contained in:
44
Symbol.py
44
Symbol.py
@@ -1,6 +1,5 @@
|
||||
import functools
|
||||
|
||||
import requests as r
|
||||
import pandas as pd
|
||||
import logging
|
||||
|
||||
|
||||
class Symbol:
|
||||
@@ -8,6 +7,7 @@ class Symbol:
|
||||
symbol: What the user calls it. ie tsla or btc
|
||||
id: What the api expects. ie tsla or bitcoin
|
||||
name: Human readable. ie Tesla or Bitcoin
|
||||
tag: Uppercase tag to call the symbol. ie $TSLA or $$BTC
|
||||
"""
|
||||
|
||||
currency = "usd"
|
||||
@@ -17,6 +17,7 @@ class Symbol:
|
||||
self.symbol = symbol
|
||||
self.id = symbol
|
||||
self.name = symbol
|
||||
self.tag = "$" + symbol
|
||||
|
||||
def __repr__(self) -> str:
|
||||
return f"<{self.__class__.__name__} instance of {self.id} at {id(self)}>"
|
||||
@@ -28,31 +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()
|
||||
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.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()
|
||||
|
Reference in New Issue
Block a user