@@ -62,11 +62,6 @@ def load_bot_configs() -> list[BotConfig]:
6262DISPLAY_NAME_MAP = {}
6363
6464
65- def get_display_name (crypto : str ) -> str :
66- """Get display name for a ticker, using shorter aliases where defined."""
67- return DISPLAY_NAME_MAP .get (crypto .upper (), crypto .upper ())
68-
69-
7065def format_price (price : float ) -> str :
7166 """Format price for display."""
7267 if price >= 1000 :
@@ -77,13 +72,6 @@ def format_price(price: float) -> str:
7772 return f"${ price :.6f} "
7873
7974
80- def calculate_change_percent (current : float , previous : float ) -> float :
81- """Calculate percentage change."""
82- if previous <= 0 :
83- return 0.0
84- return ((current - previous ) / previous ) * 100
85-
86-
8775class PriceBot (discord .Client ):
8876 def __init__ (
8977 self ,
@@ -121,32 +109,22 @@ async def get_1h_change(self, crypto: str) -> float:
121109 if len (history ) >= 2 :
122110 oldest = history [0 ][1 ]
123111 newest = history [- 1 ][1 ]
124- return calculate_change_percent (newest , oldest )
112+ if oldest > 0 :
113+ return ((newest - oldest ) / oldest ) * 100
125114 except Exception as e :
126115 logger .debug (f"Could not get 1h change for { crypto } : { e } " )
127116 return 0.0
128117
129118 async def get_price_for_crypto (self , crypto : str ) -> Optional [float ]:
130- """Get price, using database fallback for SSILVER ."""
119+ """Get price, using database fallback if fetch fails ."""
131120 price = await self .price_service .get_price (crypto )
132-
133- if price is None or price <= 0 :
134- db_price = await self .db .get_latest_price (crypto )
135- if db_price and db_price > 0 :
136- logger .debug (f"Using cached { crypto } price: ${ db_price } " )
137- return db_price
138- return None
139-
140- if crypto == "SSILVER" and price < 10 :
141- db_price = await self .db .get_latest_price (crypto )
142- if db_price and db_price > 10 :
143- logger .debug (
144- f"SSILVER: Live price { price } seems low, using cached: ${ db_price } "
145- )
146- return db_price
147- logger .warning (f"SSILVER: Price { price } below threshold, using anyway" )
148-
149- return price
121+ if price and price > 0 :
122+ return price
123+ db_price = await self .db .get_latest_price (crypto )
124+ if db_price and db_price > 0 :
125+ logger .debug (f"Using cached { crypto } price: ${ db_price } " )
126+ return db_price
127+ return None
150128
151129 async def get_conversion_prices (self ) -> dict :
152130 """Get BTC, ETH, SOL prices for conversion."""
@@ -179,7 +157,7 @@ async def update_discord_presence(
179157 return
180158
181159 formatted_price = format_price (price )
182- nickname = f"{ get_display_name ( display_crypto )} { formatted_price } "
160+ nickname = f"{ display_crypto . upper ( )} { formatted_price } "
183161
184162 # Cycle through: BTC value, ETH value, SOL value, 1h%
185163 tickers = ["BTC" , "ETH" , "SOL" ]
@@ -258,44 +236,16 @@ async def update_loop():
258236
259237
260238class ChartGroup (app_commands .Group ):
261- TIMEFRAME_OPTIONS = {
239+ TIMEFRAMES = {
262240 "1h" : 1 ,
263- "1hr" : 1 ,
264- "1hour" : 1 ,
265241 "6h" : 6 ,
266- "6hr" : 6 ,
267- "6hour" : 6 ,
268242 "12h" : 12 ,
269- "12hr" : 12 ,
270- "12hour" : 12 ,
271243 "24h" : 24 ,
272- "1d" : 24 ,
273- "24hr" : 24 ,
274- "1day" : 24 ,
275- "48h" : 48 ,
276244 "2d" : 48 ,
277- "48hr" : 48 ,
278- "2day" : 48 ,
279- "168h" : 168 ,
280- "7d" : 168 ,
281245 "1w" : 168 ,
282- "1wk" : 168 ,
283- "1week" : 168 ,
284- "336h" : 336 ,
285- "14d" : 336 ,
286246 "2w" : 336 ,
287- "2wk" : 336 ,
288- "2week" : 336 ,
289- "720h" : 720 ,
290247 "30d" : 720 ,
291- "30day" : 720 ,
292- "1m" : 720 ,
293- "1month" : 720 ,
294- "2160h" : 2160 ,
295- "90d" : 2160 ,
296248 "3m" : 2160 ,
297- "3month" : 2160 ,
298- "90day" : 2160 ,
299249 }
300250
301251 def __init__ (self , db : Database , chart_service : ChartService , crypto_name : str ):
@@ -308,10 +258,10 @@ def __init__(self, db: Database, chart_service: ChartService, crypto_name: str):
308258 @app_commands .describe (timeframe = "Timeframe (e.g., 24h, 2d, 1w, 30d, 3m)" )
309259 async def price (self , interaction : discord .Interaction , timeframe : str = "24h" ):
310260 """Generate price chart."""
311- hours = self .TIMEFRAME_OPTIONS .get (timeframe .lower ())
261+ hours = self .TIMEFRAMES .get (timeframe .lower ())
312262 if not hours :
313263 await interaction .response .send_message (
314- f"Invalid timeframe ' { timeframe } ' . Try: 24h, 2d, 1w, 30d, 3m " ,
264+ f"Invalid timeframe. Try: { ', ' . join ( self . TIMEFRAMES . keys ()) } " ,
315265 ephemeral = True ,
316266 )
317267 return
@@ -321,7 +271,7 @@ async def price(self, interaction: discord.Interaction, timeframe: str = "24h"):
321271 async def timeframe_autocomplete (
322272 self , interaction : discord .Interaction , current : str
323273 ):
324- options = list (self .TIMEFRAME_OPTIONS .keys ())
274+ options = list (self .TIMEFRAMES .keys ())
325275 filtered = (
326276 [opt for opt in options if current .lower () in opt .lower ()]
327277 if current
0 commit comments