Skip to content

Commit 8100915

Browse files
committed
refactor: Restructure hpx-transport for improved exchange SDK support
- Introduced a new `exchange.rs` module with the `ExchangeClient` trait and `RestClient` implementation for unified REST and WebSocket interactions. - Added a `rate_limit.rs` module implementing a token bucket rate limiter for managing API request rates. - Enhanced the `auth.rs` module with refined authentication strategies including HMAC and API Key support. - Streamlined error handling in `error.rs` with refined error types for better clarity and maintenance. - Removed redundant modules (`middleware.rs`, `hooks.rs`, `transport.rs`, `http.rs`) to reduce code duplication and confusion. - Updated tests and examples to align with the new architecture and ensure functionality. - Added configuration for `cargo-nextest` to manage flaky tests and retries. - Documented architectural changes and new module responsibilities in `hpx-transport-design.md`.
1 parent 9727317 commit 8100915

19 files changed

Lines changed: 1890 additions & 5414 deletions

.config/nextest.toml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Configuration for cargo-nextest
2+
# https://nexte.st/book/configuration.html
3+
4+
[profile.default]
5+
# Retry flaky tests up to 2 times
6+
retries = 2
7+
8+
# Tests that hit external network (tls.peet.ws) may fail due to network conditions
9+
[[profile.default.overrides]]
10+
filter = "package(hpx-util) & test(/emulation/)"
11+
retries = 3

Cargo.toml

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ members = ["crates/*"]
33
resolver = "3"
44

55
[workspace.package]
6-
version = "0.1.5"
6+
version = "1.0.0"
77
edition = "2024"
88
authors = ["Akagi201 <akagi201@gmail.com>"]
99
license = "Apache-2.0"
@@ -182,10 +182,8 @@ all = "warn"
182182

183183
[workspace.dependencies]
184184
# local crates
185-
fastwebsockets = { path = "crates/fastwebsockets", package = "hpx-fastwebsockets", version = "0.1.5" }
186-
hpx = { path = "crates/hpx", version = "0.1.5" }
187-
hpx-transport = { path = "crates/hpx-transport", version = "0.1.5" }
188-
hpx-util = { path = "crates/hpx-util", version = "0.1.5" }
185+
fastwebsockets = { path = "crates/fastwebsockets", package = "hpx-fastwebsockets", version = "1.0.0" }
186+
hpx = { path = "crates/hpx", version = "1.0.0" }
189187

190188
# external crates
191189
ahash = "0.8.12"
@@ -194,14 +192,14 @@ async-trait = "0.1.80"
194192
axum = "0.8.8"
195193
axum-core = "0.5.6"
196194
base64 = "0.22.1"
197-
boring = { git = "https://github.com/cloudflare/boring.git", rev = "531ac086f45e99fca28a47d501b4f0d7244b9823", version = "5.0.0-alpha.1" }
195+
boring = { git = "https://github.com/cloudflare/boring.git", rev = "5f4cf54cc5a7f488a924f48ea06d334ac121e5ac", version = "5.0.0-alpha.3" }
198196
brotli = "8.0.2"
199-
bytes = "1.11.0"
197+
bytes = "1.11.1"
200198
cookie = "0.18.1"
201-
criterion = "0.8.1"
199+
criterion = "0.8.2"
202200
encoding_rs = "0.8.35"
203201
eyre = "0.6.12"
204-
flate2 = "1.1.8"
202+
flate2 = "1.1.9"
205203
futures = "0.3.31"
206204
futures-channel = "0.3.31"
207205
futures-util = "0.3.31"
@@ -213,7 +211,6 @@ http-body = "1.0.1"
213211
http-body-util = "0.1.3"
214212
http2 = "0.5.11"
215213
httparse = "1.10.1"
216-
httpdate = "1.0.3"
217214
hyper = "1.8.1"
218215
hyper-util = "0.1.20"
219216
ipnet = "2.11.0"
@@ -232,7 +229,6 @@ rand = "0.9.2"
232229
rustls = "0.23.36"
233230
rustls-pemfile = "2.2.0"
234231
rustls-pki-types = "1.14.0"
235-
scc = "3.5.5"
236232
schnellru = "0.2.4"
237233
serde = "1.0.228"
238234
serde_json = "1.0.149"
@@ -250,7 +246,7 @@ system-configuration = "0.7.0"
250246
tempfile = "3.17.1"
251247
thiserror = "2.0.18"
252248
tokio = "1.49.0"
253-
tokio-boring = { git = "https://github.com/cloudflare/boring.git", rev = "531ac086f45e99fca28a47d501b4f0d7244b9823", version = "5.0.0-alpha.1" }
249+
tokio-boring = { git = "https://github.com/cloudflare/boring.git", rev = "5f4cf54cc5a7f488a924f48ea06d334ac121e5ac", version = "5.0.0-alpha.3" }
254250
tokio-rustls = "0.26"
255251
tokio-socks = "0.5.2"
256252
tokio-test = "0.4.5"
@@ -263,10 +259,9 @@ trybuild = "1.0.115"
263259
typed-builder = "0.23.2"
264260
url = "2.5.8"
265261
utf-8 = "0.7.6"
266-
uuid = "1.20.0"
267262
want = "0.3.1"
268-
webpki-root-certs = "1.0.5"
269-
webpki-roots = "1.0.5"
263+
webpki-root-certs = "1.0.6"
264+
webpki-roots = "1.0.6"
270265
windows-registry = "0.6.1"
271266
zstd = "0.13.3"
272267

crates/hpx-transport/Cargo.toml

Lines changed: 11 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -2,35 +2,36 @@
22
name = "hpx-transport"
33
repository.workspace = true
44
version.workspace = true
5-
description = "Transport layer for hpx HTTP client with middleware support"
5+
description = "Exchange SDK toolkit for cryptocurrency trading with authentication, WebSocket, and rate limiting"
66
edition.workspace = true
77
license.workspace = true
88

9-
[package.metadata.cargo-machete]
10-
ignored = ["http-body", "http-body-util", "tower-http"]
11-
129
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
1310

1411
[dependencies]
1512
async-trait = { workspace = true }
1613
bytes.workspace = true
14+
fastwebsockets = { workspace = true, features = ["upgrade", "unstable-split"] }
1715
futures-util.workspace = true
1816
hex.workspace = true
1917
hmac.workspace = true
18+
hpx = { workspace = true, features = [
19+
"ws",
20+
"json",
21+
"tracing",
22+
"boring",
23+
"http1",
24+
"http2",
25+
] }
2026
http = { workspace = true }
21-
http-body = { workspace = true }
22-
http-body-util = { workspace = true }
23-
httpdate.workspace = true
2427
opentelemetry = { workspace = true, features = ["metrics"] }
2528
opentelemetry-otlp = { workspace = true, features = ["grpc-tonic", "metrics"] }
2629
opentelemetry_sdk = { workspace = true, features = ["rt-tokio"] }
2730
parking_lot.workspace = true
28-
rand.workspace = true
29-
scc = { workspace = true }
3031
serde = { workspace = true, features = ["derive"] }
3132
serde_json = { workspace = true }
33+
serde_urlencoded.workspace = true
3234
sha2.workspace = true
33-
simd-json = { workspace = true, optional = true }
3435
thiserror.workspace = true
3536
tokio = { workspace = true, features = [
3637
"time",
@@ -39,41 +40,7 @@ tokio = { workspace = true, features = [
3940
"macros",
4041
"rt-multi-thread",
4142
] }
42-
43-
base64.workspace = true
44-
fastwebsockets = { workspace = true, features = ["upgrade", "unstable-split"] }
45-
hpx = { workspace = true, features = [
46-
"ws",
47-
"json",
48-
"tracing",
49-
"boring",
50-
"http1",
51-
"http2",
52-
] }
53-
tower = { workspace = true, features = [
54-
"util",
55-
"timeout",
56-
"limit",
57-
"retry",
58-
"buffer",
59-
] }
60-
tower-http = { workspace = true, features = [
61-
"trace",
62-
"timeout",
63-
"limit",
64-
"decompression-gzip",
65-
"decompression-deflate",
66-
] }
6743
tracing.workspace = true
68-
url.workspace = true
69-
uuid = { workspace = true, features = ["v4", "serde"] }
70-
71-
[features]
72-
default = ["http", "websocket", "middleware"]
73-
http = []
74-
middleware = []
75-
simd-json = ["dep:simd-json"]
76-
websocket = []
7744

7845
[dev-dependencies]
7946
criterion.workspace = true

0 commit comments

Comments
 (0)