Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 31 additions & 3 deletions examples/rest_api/market/ticker_24hr_price_change.py
Original file line number Diff line number Diff line change
@@ -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"))
def main():
"""
Main execution entry point.
"""
# 1. Configure Logging
log_level = setup_environment()