| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192 |
- mod exchange_test;
- use std::collections::BTreeMap;
- use tracing::{instrument, trace};
- use exchanges::gate_swap_rest::GateSwapRest;
- use exchanges::gate_swap_ws::GateSwapSubscribeType;
- use standard::exchange::ExchangeEnum;
- use crate::exchange_test::{test_new_exchange_wss};
- const SYMBOL: &str = "BTC_USDT";
- async fn get_user_id() -> String {
- let account_info = global::account_info::get_account_info("../test_account.toml");
- let mut params: BTreeMap<String, String> = BTreeMap::new();
- let access_key = account_info.gate_access_key;
- let secret_key = account_info.gate_secret_key;
- params.insert("access_key".to_string(), access_key);
- params.insert("secret_key".to_string(), secret_key);
- let mut gate_request = GateSwapRest::new(false, params);
- let res_data = gate_request.wallet_fee().await;
- if res_data.code == "200" {
- let res_data_json: serde_json::Value = serde_json::from_str(&res_data.data).unwrap();
- res_data_json["user_id"].to_string()
- } else {
- "".to_string()
- }
- }
- // 测试订阅深度订阅
- #[tokio::test(flavor = "multi_thread", worker_threads = 4)]
- #[instrument(level = "TRACE")]
- async fn test_get_wss_depth() {
- global::log_utils::init_log_with_trace();
- let gate_subscribe_type = vec![
- GateSwapSubscribeType::PuFuturesOrderBook
- ];
- test_new_exchange_wss(ExchangeEnum::GateSwap, SYMBOL, gate_subscribe_type, "depth").await;
- }
- // 测试订阅Ticker信息
- #[tokio::test(flavor = "multi_thread", worker_threads = 4)]
- #[instrument(level = "TRACE")]
- async fn test_get_wss_ticker() {
- global::log_utils::init_log_with_trace();
- let gate_subscribe_type = vec![
- GateSwapSubscribeType::PuFuturesOrderBook
- ];
- test_new_exchange_wss(ExchangeEnum::GateSwap, SYMBOL, gate_subscribe_type, "ticker").await;
- }
- // 测试订阅Account信息
- #[tokio::test(flavor = "multi_thread", worker_threads = 4)]
- #[instrument(level = "TRACE")]
- async fn test_get_wss_account() {
- global::log_utils::init_log_with_trace();
- let user_id = get_user_id().await;
- trace!(?user_id);
- let gate_subscribe_type = vec![
- GateSwapSubscribeType::PrFuturesBalances(user_id)
- ];
- test_new_exchange_wss(ExchangeEnum::GateSwap, SYMBOL, gate_subscribe_type, "account").await;
- }
- // 测试订阅Position信息
- #[tokio::test(flavor = "multi_thread", worker_threads = 4)]
- #[instrument(level = "TRACE")]
- async fn test_get_wss_position() {
- global::log_utils::init_log_with_trace();
- let user_id = get_user_id().await;
- let gate_subscribe_type = vec![
- GateSwapSubscribeType::PrFuturesPositions(user_id)
- ];
- test_new_exchange_wss(ExchangeEnum::GateSwap, SYMBOL, gate_subscribe_type, "position").await;
- }
- // 测试订阅Orders信息
- #[tokio::test(flavor = "multi_thread", worker_threads = 4)]
- #[instrument(level = "TRACE")]
- async fn test_get_wss_orders() {
- global::log_utils::init_log_with_trace();
- let user_id = get_user_id().await;
- let gate_subscribe_type = vec![
- GateSwapSubscribeType::PrFuturesOrders(user_id)
- ];
- test_new_exchange_wss(ExchangeEnum::GateSwap, SYMBOL, gate_subscribe_type, "orders").await;
- }
|