vnpy-export
Skill này làm gì
Skill này chuyển một chiến lược đã kiểm thử thành một file mà framework vnpy có thể tải. Skill dành cho lập trình viên và trader định lượng dùng vnpy.
Khi nào nên dùng
- ✓Khi bạn muốn chạy một chiến lược đã backtest trong bộ backtest CTA của vnpy.
- ✓Khi bạn muốn đưa một chiến lược sang giao dịch thực trên vnpy.
- ✓Khi bạn có một ý tưởng chiến lược và muốn viết nó thành một lớp CtaTemplate của vnpy.
Liên kết skill
https://github.com/HKUDS/Vibe-Trading/blob/main/agent/src/skills/vnpy-export/SKILL.mdSao chép rồi dán vào AI của bạn (Claude, ChatGPT hoặc Cursor) và nhờ nó làm theo hướng dẫn.
Cách dùng
Cách dễ nhất: sao chép tin nhắn và dán vào AI của bạn. AI sẽ đọc skill và làm theo hướng dẫn.
Tin nhắn có sẵn để dán
Dành cho Claude Code, Codex hoặc Cursor: chạy lệnh trong thư mục dự án của bạn và skill sẽ được cài đặt.
Tải tệp SKILL.md về và thả vào thư mục skill của agent.
Ví dụ cách nhờ AI
“Xuất chiến lược đường trung bình động của tôi thành một lớp vnpy để tải vào ứng dụng CTA.”
5 skill mới mỗi tuần. Đọc chỉ 1 phút.
Cách hoạt động
Skill đọc cấu hình chiến lược và logic tín hiệu, rồi viết lại thành một lớp mẫu vnpy. Nó chọn quy ước đúng cho cổ phiếu, hợp đồng tương lai hoặc crypto, và lưu một file Python sẵn sàng để tải.
Nội dung kỹ thuật (SKILL.md gốc)
Lấy nguyên văn từ GitHub, do tác giả viết bằng tiếng Anh.
Overview
This skill translates a Vibe-Trading strategy into a vnpy CtaTemplate subclass .py file
that can be loaded directly into the vnpy CTA Strategy App for live trading or vnpy backtesting.
Output file: artifacts/vnpy_strategy/<StrategyName>Strategy.py (inside the run directory).
vnpy is the most widely-used open-source quant framework in mainland China (39k+ GitHub stars).
Use this skill when the user asks to export to vnpy, requests a /vnpy command, or wants to
run a Vibe-Trading strategy inside vnpy's CTA backtester or live trading engine.
Workflow: Export from Backtest Run
load_skill("vnpy-export")— read this guideread_file("config.json")— extract instrument, dates, parameters, intervalread_file("code/signal_engine.py")— understand the Python signal logic- Determine asset class from
config.json→ choose correct CtaTemplate convention (see below) - Translate signal logic to CtaTemplate using the reference tables
write_file("artifacts/vnpy_strategy/<StrategyName>Strategy.py")— save the output- Return the class in a code block with setup instructions
Workflow: Generate from Description
load_skill("vnpy-export")— read this guide- Write a CtaTemplate class from the user's strategy description
write_file("artifacts/vnpy_strategy/<StrategyName>Strategy.py")— save the output- Return the class with setup and usage instructions
Asset Class Conventions
vnpy uses the same CtaTemplate base class for all asset types, but parameter conventions differ:
| Asset Class | Instrument Example | vt_symbol Format |
Position Unit |
|---|---|---|---|
| A-share stock | Ping An Bank | 000001.SZSE |
shares (整手, min 100) |
| Futures | IF2406 | IF2406.CFFEX |
lots |
| Crypto | BTC/USDT | BTC/USDT.BINANCE |
coin units |
For stocks: use buy / sell only (no short selling unless margin account).
For futures / crypto: use all four directions — buy, sell, short, cover.
CtaTemplate Structure
Every strategy must subclass CtaTemplate and implement these methods:
| Method | Purpose |
|---|---|
__init__ |
Declare parameters, variables, BarGenerator, ArrayManager |
on_init |
Called once at startup; call load_bar(n) to warm up indicators |
on_start |
Called when strategy is started by user |
on_stop |
Called when strategy is stopped |
on_tick |
Receives live tick data; forward to BarGenerator |
on_bar |
Main logic — called once per bar by BarGenerator |
on_order |
Order status updates |
on_trade |
Fill notifications |
on_stop_order |
Stop-order status (if using stop orders) |
Always call self.cancel_all() at the start of on_bar to avoid stale orders.
Always call self.put_event() at the end of on_bar to refresh the UI.
Full Template
See scripts/cta_template.py for a complete, runnable example (MA crossover).
The template below is the canonical skeleton — replace the # SIGNAL LOGIC section:
from vnpy_ctastrategy import (
CtaTemplate,
StopOrder,
TickData,
BarData,
TradeData,
OrderData,
BarGenerator,
ArrayManager,
)
class {{StrategyName}}Strategy(CtaTemplate):
"""
Vibe-Trading export — {{StrategyName}}
Generated from run: {{run_id}}
Instrument: {{vt_symbol}}
"""
author = "Vibe-Trading"
# ── Parameters (editable in vnpy UI) ──────────────────────────────────
{{param_name}} = {{param_default}} # add one line per parameter
parameters = [{{param_list_as_strings}}]
# ── Variables (displayed in vnpy UI, reset on strategy restart) ────────
{{var_name}} = 0.0 # add one line per runtime variable
variables = [{{var_list_as_strings}}]
def __init__(self, cta_engine, strategy_name, vt_symbol, setting):
super().__init__(cta_engine, strategy_name, vt_symbol, setting)
self.bg = BarGenerator(self.on_bar)
self.am = ArrayManager()
# initialise variable attributes to match class-level defaults
# (vnpy requires instance attributes for variables declared above)
def on_init(self):
self.write_log("Strategy initialised")
self.load_bar({{warmup_bars}}) # load enough bars to warm up all indicators
def on_start(self):
self.write_log("Strategy started")
self.put_event()
def on_stop(self):
self.write_log("Strategy st
Câu hỏi thường gặp
vnpy là gì?
vnpy là một framework giao dịch định lượng mã nguồn mở, được dùng rộng rãi ở Trung Quốc đại lục.
Tôi có cần biết Python không?
Có chút kiến thức Python sẽ giúp ích, vì kết quả là một lớp Python mà bạn tải vào vnpy.
Những loại tài sản nào được hỗ trợ?
Cổ phiếu A, hợp đồng tương lai và crypto, mỗi loại có quy ước riêng.
Chi tiết
Mô tả gốc của tác giả
Export a Vibe-Trading backtest strategy to a runnable vnpy CtaTemplate Python class — supports A-share equities, futures, and crypto via BarGenerator + ArrayManager.
repo: HKUDS/Vibe-Trading
Độ phổ biến
- Sao GitHub
- 37k
- Vị trí xếp hạng
- #7565
- Giấy phép
- MIT
- Cập nhật
- 1/11/2026
Bình luận
- …
Thêm skill từ kho mã này
vibe-trading
37kCho agent của bạn bộ công cụ nghiên cứu tài chính đầy đủ: backtest, phân tích nhân tố, định giá quyền chọn và dữ liệu thị trường nhiều nước.
adr-hshare
37kChỉ cho agent của bạn cách so sánh giá của một công ty Trung Quốc được niêm yết ở nhiều thị trường, như ADR ở Mỹ và cổ phiếu ở Hồng Kông.
akshare
37kCho agent của bạn lấy dữ liệu thị trường miễn phí: cổ phiếu Trung Quốc và toàn cầu, tương lai, ngoại hối, chỉ số kinh tế, không cần API key.
alpha-zoo
37kCho agent của bạn duyệt thư viện nhân tố cổ phiếu dựng sẵn và kiểm tra cả một nhóm nhân tố dự đoán lợi nhuận tốt đến đâu trên thị trường đã chọn.
Skill tương tự
diffs
394kGiúp agent của bạn tạo một diff có thể chia sẻ về các chỉnh sửa, dưới dạng liên kết xem hoặc file ảnh, thay vì một bản tóm tắt viết tay.
coding-agent
394kGiúp agent của bạn giao một việc lập trình lớn cho Codex, Claude Code hoặc OpenCode chạy nền, rồi theo dõi tiến độ của nó.
gh-issues
394kGiúp agent của bạn tìm issue trên GitHub, chọn những issue cần xử lý và mở pull request với bản sửa, kể cả theo dõi nhận xét đánh giá.