| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145 |
- 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<String, String> = 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)
- }
|