File size: 1,500 Bytes
85d632d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import httpx
import asyncio
import os
import time
import hmac
import hashlib
from dotenv import load_dotenv

load_dotenv()

async def verify_new_key():
    api_key = os.getenv("BYBIT_API_KEY")
    api_secret = os.getenv("BYBIT_API_SECRET")
    
    test_symbols = ["XAUUSD+", "EURUSD+", "SPX500+", "BTCUSDT"]
    url = "https://api.bybit.com/v5/market/tickers"
    
    async with httpx.AsyncClient() as client:
        for symbol in test_symbols:
            params = {"category": "linear", "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
                }

            resp = await client.get(url, params=params, headers=headers)
            print(f"Symbol: {symbol} -> {resp.json()}")

if __name__ == "__main__":
    asyncio.run(verify_new_key())