Skip to content
/ WebCTP Public

WebSocket Access for CTP (Comprehensive Transaction Platform).

License

Notifications You must be signed in to change notification settings

tab1949/WebCTP

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

43 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

English | 中文

WebCTP

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.

Overview

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.

Features

  • 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

Architecture

┌─────────────┐    WebSocket    ┌──────────────┐
│  WebSocket  │ ◄─────────────► │  C++ Server  │
│   Client    │                 │   (WebCTP)   │
└─────────────┘                 └──────┬───────┘
                                       │
                                       │ CTP API
                                       ▼
                              ┌──────────────┐
                              │  CTP Broker  │
                              │   Servers    │
                              └──────────────┘

Components

Server (C++)

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

Client Library (TypeScript)

The TypeScript client library provides:

  • MarketData class: For subscribing to market data feeds
  • Trade class: For trading operations and account queries
  • Event-driven API with callback handlers

Building

Prerequisites

  • CMake 3.10 or higher
  • C++17 compatible compiler
  • CTP SDK installed:
    • thostmduserapi_se (Market Data)
    • thosttraderapi_se (Trading)
  • uWebSockets library
  • ICU library

Build Steps

1. Make sure CTP SDK is installed

The recommended installation method is put libraries (*.a or *.lib) and includes (*.h) into directory build/ctp/.

2. Build binary

On Windows:

./build

On Linux:

./build.sh

Then wait for the script to download dependencies and build the executable. It may take some minutes to build the project for the first time.

Running

Start the server with default settings (localhost:8888):

./webctp

Or specify custom address and port:

./webctp [-a <address>] [-p <port>]

Usage

Server Endpoints

  • 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.

License

See LICENSE file for details.

About

WebSocket Access for CTP (Comprehensive Transaction Platform).

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors