Browse Source

修改Okx,Gate订阅测试
修改Okx,Gate订阅数据处理

gepangpang 1 year ago
parent
commit
2f9ce2bede

+ 28 - 1
standard/src/gate_handle.rs

@@ -1,10 +1,11 @@
 use std::str::FromStr;
 use rust_decimal::Decimal;
 use rust_decimal::prelude::FromPrimitive;
+use rust_decimal_macros::dec;
 use tracing::{debug, error};
 use exchanges::response_base::ResponseData;
 use global::trace_stack::TraceStack;
-use crate::{Account, MarketOrder, Order, Position, PositionModeEnum, SpecialDepth, SpecialOrder};
+use crate::{Account, MarketOrder, Order, Position, PositionModeEnum, SpecialDepth, SpecialOrder, SpecialTicker};
 use crate::exchange::ExchangeEnum;
 use crate::handle_info::HandleSwapInfo;
 
@@ -125,6 +126,32 @@ pub fn format_order_item(order: serde_json::Value, ct_val: Decimal) -> Order {
     debug!("format-order-end, gate_handle");
     return rst_order;
 }
+// 处理特殊Ticket信息
+pub fn handle_special_ticker(res_data: ResponseData) -> SpecialDepth {
+    let res_data_str = res_data.data;
+    let res_data_json: serde_json::Value = serde_json::from_str(&*res_data_str).unwrap();
+    format_special_ticker(res_data_json, res_data.label)
+}
+
+pub fn format_special_ticker(data: serde_json::Value, label: String) -> SpecialDepth {
+    let depth_asks = format_depth_items(data["asks"].clone());
+    let depth_bids = format_depth_items(data["bids"].clone());
+    let t = Decimal::from_str(&data["t"].to_string()).unwrap();
+
+    let ap = depth_asks[0].price;
+    let bp = depth_bids[0].price;
+    let aq = depth_asks[0].amount;
+    let bq = depth_bids[0].amount;
+    let mp = (bp + ap) * dec!(0.5);
+    let ticker_info = SpecialTicker { sell: ap, buy: bp, mid_price: mp, t };
+    let depth_info = vec![bp, bq, ap, aq];
+    SpecialDepth {
+        name: label,
+        depth: depth_info,
+        ticker: ticker_info,
+        t,
+    }
+}
 
 // 处理特殊深度数据
 pub fn handle_special_depth(res_data: ResponseData) -> SpecialDepth {

+ 2 - 3
standard/src/handle_info.rs

@@ -49,8 +49,7 @@ impl HandleSwapInfo {
                 binance_handle::handle_special_ticker(res_data)
             }
             ExchangeEnum::GateSwap => {
-                error!("暂未提供此交易所方法!handle_special_ticker:{:?}", exchange);
-                panic!("暂未提供此交易所方法!handle_special_ticker:{:?}", exchange);
+                gate_handle::handle_special_ticker(res_data)
             }
             ExchangeEnum::KucoinSwap => {
                 kucoin_handle::handle_special_ticker(res_data)
@@ -164,7 +163,7 @@ impl HandleSwapInfo {
             ExchangeEnum::OkxSwap => {
                 depth_asks = okx_handle::format_depth_items(res_data_json[0]["asks"].clone());
                 depth_bids = okx_handle::format_depth_items(res_data_json[0]["bids"].clone());
-                t = Decimal::from_str(&res_data_json["seqId"].to_string()).unwrap();
+                t = Decimal::from_str(&res_data_json[0]["seqId"].to_string()).unwrap();
             }
             ExchangeEnum::BitgetSpot => {
                 depth_asks = bitget_spot_handle::format_depth_items(res_data_json[0]["asks"].clone());

+ 192 - 133
standard/tests/exchange_test.rs

@@ -11,17 +11,18 @@ use tracing::{error, trace};
 // use exchanges::binance_spot_ws::{BinanceSpotLogin, BinanceSpotSubscribeType, BinanceSpotWs, BinanceSpotWsType};
 // use exchanges::binance_swap_ws::{BinanceSwapLogin, BinanceSwapSubscribeType, BinanceSwapWs, BinanceSwapWsType};
 // use exchanges::kucoin_swap_ws::{KucoinSwapLogin, KucoinSwapSubscribeType, KucoinSwapWs, KucoinSwapWsType};
-use exchanges::kucoin_spot_ws::{KucoinSpotLogin, KucoinSpotSubscribeType, KucoinSpotWs, KucoinSpotWsType};
-// use exchanges::bitget_spot_ws::{BitgetSpotWs, BitgetSpotSubscribeType, BitgetSpotWsType, BitgetSpotLogin};
-// use exchanges::okx_swap_ws::{OkxSubscribeType, OkxSwapWs, OkxWsType};
+// use exchanges::kucoin_spot_ws::{KucoinSpotLogin, KucoinSpotSubscribeType, KucoinSpotWs, KucoinSpotWsType};
+// use exchanges::gate_swap_ws::{GateSwapLogin, GateSwapSubscribeType, GateSwapWs, GateSwapWsType};
+// use exchanges::bitget_spot_ws::{BitgetSpotLogin, BitgetSpotSubscribeType, BitgetSpotWs, BitgetSpotWsType};
+use exchanges::okx_swap_ws::{OkxSwapLogin, OkxSwapSubscribeType, OkxSwapWs, OkxSwapWsType};
 use exchanges::response_base::ResponseData;
 use standard::exchange::{Exchange, ExchangeEnum};
 // use standard::{binance_spot_handle, Order, Platform, utils};
 // use standard::{binance_handle, Order, Platform, utils};
 // use standard::{kucoin_handle, Order, Platform, utils};
-use standard::{kucoin_spot_handle, Order, Platform, utils};
+// use standard::{gate_handle, Order, Platform, utils};
 // use standard::{bitget_spot_handle, Order, Platform, utils};
-// use standard::{okx_handle, Order, Platform, utils};
+use standard::{okx_handle, Order, Platform, utils};
 
 // 创建实体
 #[allow(dead_code)]
@@ -108,7 +109,7 @@ pub async fn test_new_exchange(exchange: ExchangeEnum, symbol: &str) -> Box<dyn
 }
 
 #[allow(dead_code)]
-pub async fn test_new_exchange_wss<T>(exchange: ExchangeEnum, symbol: &str, subscriber_type: T, mold: &str) where Vec<KucoinSpotSubscribeType>: From<T> {
+pub async fn test_new_exchange_wss<T>(exchange: ExchangeEnum, symbol: &str, subscriber_type: T, mold: &str) where Vec<OkxSwapSubscribeType>: From<T> {
     utils::proxy_handle();
     let account_info = global::account_info::get_account_info("../test_account.toml");
     match exchange {
@@ -292,134 +293,56 @@ pub async fn test_new_exchange_wss<T>(exchange: ExchangeEnum, symbol: &str, subs
             // try_join!(t1).unwrap();
         }
         ExchangeEnum::KucoinSpot => {
-            let symbol_format = utils::format_symbol(symbol.to_string(), "-").to_uppercase();
-            let symbol_back = utils::format_symbol(symbol.to_string(), "_");
-            trace!(symbol_format);
-            let name = format!("kucoin_spot@{}", symbol.to_string().to_lowercase());
-            let (write_tx, write_rx) = futures_channel::mpsc::unbounded();
-            let (read_tx, mut read_rx) = futures_channel::mpsc::unbounded::<ResponseData>();
-            let write_tx_am = Arc::new(Mutex::new(write_tx));
-            let bool_v1 = Arc::new(AtomicBool::new(true));
-
-            let params = KucoinSpotLogin {
-                access_key: account_info.kucoin_access_key,
-                secret_key: account_info.kucoin_secret_key,
-                pass_key: account_info.kucoin_pass,
-            };
-            let mut exchange_wss = if ["depth", "ticker"].contains(&mold) {
-                KucoinSpotWs::new_label(name, false, Option::from(params), KucoinSpotWsType::Public).await
-            } else {
-                KucoinSpotWs::new_label(name, false, Option::from(params), KucoinSpotWsType::Private).await
-            };
-            exchange_wss.set_symbols(vec![symbol_format]);
-            exchange_wss.set_subscribe(subscriber_type.into());
-
-            let mold_arc = Arc::new(mold.to_string());
-            tokio::spawn(async move {
-                let mold_clone = Arc::clone(&mold_arc);
-                loop {
-                    if let Some(data) = read_rx.next().await {
-                        trace!("原始数据 data:{:?}",data);
-                        match mold_clone.as_str() {
-                            "depth" => {
-                                if data.data != "" {
-                                    let result = kucoin_spot_handle::handle_special_depth(data);
-                                    trace!(?result)
-                                }
-                            }
-                            "ticker" => {
-                                if data.data != "" {
-                                    let result = kucoin_spot_handle::handle_special_ticker(data);
-                                    trace!(?result)
-                                }
-                            }
-                            "account" => {
-                                if data.data != "" {
-                                    let result = kucoin_spot_handle::handle_account_info(data, symbol_back.clone());
-                                    trace!(?result)
-                                }
-                            }
-                            "orders" => {
-                                if data.data != "" {
-                                    let result = kucoin_spot_handle::handle_order(data, dec!(1));
-                                    trace!(?result)
-                                }
-                            }
-                            _ => {
-                                error!("没有该命令!mode={}", mold_clone);
-                                panic!("没有该命令!mode={}", mold_clone)
-                            }
-                        }
-                    }
-                }
-            });
-            let t1 = tokio::spawn(async move {
-                //链接
-                let bool_v3_clone = Arc::clone(&bool_v1);
-                exchange_wss.ws_connect_async(bool_v3_clone, &write_tx_am, write_rx, read_tx).await.expect("链接失败(内部一个心跳线程应该已经关闭了)");
-            });
-            try_join!(t1).unwrap();
-        }
-        ExchangeEnum::GateSwap => {
-            error!("该交易所不支持!test_new_exchange_wss:{:?}",exchange);
-            panic!("该交易所不支持!test_new_exchange_wss:{:?}", exchange)
-        }
-        ExchangeEnum::BitgetSpot => {
             // let symbol_format = utils::format_symbol(symbol.to_string(), "-").to_uppercase();
             // let symbol_back = utils::format_symbol(symbol.to_string(), "_");
             // trace!(symbol_format);
-            // let name = format!("bitget_spot@{}", symbol.to_string().to_lowercase());
+            // let name = format!("kucoin_spot@{}", symbol.to_string().to_lowercase());
             // let (write_tx, write_rx) = futures_channel::mpsc::unbounded();
             // let (read_tx, mut read_rx) = futures_channel::mpsc::unbounded::<ResponseData>();
             // let write_tx_am = Arc::new(Mutex::new(write_tx));
             // let bool_v1 = Arc::new(AtomicBool::new(true));
             //
-            // let api_key = env::var("bitget_access_key").unwrap_or("".to_string());
-            // let secret_key = env::var("bitget_secret_key").unwrap_or("".to_string());
-            // let passphrase_key = env::var("bitget_pass_key").unwrap_or("".to_string());
-            // let params = BitgetSpotLogin {
-            //     api_key,
-            //     secret_key,
-            //     passphrase_key,
+            // let params = KucoinSpotLogin {
+            //     access_key: account_info.kucoin_access_key,
+            //     secret_key: account_info.kucoin_secret_key,
+            //     pass_key: account_info.kucoin_pass,
             // };
-            //
             // let mut exchange_wss = if ["depth", "ticker"].contains(&mold) {
-            //     BitgetSpotWs::new_label(name, false, Option::from(params), BitgetSpotWsType::Public)
+            //     KucoinSpotWs::new_label(name, false, Option::from(params), KucoinSpotWsType::Public).await
             // } else {
-            //     BitgetSpotWs::new_label(name, false, Option::from(params), BitgetSpotWsType::Private)
+            //     KucoinSpotWs::new_label(name, false, Option::from(params), KucoinSpotWsType::Private).await
             // };
             // exchange_wss.set_symbols(vec![symbol_format]);
             // exchange_wss.set_subscribe(subscriber_type.into());
             //
             // let mold_arc = Arc::new(mold.to_string());
-            // //读取
             // tokio::spawn(async move {
+            //     let mold_clone = Arc::clone(&mold_arc);
             //     loop {
-            //         let mold_clone = Arc::clone(&mold_arc);
             //         if let Some(data) = read_rx.next().await {
             //             trace!("原始数据 data:{:?}",data);
             //             match mold_clone.as_str() {
             //                 "depth" => {
             //                     if data.data != "" {
-            //                         let result = bitget_spot_handle::handle_special_depth(data);
+            //                         let result = kucoin_spot_handle::handle_special_depth(data);
             //                         trace!(?result)
             //                     }
             //                 }
             //                 "ticker" => {
             //                     if data.data != "" {
-            //                         let result = bitget_spot_handle::handle_special_ticker(data);
+            //                         let result = kucoin_spot_handle::handle_special_ticker(data);
             //                         trace!(?result)
             //                     }
             //                 }
             //                 "account" => {
             //                     if data.data != "" {
-            //                         let result = bitget_spot_handle::handle_account_info(data, symbol_back.clone());
+            //                         let result = kucoin_spot_handle::handle_account_info(data, symbol_back.clone());
             //                         trace!(?result)
             //                     }
             //                 }
             //                 "orders" => {
             //                     if data.data != "" {
-            //                         let result = bitget_spot_handle::handle_order(data, dec!(1));
+            //                         let result = kucoin_spot_handle::handle_order(data, dec!(1));
             //                         trace!(?result)
             //                     }
             //                 }
@@ -438,69 +361,122 @@ pub async fn test_new_exchange_wss<T>(exchange: ExchangeEnum, symbol: &str, subs
             // });
             // try_join!(t1).unwrap();
         }
-        ExchangeEnum::OkxSwap => {
+        ExchangeEnum::GateSwap => {
+            // let symbol_format = utils::format_symbol(symbol.to_string(), "_").to_uppercase();
+            // trace!(symbol_format);
+            // let name = format!("gate_swap@{}", symbol.to_string().to_lowercase());
+            // let (write_tx, write_rx) = futures_channel::mpsc::unbounded();
+            // let (read_tx, mut read_rx) = futures_channel::mpsc::unbounded::<ResponseData>();
+            // let write_tx_am = Arc::new(Mutex::new(write_tx));
+            // let bool_v1 = Arc::new(AtomicBool::new(true));
+            //
+            // let params = GateSwapLogin {
+            //     api_key: account_info.gate_access_key,
+            //     secret: account_info.gate_secret_key,
+            // };
+            // let mut exchange_wss = GateSwapWs::new_label(name, false, Option::from(params), GateSwapWsType::PublicAndPrivate("usdt".to_string()));
+            // exchange_wss.set_symbols(vec![symbol_format.clone()]);
+            // exchange_wss.set_subscribe(subscriber_type.into());
+            //
+            // let mold_arc = Arc::new(mold.to_string());
+            // tokio::spawn(async move {
+            //     let mold_clone = Arc::clone(&mold_arc);
+            //     loop {
+            //         if let Some(data) = read_rx.next().await {
+            //             trace!("原始数据 data:{:?}",data);
+            //             match mold_clone.as_str() {
+            //                 "depth" => {
+            //                     if data.data != "" {
+            //                         let result = gate_handle::handle_special_depth(data);
+            //                         trace!(?result)
+            //                     }
+            //                 }
+            //                 "ticker" => {
+            //                     if data.data != "" {
+            //                         let result = gate_handle::handle_special_ticker(data);
+            //                         trace!(?result)
+            //                     }
+            //                 }
+            //                 "account" => {
+            //                     if data.data != "" {
+            //                         let result = gate_handle::handle_account_info(data, symbol_format.clone());
+            //                         trace!(?result)
+            //                     }
+            //                 }
+            //                 "orders" => {
+            //                     if data.data != "" {
+            //                         let result = gate_handle::handle_order(data, dec!(1));
+            //                         trace!(?result)
+            //                     }
+            //                 }
+            //                 _ => {
+            //                     error!("没有该命令!mode={}", mold_clone);
+            //                     panic!("没有该命令!mode={}", mold_clone)
+            //                 }
+            //             }
+            //         }
+            //     }
+            // });
+            // let t1 = tokio::spawn(async move {
+            //     //链接
+            //     let bool_v3_clone = Arc::clone(&bool_v1);
+            //     exchange_wss.ws_connect_async(bool_v3_clone, &write_tx_am, write_rx, read_tx).await.expect("链接失败(内部一个心跳线程应该已经关闭了)");
+            // });
+            // try_join!(t1).unwrap();
+        }
+        ExchangeEnum::BitgetSpot => {
             // let symbol_format = utils::format_symbol(symbol.to_string(), "-").to_uppercase();
             // let symbol_back = utils::format_symbol(symbol.to_string(), "_");
             // trace!(symbol_format);
-            // let name = format!("okx_usdt_swap@{}", symbol.to_string().to_lowercase());
+            // let name = format!("bitget_spot@{}", symbol.to_string().to_lowercase());
+            // let (write_tx, write_rx) = futures_channel::mpsc::unbounded();
+            // let (read_tx, mut read_rx) = futures_channel::mpsc::unbounded::<ResponseData>();
+            // let write_tx_am = Arc::new(Mutex::new(write_tx));
             // let bool_v1 = Arc::new(AtomicBool::new(true));
             //
-            // let (res_sender, mut res_receiver): (Sender<ResponseData>, Receiver<ResponseData>) = channel(1024);
-            // let mut params: BTreeMap<String, String> = BTreeMap::new();
-            // let access_key = env::var("okx_access_key").unwrap_or("".to_string());
-            // let secret_key = env::var("okx_secret_key").unwrap_or("".to_string());
-            // let passphrase = env::var("okx_passphrase").unwrap_or("".to_string());
-            // params.insert("access_key".to_string(), access_key);
-            // params.insert("secret_key".to_string(), secret_key);
-            // params.insert("pass_key".to_string(), passphrase);
+            // let params = BitgetSpotLogin {
+            //     api_key: account_info.bitget_access_key,
+            //     secret_key: account_info.bitget_secret_key,
+            //     passphrase_key: account_info.bitget_pass,
+            // };
             //
             // let mut exchange_wss = if ["depth", "ticker"].contains(&mold) {
-            //     OkxSwapWs::new_label(name, false, params, OkxWsType::Public, res_sender)
-            // } else if ["account", "orders", "position"].contains(&mold) {
-            //     OkxSwapWs::new_label(name, false, params, OkxWsType::Private, res_sender)
+            //     BitgetSpotWs::new_label(name, false, Option::from(params), BitgetSpotWsType::Public)
             // } else {
-            //     OkxSwapWs::new_label(name, false, params, OkxWsType::Business, res_sender)
+            //     BitgetSpotWs::new_label(name, false, Option::from(params), BitgetSpotWsType::Private)
             // };
-            //
+            // exchange_wss.set_symbols(vec![symbol_format]);
             // exchange_wss.set_subscribe(subscriber_type.into());
             //
-            // let t1 = tokio::spawn(async move {
-            //     exchange_wss.custom_subscribe(bool_v1, vec![symbol_format]).await;
-            // });
             // let mold_arc = Arc::new(mold.to_string());
-            // let t2 = tokio::spawn(async move {
-            //     let mold_clone = Arc::clone(&mold_arc);
+            // //读取
+            // tokio::spawn(async move {
             //     loop {
-            //         tokio::time::sleep(Duration::from_millis(1)).await;
-            //         if let Ok(received) = res_receiver.try_recv() {
+            //         let mold_clone = Arc::clone(&mold_arc);
+            //         if let Some(data) = read_rx.next().await {
+            //             trace!("原始数据 data:{:?}",data);
             //             match mold_clone.as_str() {
             //                 "depth" => {
-            //                     if received.data != "" {
-            //                         let result = okx_handle::handle_special_depth(received);
+            //                     if data.data != "" {
+            //                         let result = bitget_spot_handle::handle_special_depth(data);
             //                         trace!(?result)
             //                     }
             //                 }
             //                 "ticker" => {
-            //                     if received.data != "" {
-            //                         let result = okx_handle::handle_special_ticker(received);
+            //                     if data.data != "" {
+            //                         let result = bitget_spot_handle::handle_special_ticker(data);
             //                         trace!(?result)
             //                     }
             //                 }
             //                 "account" => {
-            //                     if received.data != "" {
-            //                         let result = okx_handle::handle_account_info(received, symbol_back.clone());
-            //                         trace!(?result)
-            //                     }
-            //                 }
-            //                 "position" => {
-            //                     if received.data != "" {
-            //                         let result = okx_handle::handle_position(received, dec!(10));
+            //                     if data.data != "" {
+            //                         let result = bitget_spot_handle::handle_account_info(data, symbol_back.clone());
             //                         trace!(?result)
             //                     }
             //                 }
             //                 "orders" => {
-            //                     if received.data != "" {
-            //                         let result = okx_handle::handle_order(received, dec!(10));
+            //                     if data.data != "" {
+            //                         let result = bitget_spot_handle::handle_order(data, dec!(1));
             //                         trace!(?result)
             //                     }
             //                 }
@@ -512,7 +488,90 @@ pub async fn test_new_exchange_wss<T>(exchange: ExchangeEnum, symbol: &str, subs
             //         }
             //     }
             // });
-            // try_join!(t1, t2).unwrap();
+            // let t1 = tokio::spawn(async move {
+            //     //链接
+            //     let bool_v3_clone = Arc::clone(&bool_v1);
+            //     exchange_wss.ws_connect_async(bool_v3_clone, &write_tx_am, write_rx, read_tx).await.expect("链接失败(内部一个心跳线程应该已经关闭了)");
+            // });
+            // try_join!(t1).unwrap();
+        }
+        ExchangeEnum::OkxSwap => {
+            let symbol_format = utils::format_symbol(symbol.to_string(), "-").to_uppercase();
+            trace!(symbol_format);
+            let name = format!("okx_swap@{}", symbol.to_string().to_lowercase());
+            let (write_tx, write_rx) = futures_channel::mpsc::unbounded();
+            let (read_tx, mut read_rx) = futures_channel::mpsc::unbounded::<ResponseData>();
+            let write_tx_am = Arc::new(Mutex::new(write_tx));
+            let bool_v1 = Arc::new(AtomicBool::new(true));
+
+            let params = OkxSwapLogin {
+                api_key: account_info.okx_access_key,
+                secret_key: account_info.okx_secret_key,
+                passphrase: account_info.okx_pass,
+            };
+
+            let mut exchange_wss = if ["depth", "ticker"].contains(&mold) {
+                OkxSwapWs::new_label(name, false, Option::from(params), OkxSwapWsType::Public)
+            } else if ["account", "orders", "position"].contains(&mold) {
+                OkxSwapWs::new_label(name, false, Option::from(params), OkxSwapWsType::Private)
+            } else {
+                OkxSwapWs::new_label(name, false, Option::from(params), OkxSwapWsType::Business)
+            };
+
+            exchange_wss.set_symbols(vec![symbol_format.clone()]);
+            exchange_wss.set_subscribe(subscriber_type.into());
+
+            let mold_arc = Arc::new(mold.to_string());
+            tokio::spawn(async move {
+                let mold_clone = Arc::clone(&mold_arc);
+                loop {
+                    if let Some(data) = read_rx.next().await {
+                        match mold_clone.as_str() {
+                            "depth" => {
+                                if data.data != "" {
+                                    let result = okx_handle::handle_special_depth(data);
+                                    trace!(?result)
+                                }
+                            }
+                            "ticker" => {
+                                if data.data != "" {
+                                    let result = okx_handle::handle_special_ticker(data);
+                                    trace!(?result)
+                                }
+                            }
+                            "account" => {
+                                if data.data != "" {
+                                    let result = okx_handle::handle_account_info(data, symbol_format.clone());
+                                    trace!(?result)
+                                }
+                            }
+                            "position" => {
+                                if data.data != "" {
+                                    let result = okx_handle::handle_position(data, dec!(10));
+                                    trace!(?result)
+                                }
+                            }
+                            "orders" => {
+                                if data.data != "" {
+                                    let result = okx_handle::handle_order(data, dec!(10));
+                                    trace!(?result)
+                                }
+                            }
+                            _ => {
+                                error!("没有该命令!mode={}", mold_clone);
+                                panic!("没有该命令!mode={}", mold_clone)
+                            }
+                        }
+                    }
+                }
+            });
+
+            let t1 = tokio::spawn(async move {
+                //链接
+                let bool_v3_clone = Arc::clone(&bool_v1);
+                exchange_wss.ws_connect_async(bool_v3_clone, &write_tx_am, write_rx, read_tx).await.expect("链接失败(内部一个心跳线程应该已经关闭了)");
+            });
+            try_join!(t1).unwrap();
         }
         _ => {
             error!("该交易所不支持!test_new_exchange_wss:{:?}",exchange);

+ 83 - 11
standard/tests/gate_handle_test.rs

@@ -1,20 +1,92 @@
 mod exchange_test;
 
-use tracing::{instrument};
-use exchanges::gate_swap_ws::GateSubscribeType;
+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;
+use crate::exchange_test::{test_new_exchange_wss};
 
-const SYMBOL: &str = "BLZ_USDT";
+const SYMBOL: &str = "BTC_USDT";
 
-// 测试获取Exchange实体
-#[tokio::test]
+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_self_exchange() {
+async fn test_get_wss_orders() {
     global::log_utils::init_log_with_trace();
 
-    // let gate_subscribe_type = vec![
-    //     GateSubscribeType::PuFuturesOrderBook
-    // ];
-    // test_new_exchange_wss(ExchangeEnum::KucoinSwap, SYMBOL, gate_subscribe_type, "depth").await;
+    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;
 }

+ 7 - 7
standard/tests/okx_handle_test.rs

@@ -1,11 +1,11 @@
 mod exchange_test;
 
 use tracing::{instrument};
-use exchanges::okx_swap_ws::OkxSubscribeType;
+use exchanges::okx_swap_ws::OkxSwapSubscribeType;
 use standard::exchange::ExchangeEnum;
 use crate::exchange_test::test_new_exchange_wss;
 
-const SYMBOL: &str = "ARB_USDT";
+const SYMBOL: &str = "BTC_USDT";
 
 // 测试订阅深度订阅
 #[tokio::test(flavor = "multi_thread", worker_threads = 4)]
@@ -14,7 +14,7 @@ async fn test_get_wss_depth() {
     global::log_utils::init_log_with_trace();
 
     let okx_subscribe_type = vec![
-        OkxSubscribeType::PuBooks50L2tbt
+        OkxSwapSubscribeType::PuBooks5
     ];
     test_new_exchange_wss(ExchangeEnum::OkxSwap, SYMBOL, okx_subscribe_type, "depth").await;
 }
@@ -26,7 +26,7 @@ async fn test_get_wss_ticker() {
     global::log_utils::init_log_with_trace();
 
     let okx_subscribe_type = vec![
-        OkxSubscribeType::PuBooks5
+        OkxSwapSubscribeType::PuBooks5
     ];
     test_new_exchange_wss(ExchangeEnum::OkxSwap, SYMBOL, okx_subscribe_type, "ticker").await;
 }
@@ -38,7 +38,7 @@ async fn test_get_wss_account() {
     global::log_utils::init_log_with_trace();
 
     let okx_subscribe_type = vec![
-        OkxSubscribeType::PrAccount("USDT".to_string())
+        OkxSwapSubscribeType::PrAccount("USDT".to_string())
     ];
     test_new_exchange_wss(ExchangeEnum::OkxSwap, SYMBOL, okx_subscribe_type, "account").await;
 }
@@ -50,7 +50,7 @@ async fn test_get_wss_position() {
     global::log_utils::init_log_with_trace();
 
     let okx_subscribe_type = vec![
-        OkxSubscribeType::PrPositions
+        OkxSwapSubscribeType::PrPositions
     ];
     test_new_exchange_wss(ExchangeEnum::OkxSwap, SYMBOL, okx_subscribe_type, "position").await;
 }
@@ -62,7 +62,7 @@ async fn test_get_wss_orders() {
     global::log_utils::init_log_with_trace();
 
     let okx_subscribe_type = vec![
-        OkxSubscribeType::PrOrders
+        OkxSwapSubscribeType::PrOrders
     ];
     test_new_exchange_wss(ExchangeEnum::OkxSwap, SYMBOL, okx_subscribe_type, "orders").await;
 }