deribit_base/
lib.rs

1//! # Deribit Base
2//!
3//! A comprehensive Rust library providing common data structures, utilities, and constants
4//! for building Deribit cryptocurrency derivatives trading applications.
5//!
6//! This crate serves as the foundation for all Deribit API client implementations,
7//! supporting FIX 4.4, HTTP REST, and WebSocket protocols with a unified, type-safe interface.
8//!
9//! ## Features
10//!
11//! - **๐Ÿ”ง Complete API Constants**: All Deribit API v2.1.1 configuration values
12//! - **๐Ÿ“Š Trading Data Models**: Orders, positions, market data, and account structures
13//! - **๐Ÿ›ก๏ธ Comprehensive Error Handling**: 100+ official Deribit error codes with categorization
14//! - **๐Ÿ” Cryptographic Utilities**: Secure authentication, checksums, and FIX protocol support
15//! - **โšก Protocol Agnostic**: Compatible with FIX, HTTP REST, and WebSocket implementations
16//! - **๐Ÿงช Fully Tested**: 74 comprehensive unit tests ensuring reliability
17//! - **๐Ÿ“š Complete Documentation**: Extensive API documentation with examples
18//!
19//! ## Supported Protocols
20//!
21//! | Protocol | Version | Status |
22//! |----------|---------|--------|
23//! | **FIX** | 4.4 | โœ… Alpha Support |
24//! | **HTTP REST** | v2.1.1 | โœ… Alpha Support |
25//! | **WebSocket** | v2.1.1 | โœ… Alpha Support |
26//!
27//! ## Supported Assets
28//!
29//! - **Bitcoin (BTC)** - Perpetuals, Futures, Options
30//! - **Ethereum (ETH)** - Perpetuals, Futures, Options
31//! - **Solana (SOL)** - Perpetuals, Futures, Options
32//! - **Stablecoins** - USDC, USDT, EURR
33//!
34//! ## Quick Start
35//!
36//! Add this to your `Cargo.toml`:
37//!
38//! ```toml
39//! [dependencies]
40//! deribit-base = "0.2"
41//! ```
42//!
43//! ### Basic Usage
44//!
45//! The crate provides a comprehensive prelude module that exports all commonly used types:
46//! - API constants for endpoints, rate limits, and configuration
47//! - Error handling with categorized Deribit error codes
48//! - Trading data structures for orders, positions, and market data
49//! - Utility functions for FIX protocol, authentication, and data formatting
50//!
51//! ### FIX Protocol Utilities
52//!
53//! The utils module provides essential functions for FIX protocol integration:
54//! - Secure nonce generation for authentication
55//! - FIX timestamp formatting and parsing
56//! - Message checksum calculation and validation
57//! - Order data conversion to FIX field formats
58//!
59//! ## Module Overview
60//!
61//! ### [`constants`]
62//! Complete set of Deribit API configuration values including:
63//! - API endpoints (production & test)
64//! - Rate limits and timeouts
65//! - Supported currencies and instruments
66//! - Order limits and precision settings
67//! - FIX protocol constants
68//!
69//! ### [`error`]
70//! Comprehensive error handling with:
71//! - 100+ official Deribit error codes
72//! - Error categorization and helper methods
73//! - Serde support for JSON serialization
74//! - Standard Error trait implementations
75//!
76//! ### [`model`]
77//! Protocol-agnostic data structures for:
78//! - **Trading**: Orders, positions, trades, settlements
79//! - **Market Data**: Tickers, order books, instruments, candles
80//! - **Account**: Portfolios, balances, transfers, subaccounts
81//! - **Configuration**: Request/response wrappers, authentication
82//!
83//! ### [`utils`]
84//! Utility functions for:
85//! - **Cryptographic Operations**: Nonce generation, checksums, hashing
86//! - **FIX Protocol**: Message formatting, field conversions, validation
87//! - **Data Processing**: Price/quantity formatting, decimal parsing
88//! - **Logging**: Structured logging setup and configuration
89//!
90//! ## Technical Specifications
91//!
92//! ### Rate Limits
93//! - **Authenticated**: 20 requests/second
94//! - **Unauthenticated**: 10 requests/second
95//! - **WebSocket Subscriptions**: 200 per connection
96//!
97//! ### Order Limits
98//! | Currency | Min Order | Max Order | Price Precision | Amount Precision |
99//! |----------|-----------|-----------|-----------------|------------------|
100//! | BTC | 0.0001 | 1,000,000 | 8 decimals | 4 decimals |
101//! | ETH | 0.001 | 10,000,000 | 4 decimals | 3 decimals |
102//! | SOL | 0.1 | 100,000,000 | 4 decimals | 1 decimal |
103//!
104//! ### Authentication
105//! - **Access Token**: 8 hours (28,800 seconds)
106//! - **Refresh Token**: 30 days (2,592,000 seconds)
107//! - **Refresh Buffer**: 5 minutes before expiration
108//!
109//! ## Error Handling
110//!
111//! The crate provides comprehensive error handling with categorized error codes:
112//! - 100+ official Deribit error codes with descriptive names
113//! - Error categorization methods for different error types
114//! - Automatic conversion between numeric codes and enum variants
115//! - Support for authorization, rate limiting, trading, and validation errors
116//!
117//! ## Testing
118//!
119//! The crate includes comprehensive test coverage with 74 unit tests covering:
120//! - All API constants and their relationships
121//! - Error code conversions and categorization
122//! - Data model serialization and validation
123//! - Utility function correctness and edge cases
124//!
125//! ## Compatibility
126//!
127//! - **Rust Version**: 1.70.0 or higher
128//! - **Deribit API**: v2.1.1
129//! - **FIX Protocol**: 4.4
130//! - **Platforms**: Linux, macOS, Windows
131//!
132//! ## License
133//!
134//! This project is licensed under the MIT License - see the LICENSE file for details.
135//!
136//! ## Links
137//!
138//! - [Deribit API Documentation](https://docs.deribit.com/)
139//! - [FIX 4.4 Specification](https://www.fixtrading.org/)
140//! - [Repository](https://github.com/joaquinbejar/deribit-rs)
141
142/// Constants and configuration settings
143pub mod constants;
144/// Error handling types and utilities
145pub mod error;
146/// Data models for orders, positions, and other trading entities
147pub mod model;
148/// Re-export commonly used types for convenience
149pub mod prelude;
150/// Utility functions and helpers
151pub mod utils;