use std::collections::BTreeMap; use serde_json::json; use tracing::{info}; use exchanges::gate_swap_rest::GateSwapRest; const ACCESS_KEY: &str = "92847413a17bf5b786c519b1640f359e"; const SECRET_KEY: &str = "b4ebcddbd8df5985940cacf7290a8656f2a9c6554f288cd7b7ebcb5e6f7e7026"; //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; if response_data.code == 200 { // let response_obj: serde_json::Value = serde_json::from_str(response_data.data.as_str()).unwrap(); // // info!("resp={:?}", response_obj.as_object().unwrap()); } else { // error!(?response_data); } } #[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.account_book("usdt".to_string()).await; println!("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 req_data = ret.sub_account().await; let value = json!([ { "remark": "account1", "login_name": "sub_account_for_trades", "user_id": 10001, "state": 1, "create_time": 168888888 }, { "remark": "account2", "login_name": "sub_account_for_trades", "user_id": 10002, "state": 1, "create_time": 168888888 } ]); for account in value.as_array().unwrap() { 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!("{}, {}, {}", remark, login_name, user_id) } } // 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 }