接口使用 (API 集成与调用示例)
QuantumExecute 提供完善的 API 接口,方便用户将算法交易功能集成到自有系统中,实现程序化控制。本节介绍 API 集成的基本流程和注意事项,并给出调用示例。
1. 集成流程
2. 调用示例
import time, hmac, hashlib
import requests
# Credentials (obtained from QE)
CLIENT_ID = "your_client_id"
API_SECRET = b"your_api_secret_bytes" # ensure this is in bytes for HMAC
# Example order parameters
payload = {
"exchange": "Binance",
"symbol": "BTCUSDT",
"side": "buy",
"strategy": "TWAP",
"order_quantity": 100, # total quantity to buy
"duration": 3600, # execution duration in seconds (e.g., 1 hour)
"start_time": int(time.time()) # start now (current epoch time)
# ... other optional parameters like price limits, etc.
}
# Convert payload to JSON string
import json
body = json.dumps(payload)
# Prepare authentication headers
timestamp = str(int(time.time() * 1000)) # current timestamp in ms
# Create signature: HMAC_SHA256(secret, <timestamp + body>)
signing_payload = (timestamp + body).encode('utf-8')
signature = hmac.new(API_SECRET, signing_payload, hashlib.sha256).hexdigest()
headers = {
"X-QE-CLIENTID": CLIENT_ID,
"X-QE-TIMESTAMP": timestamp,
"X-QE-SIGNATURE": signature,
"Content-Type": "application/json"
}
# Send request (assuming endpoint URL and path)
url = "https://api.quantumexecute.com/v1/algo_order"
response = requests.post(url, data=body, headers=headers)
res_data = response.json()
print("Order Status:", res_data)3 注意事项
最后更新于