跳到主要内容

🚀 OpenQuant 快速开始指南

欢迎使用OpenQuant!本指南将帮助您在几分钟内快速上手并运行您的第一个策略。

📋 前置要求

  • Python 3.10
  • 网络连接
  • 交易所API密钥(用于实盘交易)

⚡ 5分钟快速开始

第一步:下载open_quant文件

下载最新版本的open_quant文件,并解压赋予执行权限

chmod +x open_quant

第二步:创建配置文件

创建 config.toml 文件:

# 策略文件路径
strategy_path = "my_strategy.py"
# 策略配置文件路径
strategy_config_path = "strategy.json"
# 交易引擎版本
trader_version = "V2"

[web]
is_production = false
secret_id = "your_secret_id"
secret_key = "your_secret_key"

[[exchanges]]
exchange = "GateSwap"
is_testnet = true
key = "your_api_key"
secret = "your_secret"

第三步:创建策略文件

创建 my_strategy.py

import base_strategy
import traderv2

class MyStrategy(base_strategy.BaseStrategy):
def __init__(self, cex_configs, dex_configs, config, trader: traderv2.TraderV2):
self.trader = trader
self.config = config

def name(self):
return "我的第一个策略"

def start(self):
"""策略启动函数"""
self.trader.log("策略启动成功!")

# 获取账户信息
result = self.trader.get_account_info(0)
if "Ok" in result:
account_info = result["Ok"]
self.trader.log(f"账户信息: {account_info}")
else:
self.trader.log(f"获取账户信息失败: {result.get('Err')}")

def subscribes(self):
"""数据订阅配置"""
return [
{
"account_id": 0,
"event_handle_mode": "Latest",
"sub": {
"SubscribeWs": [{"Bbo": ["BTC_USDT"]}]
}
}
]

def on_bbo(self, data):
"""行情数据回调"""
self.trader.log(f"收到行情数据: {data}")

第四步:运行策略

python -m open_quant_sdk

📚 下一步学习

基础功能

核心功能

高级功能

🔧 常见问题

Q: 如何获取访问密钥?

A: 请参考 配置文件说明 中的详细步骤。

Q: 支持哪些交易所?

A: 支持主流中心化交易所和DEX,详见 交易所对接规范

Q: 如何调试策略?

A: 使用日志功能记录关键信息,参考 日志管理

📞 获取帮助

  • 📖 查看完整文档
  • 💬 加入社区讨论
  • 🐛 报告问题

开始您的量化交易之旅!