WebCTP is a WebSocket-based gateway that bridges the CTP (Comprehensive Transaction Platform) API to modern web applications. It provides a C++ server implementation and a TypeScript client library, enabling developers to interact with Chinese futures trading systems through WebSocket connections.
WebCTP wraps the official CTP API (ThostFtdcMdApi and ThostFtdcTraderApi) and exposes it via WebSocket endpoints, making it accessible from web browsers, Node.js applications, and other WebSocket-compatible clients.
- Market Data WebSocket Endpoint (
/market_data): Real-time market data streaming - Trading WebSocket Endpoint (
/trade): Order insertion, account queries, and trading operations - TypeScript Client Library: Full-featured client SDK for easy integration
- High Performance: Built on uWebSockets for efficient WebSocket handling
- CTP API Compatibility: Supports official CTP API versions
┌─────────────┐ WebSocket ┌──────────────┐
│ WebSocket │ ◄─────────────► │ C++ Server │
│ Client │ │ (WebCTP) │
└─────────────┘ └──────┬───────┘
│
│ CTP API
▼
┌──────────────┐
│ CTP Broker │
│ Servers │
└──────────────┘
The server is implemented in C++17 and uses:
- uWebSockets: High-performance WebSocket server
- CTP API: Official ThostFtdcMdApi and ThostFtdcTraderApi libraries
- JSON: For message serialization
The TypeScript client library provides:
MarketDataclass: For subscribing to market data feedsTradeclass: For trading operations and account queries- Event-driven API with callback handlers
- CMake 3.10 or higher
- C++17 compatible compiler
- CTP SDK installed:
thostmduserapi_se(Market Data)thosttraderapi_se(Trading)
- uWebSockets library
- ICU library
The recommended installation method is put libraries (*.a or *.lib) and includes (*.h) into directory build/ctp/.
On Windows:
./buildOn Linux:
./build.shThen wait for the script to download dependencies and build the executable. It may take some minutes to build the project for the first time.
Start the server with default settings (localhost:8888):
./webctpOr specify custom address and port:
./webctp [-a <address>] [-p <port>]- Health Check:
GET /health - Market Data:
WS /market_data - Trading:
WS /trade
For detailed documentation and usage examples, please refer to:
See also the documentation index for a complete overview.
See LICENSE file for details.