use std::collections::BTreeMap; use serde_json::json; use tracing::{info}; use exchanges::gate_swap_rest::GateSwapRest; const ACCESS_KEY: &str = ""; const SECRET_KEY: &str = ""; //rest-设置持仓模式 #[tokio::test] async fn rest_cancel_order_all_test() { let _guard = global::log_utils::init_log_with_trace(); let mut ret = get_rest(); let req_data = ret.cancel_order_all().await; println!("okx--设置持仓模式--{:?}", req_data); } //rest-下一个自动单 #[tokio::test] async fn price_order_test() { let _guard = global::log_utils::init_log_with_info(); let mut rest = get_rest(); let mut params = json!({}); params["initial"] = json!({ "contract": "XRP_USDT", "price": "0", "tif": "ioc", "reduce_only": true, // [平多:close_long, 平空:close_short] "auto_size": "close_long" }); params["trigger"] = json!({ // [平多:close-long-position, 平空:close-short-position] "order_type": "close-long-position", // 一般都默认用0 "strategy_type": 0, // [0 - 最新成交价,1 - 标记价格,2 - 指数价格] "price_type": 0, // [1: 引用价格大于等于我们传的价格,2:引用价格小于等于我们传的价格] // 在止损的情况下: // 1 可以理解为向上突破触发价(一般是给空单用) // 2 可以理解为向下突破触发价(一般是给多单用) "rule": 2, // 订单触发价格 "price": "0.5600", }); let response_data = rest.place_price_order("usdt".to_string(), params).await; info!("resp={:?}", response_data.data.to_string()); } #[tokio::test] async fn price_order_cancel_test() { let _guard = global::log_utils::init_log_with_info(); let mut rest = get_rest(); // 这边取消订单只能使用系统返回的 let rst = rest.cancel_price_order("usdt".to_string(), "58002898".to_string()).await; info!(?rst); } //rest-查询合约账户变更历史 #[tokio::test] async fn rest_account_book_test() { let _guard = global::log_utils::init_log_with_trace(); let mut ret = get_rest(); let req_data = ret.wallet_fee().await; // let req_data = ret.account_book("usdt".to_string()).await; info!("okx--查询合约账户变更历史--{:?}", req_data); } //rest-查询子账户列表 #[tokio::test] async fn rest_sub_accounnt() { let _guard = global::log_utils::init_log_with_info(); let mut ret = get_rest(); let response = ret.sub_account().await; let accounts = response.data; let accounts_array = accounts.as_array().unwrap(); // g2024002~g2024101获取方法 // for i in 0..accounts_array.len() { // let account = &accounts_array[i]; // let remark = account.get("remark").unwrap().as_str().unwrap(); // // let login_name = account.get("login_name").unwrap().as_str().unwrap(); // let user_id = account.get("user_id").unwrap().as_i64().unwrap(); // // info!("{},{},{}", i, remark, user_id); // // // let create_rst = ret.create_keys(user_id).await; // // let key = create_rst.data.get("key").unwrap().as_str().unwrap(); // // let secret = create_rst.data.get("secret").unwrap().as_str().unwrap(); // // // // info!("{},{},{}", remark, key, secret) // } // gate111-gate290获取方法 for i in 110..290 { let account = &accounts_array[i]; let remark = account.get("remark").unwrap().as_str().unwrap(); // let login_name = account.get("login_name").unwrap().as_str().unwrap(); let user_id = account.get("user_id").unwrap().as_i64().unwrap(); info!("{},{},{}", i, remark, user_id); // let create_rst = ret.create_keys(user_id).await; // let key = create_rst.data.get("key").unwrap().as_str().unwrap(); // let secret = create_rst.data.get("secret").unwrap().as_str().unwrap(); // // info!("{},{},{}", format!("gate{}",i+1), key, secret) } // let create_rst = ret.create_keys(12574400).await; // let key = create_rst.data.get("key").unwrap().as_str().unwrap(); // let secret = create_rst.data.get("secret").unwrap().as_str().unwrap(); // // info!("{},{},{}", "gate111", key, secret) } // fn get_ws(btree_map: Option) -> GateSwapWs { // let binance_ws = GateSwapWs::new(false, // btree_map, // GateSwapWsType::PublicAndPrivate("usdt".to_string())); // binance_ws // } fn get_rest() -> GateSwapRest { 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()); let ba_exc = GateSwapRest::new(false, btree_map); ba_exc }