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