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
//! The HTTP transport abstraction.
//!
//! [`Transport`] is intentionally minimal: it knows nothing about OKX
//! authentication, endpoints, or response envelopes. It only sends a fully
//! built [`http::Request`] and returns the raw [`http::Response`]. This keeps
//! custom and mock implementations trivial, and lets cross-cutting concerns
//! (retries, logging, rate limiting) be added as wrapper types instead of new
//! trait methods.
//!
//! The trait uses return-position `impl Future` (no `async_trait`), so calling
//! it incurs no boxing or dynamic dispatch — the [`OkxClient`](crate::OkxClient)
//! is generic over `T: Transport`.
use Future;
use Bytes;
pub use ReqwestTransport;
/// The default transport type used as the `OkxClient<T>` type parameter.
///
/// When the `reqwest` feature is enabled this is [`ReqwestTransport`]. Otherwise
/// it is a placeholder that does not implement [`Transport`]; you must then
/// supply your own transport via [`OkxClient::with_transport`](crate::OkxClient::with_transport).
pub type DefaultTransport = ReqwestTransport;
/// See [`DefaultTransport`].
pub type DefaultTransport = UnconfiguredTransport;
/// Placeholder used as the default `OkxClient` transport when no built-in
/// transport feature is enabled. It does not implement [`Transport`].
;
/// An opaque transport-layer error.
///
/// The concrete source error (e.g. `reqwest::Error`) is boxed so it does not
/// leak into this crate's public API.
;
/// Sends HTTP requests on behalf of the client.
///
/// Implementors receive a complete request (URL, method, headers, and body
/// already set, including authentication headers) and return the raw response.
///
/// # Example
///
/// ```
/// use bytes::Bytes;
/// use rust_okx::{Transport, TransportError};
///
/// #[derive(Clone)]
/// struct AlwaysOk;
///
/// impl Transport for AlwaysOk {
/// fn send(
/// &self,
/// _request: http::Request<Bytes>,
/// ) -> impl std::future::Future<Output = Result<http::Response<Bytes>, TransportError>> + Send
/// {
/// async move {
/// Ok(http::Response::builder()
/// .status(200)
/// .body(Bytes::from_static(b"{\"code\":\"0\",\"msg\":\"\",\"data\":[]}"))
/// .unwrap())
/// }
/// }
/// }
/// ```