import httpx import asyncio import os import time import hmac import hashlib from dotenv import load_dotenv load_dotenv() async def test_tradfi_category(): api_key = os.getenv("BYBIT_API_KEY") api_secret = os.getenv("BYBIT_API_SECRET") # Try different categories test_categories = ["tradfi", "mt5", "cfd", "linear"] symbol = "XAUUSD+" url = "https://api.bybit.com/v5/market/tickers" async with httpx.AsyncClient() as client: for cat in test_categories: params = {"category": cat, "symbol": symbol} headers = {} if api_key and api_secret: timestamp = str(int(time.time() * 1000)) recv_window = "5000" sorted_params = "&".join([f"{k}={v}" for k, v in sorted(params.items())]) raw_str = timestamp + api_key + recv_window + sorted_params signature = hmac.new(api_secret.encode('utf-8'), raw_str.encode('utf-8'), hashlib.sha256).hexdigest() headers = { 'X-BAPI-API-KEY': api_key, 'X-BAPI-TIMESTAMP': timestamp, 'X-BAPI-SIGN-TYPE': '2', 'X-BAPI-RECV-WINDOW': recv_window, 'X-BAPI-SIGN': signature } try: resp = await client.get(url, params=params, headers=headers) data = resp.json() print(f"Category: {cat} -> {data.get('retMsg')} ({data.get('retCode')})") except Exception as e: print(f"Error for {cat}: {e}") if __name__ == "__main__": asyncio.run(test_tradfi_category())