From bb44ee88c8a72e828ea8c08342749f4a0fc4c045 Mon Sep 17 00:00:00 2001 From: maoper Date: Sun, 23 Nov 2025 02:55:42 +0300 Subject: [PATCH] Update ticker_24hr_price_change.py --- .../market/ticker_24hr_price_change.py | 34 +++++++++++++++++-- 1 file changed, 31 insertions(+), 3 deletions(-) diff --git a/examples/rest_api/market/ticker_24hr_price_change.py b/examples/rest_api/market/ticker_24hr_price_change.py index 6532154..9ae51c6 100644 --- a/examples/rest_api/market/ticker_24hr_price_change.py +++ b/examples/rest_api/market/ticker_24hr_price_change.py @@ -1,8 +1,36 @@ import logging +import os +import sys +from typing import Optional, Any + +# Import from the custom library from aster.rest_api import Client from aster.lib.utils import config_logging -config_logging(logging, logging.DEBUG) +def setup_environment() -> int: + """ + Determines the logging level from environment variables. + Defaults to INFO if not specified. + """ + level_name = os.getenv("LOG_LEVEL", "INFO").upper() + return getattr(logging, level_name, logging.INFO) + +def fetch_ticker_data(client: Client, symbol: str) -> Optional[Any]: + """ + Safely fetches ticker data with error handling. + """ + try: + logging.info(f"Fetching 24hr price change for {symbol}...") + data = client.ticker_24hr_price_change(symbol) + return data + except Exception as e: + # Catch network or API errors to prevent the script from crashing unexpectedly + logging.error(f"Failed to fetch data for {symbol}: {e}") + return None -client = Client() -logging.info(client.ticker_24hr_price_change("BTCUSDT")) \ No newline at end of file +def main(): + """ + Main execution entry point. + """ + # 1. Configure Logging + log_level = setup_environment()