vn.py is a Python-based open-source framework designed for building high-performance quantitative trading systems. First released in January 2015, it has evolved through continuous community contributions into a full-featured trading platform trusted by over 300 financial institutions worldwide—including hedge funds, proprietary trading firms, asset management divisions, research institutions, and cryptocurrency funds.
The framework supports a broad range of markets: domestic and international equities, futures, options, forex, and digital assets. With its modular architecture and ease of customization, vn.py empowers traders and developers to design, backtest, and deploy algorithmic strategies efficiently.
Whether you're developing CTA strategies, executing arbitrage models, or managing risk in real-time production environments, vn.py offers the tools and flexibility needed for professional-grade trading applications.
👉 Discover how to integrate advanced trading algorithms with powerful execution tools.
Key Features of vn.py
1. Comprehensive Trading Interface Support
vn.py connects seamlessly to a wide array of market gateways across multiple asset classes:
Domestic Markets
- CTP: Futures and options in China
- XTP: A-share trading via ZT Securities
- Femas: Futures trading infrastructure
- OES: Equity trading from Wantong
- Tora: HuaXin Qidian A-share connectivity
International Markets
- Interactive Brokers (IB): Global equities, futures, and forex
- Futu & Tiger Brokers: Access to Hong Kong and U.S. stock markets
- EasyFuture 9.0 (Tap): Overseas futures
- Direct Access (DA): Global futures execution
Cryptocurrency Exchanges
- Binance & Huobi: Spot trading support
- OKX: Spot and derivatives (futures, perpetuals)
- BitMEX & Bitfinex: Crypto futures and perpetual swaps
- Coinbase: Major spot pairs
- 1Token: Integrated crypto brokerage services
These gateways are abstracted into a unified API layer, allowing developers to write strategy logic once and deploy across different exchanges with minimal changes.
2. Ready-to-Use Quantitative Applications
vn.py comes with several plug-and-play modules that accelerate development and deployment:
- CTA Strategy Engine: Build trend-following or mean-reversion systems with fine control over order submission and cancellation logic—ideal for reducing slippage and enabling high-frequency strategies.
- CTA Backtester: Perform parameter optimization and performance analysis using an intuitive GUI—no need for Jupyter notebooks. Supports tick-level and bar-based backtesting.
- Spread Trading Module: Define custom spreads between instruments, monitor live pricing, and execute semi-automated or fully automated spread trades.
- Algorithmic Trading Tools: Deploy common algo strategies like TWAP, Iceberg, Sniper, and Best Limit orders with configurable parameters.
- Script Trader: Execute quick trading scripts directly in REPL mode or manage multi-leg strategies via command-line interface.
- Data Recorder: Capture real-time tick or K-line data into a local database for historical analysis or live system initialization.
- Risk Management System: Enforce rules on order flow, position size, active orders, and cancellation frequency to ensure front-end compliance.
Each module operates independently but integrates smoothly under the same event-driven core engine.
3. Core Architecture Components
Underpinning the entire system are robust foundational components:
- Event Engine (
vnpy.event): A lightweight publish-subscribe model that powers real-time message routing between components. - Main Engine (
vnpy.trader.engine): Central hub managing connections to gateways, strategy apps, and UI modules. - RPC Service (
vnpy.rpc): Enables distributed deployment by allowing remote processes to connect securely over TCP or WebSocket. - High-Performance Charting (
vnpy.chart): Visualize large datasets with smooth rendering and live updates—perfect for monitoring strategy behavior during live trading.
This modular design allows users to scale from single-machine setups to enterprise-level distributed architectures.
Getting Started with vn.py
Environment Setup
To ensure compatibility and reduce setup friction:
- Use VNStudio 2.0.7, a Python distribution tailored for quantitative finance that includes vn.py and VN Station pre-installed.
- Supported OS: Windows 7+, Windows Server 2008+, Ubuntu 18.04 LTS
- Required Python version: Python 3.7 (64-bit only)
👉 Learn how to set up your first automated trading environment in minutes.
Installation Steps
- Download the latest release from the official GitHub repository.
- Extract the package.
- Install dependencies using
pip install -e .in the project root directory.
For Windows users, simply run:
pip install vnpyOn Ubuntu:
sudo apt-get update
pip install vnpyQuick Start Guide
- Create a simulation account on SimNow for CTP futures testing.
- Register on the vn.py community forum—your login credentials work across all platform tools.
- Launch VN Station (desktop shortcut installed with VNStudio) and log in.
- Click the VN Trader Lite button at the bottom to begin trading.
⚠️ Note: Keep VN Station running while using VN Trader; closing it will terminate connected processes.
For advanced users requiring modular configuration, switch to VN Trader Pro.
Running Custom Scripts
Beyond the GUI-based launcher, you can create standalone scripts for maximum flexibility.
Create a file named run.py with the following code:
from vnpy.event import EventEngine
from vnpy.trader.engine import MainEngine
from vnpy.trader.ui import MainWindow, create_qapp
from vnpy.gateway.ctp import CtpGateway
from vnpy.app.cta_strategy import CtaStrategyApp
from vnpy.app.cta_backtester import CtaBacktesterApp
def main():
"""Start VN Trader"""
qapp = create_qapp()
event_engine = EventEngine()
main_engine = MainEngine(event_engine)
main_engine.add_gateway(CtpGateway)
main_engine.add_app(CtaStrategyApp)
main_engine.add_app(CtaBacktesterApp)
main_window = MainWindow(main_engine, event_engine)
main_window.showMaximized()
qapp.exec_()
if __name__ == "__main__":
main()Run it from the terminal:
python run.pyThis approach enables integration with custom logging, monitoring, or CI/CD pipelines.
Contribute to the Project
vn.py is hosted on GitHub and welcomes contributions:
- Open an issue to discuss major changes.
- Fork the repository.
- Clone your fork:
git clone https://github.com/$userid/vnpy.git - Sync outdated forks using GitHub’s sync guide.
- Create a feature branch from
dev:git checkout -b my_feature dev - Push changes and submit a Pull Request to the
devbranch. - Wait for code review before merge.
Ensure code quality by:
- Formatting with
autopep8 --in-place --recursive . - Validating with
flake8(no errors or warnings)
FAQs
Q: Is vn.py free to use?
A: Yes. vn.py is open-source under the MIT license and completely free for personal and commercial use.
Q: Can I use vn.py for cryptocurrency trading?
A: Absolutely. The framework supports major crypto exchanges including Binance, OKX, Huobi, BitMEX, and Coinbase—both spot and derivatives.
Q: Does vn.py support backtesting?
A: Yes, via the built-in CTA Backtester module with GUI-based optimization and visual analytics.
Q: How do I handle large-scale deployments?
A: Use the RPC service module to build distributed systems where multiple clients connect to a central trading server.
Q: Are there learning resources available?
A: Yes. Check out the official documentation, Zhihu column, and community forum for tutorials and case studies.
Q: Can I donate to support development?
A: While not required, donations help sustain the project via the vn.py community fund. All contributors are acknowledged publicly.
Final Thoughts
vn.py stands out as one of the most mature open-source frameworks for algorithmic trading in Python. Its extensive gateway support, modular design, and active community make it ideal for both beginners and institutional developers.
With native support for cryptocurrency markets and seamless integration with global exchanges, it's a powerful tool for building next-generation trading systems.
👉 Explore how top traders automate strategies using integrated platforms like OKX.