58 lines
1.9 KiB
Python
58 lines
1.9 KiB
Python
"""
|
|
测试实盘交易 API 端点
|
|
"""
|
|
import requests
|
|
import json
|
|
|
|
BASE_URL = "http://localhost:8000"
|
|
|
|
def test_api():
|
|
print("=" * 60)
|
|
print("测试实盘交易 API")
|
|
print("=" * 60)
|
|
|
|
# 测试 /api/real-trading/status
|
|
print("\n1. 测试 /api/real-trading/status")
|
|
try:
|
|
response = requests.get(f"{BASE_URL}/api/real-trading/status")
|
|
print(f" 状态码: {response.status_code}")
|
|
print(f" 响应: {json.dumps(response.json(), indent=2, ensure_ascii=False)}")
|
|
except Exception as e:
|
|
print(f" 错误: {e}")
|
|
|
|
# 测试 /api/real-trading/account
|
|
print("\n2. 测试 /api/real-trading/account")
|
|
try:
|
|
response = requests.get(f"{BASE_URL}/api/real-trading/account")
|
|
print(f" 状态码: {response.status_code}")
|
|
print(f" 响应: {json.dumps(response.json(), indent=2, ensure_ascii=False)}")
|
|
except Exception as e:
|
|
print(f" 错误: {e}")
|
|
|
|
# 测试 /api/real-trading/positions
|
|
print("\n3. 测试 /api/real-trading/positions")
|
|
try:
|
|
response = requests.get(f"{BASE_URL}/api/real-trading/positions")
|
|
print(f" 状态码: {response.status_code}")
|
|
print(f" 响应: {json.dumps(response.json(), indent=2, ensure_ascii=False)}")
|
|
except Exception as e:
|
|
print(f" 错误: {e}")
|
|
|
|
# 测试 /api/real-trading/orders
|
|
print("\n4. 测试 /api/real-trading/orders?status=orders&limit=10")
|
|
try:
|
|
response = requests.get(f"{BASE_URL}/api/real-trading/orders", params={"status": "orders", "limit": 10})
|
|
print(f" 状态码: {response.status_code}")
|
|
data = response.json()
|
|
print(f" Success: {data.get('success')}")
|
|
print(f" Count: {data.get('count')}")
|
|
if data.get('orders'):
|
|
print(f" Orders: {len(data.get('orders', []))} 条")
|
|
except Exception as e:
|
|
print(f" 错误: {e}")
|
|
|
|
print("\n" + "=" * 60)
|
|
|
|
if __name__ == "__main__":
|
|
test_api()
|