Volver al ranking

timercrack/trader

C

期货自动交易

tradectpalgorithmfuturesstockquant
Crecimiento de estrellas
Estrellas
8.3k
Forks
1.9k
Crecimiento semanal
Issues
8
5k
jul 2016nov 2019mar 2023jul 2026
README

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_idinvestor_idpasswordappidauthcode 等)

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

  • CorpID
  • Secret
  • TokenEncodingAESKey(保留与 flower 配置结构对齐)

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

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

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

trade:
  command_timeout: 5
  ignore_inst: ""
  transport: native

ctp_native:
  gateway: pybind
  module: ctp_bridge_native
  client_class: CtpClient
  module_path: /path/to/trader/native/ctp_bridge/build
  dll_dir: /path/to/trader/native/ctp_bridge/api/win
  trade_front: tcp://xxx:xxx
  market_front: tcp://xxx:xxx
  broker_id: "9999"
  investor_id: "123456"
  password: passwd
  appid: xxx
  authcode: xxx
  userinfo: xxx
  flow_path: /path/to/trader/native/ctp_bridge/flow
  request_timeout_ms: 10000
  test_instrument: IF99

log:
  level: DEBUG
  format: "%(asctime)s %(name)s [%(levelname)s] %(message)s"
  weixin_level: INFO
  weixin_format: "[%(levelname)s] %(message)s"

host:
  ip: 1.2.3.4
  mac: 02:03:04:5a:6b:7c

ssh_tunnel:
  enabled: false
  host: 127.0.0.1
  port: 22
  local_node: localhost
  private_key_linux: /root/.ssh/id_ed25519
  private_key_win: C:\\Users\\timer\\.ssh\\id_ed25519.ppk

weixin:
  Token: ""
  EncodingAESKey: ""
  CorpID: ""
  Secret: ""

3) 常用命令

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

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

若需要本地编译 ctp_bridge_native

  • Windows(MSVC):
cd native/ctp_bridge
cmake -S . -B build -G "Visual Studio 17 2022" -A x64
cmake --build build --config Release
  • Linux:
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:策略实现
  • dashboardpaneltemplatesstatic:Web 展示与后台
Repositorios relacionados
freqtrade/freqtrade

Free, open source crypto trading bot

PythonPyPIGNU General Public License v3.0pythoncryptocurrencies
freqtrade.io
52.5k10.9k
ccxt/ccxt

A unified trading API with more than 100 crypto exchanges and prediction markets in JavaScript / TypeScript / Python / C# / PHP / Go / Java

PythonPyPIMIT Licensealtcoinapi
docs.ccxt.com
43.4k8.7k
bbfamily/abu

阿布量化交易系统(股票,期权,期货,比特币,机器学习) 基于python的开源量化交易,量化投资架构

PythonPyPIGNU General Public License v3.0quanttrade
abuquant.com
17.9k4.6k
OpenByteInc/QuantDinger

AI quantitative trading platform for crypto, stocks, and forex with backtesting, live trading, market data, and multi-agent research.vibe-trading ,trading-agents,ai-trader,ai-trading

PythonPyPIApache License 2.0quantitative-financequant
quantdinger.com
9.8k2.1k
brokermr810/QuantDinger

AI quantitative trading platform for crypto, stocks, and forex with backtesting, live trading, market data, and multi-agent research.vibe-trading ,trading-agents,ai-trader,ai-trading

PythonPyPIApache License 2.0quantitative-financequant
quantdinger.com
9.7k2k
DeviaVir/zenbot

Zenbot is a command-line cryptocurrency trading bot using Node.js and MongoDB.

HTMLMIT Licensezenbottrade
8.3k2k
jesse-ai/jesse

An advanced crypto trading bot written in Python

JavaScriptnpmMIT Licensecryptocurrencytrading-bot
jesse.trade
8.2k1.2k
BigBrotherTrade/trader

交易模块

PythonPyPIApache License 2.0tradectp
5.9k1.3k
michaelgrosner/tribeca

A high frequency, market making cryptocurrency trading platform in node.js

TypeScriptnpmOthertradingtrading-bot
4.1k937
ctubio/Krypto-trading-bot

Self-hosted crypto trading bot (automated high frequency market making) written in C++

C++Otherbitcoincryptocurrency
127.0.0.1
3.7k831
yasinkuyu/binance-trader

💰 Cryptocurrency Trading Bot for Binance (Experimental)

PythonPyPIbitcoinbinance
2.7k829
olaxbt/ai-market-maker

Agentic AI Hedge Fund OS (AIMM)

PythonPyPIGNU Affero General Public License v3.0trade-bottrade
2.2k320