The latest version of the CTP (Comprehensive Trading Platform) API, developed by Shanghai Futures Information Technology Co., Ltd., is a critical interface for programmatic trading in Chinese futures markets, including commodity futures. It is used in the SimNow simulation environment and real trading systems for exchanges like the Shanghai Futures Exchange (SHFE), Dalian Commodity Exchange (DCE), Zhengzhou Commodity Exchange (CZCE), and China Financial Futures Exchange (CFFEX). As of June 17, 2025, the latest CTP API version available from the SimNow website (http://www.simnow.com.cn/static/apiDownload.action) is typically the one referenced in recent updates, such as version 6.6.9 or later, though exact versioning may depend on the specific futures company or exchange deployment. Below, I’ll provide a detailed explanation of the key knowledge points for the latest CTP API interface, focusing on its structure, functionalities, integration, and operational considerations, particularly for SimNow.


1. Overview of the CTP API Interface

The CTP API is a C++-based interface that enables developers to build trading applications for accessing market data, submitting orders, and managing accounts in futures markets. The interface is split into two primary components:

  • ThostFtdcMdApi (Market Data API): For subscribing to and receiving real-time market quotes and depth data.
  • ThostFtdcTraderApi (Trading API): For order placement, cancellation, and account/position queries.

The latest version of the CTP API introduces improvements in performance, stability, and compatibility with modern systems, while maintaining backward compatibility with earlier versions. It supports both Windows and Linux platforms, with dynamic link libraries (DLLs) or shared objects (SO files) provided for integration.

Key Features of the Latest Interface:

  • Enhanced performance for low-latency trading.
  • Improved error handling and logging.
  • Support for new exchange rules and contract types.
  • Compatibility with modern development environments (e.g., C++11/14, Python wrappers).

Note: The exact version number (e.g., 6.6.9) and detailed release notes are available from the SimNow website or futures companies. Since specific versioning details may not be publicly disclosed for the latest updates, I’ll focus on the general structure and functionalities based on the most recent information available.


2. Key Knowledge Points of the CTP API Interface

2.1. Interface Components

The CTP API interface is defined by header files and libraries, which are downloaded from http://www.simnow.com.cn/static/apiDownload.action. The key components include:

  • Header Files:
    • ThostFtdcUserApiDataType.h: Defines data types (e.g., TThostFtdcPriceType, TThostFtdcVolumeType) for prices, volumes, and other trading parameters.
    • ThostFtdcUserApiStruct.h: Defines data structures (e.g., CThostFtdcReqUserLoginField, CThostFtdcDepthMarketDataField) for requests and responses.
    • ThostFtdcMdApi.h: Declares the market data interface and its methods.
    • ThostFtdcTraderApi.h: Declares the trading interface and its methods.
  • Libraries:
    • Windows: thostmduserapi_se.dll (market data), thosttraderapi_se.dll (trading).
    • Linux: thostmduserapi_se.so, thosttraderapi_se.so.
    • Corresponding .lib files for linking in C++ projects.
  • Protocol: Uses the proprietary FTD (Futures Trading Data) protocol over TCP for reliable, low-latency communication.

2.2. Communication Modes

The CTP API supports three communication modes, which are critical for understanding how the interface interacts with the counter system:

  • Dialogue Mode: Client sends requests (e.g., login, order submission) and receives synchronous responses. Example: ReqUserLogin returns OnRspUserLogin.
  • Private Mode: Server pushes client-specific updates, such as order status (OnRtnOrder), trade confirmations (OnRtnTrade), or errors (OnRspError).
  • Broadcast Mode: Server broadcasts market data to all subscribed clients (e.g., OnRtnDepthMarketData for tick data).

2.3. Authentication

  • Login Parameters:
    • Broker ID: 9999 for SimNow.
    • Investor ID: Assigned during SimNow registration.
    • Password: Set or changed via the SimNow website or client software.
    • APPID: Default is simnow_client_test.
    • Authentication Code: Default is 0000000000000000 (16 zeros). Terminal authentication can be disabled for programmatic access.
  • Process: Call ReqUserLogin to authenticate with the trading or market data front. The latest API version includes improved security for session management and encryption.

2.4. Market Data Interface (ThostFtdcMdApi)

The market data interface allows subscription to real-time quotes and depth data. Key methods and callbacks include:

  • Methods:
    • CreateFtdcMdApi: Initializes the market data API instance, specifying a flow control directory for storing temporary data.
    • Init: Starts the API and connects to the market data front.
    • SubscribeMarketData: Subscribes to specific instrument IDs (e.g., cu2312 for copper futures).
    • UnSubscribeMarketData: Cancels subscriptions.
    • ReqUserLogin: Authenticates the client for market data access.
  • Callbacks:
    • OnFrontConnected: Triggered when the connection to the market data front is established.
    • OnRspSubMarketData: Confirms successful subscription.
    • OnRtnDepthMarketData: Delivers tick data, including bid/ask prices, volume, and open interest.
    • OnRspError: Reports errors, such as invalid instrument IDs.
  • Data Characteristics:
    • Tick frequency: Approximately 2 ticks per second in SimNow (lower than some cryptocurrency APIs).
    • Data types: Level 1 (bid/ask, last price) and depth data (top 5 bid/ask levels for supported contracts).
    • Limitation: No historical data or tick-by-tick transaction data in SimNow.

2.5. Trading Interface (ThostFtdcTraderApi)

The trading interface handles order placement, cancellation, and account queries. Key methods and callbacks include:

  • Methods:
    • CreateFtdcTraderApi: Initializes the trading API instance.
    • Init: Connects to the trading front.
    • ReqUserLogin: Authenticates the client for trading.
    • ReqOrderInsert: Submits a new order (e.g., limit, FAK, FOK).
    • ReqOrderAction: Modifies or cancels an existing order.
    • ReqQryTradingAccount: Queries account balance and margin.
    • ReqQryInvestorPosition: Retrieves open positions.
    • ReqQryOrder: Queries order history.
    • ReqQryTrade: Queries trade history.
  • Callbacks:
    • OnFrontConnected: Confirms connection to the trading front.
    • OnRspOrderInsert: Confirms order submission or reports errors.
    • OnRtnOrder: Updates order status (e.g., pending, filled, canceled).
    • OnRtnTrade: Confirms trade execution.
    • OnRspQryTradingAccount: Returns account details.
    • OnRspQryInvestorPosition: Returns position details.
  • Order Types (SimNow-specific):
    • Limit Orders: Specify price and quantity.
    • Fill-and-Kill (FAK): Executes immediately or cancels.
    • Fill-or-Kill (FOK): Executes fully or cancels.
    • Market Orders: Not supported in SimNow.
  • Improvements in Latest Version:
    • Faster order processing and response times.
    • Enhanced error codes for better debugging (e.g., specific reasons for order rejection).
    • Support for new contract types and exchange rules.

2.6. Error Handling and Logging

  • Error Callbacks:
    • OnRspError: General errors (e.g., authentication failure).
    • OnErrRtnOrderInsert: Order-specific errors (e.g., price outside limits).
  • Logging: The API writes logs to the flow control directory specified during initialization. Developers should monitor logs for debugging issues like connection failures or rate limit violations.
  • Rate Limits: The latest version enforces stricter request frequency limits (e.g., one request every 2 seconds) to prevent system overload.

2.7. Server Configurations (SimNow)

The CTP API connects to specific trading and market data fronts. SimNow provides multiple server groups:

  • First Group (Telecom):
    • Trade Front: 180.168.146.187:10201
    • Market Front: 180.168.146.187:10211
  • Second Group (Telecom):
    • Trade Front: 180.168.146.187:10202
    • Market Front: 180.168.146.187:10212
  • Third Group (Mobile):
    • Trade Front: 218.202.237.33:10203
    • Market Front: 218.202.237.33:10213
  • 7x24 Environment:
    • Trade Front: 180.168.146.187:10130
    • Market Front: 180.168.146.187:10131
  • Availability:
    • First and second groups: Available during trading hours (Monday–Friday, including night sessions).
    • 7x24 environment: Available outside trading hours with historical data playback (no settlement).
    • Second environment: API testing only, no settlement.

2.8. Development and Integration

  • Supported Languages:
    • Primary: C++ (native support).
    • Wrapped: Python (via pybind11), Rust (via cc-rs), or other languages using FFI.
    • Example: Python wrappers are available on GitHub or CSDN (e.g., https://zhuanlan.zhihu.com/p/20031660).
  • Setup Steps:
    1. Download API files from http://www.simnow.com.cn/static/apiDownload.action.
    2. Configure server addresses in your application.
    3. Implement callback functions for asynchronous responses.
    4. Test connectivity using telnet (e.g., telnet 180.168.146.187 10201).
    5. Initialize APIs with CreateFtdcMdApi and CreateFtdcTraderApi, specifying flow control directories.
  • Best Practices:
    • Use separate threads for market data and trading to avoid blocking.
    • Implement robust error handling for network disconnections or order rejections.
    • Monitor logs for initialization and connection status.
    • Ensure memory safety when unloading libraries to avoid crashes.

2.9. New Features in the Latest Version

While specific release notes for the latest version (e.g., 6.6.9 or newer) are not publicly detailed, recent updates typically include:

  • Performance Optimization: Reduced latency for order submission and market data updates.
  • Extended Contract Support: Compatibility with new futures contracts introduced by exchanges.
  • Improved Stability: Better handling of network interruptions and session management.
  • Enhanced Security: Stronger encryption and authentication mechanisms.
  • Cross-Platform Support: Improved compatibility with Linux and modern C++ standards (e.g., C++11/14).

2.10. Limitations

  • No Market Orders: SimNow only supports limit, FAK, and FOK orders.
  • Data Limitations: No historical data or tick-by-tick transaction data in SimNow.
  • Rate Limits: Strict request frequency limits to prevent abuse.
  • SimNow-Specific Constraints: The 7x24 environment lacks settlement, and the second environment is for API testing only.

3. Practical Workflow for Using the CTP API Interface

  1. Register on SimNow: Obtain an Investor ID and password at http://www.simnow.com.cn/.
  2. Download API Files: Get DLLs/SO files and headers from the SimNow website.
  3. Develop Application:
    • Initialize ThostFtdcMdApi and ThostFtdcTraderApi.
    • Implement callbacks for market data (OnRtnDepthMarketData) and trading (OnRtnOrder, OnRtnTrade).
    • Subscribe to instruments and place test orders.
  4. Configure Servers: Use appropriate trading and market data front addresses.
  5. Test in SimNow: Run during trading hours to validate real-time performance.
  6. Debug and Optimize: Monitor logs and handle errors (e.g., OnRspError).
  7. Prepare for Live Trading: Update server addresses and credentials for real exchange environments.

4. Comparison with Other APIs

  • CTP vs. Cryptocurrency APIs:
    • CTP uses TCP-based FTD protocol, while crypto APIs use REST/WebSocket.
    • CTP has lower tick frequency (2 ticks/second vs. 10 ticks/second for crypto).
    • CTP is tailored for regulated futures markets with strict risk controls.
  • CTP vs. Global Futures APIs:
    • Unlike CME Group or Eurex APIs, CTP is optimized for Chinese exchanges.
    • CTP offers high stability but lacks some advanced features (e.g., market orders in SimNow).

5. Additional Resources

  • SimNow Website: http://www.simnow.com.cn/ for registration, API downloads, and server details.
  • API Documentation: http://www.sfit.com.cn/5_2_DocumentDown.htm.
  • Community Support: GitHub, CSDN, or forums for sample code (e.g., Python/Rust wrappers).
  • Client Software: SimNow Fast Client (e.g., TradeNow, Quick 3) for manual trading and testing.

6. Key Considerations

  • Simulation vs. Real Trading: SimNow mirrors real exchanges but lacks some features (e.g., market orders). Test thoroughly before live deployment.
  • Connectivity: Use telnet to verify server availability if connection issues occur.
  • Security: Use unique credentials for SimNow to avoid conflicts with real accounts.
  • Performance: Optimize for low latency, as the API handles high-frequency requests.

Note on Web Results: The provided web results (e.g.,,) refer to unrelated CTP APIs (e.g., Chinese Text Project, DevExpress) and are not relevant to the futures trading CTP API. I’ve relied on information specific to the SimNow CTP API and general knowledge of futures trading interfaces.

Comments