Skip to content

Interfaces API Reference

Abstract base classes defining contracts for extensibility.

financelib.interfaces.BaseDataFetcher

Bases: ABC

Interface for all data fetching implementations.

Any data source (Yahoo Finance, Binance, custom APIs) should implement this interface.

Functions

fetch_historical(symbol: str, period: str = '1mo', interval: str = '1d') -> Optional[pd.DataFrame] abstractmethod

Fetch historical OHLCV data.

Source code in financelib/interfaces.py
@abstractmethod
def fetch_historical(
    self, symbol: str, period: str = "1mo", interval: str = "1d"
) -> Optional[pd.DataFrame]:
    """Fetch historical OHLCV data."""
    ...

fetch_price(symbol: str) -> Optional[float] abstractmethod

Fetch the current price for a symbol.

Source code in financelib/interfaces.py
@abstractmethod
def fetch_price(self, symbol: str) -> Optional[float]:
    """Fetch the current price for a symbol."""
    ...

financelib.interfaces.BaseStrategy

Bases: ABC

Interface for all trading strategies.

Strategies analyze market data and produce trading signals.

Functions

analyze(symbol: str, **kwargs: Any) -> Optional[Dict[str, Any]] abstractmethod

Analyze a symbol and return analysis results with signals.

Source code in financelib/interfaces.py
@abstractmethod
def analyze(self, symbol: str, **kwargs: Any) -> Optional[Dict[str, Any]]:
    """Analyze a symbol and return analysis results with signals."""
    ...

generate_signal(data: pd.DataFrame) -> str abstractmethod

Generate a trading signal from data. Returns 'BUY', 'SELL', or 'HOLD'.

Source code in financelib/interfaces.py
@abstractmethod
def generate_signal(self, data: pd.DataFrame) -> str:
    """Generate a trading signal from data. Returns 'BUY', 'SELL', or 'HOLD'."""
    ...

financelib.interfaces.BaseDatabaseBackend

Bases: ABC

Interface for all database backends (SQLite, PostgreSQL, etc.).

Functions

close() -> None abstractmethod

Close the database connection.

Source code in financelib/interfaces.py
@abstractmethod
def close(self) -> None:
    """Close the database connection."""
    ...

execute(query: str, params: Optional[tuple] = None) -> None abstractmethod

Execute an arbitrary SQL query.

Source code in financelib/interfaces.py
@abstractmethod
def execute(self, query: str, params: Optional[tuple] = None) -> None:
    """Execute an arbitrary SQL query."""
    ...

fetchall(query: str, params: Optional[tuple] = None) -> List[Tuple] abstractmethod

Execute a query and return all results.

Source code in financelib/interfaces.py
@abstractmethod
def fetchall(self, query: str, params: Optional[tuple] = None) -> List[Tuple]:
    """Execute a query and return all results."""
    ...

fetchone(query: str, params: Optional[tuple] = None) -> Optional[Tuple] abstractmethod

Execute a query and return the first result.

Source code in financelib/interfaces.py
@abstractmethod
def fetchone(self, query: str, params: Optional[tuple] = None) -> Optional[Tuple]:
    """Execute a query and return the first result."""
    ...

insert_article(news: Any) -> None abstractmethod

Insert a single news article.

Source code in financelib/interfaces.py
@abstractmethod
def insert_article(self, news: Any) -> None:
    """Insert a single news article."""
    ...

insert_stock_data(stock_data: Any) -> None abstractmethod

Insert stock data.

Source code in financelib/interfaces.py
@abstractmethod
def insert_stock_data(self, stock_data: Any) -> None:
    """Insert stock data."""
    ...

financelib.interfaces.BaseCacheBackend

Bases: ABC

Interface for cache backends (memory, Redis, etc.).

Functions

clear() -> None abstractmethod

Clear all cached entries.

Source code in financelib/interfaces.py
@abstractmethod
def clear(self) -> None:
    """Clear all cached entries."""
    ...

delete(key: str) -> bool abstractmethod

Delete a key. Returns True if the key existed.

Source code in financelib/interfaces.py
@abstractmethod
def delete(self, key: str) -> bool:
    """Delete a key. Returns True if the key existed."""
    ...

get(key: str) -> Optional[Any] abstractmethod

Get a value by key. Returns None if not found or expired.

Source code in financelib/interfaces.py
@abstractmethod
def get(self, key: str) -> Optional[Any]:
    """Get a value by key. Returns None if not found or expired."""
    ...

set(key: str, value: Any, ttl: Optional[int] = None) -> None abstractmethod

Set a value with optional TTL in seconds.

Source code in financelib/interfaces.py
@abstractmethod
def set(self, key: str, value: Any, ttl: Optional[int] = None) -> None:
    """Set a value with optional TTL in seconds."""
    ...