use std::collections::BTreeMap; use serde_json::json; use tracing::{info}; use exchanges::bitget_swap_rest::BitgetSwapRest; const ACCESS_KEY: &str = ""; const SECRET_KEY: &str = ""; const PASS_KEY: &str = ""; // 测试账户信息获取 #[tokio::test] async fn rest_get_account_info_test() { global::log_utils::init_log_with_info(); let mut rest = get_rest(); let rep_data = rest.get_account_info().await; info!(?rep_data) } // 下单测试 #[tokio::test] async fn post_order_test() { global::log_utils::init_log_with_info(); let mut rest = get_rest(); let params = json!({ "symbol": "BTCUSDT", "productType": "USDT-FUTURES", "marginMode": "crossed", "marginCoin": "USDT", "size": "0.001", "side": "buy", "tradeSide": "close", "orderType": "market", "clientOid": "1130615113245" }); let response = rest.swap_order(params).await; info!(?response) } // 撤单测试 #[tokio::test] async fn cancel_order_test() { global::log_utils::init_log_with_info(); let mut rest = get_rest(); let params = json!({ "symbol": "ethusdt", "productType": "USDT-FUTURES", "clientOid": "1130615111", }); let response = rest.cancel_order(params).await; info!(?response) } // 获取订单详情测试 #[tokio::test] async fn get_order_test() { global::log_utils::init_log_with_info(); let mut rest = get_rest(); let params = json!({ "symbol": "ETHUSDT", "productType": "USDT-FUTURES", "clientOid": "1130615132", }); let response = rest.get_order(params).await; info!(?response) } // 获取当前的pending订单 #[tokio::test] async fn get_pending_orders_test() { global::log_utils::init_log_with_info(); let mut rest = get_rest(); let response = rest.get_pending_orders().await; info!(?response) } // 设置杠杆测试 #[tokio::test] async fn set_leverage_test() { global::log_utils::init_log_with_info(); let mut rest = get_rest(); let params = json!({ "symbol": "ETHUSDT", "productType": "USDT-FUTURES", "marginCoin": "USDT", "leverage": "5" }); let response = rest.set_leverage(params).await; info!(?response) } // 设置持仓模式 #[tokio::test] async fn set_position_mode_test() { global::log_utils::init_log_with_info(); let mut rest = get_rest(); let params = json!({ "productType": "USDT-FUTURES", "posMode": "hedge_mode", }); let response = rest.set_position_mode(params).await; info!(?response) } // 获取仓位信息 #[tokio::test] async fn get_single_position_test() { global::log_utils::init_log_with_info(); let mut rest = get_rest(); let params = json!({ "productType": "USDT-FUTURES", "symbol": "ETHUSDT", "marginCoin": "USDT" }); let response = rest.get_single_position(params).await; info!(?response) } fn get_rest() -> BitgetSwapRest { let mut btree_map: BTreeMap = BTreeMap::new(); btree_map.insert("access_key".to_string(), ACCESS_KEY.to_string()); btree_map.insert("secret_key".to_string(), SECRET_KEY.to_string()); btree_map.insert("pass_key".to_string(), PASS_KEY.to_string()); BitgetSwapRest::new(false, btree_map) }