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
//! Exchange connector definitions.
//!
//! This is the single place where exchange-specific configuration lives.
//! The generic HTTP machinery ([`crate::client::KuCoinClient`]), WS runner
//! ([`crate::ws::runner`]), and data types ([`crate::actors`]) are all
//! exchange-agnostic; connectors wire them to a specific exchange.
//!
//! # Adding a new exchange
//!
//! 1. Add an `<Exchange>Env` enum listing the environment variants (live,
//! testnet, …) and implement `rest_base()` / `ws_base()` on it.
//! 2. Add an `<Exchange>` config struct that holds the credentials and
//! environment, and implement [`ExchangeConfig`] on it.
//! 3. Provide a `rest_client()` method on your struct that returns a
//! [`KuCoinClient`]-equivalent (or the shared [`KuCoinClient`] pointing at
//! the new base URL if the HTTP envelope is compatible).
//! 4. Implement [`crate::actors::ExchangeConnector`] for your WS connector
//! struct in a new `ws/` submodule or alongside it in this file.
//! 5. Re-export the new types from `lib.rs`.
//!
//! # Example — KuCoin Futures
//!
//! ```no_run
//! use exchange_apiws::client::Credentials;
//! use exchange_apiws::connectors::{KuCoin, KucoinEnv};
//! use exchange_apiws::ws::KucoinConnector;
//! use std::sync::Arc;
//!
//! # async fn example() -> exchange_apiws::Result<()> {
//! let kucoin = KuCoin::futures(Credentials::from_env()?);
//! let client = kucoin.rest_client()?;
//!
//! let bal = client.get_balance("USDT").await?;
//! let token = client.get_ws_token_public().await?;
//! let ws = Arc::new(KucoinConnector::new(&token, kucoin.env())?);
//! # Ok(())
//! # }
//! ```
use crate;
// ── Exchange config trait ─────────────────────────────────────────────────────
/// Minimal configuration that every exchange connector must provide.
///
/// Implement this trait to make a new exchange usable with the shared runner
/// and logging infrastructure. Exchange-specific concerns (auth signing,
/// response envelope format) stay inside the connector's own methods and are
/// not part of this trait — they vary too much to unify at this level.
// ── KuCoin ────────────────────────────────────────────────────────────────────
/// KuCoin API environment — selects between Spot, Futures, and Unified.
///
/// Pass this to [`KuCoin::new`], [`KuCoinClient::new`], or
/// [`KucoinConnector::new`][crate::ws::KucoinConnector::new] to route requests
/// to the correct base URL.
// ── KuCoin connector config ───────────────────────────────────────────────────
/// KuCoin connector configuration.
///
/// Bundles [`Credentials`] and [`KucoinEnv`] into a single struct that acts
/// as the entry point for all KuCoin interaction. Use the named constructors
/// ([`KuCoin::futures`], [`KuCoin::spot`], [`KuCoin::unified`]) rather than
/// building a client and env separately.
///
/// ```no_run
/// # use exchange_apiws::client::Credentials;
/// # use exchange_apiws::connectors::KuCoin;
/// let kucoin = KuCoin::futures(Credentials::from_env().unwrap());
/// let client = kucoin.rest_client().unwrap();
/// ```
// ── KuCoinClient::new lives here ──────────────────────────────────────────────
//
// `client.rs` contains only exchange-agnostic HTTP plumbing and knows nothing
// about KuCoin environments. The named constructor `KuCoinClient::new` is
// implemented here (Rust allows impl blocks in any file of the same crate) so
// callers that want a one-liner can still use it without importing `KuCoin`.