vnpy-export
하는 일
이 스킬은 시험을 마친 전략을 vnpy 프레임워크가 불러올 수 있는 파일로 바꿉니다. vnpy를 쓰는 개발자와 계량 트레이더를 위한 스킬입니다.
사용하는 경우
- ✓백테스트한 전략을 vnpy의 CTA 백테스터 안에서 실행하고 싶을 때.
- ✓vnpy에서 실거래 쪽으로 전략을 옮기고 싶을 때.
- ✓전략 아이디어를 vnpy CtaTemplate 클래스로 작성하고 싶은 경우.
스킬 링크
https://github.com/HKUDS/Vibe-Trading/blob/main/agent/src/skills/vnpy-export/SKILL.md복사해서 AI(Claude, ChatGPT, Cursor)에 붙여넣고 지침을 따르도록 요청하세요.
사용 방법
가장 쉬운 방법입니다. 메시지를 복사해 AI에 붙여넣으세요. AI가 스킬을 읽고 지침을 따릅니다.
바로 붙여넣을 수 있는 메시지
Claude Code, Codex, Cursor용입니다. 프로젝트 폴더에서 실행하면 스킬이 설치됩니다.
SKILL.md를 다운로드해 에이전트의 스킬 폴더에 넣으세요.
AI에게 요청하는 예시
“제 이동평균 전략을 CTA 앱에 불러올 수 있는 vnpy 클래스로 내보내 주세요.”
매주 새 스킬 5개. 읽는 데 1분.
작동 방식
에이전트는 전략 설정과 신호 로직을 읽고, 이를 vnpy 템플릿 클래스로 다시 씁니다. 주식, 선물, 암호화폐에 맞는 관례를 고르고, 바로 불러올 수 있는 Python 파일을 저장합니다.
기술 내용 (원본 SKILL.md)
작성자의 영어 원문을 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
자주 묻는 질문
vnpy란 무엇인가요?
중국 본토에서 널리 쓰이는 오픈소스 계량 거래 프레임워크입니다.
Python을 알아야 하나요?
출력이 vnpy에 불러올 Python 클래스이므로 Python 지식이 있으면 도움이 됩니다.
어떤 자산 유형을 지원하나요?
중국 A주 주식, 선물, 암호화폐를 지원하며, 각각 고유한 관례가 있습니다.
상세 정보
작성자의 원본 설명
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
인기도
- GitHub 스타
- 37k
- 순위
- #7565
- 라이선스
- MIT
- 업데이트
- 2026. 11. 1.
댓글
- …
이 저장소의 다른 스킬
vibe-trading
37k에이전트에게 백테스트, 팩터 분석, 옵션 가격 결정, 여러 시장의 시장 데이터를 포함하는 완전한 금융 연구 도구 모음을 제공합니다.
adr-hshare
37k에이전트에게 미국 ADR과 홍콩 주식처럼 여러 시장에 상장된 중국 기업의 가격을 비교하는 방법을 보여 줍니다.
akshare
37k에이전트가 API 키 없이 중국과 해외 주식, 선물, 외환, 경제 지표의 무료 시장 데이터를 가져오도록 돕습니다.
alpha-zoo
37k에이전트가 만들어진 주식 팩터 라이브러리를 둘러보고, 선택한 시장에서 팩터 묶음이 수익률을 얼마나 잘 예측하는지 시험하도록 돕습니다.