#![allow(clippy::disallowed_methods)]
use ccxt_core::ExchangeConfig;
use ccxt_exchanges::binance::Binance;
use rust_decimal::Decimal;
use serde_json::json;
use std::str::FromStr;
#[cfg(test)]
mod margin_tests {
use super::*;
fn create_test_futures() -> Binance {
let config = ExchangeConfig {
api_key: Some(ccxt_core::SecretString::new("test_api_key")),
secret: Some(ccxt_core::SecretString::new("test_secret")),
sandbox: false,
..Default::default()
};
Binance::new_swap(config).unwrap()
}
#[test]
fn test_modify_isolated_position_margin_increase() {
let _binance = create_test_futures();
let symbol = "BTC/USDT";
let amount = Decimal::from_str("100.0").unwrap();
assert!(amount > Decimal::ZERO);
assert!(!symbol.is_empty());
}
#[test]
fn test_modify_isolated_position_margin_decrease() {
let _binance = create_test_futures();
let symbol = "BTC/USDT";
let amount = Decimal::from_str("-50.0").unwrap();
assert!(amount < Decimal::ZERO);
assert!(!symbol.is_empty());
}
#[test]
fn test_modify_isolated_position_margin_with_position_side() {
let _binance = create_test_futures();
let params = json!({
"positionSide": "LONG"
});
assert_eq!(params["positionSide"], "LONG");
}
#[test]
fn test_fetch_position_risk_all() {
let _binance = create_test_futures();
}
#[test]
fn test_fetch_position_risk_single_symbol() {
let _binance = create_test_futures();
let symbol = "BTC/USDT";
assert!(!symbol.is_empty());
}
#[test]
fn test_fetch_leverage_bracket_all() {
let _binance = create_test_futures();
}
#[test]
fn test_fetch_leverage_bracket_single_symbol() {
let _binance = create_test_futures();
let symbol = "BTC/USDT";
assert!(!symbol.is_empty());
}
#[test]
fn test_margin_amount_validation() {
let positive = Decimal::from_str("100.0").unwrap();
let negative = Decimal::from_str("-50.0").unwrap();
let zero = Decimal::ZERO;
assert!(positive > Decimal::ZERO);
assert!(negative < Decimal::ZERO);
assert_eq!(zero, Decimal::ZERO);
assert_eq!(positive.abs(), Decimal::from_str("100.0").unwrap());
assert_eq!(negative.abs(), Decimal::from_str("50.0").unwrap());
}
}
#[cfg(test)]
mod integration_tests {
use super::*;
#[tokio::test]
#[ignore = "Futures margin methods not yet migrated to new modular structure"]
async fn test_modify_margin_integration() {
let _config = ExchangeConfig {
api_key: std::env::var("BINANCE_API_KEY")
.ok()
.map(ccxt_core::SecretString::new),
secret: std::env::var("BINANCE_API_SECRET")
.ok()
.map(ccxt_core::SecretString::new),
sandbox: false,
..Default::default()
};
}
#[tokio::test]
#[ignore = "Futures margin methods not yet migrated to new modular structure"]
async fn test_fetch_position_risk_integration() {
let _config = ExchangeConfig {
api_key: std::env::var("BINANCE_API_KEY")
.ok()
.map(ccxt_core::SecretString::new),
secret: std::env::var("BINANCE_API_SECRET")
.ok()
.map(ccxt_core::SecretString::new),
sandbox: false,
..Default::default()
};
}
#[tokio::test]
#[ignore = "Futures margin methods not yet migrated to new modular structure"]
async fn test_fetch_leverage_bracket_integration() {
let _config = ExchangeConfig {
api_key: std::env::var("BINANCE_API_KEY")
.ok()
.map(ccxt_core::SecretString::new),
secret: std::env::var("BINANCE_API_SECRET")
.ok()
.map(ccxt_core::SecretString::new),
sandbox: false,
..Default::default()
};
}
#[tokio::test]
#[ignore = "Futures margin methods not yet migrated to new modular structure"]
async fn test_margin_management_workflow() {
let _config = ExchangeConfig {
api_key: std::env::var("BINANCE_API_KEY")
.ok()
.map(ccxt_core::SecretString::new),
secret: std::env::var("BINANCE_API_SECRET")
.ok()
.map(ccxt_core::SecretString::new),
sandbox: false,
..Default::default()
};
}
}