实盘交易
📚 实盘交易概览
✨ 核心特性
🚀 快速开始
1. 实盘部署
from QUANTAXIS.QAStrategy import QAStrategyCtaBase
class LiveStrategy(QAStrategyCtaBase):
"""实盘策略"""
def user_init(self):
self.ma_period = 20
def on_bar(self, bar):
# 策略逻辑(与回测完全相同)
data = self.get_code_marketdata(bar.code)
if len(data) < self.ma_period:
return
close_prices = [x['close'] for x in data]
ma = sum(close_prices[-self.ma_period:]) / self.ma_period
positions = self.acc.positions
if bar.close > ma and bar.code not in positions:
self.BuyOpen(bar.code, 1)
elif bar.close < ma and bar.code in positions:
self.SellClose(bar.code, 1)
# 实盘配置
strategy = LiveStrategy(
code='rb2501',
frequence='5min',
strategy_id='live_ma_strategy',
# 实盘模式
model='live', # 'sim' 模拟, 'live' 实盘
# EventMQ配置(数据)
data_host='192.168.1.100',
data_port=5672,
data_user='admin',
data_password='admin',
# EventMQ配置(交易)
trade_host='192.168.1.100',
trade_port=5672,
trade_user='admin',
trade_password='admin',
# 通知
send_wx=True, # 微信通知
)
# 启动实盘
strategy.run()⚙️ 系统架构
实盘组件
组件说明
🔐 风险控制
1. 仓位控制
2. 止损止盈
3. 时间控制
📊 监控管理
1. 实时日志
2. 微信通知
3. 性能监控
🛠️ 故障处理
1. 断线重连
2. 异常处理
📝 最佳实践
1. 逐步上线
2. 实盘检查清单
3. 持续优化
⚠️ 常见问题
Q1: 实盘和回测结果差异大?
Q2: 如何保证策略稳定运行?
Q3: 如何控制实盘风险?
🔗 相关资源
📝 总结
Last updated
Was this helpful?