Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions ccxt-exchanges/benches/binance_benchmark.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![allow(clippy::disallowed_methods)]
#![allow(deprecated)]
use ccxt_core::ExchangeConfig;
use ccxt_exchanges::binance::Binance;
use ccxt_exchanges::binance::parser;
Expand Down Expand Up @@ -234,8 +236,8 @@ fn bench_exchange_with_credentials(c: &mut Criterion) {
c.bench_function("create_exchange_with_credentials", |b| {
b.iter(|| {
let config = ExchangeConfig {
api_key: Some("test_key".to_string()),
secret: Some("test_secret".to_string()),
api_key: Some("test_key".to_string().into()),
secret: Some("test_secret".to_string().into()),
..Default::default()
};
let _ = Binance::new(black_box(config));
Expand Down
17 changes: 7 additions & 10 deletions ccxt-exchanges/benches/bybit_benchmark.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![allow(clippy::disallowed_methods)]
#![allow(deprecated)]
//! Bybit exchange performance benchmarks.
//!
//! Benchmarks for Bybit API calls, data parsing, and other operations.
Expand All @@ -19,12 +21,7 @@ fn bench_fetch_ticker(c: &mut Criterion) {

c.bench_function("bybit_fetch_ticker_btc_usdt", |b| {
b.to_async(&rt).iter(|| async {
let _ = bybit
.fetch_ticker(
black_box("BTC/USDT"),
ccxt_core::types::TickerParams::default(),
)
.await;
let _ = bybit.fetch_ticker(black_box("BTC/USDT")).await;
});
});
}
Expand Down Expand Up @@ -75,7 +72,7 @@ fn bench_fetch_ohlcv(c: &mut Criterion) {
|b, timeframe| {
b.to_async(&rt).iter(|| async {
let _ = bybit
.fetch_ohlcv(black_box("BTC/USDT"), timeframe, None, Some(100), None)
.fetch_ohlcv(black_box("BTC/USDT"), timeframe, None, Some(100))
.await;
});
},
Expand Down Expand Up @@ -182,8 +179,8 @@ fn bench_exchange_with_credentials(c: &mut Criterion) {
c.bench_function("bybit_create_exchange_with_credentials", |b| {
b.iter(|| {
let config = ExchangeConfig {
api_key: Some("test_key".to_string()),
secret: Some("test_secret".to_string()),
api_key: Some("test_key".to_string().into()),
secret: Some("test_secret".to_string().into()),
..Default::default()
};
let _ = Bybit::new(black_box(config));
Expand Down Expand Up @@ -215,7 +212,7 @@ fn bench_concurrent_ticker_fetches(c: &mut Criterion) {

let futures: Vec<_> = symbols
.into_iter()
.map(|symbol| bybit.fetch_ticker(symbol, ccxt_core::types::TickerParams::default()))
.map(|symbol| bybit.fetch_ticker(symbol))
.collect();

let _ = futures::future::join_all(futures).await;
Expand Down
17 changes: 6 additions & 11 deletions ccxt-exchanges/benches/hyperliquid_benchmark.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
#![allow(clippy::disallowed_methods)]
#![allow(deprecated)]
//! HyperLiquid exchange performance benchmarks.
//!
//! Benchmarks for HyperLiquid API calls, data parsing, and other operations.
//!
//! Run with: cargo bench --bench hyperliquid_benchmark

use ccxt_exchanges::hyperliquid::{HyperLiquid, HyperLiquidBuilder};
use ccxt_exchanges::hyperliquid::HyperLiquidBuilder;
use criterion::{BenchmarkId, Criterion, black_box, criterion_group, criterion_main};
use serde_json::json;
use tokio::runtime::Runtime;
Expand All @@ -21,12 +23,7 @@ fn bench_fetch_ticker(c: &mut Criterion) {

c.bench_function("hyperliquid_fetch_ticker_btc_usdc", |b| {
b.to_async(&rt).iter(|| async {
let _ = hyperliquid
.fetch_ticker(
black_box("BTC/USDC:USDC"),
ccxt_core::types::TickerParams::default(),
)
.await;
let _ = hyperliquid.fetch_ticker(black_box("BTC/USDC:USDC")).await;
});
});
}
Expand Down Expand Up @@ -88,7 +85,7 @@ fn bench_fetch_ohlcv(c: &mut Criterion) {
|b, timeframe| {
b.to_async(&rt).iter(|| async {
let _ = hyperliquid
.fetch_ohlcv(black_box("BTC/USDC:USDC"), timeframe, None, Some(100), None)
.fetch_ohlcv(black_box("BTC/USDC:USDC"), timeframe, None, Some(100))
.await;
});
},
Expand Down Expand Up @@ -231,9 +228,7 @@ fn bench_concurrent_ticker_fetches(c: &mut Criterion) {

let futures: Vec<_> = symbols
.into_iter()
.map(|symbol| {
hyperliquid.fetch_ticker(symbol, ccxt_core::types::TickerParams::default())
})
.map(|symbol| hyperliquid.fetch_ticker(symbol))
.collect();

let _ = futures::future::join_all(futures).await;
Expand Down
17 changes: 7 additions & 10 deletions ccxt-exchanges/benches/okx_benchmark.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![allow(clippy::disallowed_methods)]
#![allow(deprecated)]
//! OKX exchange performance benchmarks.
//!
//! Benchmarks for OKX API calls, data parsing, and other operations.
Expand All @@ -19,12 +21,7 @@ fn bench_fetch_ticker(c: &mut Criterion) {

c.bench_function("okx_fetch_ticker_btc_usdt", |b| {
b.to_async(&rt).iter(|| async {
let _ = okx
.fetch_ticker(
black_box("BTC/USDT"),
ccxt_core::types::TickerParams::default(),
)
.await;
let _ = okx.fetch_ticker(black_box("BTC/USDT")).await;
});
});
}
Expand Down Expand Up @@ -75,7 +72,7 @@ fn bench_fetch_ohlcv(c: &mut Criterion) {
|b, timeframe| {
b.to_async(&rt).iter(|| async {
let _ = okx
.fetch_ohlcv(black_box("BTC/USDT"), timeframe, None, Some(100), None)
.fetch_ohlcv(black_box("BTC/USDT"), timeframe, None, Some(100))
.await;
});
},
Expand Down Expand Up @@ -181,8 +178,8 @@ fn bench_exchange_with_credentials(c: &mut Criterion) {
c.bench_function("okx_create_exchange_with_credentials", |b| {
b.iter(|| {
let config = ExchangeConfig {
api_key: Some("test_key".to_string()),
secret: Some("test_secret".to_string()),
api_key: Some("test_key".to_string().into()),
secret: Some("test_secret".to_string().into()),
..Default::default()
};
let _ = Okx::new(black_box(config));
Expand Down Expand Up @@ -214,7 +211,7 @@ fn bench_concurrent_ticker_fetches(c: &mut Criterion) {

let futures: Vec<_> = symbols
.into_iter()
.map(|symbol| okx.fetch_ticker(symbol, ccxt_core::types::TickerParams::default()))
.map(|symbol| okx.fetch_ticker(symbol))
.collect();

let _ = futures::future::join_all(futures).await;
Expand Down
26 changes: 19 additions & 7 deletions ccxt-exchanges/src/binance/auth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ mod tests {
let signature = auth.sign(query);
assert!(signature.is_ok());

let sig = signature.unwrap();
let sig = signature.expect("Signature failed");
assert!(!sig.is_empty());
assert_eq!(sig.len(), 64); // HMAC-SHA256 produces 64 hex characters
}
Expand All @@ -234,9 +234,12 @@ mod tests {
let signed = auth.sign_params(&params);
assert!(signed.is_ok());

let signed_params = signed.unwrap();
let signed_params = signed.expect("Sign params failed");
assert!(signed_params.contains_key("signature"));
assert_eq!(signed_params.get("symbol").unwrap(), "BTCUSDT");
assert_eq!(
signed_params.get("symbol").expect("Missing symbol"),
"BTCUSDT"
);
}

#[test]
Expand All @@ -248,12 +251,18 @@ mod tests {
let signed = auth.sign_with_timestamp(&params, timestamp, Some(5000));
assert!(signed.is_ok());

let signed_params = signed.unwrap();
let signed_params = signed.expect("Sign timestamp failed");
assert!(signed_params.contains_key("timestamp"));
assert!(signed_params.contains_key("recvWindow"));
assert!(signed_params.contains_key("signature"));
assert_eq!(signed_params.get("timestamp").unwrap(), "1234567890");
assert_eq!(signed_params.get("recvWindow").unwrap(), "5000");
assert_eq!(
signed_params.get("timestamp").expect("Missing timestamp"),
"1234567890"
);
assert_eq!(
signed_params.get("recvWindow").expect("Missing recvWindow"),
"5000"
);
}

#[test]
Expand All @@ -275,7 +284,10 @@ mod tests {
auth.add_auth_headers(&mut headers);

assert!(headers.contains_key("X-MBX-APIKEY"));
assert_eq!(headers.get("X-MBX-APIKEY").unwrap(), "my_api_key");
assert_eq!(
headers.get("X-MBX-APIKEY").expect("Missing header"),
"my_api_key"
);
}

#[test]
Expand Down
30 changes: 23 additions & 7 deletions ccxt-exchanges/src/binance/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -492,7 +492,11 @@ mod tests {
fn test_builder_api_key() {
let builder = BinanceBuilder::new().api_key("test-key");
assert_eq!(
builder.config.api_key.as_ref().map(|s| s.expose_secret()),
builder
.config
.api_key
.as_ref()
.map(ccxt_core::SecretString::expose_secret),
Some("test-key")
);
}
Expand All @@ -501,7 +505,11 @@ mod tests {
fn test_builder_secret() {
let builder = BinanceBuilder::new().secret("test-secret");
assert_eq!(
builder.config.secret.as_ref().map(|s| s.expose_secret()),
builder
.config
.secret
.as_ref()
.map(ccxt_core::SecretString::expose_secret),
Some("test-secret")
);
}
Expand Down Expand Up @@ -580,11 +588,19 @@ mod tests {
.default_type(DefaultType::Spot);

assert_eq!(
builder.config.api_key.as_ref().map(|s| s.expose_secret()),
builder
.config
.api_key
.as_ref()
.map(ccxt_core::SecretString::expose_secret),
Some("key")
);
assert_eq!(
builder.config.secret.as_ref().map(|s| s.expose_secret()),
builder
.config
.secret
.as_ref()
.map(ccxt_core::SecretString::expose_secret),
Some("secret")
);
assert!(builder.config.sandbox);
Expand All @@ -598,7 +614,7 @@ mod tests {
let result = BinanceBuilder::new().build();
assert!(result.is_ok());

let binance = result.unwrap();
let binance = result.expect("Failed to build Binance");
assert_eq!(binance.id(), "binance");
assert_eq!(binance.name(), "Binance");
}
Expand Down Expand Up @@ -643,7 +659,7 @@ mod tests {
.build();

assert!(result.is_ok());
let binance = result.unwrap();
let binance = result.expect("Failed to build Binance");

// Verify the TimeSyncManager was created with correct config
let time_sync = binance.time_sync();
Expand All @@ -659,7 +675,7 @@ mod tests {
let result = BinanceBuilder::new().auto_time_sync(false).build();

assert!(result.is_ok());
let binance = result.unwrap();
let binance = result.expect("Failed to build Binance");

// Verify auto_sync is disabled
let time_sync = binance.time_sync();
Expand Down
32 changes: 20 additions & 12 deletions ccxt-exchanges/src/binance/endpoint_router.rs
Original file line number Diff line number Diff line change
Expand Up @@ -477,10 +477,12 @@ mod tests {
#[test]
fn test_rest_endpoint_option_public() {
let binance = create_test_binance();
let mut market = Market::default();
market.id = "BTC-250328-100000-C".to_string();
market.symbol = "BTC/USDT:USDT-250328-100000-C".to_string();
market.market_type = MarketType::Option;
let market = Market {
id: "BTC-250328-100000-C".to_string(),
symbol: "BTC/USDT:USDT-250328-100000-C".to_string(),
market_type: MarketType::Option,
..Default::default()
};

let url = binance.rest_endpoint(&market, EndpointType::Public);
assert!(url.contains("eapi.binance.com"));
Expand All @@ -489,10 +491,12 @@ mod tests {
#[test]
fn test_rest_endpoint_option_private() {
let binance = create_test_binance();
let mut market = Market::default();
market.id = "BTC-250328-100000-C".to_string();
market.symbol = "BTC/USDT:USDT-250328-100000-C".to_string();
market.market_type = MarketType::Option;
let market = Market {
id: "BTC-250328-100000-C".to_string(),
symbol: "BTC/USDT:USDT-250328-100000-C".to_string(),
market_type: MarketType::Option,
..Default::default()
};

let url = binance.rest_endpoint(&market, EndpointType::Private);
assert!(url.contains("eapi.binance.com"));
Expand Down Expand Up @@ -646,8 +650,10 @@ mod tests {
#[test]
fn test_swap_defaults_to_linear_when_not_specified() {
let binance = create_test_binance();
let mut market = Market::default();
market.market_type = MarketType::Swap;
let market = Market {
market_type: MarketType::Swap,
..Default::default()
};
// linear and inverse are None

let url = binance.rest_endpoint(&market, EndpointType::Public);
Expand All @@ -658,8 +664,10 @@ mod tests {
#[test]
fn test_futures_defaults_to_linear_when_not_specified() {
let binance = create_test_binance();
let mut market = Market::default();
market.market_type = MarketType::Futures;
let market = Market {
market_type: MarketType::Futures,
..Default::default()
};
// linear and inverse are None

let url = binance.rest_endpoint(&market, EndpointType::Public);
Expand Down
Loading