核心功能: - 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个并发客户端连接
56 lines
1.5 KiB
Python
56 lines
1.5 KiB
Python
#!/usr/bin/env python3
|
|
"""
|
|
简化版Socket通信测试
|
|
测试极简版Socket服务器和客户端
|
|
"""
|
|
|
|
import sys
|
|
import os
|
|
import time
|
|
|
|
# 添加项目根目录到Python路径
|
|
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
|
|
|
from src.network_model.simple_socket_client import SimpleQTradeSocketClient
|
|
|
|
|
|
def test_simple_socket_communication():
|
|
"""测试简化版Socket通信"""
|
|
print("🧪 简化版Socket通信测试")
|
|
print("=" * 50)
|
|
|
|
# 创建客户端
|
|
client = SimpleQTradeSocketClient("127.0.0.1", 8081)
|
|
|
|
try:
|
|
# 连接测试
|
|
if client.connect():
|
|
print("✅ 连接成功")
|
|
|
|
# 测试各种消息类型
|
|
test_cases = [
|
|
("ping", "Ping测试"),
|
|
({"type": "get_server_status"}, "获取服务器状态"),
|
|
({"type": "update_kline", "data": {"close": 5.0}}, "K线数据更新"),
|
|
({"type": "test_sync", "data": "测试数据"}, "同步消息测试"),
|
|
]
|
|
|
|
for message, description in test_cases:
|
|
print(f"\n🔸 {description}")
|
|
response = client.send_message_sync(message)
|
|
print(f"响应: {response}")
|
|
time.sleep(0.5)
|
|
|
|
print("\n✅ 所有测试完成")
|
|
else:
|
|
print("❌ 连接失败")
|
|
|
|
except Exception as e:
|
|
print(f"❌ 测试过程中发生错误: {e}")
|
|
finally:
|
|
client.disconnect()
|
|
|
|
|
|
if __name__ == "__main__":
|
|
test_simple_socket_communication()
|