vnpy-export
What it does
This skill converts a tested strategy into a file that the vnpy trading framework can load. It is for developers and quant traders who use vnpy.
When to use it
- βWhen you want to run a backtested strategy inside vnpy's CTA backtester.
- βWhen you want to move a strategy toward live trading in vnpy.
- βWhen you have a strategy idea and want it written as a vnpy CtaTemplate class.
Skill link
https://github.com/HKUDS/Vibe-Trading/blob/main/agent/src/skills/vnpy-export/SKILL.mdCopy it and paste it into your AI (Claude, ChatGPT or Cursor), asking it to follow the instructions.
How to use
The easiest way: copy the message and paste it into your AI. It reads the skill and follows the instructions.
Ready-to-paste message
For Claude Code, Codex or Cursor: run it in your project folder and the skill gets installed.
Download the SKILL.md and drop it into your agentβs skills folder.
Example of what to ask your AI
βExport my moving average strategy as a vnpy class I can load into the CTA app.β
5 new skills a week. 1 minute to read.
How it works
It reads the strategy config and signal logic, then rewrites them as a vnpy template class. It picks the right conventions for stocks, futures, or crypto and saves a Python file ready to load.
Technical content (original SKILL.md)
Original text by the author, straight from GitHub.
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
FAQ
What is vnpy?
vnpy is an open-source quant trading framework that is widely used in mainland China.
Do I need to know Python?
Some Python knowledge helps, since the output is a Python class that you load into vnpy.
Which asset types are supported?
It supports A-share equities, futures, and crypto, each with its own conventions.
Details
Original description by the author
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
Popularity
- GitHub stars
- 37k
- Ranking position
- #7565
- License
- MIT
- Updated
- 11/1/2026
Comments
- β¦
More skills from this repository
vibe-trading
37kGives your agent a full finance research toolkit, covering backtests, factor analysis, options pricing and market data across many markets.
adr-hshare
37kShows your agent how to compare the price of a Chinese company listed in several markets, such as a US ADR and a Hong Kong share.
akshare
37kLets your agent pull free market data for Chinese and global stocks, futures, forex and economic indicators, with no API key needed.
alpha-zoo
37kLets your agent browse a library of ready-made stock factors and test how well a whole set of them predicts returns on a chosen market.
Similar skills
diffs
394kLets your agent produce a real, shareable diff of edits as a viewer link or image file, instead of a hand-written summary.
coding-agent
394kHelps your agent hand a larger coding job to Codex, Claude Code, or OpenCode as a background worker, then check on its progress.
gh-issues
394kHelps your agent find GitHub issues, pick the ones to work on, and open pull requests with fixes, including follow-up on review comments.