deribit_fix/lib.rs
1//! # Deribit FIX Framework
2//!
3//! [](./LICENSE)
4//! [](https://crates.io/crates/deribit-fix)
5//! [](https://crates.io/crates/deribit-fix)
6//! [](https://docs.rs/deribit-fix)
7//!
8//! **Version:** 0.2.0 | **Status:** Production Ready | **Repository:** <https://github.com/joaquinbejar/deribit-fix>
9//!
10//! A comprehensive, production-ready FIX protocol client framework for Deribit cryptocurrency exchange.
11//! This library provides a complete, type-safe, and async foundation for building sophisticated trading applications
12//! that connect to Deribit using the FIX 4.4 protocol with custom extensions.
13//!
14//! ## ๐๏ธ Project Status
15//!
16//! **Current Version: 0.2.0** - Feature Complete & Production Ready
17//!
18//! This release represents a complete implementation of the Deribit FIX specification with:
19//! - โ
Full FIX 4.4 protocol support with Deribit extensions
20//! - โ
Complete trading operations (orders, positions, mass operations)
21//! - โ
Real-time market data streaming and snapshots
22//! - โ
Comprehensive session management and error handling
23//! - โ
Production-grade connection management with SSL support
24//! - โ
Extensive test suite with 90%+ coverage
25//! - โ
Rich examples and documentation
26//!
27//! ## ๐ Quick Start
28//!
29//! Add to your `Cargo.toml`:
30//! ```toml
31//! [dependencies]
32//! deribit-fix = "0.2.0"
33//! ```
34//!
35//! Basic usage:
36//! ```rust,no_run
37//! use deribit_fix::prelude::*;
38//!
39//! #[tokio::main]
40//! async fn main() -> Result<()> {
41//! let config = DeribitFixConfig::default()
42//! .with_credentials("your_key".to_string(), "your_secret".to_string())
43//! .with_heartbeat_interval(30);
44//!
45//! let mut client = DeribitFixClient::new(config).await?;
46//! client.connect().await?;
47//!
48//! // Start trading!
49//! let positions = client.get_positions().await?;
50//! println!("Current positions: {}", positions.len());
51//!
52//! client.disconnect().await?;
53//! Ok(())
54//! }
55//! ```
56//!
57//! ## ๐ Supported Environments
58//!
59//! | Environment | Raw TCP | SSL |
60//! |-------------|---------|-----|
61//! | **Production** | `www.deribit.com:9880` | `www.deribit.com:9883` |
62//! | **Test** | `test.deribit.com:9881` | `test.deribit.com:9883` |
63//!
64//! ## ๐ฏ Core Features
65//!
66//! ### ๐ก Session Management
67//! - **Logon/Logout (A/5)**: Secure authentication with SHA256 + nonce
68//! - **Heartbeat (0)**: Configurable keep-alive mechanism
69//! - **Test Request (1)**: Connection health monitoring
70//! - **Resend Request (2)**: Message recovery and gap filling
71//! - **Sequence Reset (4)**: Sequence number management
72//! - **Reject (3)**: Comprehensive error handling with detailed codes
73//!
74//! ### ๐ Trading Operations
75//! - **Order Management**:
76//! - New Order Single (D) - Place orders with full parameter support
77//! - Order Cancel Request (F) - Cancel individual orders
78//! - Order Cancel/Replace Request (G) - Modify existing orders
79//! - **Mass Operations**:
80//! - Order Mass Cancel Request (q) - Cancel multiple orders
81//! - Order Mass Status Request (AF) - Bulk order status queries
82//! - **Execution Reports**: Real-time order status updates and fill notifications
83//! - **Position Management**:
84//! - Request For Positions (AN) - Query current positions
85//! - Position Report (AP) - Real-time position updates
86//!
87//! ### ๐ Market Data
88//! - **Real-time Streaming**:
89//! - Market Data Request (V) - Subscribe to live data feeds
90//! - Market Data Snapshot/Full Refresh (W) - Complete market snapshots
91//! - Market Data Incremental Refresh (X) - Efficient incremental updates
92//! - **Security Information**:
93//! - Security List Request (x) - Available instruments
94//! - Security Definition Request (c) - Detailed instrument specifications
95//! - Security Status Request (e) / Security Status (f) - Instrument status updates
96//!
97//! ### ๐ผ Advanced Trading Features
98//! - **Market Making**:
99//! - Mass Quote (i) - Bulk quote submission
100//! - Quote Request (R) - Request for quotes
101//! - Quote Cancel (Z) - Quote cancellation
102//! - **RFQ (Request for Quote) System**:
103//! - RFQ Request (AH) - Submit RFQ requests
104//! - Quote Status Report (AI) - Quote status updates
105//! - **Risk Management**:
106//! - MMProtection Limits (MM) - Market maker protection
107//! - MMProtection Reset (MZ) - Reset protection limits
108//! - **Trade Reporting**:
109//! - TradeCaptureReportRequest (AD) - Request trade reports
110//! - TradeCaptureReport (AE) - Trade execution reports
111//!
112//! ### ๐ Security & Authentication
113//! - **SHA256 Authentication**: Secure credential-based authentication
114//! - **Application Registration**: Support for registered apps with DeribitAppSig
115//! - **Cancel on Disconnect**: Automatic order cancellation on connection loss
116//! - **User Management**: User Request (BE) / User Response (BF)
117//! - **SSL/TLS Support**: Encrypted connections for production environments
118//!
119//! ## โก Technical Architecture
120//!
121//! ### ๐๏ธ Built on Modern Rust
122//! - **Rust 2024 Edition**: Latest language features and performance
123//! - **Async/Await**: Full async support with Tokio runtime
124//! - **Type Safety**: Zero-cost abstractions with compile-time guarantees
125//! - **Memory Safety**: No segfaults, buffer overflows, or memory leaks
126//!
127//! ### ๐ Connection Management
128//! - **Automatic Reconnection**: Configurable backoff strategies
129//! - **Connection Pooling**: Efficient resource utilization
130//! - **Timeout Handling**: Robust timeout management
131//! - **SSL/TLS Support**: Production-grade encrypted connections
132//!
133//! ### ๐ฏ Message Processing
134//! - **FIX Protocol Compliance**: Full FIX 4.4 with Deribit extensions
135//! - **Message Validation**: Comprehensive parsing and validation
136//! - **Sequence Management**: Automatic sequence number handling
137//! - **Gap Detection**: Automatic message gap detection and recovery
138//!
139//! ### ๐ก๏ธ Error Handling
140//! - **Detailed Error Types**: Comprehensive error classification
141//! - **Context Preservation**: Rich error context for debugging
142//! - **Recovery Strategies**: Automatic recovery from transient errors
143//! - **Logging Integration**: Structured logging with tracing support
144//!
145//! ## ๐ Examples & Documentation
146//!
147//! The framework includes comprehensive examples covering all major use cases:
148//!
149//! ### ๐ง Basic Examples
150//! - **Basic Client** (`examples/basic/`): Simple client setup and connection
151//! - **Login Test** (`examples/session/login_test.rs`): Authentication examples
152//! - **Heartbeat** (`examples/session/heartbeat_example.rs`): Keep-alive handling
153//!
154//! ### ๐ Trading Examples
155//! - **Order Management** (`examples/order_management/`): Complete order lifecycle
156//! - **Position Management** (`examples/position_management/`): Position tracking
157//! - **Market Data** (`examples/market_data/`): Real-time data streaming
158//!
159//! ### ๐จ Advanced Examples
160//! - **Error Handling** (`examples/error_handling/`): Comprehensive error scenarios
161//! - **Session Management** (`examples/session/session_management.rs`): Advanced session handling
162//! - **Test Requests** (`examples/session/test_request_example.rs`): Connection monitoring
163//! - **Resend Requests** (`examples/session/resend_request_example.rs`): Message recovery
164//!
165//! ## ๐งช Testing & Quality
166//!
167//! ### ๐ฌ Comprehensive Test Suite
168//! - **Unit Tests**: 100+ unit tests covering all modules
169//! - **Integration Tests**: End-to-end scenarios with mock servers
170//! - **Coverage**: 90%+ code coverage with detailed reports
171//! - **Continuous Integration**: Automated testing on multiple platforms
172//!
173//! ### ๐ Quality Assurance
174//! - **Clippy Linting**: Strict code quality enforcement
175//! - **Rustfmt**: Consistent code formatting
176//! - **Documentation**: 100% public API documentation
177//! - **Benchmarks**: Performance regression testing
178//!
179//! ## ๐ฆ Installation & Setup
180//!
181//! ### Prerequisites
182//! - Rust 1.75+ (specified in `rust-toolchain.toml`)
183//! - Tokio async runtime
184//! - Valid Deribit API credentials
185//!
186//! ### Build Commands
187//! ```bash
188//! # Standard build
189//! cargo build
190//!
191//! # Release build (recommended for production)
192//! cargo build --release
193//!
194//! # Run tests
195//! cargo test
196//!
197//! # Run examples
198//! cargo run --example basic_client
199//! ```
200//!
201//! ## ๐ Performance
202//!
203//! - **Low Latency**: Optimized for high-frequency trading
204//! - **Memory Efficient**: Zero-copy message parsing where possible
205//! - **Async I/O**: Non-blocking network operations
206//! - **Connection Pooling**: Efficient resource utilization
207//!
208//! ## ๐ ๏ธ Development Tools
209//!
210//! The project includes comprehensive development tooling:
211//! ```bash
212//! # Format code
213//! make fmt
214//!
215//! # Lint code
216//! make lint
217//!
218//! # Run tests
219//! make test
220//!
221//! # Generate documentation
222//! make doc
223//!
224//! # Run benchmarks
225//! make bench
226//! ```
227//!
228//! ## โ ๏ธ Important Notes
229//!
230//! - **Testing Required**: Always test with demo account before live trading
231//! - **Risk Management**: Implement proper risk controls in your application
232//! - **Rate Limits**: Respect Deribit's API rate limits
233//! - **Error Handling**: Implement robust error handling for production use
234//!
235//! ## ๐ License & Disclaimer
236//!
237//! Licensed under MIT License. This software is not officially associated with Deribit.
238//! Trading financial instruments carries risk - use at your own discretion.
239//!
240
241pub mod client;
242pub mod config;
243pub mod connection;
244/// FIX protocol constants
245pub mod constants;
246pub mod error;
247pub mod message;
248/// FIX message models and data structures
249pub mod model;
250pub mod session;
251
252pub use client::DeribitFixClient;
253pub use config::DeribitFixConfig;
254pub use error::{DeribitFixError, Result};
255pub use message::admin::*;
256pub use model::*;
257
258/// Re-export commonly used types for convenience
259pub mod prelude {
260
261 pub use crate::{
262 client::DeribitFixClient,
263 config::DeribitFixConfig,
264 config::gen_id,
265 error::{DeribitFixError, Result},
266 message::admin::*,
267 message::market_data::*,
268 message::orders::*,
269 message::security_list::*,
270 model::*,
271 };
272}