rtpx

Crates.iortpx
lib.rsrtpx
version1.0.2
sourcesrc
created_at2024-12-02 18:27:41.090359
updated_at2024-12-09 21:28:49.093363
descriptionSafe Rust bindings for CTP (Comprehensive Transaction Platform) and its variations for Chinese financial markets
homepagehttps://github.com/glacierx/RTP
repositoryhttps://github.com/glacierx/RTP
max_upload_size
id1469098
size23,010,173
(glacierx)

documentation

README

rtp

Rust binding for CTP and it's variations

🦀 rtp: Safe Rust Bindings for CTP Trading System(and it's variations)

Crates.io Documentation License

rtp provides safe and ergonomic Rust bindings for the CTP (Comprehensive Transaction Platform) trading system, widely used in Chinese financial markets. This project aims to bring Rust's safety and performance guarantees to the CTP ecosystem while maintaining compatibility with various CTP-compatible implementations.

CTP versions

sdk version original URL
CTP 6.7.7_210240607 http://www.sfit.com.cn/DocumentDown/api_3/5_2_2/v6.7.7_traderapi_20240607.zip
ATP 6.3.15 N/A

🌟 Features

  • Safe Abstractions: Zero-cost abstractions over CTP's C++ interfaces with Rust's safety guarantees
  • Multiple CTP Variants: Support for different CTP implementations across brokers and markets
  • Error Handling: Rust-native error handling replacing C++ exceptions
  • Async Support: Modern async/await API for event handling
  • Cross-Platform: Windows and Linux support
  • Zero Overhead: Direct FFI bindings with no runtime cost
  • Type Safety: Strong typing for market data and trading interfaces

🚀 Quick Start

use rust_ctp::prelude::*;

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    // Create a new CTP client
    let mut client = CtpTradingClient::new()
        .front_addr("tcp://180.168.146.187:10130")
        .broker_id("9999")
        .build()?;

    // Connect and login
    client.connect().await?;
    client.login("YOUR_USERNAME", "YOUR_PASSWORD").await?;

    // Subscribe to market data
    client.subscribe(&["rb2410"]).await?;

    // Handle market data
    while let Some(data) = client.next_tick().await {
        println!("Received tick: {:?}", data);
    }

    Ok(())
}

📦 Installation

Add this to your Cargo.toml:

[dependencies]
rtp = "0.1.0"

🔧 Supported CTP Variants

  • CTP Standard Version (CTPSE)
  • CTPMIN (Simulated Trading)
  • Simnow Trading Platform
  • Custom broker implementations (extensible)

🛠️ Building from Source

# Clone the repository
git clone https://github.com/glacierx/rtp
cd rtp

# Build the project
cargo build --release

# Run tests
cargo test

📚 Documentation

For detailed documentation and examples, visit docs.rs/rtp.

The documentation includes:

  • Complete API reference
  • Trading examples
  • Market data handling
  • Error handling patterns
  • Best practices

🤝 Contributing

Contributions are welcome! Please feel free to submit a Pull Request. For major changes, please open an issue first to discuss what you would like to change.

Please make sure to update tests as appropriate.

⚠️ Disclaimer

This software is provided "as is", without warranty of any kind. Trading in financial markets carries significant risk. Make sure to test thoroughly in a simulated environment before using in production.

📄 License

Licensed under either of

at your option.

🙏 Acknowledgments

  • CTP development team for the original C++ SDK
  • Rust FFI community for guidance and tools
  • Contributors who helped make this project possible

Note: This is an unofficial Rust binding. CTP is a trademark of Shanghai Futures Exchange.

Commit count: 15

cargo fmt