Utilities API Reference¶
financelib.utils
¶
Utility functions for FinanceLib.
Functions¶
format_currency(amount: float, currency: str = 'TRY', decimals: int = 2) -> str
¶
Format a number as currency.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
amount
|
float
|
The monetary amount. |
required |
currency
|
str
|
Currency code (e.g., 'TRY', 'USD'). |
'TRY'
|
decimals
|
int
|
Number of decimal places. |
2
|
Returns:
| Type | Description |
|---|---|
str
|
Formatted string like '1,234.56 TRY'. |
Source code in financelib/utils.py
format_percentage(value: float, decimals: int = 2) -> str
¶
Format a number as a percentage string.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value
|
float
|
The percentage value. |
required |
decimals
|
int
|
Number of decimal places. |
2
|
Returns:
| Type | Description |
|---|---|
str
|
Formatted string like '+1.44%' or '-2.30%'. |
Source code in financelib/utils.py
get_today() -> datetime.datetime
¶
get_yesterday() -> datetime.datetime
¶
rate_limiter(calls: int = 1, period: float = 1.0) -> Callable[[F], F]
¶
Thread-safe rate limiter decorator.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
calls
|
int
|
Maximum number of calls allowed per period. |
1
|
period
|
float
|
Time period in seconds. |
1.0
|
Returns:
| Type | Description |
|---|---|
Callable[[F], F]
|
Decorated function. |
Source code in financelib/utils.py
retry(max_retries: int = 3, delay: float = 1.0, backoff: float = 2.0, exceptions: tuple = (Exception,)) -> Callable[[F], F]
¶
Retry decorator with exponential backoff.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
max_retries
|
int
|
Maximum number of retry attempts. |
3
|
delay
|
float
|
Initial delay between retries in seconds. |
1.0
|
backoff
|
float
|
Multiplier applied to delay after each retry. |
2.0
|
exceptions
|
tuple
|
Tuple of exception types to catch. |
(Exception,)
|
Returns:
| Type | Description |
|---|---|
Callable[[F], F]
|
Decorated function. |
Source code in financelib/utils.py
today_str() -> str
¶
today_str_dmy() -> str
¶
today_str_slash() -> str
¶
today_str_slash_dmy() -> str
¶
today_str_underline() -> str
¶
validate_stock_symbol(symbol: str) -> bool
¶
Validate that a stock symbol is in the expected format.
Accepts symbols like 'THYAO', 'THYAO.IS', 'AAPL', 'GOOG'.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
symbol
|
str
|
The stock symbol to validate. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True if the symbol matches expected format, False otherwise. |