Stock API Reference¶
financelib.stock.client.Stock(symbol: str)
¶
Stock data fetcher and display utility.
Provides methods for fetching real-time stock prices, searching stocks by symbol or company name, and displaying formatted stock information.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
symbol
|
str
|
Stock ticker symbol (e.g., 'THYAO.IS', 'AAPL'). |
required |
Attributes:
| Name | Type | Description |
|---|---|---|
symbol |
Uppercase stock ticker symbol. |
|
COMMON_STOCKS |
Dict[str, str]
|
Dictionary of common BIST stock symbols and names. |
Example
stock = Stock("THYAO.IS") data = stock.get_data() Stock.search_stock("Garanti")
Initialize stock with symbol.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
symbol
|
str
|
Stock ticker symbol. |
required |
Source code in financelib/stock/client.py
Functions¶
display_stock_info(company_name: str, return_info: bool = False) -> Optional[List[Dict[str, Any]]]
classmethod
¶
Display detailed stock information for a company.
Searches by company name, fetches full info from Yahoo Finance, and either prints or returns the results.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
company_name
|
str
|
Company name or stock symbol to search for. |
required |
return_info
|
bool
|
If True, return data instead of printing. |
False
|
Returns:
| Type | Description |
|---|---|
Optional[List[Dict[str, Any]]]
|
List of stock info dictionaries if return_info is True, else None. |
Source code in financelib/stock/client.py
display_stock_infos(query_list: List[str], return_info: bool = False) -> Optional[List[Dict[str, Any]]]
classmethod
¶
Display information for multiple stocks.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
query_list
|
List[str]
|
List of company names or symbols to look up. |
required |
return_info
|
bool
|
If True, return the data instead of printing. |
False
|
Returns:
| Type | Description |
|---|---|
Optional[List[Dict[str, Any]]]
|
List of stock info dicts if return_info is True, else None. |
Source code in financelib/stock/client.py
get_data() -> Dict[str, Any]
¶
Get current stock quote data from Yahoo Finance.
Returns:
| Type | Description |
|---|---|
Dict[str, Any]
|
Dictionary containing quote data (symbol, exchange, score, etc.). |
Raises:
| Type | Description |
|---|---|
InvalidSymbolError
|
If symbol is empty or no match is found. |
Source code in financelib/stock/client.py
get_historical_data(period: str = '1mo', interval: str = '1d') -> Optional[pd.DataFrame]
¶
Get historical price data.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
period
|
str
|
Data period (e.g., '1d', '5d', '1mo', '3mo', '1y'). |
'1mo'
|
interval
|
str
|
Data interval (e.g., '1m', '5m', '1h', '1d'). |
'1d'
|
Returns:
| Type | Description |
|---|---|
Optional[DataFrame]
|
DataFrame with OHLCV data, or None on failure. |
Source code in financelib/stock/client.py
get_live_stock_state(symbol: str) -> None
classmethod
¶
Display real-time stock price with colored terminal output.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
symbol
|
str
|
Stock ticker symbol (Yahoo Finance format, e.g., 'THYAO.IS'). |
required |
Source code in financelib/stock/client.py
get_price_data() -> Optional[Dict[str, Any]]
¶
Get current price, change, and volume data.
Returns:
| Type | Description |
|---|---|
Optional[Dict[str, Any]]
|
Dictionary with price data or None if fetch fails. |
search_stock(company_name: str) -> Dict[str, Any]
classmethod
¶
Search for a stock by company name or symbol.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
company_name
|
str
|
Company name or stock symbol to search. |
required |
Returns:
| Type | Description |
|---|---|
Dict[str, Any]
|
Dictionary with the first matching stock's data, |
Dict[str, Any]
|
or an error dict if no match is found. |