SuperAI_Forecast / backend /sign_agreement.py
Thang6822
Update Kronos Platform: New UI, enhanced backend stability and restored Dockerfile
85d632d
Raw
History Blame
1.24 kB
import httpx
import asyncio
import os
import time
import hmac
import hashlib
import json
from dotenv import load_dotenv
load_dotenv()
async def sign_tradfi_agreement():
api_key = os.getenv("BYBIT_API_KEY")
api_secret = os.getenv("BYBIT_API_SECRET")
url = "https://api.bybit.com/v5/user/sign-agreement"
timestamp = str(int(time.time() * 1000))
recv_window = "5000"
payload = json.dumps({"agreementId": "1"})
raw_str = timestamp + api_key + recv_window + payload
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,
'Content-Type': 'application/json'
}
async with httpx.AsyncClient() as client:
resp = await client.post(url, data=payload, headers=headers)
print(f"Status: {resp.status_code}")
print(f"Content: {resp.text}")
if resp.text:
print(f"Sign Agreement Result: {resp.json()}")
if __name__ == "__main__":
asyncio.run(sign_tradfi_agreement())