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
//! # hpx-transport
//!
//! Exchange SDK toolkit for cryptocurrency trading applications.
//!
//! This crate builds on `hpx` to provide exchange-specific functionality:
//!
//! - **Authentication**: API key, HMAC signing, and custom auth strategies
//! - **WebSocket**: Single-task connection with `Connection`/`Handle`/`Stream` split API
//! - **SSE** *(feature `sse`)*: Server-Sent Events transport with auto-reconnection,
//! protocol handlers, and `SseConnection`/`SseHandle`/`SseStream` split API
//! - **Typed Responses**: Generic response wrapper with metadata
//! - **Rate Limiting**: Token bucket rate limiter
//! - **Metrics**: OpenTelemetry metrics integration
//!
//! ## Quick Start
//!
//! ```rust,no_run
//! use hpx_transport::{
//! auth::ApiKeyAuth,
//! exchange::{ExchangeClient, RestClient, RestConfig},
//! };
//!
//! #[tokio::main]
//! async fn main() -> Result<(), Box<dyn std::error::Error>> {
//! let config =
//! RestConfig::new("https://api.example.com").timeout(std::time::Duration::from_secs(30));
//!
//! let auth = ApiKeyAuth::header("X-API-Key", "my-api-key");
//! let client = RestClient::new(config, auth)?;
//!
//! // Use the client...
//! Ok(())
//! }
//! ```
//!
//! ## WebSocket Quick Start (Split API)
//!
//! ```rust,no_run
//! use hpx_transport::websocket::{Connection, Event, WsConfig, handlers::GenericJsonHandler};
//!
//! # async fn example() -> Result<(), Box<dyn std::error::Error>> {
//! let config = WsConfig::new("wss://api.exchange.com/ws");
//! let handler = GenericJsonHandler::new();
//!
//! let connection = Connection::connect_stream(config, handler).await?;
//! let (handle, mut stream) = connection.split();
//!
//! handle.subscribe("trades.BTC").await?;
//! while let Some(event) = stream.next().await {
//! if let Event::Message(msg) = event {
//! println!("Control/unknown message: {:?}", msg.kind);
//! }
//! }
//! # Ok(())
//! # }
//! ```
//!
//! ## Rate Limiting Example
//!
//! ```rust
//! use hpx_transport::rate_limit::RateLimiter;
//!
//! let limiter = RateLimiter::new();
//! limiter.add_limit("orders", 10, 1.0)?; // 10 capacity, 1/sec refill
//!
//! if limiter.try_acquire("orders") {
//! println!("Request allowed");
//! }
//! # Ok::<(), hpx_transport::rate_limit::RateLimitError>(())
//! ```
// Re-export commonly used types
pub use ;
pub use ;
pub use ;
pub use ;
pub use ;
pub use ;