Baike.dev
All toolsOnline toolsAI codingTrendingOpen sourceNewsSubmit
Log in
< Back to tools
T

trader

> 编程语言
Open source

期货自动交易

8.4K stars0 likes2 views
WebsiteGitHub

About

期货自动交易

trader

trader 是一个以 CTP 原生链路 为核心的交易项目,包含:

  • 原生网关(native/ctp_bridge + ctp_native)
  • 策略执行(strategy)
  • Django 管理与可视化(dashboard + panel)

架构概览

核心模块

  • runtime_config.py:运行时配置入口(仅读取根目录 config.yaml)
  • ctp_native/:Python 侧网关与本地消息总线
  • native/ctp_bridge/:pybind11 C++ 扩展,连接 Thost API
  • strategy/:交易策略与查询/报单流程
  • dashboard/ + panel/:Django 后台与页面展示

运行链路(简化)

  1. 读取 config.yaml
  2. 初始化 ctp_bridge_native 并登录 CTP
  3. ctp_native 在本地总线上分发请求/回报
  4. strategy 消费事件并执行策略逻辑

快速开始

1) 环境准备

  • Python 3.14(项目当前使用版本)
  • 安装依赖:requirements.txt
  • Windows 如使用 CTP 原生扩展:需可用 MSVC + CMake

2) 配置

编辑项目根目录 config.yaml,重点检查 ctp_native 章节:

  • gateway = pybind
  • module = ctp_bridge_native
  • module_path 指向本地编译输出目录
  • 补齐登录参数(broker_id、investor_id、password、appid、authcode 等)

企业微信日志推送配置在 weixin 章节:

  • CorpID
  • Secret
  • Token、EncodingAESKey(保留与 flower 配置结构对齐)

发送策略默认沿用旧 flower 行为:agentid=0、touser=@all。

配置后,trader 会直接推送日志到企业微信,不再依赖单独运行 flower。

默认配置键结构(示例值)如下,和当前代码中的默认配置字典保持一致:

…

3) 常用命令

  • 启动交易主程序:python main.py
  • Django 检查:python manage.py check
  • Native 查询烟测:python test/test_ctp.py

4) 原生扩展构建(可选)

若需要本地编译 ctp_bridge_native:

  • Windows(MSVC):
powershell
cd native/ctp_bridge
cmake -S . -B build -G "Visual Studio 17 2022" -A x64
cmake --build build --config Release
  • Linux:
bash
cd native/ctp_bridge
cmake -S . -B build -DCMAKE_BUILD_TYPE=Release
cmake --build build -j

详细说明见:native/ctp_bridge/README.md

目录说明

  • native/ctp_bridge:C++ 扩展源码与 CMake
  • ctp_native:Python 网关封装
  • strategy:策略实现
  • dashboard、panel、templates、static:Web 展示与后台

Issues· 9 open

View all issuesOpen on GitHub
  • #20

    能帮忙提供一下初始化的dml语句吗

    Updated May 6, 2026
  • #19

    CTPApi [WARNING] TradingAccount 发生错误: TimeoutError()

    Updated Mar 5, 2026
  • #18

    大佬,有sql吗?

    Updated Feb 10, 2026
  • #16

    Add Official Docker Image for Trader Project

    Updated Sep 24, 2025
  • #5

    是不是缺少大哥2.2策略?

    Updated Sep 8, 2025
  • #8

    大佬能弄个docker镜像嘛

    Updated Apr 8, 2025
  • #6

    关于strategy的初始参数问题

    Updated Feb 14, 2025
  • #7

    大哥,整个币圈的呢

    Updated Jun 14, 2024

> Tags

Calgorithmctpfuturesquant

No comments yet. Be the first to share.

> Details

PublishedAug 1, 2026
UpdatedOct 1, 2026
Category编程语言
PricingOpen source

> Related tools

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言