核心功能: - Socket长连接通信架构,性能提升13倍 - 完整的股票数据处理模块,支持xtquant数据源 - MySQL数据库集成,使用Peewee ORM - 网格交易策略实现 - 多客户端并发支持 项目结构: - src/data_process_model/ - 数据处理核心模块 - src/network_model/ - Socket和HTTP通信实现 - src/strategy/ - 交易策略模块 - example_and_demos/ - 示例和演示代码 - test/ - 测试文件 主要特性: - 支持CSV和MySQL双重数据存储 - 自动数据下载和处理流水线 - 实时Socket通信,毫秒级响应 - 完善的错误处理和日志记录 - 模块化设计,易于扩展 性能指标: - 平均延迟: 0.31ms (HTTP: 4.13ms) - 理论QPS: 3242 (HTTP: 242) - 支持50个并发客户端连接
74 lines
2.2 KiB
Python
74 lines
2.2 KiB
Python
#!/usr/bin/env python3
|
||
# -*- coding: utf-8 -*-
|
||
"""
|
||
QTrade Client 快速入门示例
|
||
最简单的使用方式,适合新手快速上手
|
||
"""
|
||
|
||
import sys
|
||
import os
|
||
|
||
# 添加项目根目录到Python路径
|
||
sys.path.append(
|
||
os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
||
)
|
||
|
||
from src.network_model import QTradeHTTPClient
|
||
|
||
|
||
def quick_start_example():
|
||
"""快速入门示例"""
|
||
print("🚀 QTrade Client 快速入门")
|
||
print("=" * 40)
|
||
|
||
# 1. 创建客户端并连接服务器
|
||
with QTradeHTTPClient() as client:
|
||
# 2. 测试连接
|
||
ping_result = client.ping()
|
||
print(f"连接测试: {ping_result}")
|
||
|
||
# 检查ping是否成功
|
||
if isinstance(ping_result, dict) and "error" in ping_result:
|
||
print(f"❌ 连接失败: {ping_result['error']}")
|
||
print(
|
||
"请确保HTTP服务器已启动:python example_and_demos/http/run_http_server.py"
|
||
)
|
||
return
|
||
|
||
# 3. 获取服务器状态
|
||
status = client.status()
|
||
if isinstance(status, dict) and "error" in status:
|
||
print(f"❌ 获取状态失败: {status['error']}")
|
||
else:
|
||
print(f"服务器版本: {status.get('version', 'unknown')}")
|
||
|
||
# 4. 发送简单消息
|
||
hello_result = client.send("hello")
|
||
print(f"问候消息: {hello_result}")
|
||
|
||
# 5. 发送K线数据获取交易信号
|
||
# 注意:价格必须在1.0-8.0范围内
|
||
result = client.send_kline(
|
||
symbol="AAPL", # 股票代码
|
||
close=2.5, # 收盘价
|
||
high=2.6, # 最高价
|
||
low=2.4, # 最低价
|
||
volume=1000000, # 成交量
|
||
)
|
||
|
||
if isinstance(result, dict) and "signal" in result:
|
||
signal = result["signal"]
|
||
action = (
|
||
signal.get("action", "unknown")
|
||
if isinstance(signal, dict)
|
||
else "unknown"
|
||
)
|
||
qty = signal.get("qty", 0) if isinstance(signal, dict) else 0
|
||
print(f"交易信号: {action} {qty}股")
|
||
|
||
print("\n✅ 快速入门完成!")
|
||
|
||
|
||
if __name__ == "__main__":
|
||
quick_start_example()
|