Expand description
Time synchronization manager for Binance API.
This module provides a thread-safe time synchronization mechanism that caches the time offset between local system time and Binance server time. This optimization reduces the number of network round-trips for signed API requests from 2 to 1.
§Overview
When making signed requests to Binance, a timestamp is required. Previously,
each signed request required fetching the server time first. With TimeSyncManager,
the time offset is cached and used to calculate server timestamps locally.
§Example
use ccxt_exchanges::binance::time_sync::{TimeSyncConfig, TimeSyncManager};
use std::time::Duration;
// Create with default configuration
let manager = TimeSyncManager::new();
// Or with custom configuration
let config = TimeSyncConfig {
sync_interval: Duration::from_secs(60),
auto_sync: true,
max_offset_drift: 3000,
};
let manager = TimeSyncManager::with_config(config);
// Simulate receiving server time and updating offset
let server_time = 1704110400000i64; // Example server timestamp
manager.update_offset(server_time);
// Get estimated server timestamp using cached offset
let estimated_server_time = manager.get_server_timestamp();Structs§
- Time
Sync Config - Time synchronization configuration.
- Time
Sync Manager - Thread-safe time synchronization manager.