Functional Discord bot with automated hourly stock price updates during NYSE trading hours. Supports manual queries for any ticker via prefix commands. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
40 lines
1.1 KiB
Python
40 lines
1.1 KiB
Python
from abc import ABC, abstractmethod
|
|
from typing import Optional, Dict, Any
|
|
|
|
|
|
class StockAPIBase(ABC):
|
|
"""
|
|
Abstract base class for stock price data providers.
|
|
This design allows seamless switching between different stock APIs.
|
|
"""
|
|
|
|
@abstractmethod
|
|
def get_stock_price(self, ticker: str) -> Optional[Dict[str, Any]]:
|
|
"""
|
|
Retrieve current stock price and related data for a given ticker.
|
|
|
|
Args:
|
|
ticker: Stock ticker symbol (e.g., 'PYPL', 'AAPL')
|
|
|
|
Returns:
|
|
Dictionary containing:
|
|
- ticker: str
|
|
- current_price: float
|
|
- previous_close: float
|
|
- change_dollar: float
|
|
- change_percent: float
|
|
- market_open: bool
|
|
Returns None if ticker is invalid or data unavailable.
|
|
"""
|
|
pass
|
|
|
|
@abstractmethod
|
|
def is_available(self) -> bool:
|
|
"""
|
|
Check if the API service is currently available.
|
|
|
|
Returns:
|
|
True if API is accessible, False otherwise.
|
|
"""
|
|
pass
|