|
|
@@ -17,14 +17,19 @@ use std::net::{TcpStream, ToSocketAddrs};
|
|
|
use std::time::Duration;
|
|
|
use tokio::sync::mpsc::channel;
|
|
|
use tokio::try_join;
|
|
|
+use tracing::{debug, trace};
|
|
|
+use tracing::field::debug;
|
|
|
use exchanges::gate_swap_ws::{GateSubscribeType, GateSwapWs, GateWsType};
|
|
|
|
|
|
|
|
|
#[tokio::test]
|
|
|
async fn test_import() {
|
|
|
+ global::log_utils::init_log_with_trace();
|
|
|
+
|
|
|
+
|
|
|
/*******走代理:根据环境变量配置来决定,如果配置了走代理,没有配置不走*******/
|
|
|
if proxy::ParsingDetail::http_enable_proxy() {
|
|
|
- println!("检测有代理配置,配置走代理")
|
|
|
+ trace!("检测有代理配置,配置走代理");
|
|
|
}
|
|
|
|
|
|
//获取代理
|
|
|
@@ -53,7 +58,7 @@ async fn test_import() {
|
|
|
//okx - Business 频道
|
|
|
// demo_ws_okx_bu().await;
|
|
|
//okx - public 频道
|
|
|
- demo_ws_okx_pu().await;
|
|
|
+ // demo_ws_okx_pu().await;
|
|
|
|
|
|
|
|
|
// demo_so();
|
|
|
@@ -110,7 +115,7 @@ fn demo_so() {
|
|
|
//
|
|
|
// // 检查代理响应是否成功
|
|
|
// if !response.contains("200 Connection established") {
|
|
|
- // println!("Proxy connection failed: {}", response);
|
|
|
+ // trace!("Proxy connection failed: {}", response);
|
|
|
// }
|
|
|
//
|
|
|
// // 从代理连接中获取原始 TCP 流
|
|
|
@@ -127,9 +132,9 @@ fn demo_so() {
|
|
|
//
|
|
|
// // 将读取的数据转换为字符串并打印
|
|
|
// if let Ok(data) = std::str::from_utf8(&buffer[..bytes_read]) {
|
|
|
- // println!("Received data: {}", data);
|
|
|
+ // trace!("Received data: {}", data);
|
|
|
// } else {
|
|
|
- // println!("Received data contains non-UTF8 characters");
|
|
|
+ // trace!("Received data contains non-UTF8 characters");
|
|
|
// }
|
|
|
// }
|
|
|
//
|
|
|
@@ -186,7 +191,7 @@ async fn demo_ws_kucoin_pr() {
|
|
|
btree_map.insert("access_key".to_string(), "6393f3565f0d4500011f846b".to_string());
|
|
|
btree_map.insert("secret_key".to_string(), "9c0df8b7-daaa-493e-a53a-82703067f7dd".to_string());
|
|
|
btree_map.insert("pass_key".to_string(), "b87d055f".to_string());
|
|
|
- println!("----------------------btree_map{:?}", btree_map.clone());
|
|
|
+ trace!("----------------------btree_map{:?}", btree_map.clone());
|
|
|
let (tx, mut rx) = channel(1024);
|
|
|
let mut ku_ws = KuconinSwapWs::new(false, btree_map.clone(),
|
|
|
KuconinWsType::Private, tx).await;
|
|
|
@@ -237,21 +242,21 @@ async fn demo_rest_kucoin() {
|
|
|
|
|
|
let kucoin_exc = KucoinSwapRest::new(false, btree_map);
|
|
|
let res_data = kucoin_exc.get_server_time().await;
|
|
|
- println!("kucoin_exc-rest - get_server_time- {:?}", res_data);
|
|
|
+ trace!("kucoin_exc-rest - get_server_time- {:?}", res_data);
|
|
|
// let res_data = kucoin_exc.get_account("USDT".to_string()).await;
|
|
|
- // println!("kucoin_exc-rest - get_account- {:?}", res_data);
|
|
|
+ // trace!("kucoin_exc-rest - get_account- {:?}", res_data);
|
|
|
// let res_data = kucoin_exc.get_position("XBTUSDM".to_string()).await;
|
|
|
- // println!("kucoin_exc-rest - get_position- {:?}", res_data);
|
|
|
+ // trace!("kucoin_exc-rest - get_position- {:?}", res_data);
|
|
|
// let res_data = kucoin_exc.get_market_details().await;
|
|
|
- // println!("kucoin_exc-rest - get_market_details- {:?}", res_data);
|
|
|
+ // trace!("kucoin_exc-rest - get_market_details- {:?}", res_data);
|
|
|
// let res_data = kucoin_exc.get_ticker("ROSEUSDTM".to_string()).await;
|
|
|
- // println!("kucoin_exc-rest - get_ticker- {:?}", res_data);
|
|
|
+ // trace!("kucoin_exc-rest - get_ticker- {:?}", res_data);
|
|
|
// let res_data = kucoin_exc.get_orders("active".to_string(), "ROSEUSDTM".to_string()).await;
|
|
|
- // println!("kucoin_exc-rest - get_orders- {:?}", res_data);
|
|
|
+ // trace!("kucoin_exc-rest - get_orders- {:?}", res_data);
|
|
|
// let res_data = kucoin_exc.get_positions("USDT".to_string()).await;
|
|
|
- // println!("kucoin_exc-rest - get_positions- {:?}", res_data);
|
|
|
+ // trace!("kucoin_exc-rest - get_positions- {:?}", res_data);
|
|
|
// let res_data = kucoin_exc.get_orders_details("111".to_string(), "".to_string()).await;
|
|
|
- // println!("kucoin_exc-rest - get_orders_details- {:?}", res_data);
|
|
|
+ // trace!("kucoin_exc-rest - get_orders_details- {:?}", res_data);
|
|
|
// let res_data = kucoin_exc.swap_bazaar_order(
|
|
|
// "cs_202309111808".to_string(),
|
|
|
// "ROSEUSDTM".to_string(),
|
|
|
@@ -261,12 +266,12 @@ async fn demo_rest_kucoin() {
|
|
|
// "0.03856".to_string(),
|
|
|
// "limit".to_string(),
|
|
|
// ).await;
|
|
|
- // println!("kucoin_exc-rest - swap_bazaar_order- {:?}
|
|
|
+ // trace!("kucoin_exc-rest - swap_bazaar_order- {:?}
|
|
|
// let res_data = kucoin_exc.cancel_order("12312".to_string(), "".to_string()).await;
|
|
|
- // println!("kucoin_exc-rest - cancel_order- {:?}", res_data);
|
|
|
+ // trace!("kucoin_exc-rest - cancel_order- {:?}", res_data);
|
|
|
|
|
|
// let res_data = kucoin_exc.get_public_token().await;
|
|
|
- // println!("kucoin_exc-rest - get_public_token- {:?}", res_data);
|
|
|
+ // trace!("kucoin_exc-rest - get_public_token- {:?}", res_data);
|
|
|
}
|
|
|
|
|
|
async fn demo_rest_gate() {
|
|
|
@@ -276,19 +281,19 @@ async fn demo_rest_gate() {
|
|
|
|
|
|
let gate_exc = GateSwapRest::new(false, btree_map);
|
|
|
let res_data = gate_exc.get_account("usdt".to_string()).await;
|
|
|
- println!("gate-rest -账户信息{:?}", res_data);
|
|
|
+ trace!("gate-rest -账户信息{:?}", res_data);
|
|
|
// let res_data = gate_exc.get_position("usdt".to_string(), "CYBER_USDT".to_string()).await;
|
|
|
- // println!("gate-rest -持仓信息{:?}", res_data);
|
|
|
+ // trace!("gate-rest -持仓信息{:?}", res_data);
|
|
|
// let res_data = gate_exc.get_ticker("usdt".to_string()).await;
|
|
|
- // println!("gate-rest -ticker{:?}", res_data);
|
|
|
+ // trace!("gate-rest -ticker{:?}", res_data);
|
|
|
// let res_data = gate_exc.get_server_time().await;
|
|
|
- // println!("gate-rest -get_server_time{:?}", res_data);
|
|
|
+ // trace!("gate-rest -get_server_time{:?}", res_data);
|
|
|
// let res_data = gate_exc.get_user_position("usdt".to_string()).await;
|
|
|
- // println!("gate-rest -get_server_time{:?}", res_data);
|
|
|
+ // trace!("gate-rest -get_server_time{:?}", res_data);
|
|
|
// let res_data = gate_exc.get_order_details("usdt".to_string(), "11335522".to_string()).await;
|
|
|
- // println!("gate-rest -get_order_details{:?}", res_data);
|
|
|
+ // trace!("gate-rest -get_order_details{:?}", res_data);
|
|
|
// let res_data = gate_exc.get_orders("usdt".to_string(), "open".to_string()).await;
|
|
|
- // println!("gate-rest -get_orders{:?}", res_data);
|
|
|
+ // trace!("gate-rest -get_orders{:?}", res_data);
|
|
|
// let params = serde_json::json!({
|
|
|
// "contract":"CYBER_USDT",
|
|
|
// "size":-1,
|
|
|
@@ -296,27 +301,27 @@ async fn demo_rest_gate() {
|
|
|
// "tif":"ioc",
|
|
|
// });
|
|
|
// let res_data = gate_exc.take_order("usdt".to_string(), params).await;
|
|
|
- // println!("gate-rest -get_orders{:?}", res_data);
|
|
|
+ // trace!("gate-rest -get_orders{:?}", res_data);
|
|
|
// let res_data = gate_exc.setting_dual_mode("usdt".to_string(), true).await;
|
|
|
- // println!("gate-rest -setting_dual_mode{:?}", res_data);
|
|
|
+ // trace!("gate-rest -setting_dual_mode{:?}", res_data);
|
|
|
// let res_data = gate_exc.setting_dual_leverage("usdt".to_string(),
|
|
|
// "CYBER_USDT".to_string(),
|
|
|
// "20".to_string(),
|
|
|
// ).await;
|
|
|
- // println!("gate-rest -setting_dual_mode{:?}", res_data);
|
|
|
+ // trace!("gate-rest -setting_dual_mode{:?}", res_data);
|
|
|
// let res_data = gate_exc.wallet_transfers("usdt".to_string(),
|
|
|
// "CYBER_USDT".to_string(),
|
|
|
// "20".to_string(),
|
|
|
// ).await;
|
|
|
- // println!("gate-rest -setting_dual_mode{:?}", res_data);
|
|
|
+ // trace!("gate-rest -setting_dual_mode{:?}", res_data);
|
|
|
// let res_data = gate_exc.cancel_order("usdt".to_string(),
|
|
|
// "12345".to_string(),
|
|
|
// ).await;
|
|
|
- // println!("gate-rest -setting_dual_mode{:?}", res_data);
|
|
|
+ // trace!("gate-rest -setting_dual_mode{:?}", res_data);
|
|
|
// let res_data = gate_exc.cancel_orders("usdt".to_string(),
|
|
|
// "CYBER_USDT".to_string(),
|
|
|
// ).await;
|
|
|
- // println!("gate-rest -cancel_orders{:?}", res_data);
|
|
|
+ // trace!("gate-rest -cancel_orders{:?}", res_data);
|
|
|
// let res_data = gate_exc.order(
|
|
|
// "usdt".to_string(),
|
|
|
// "long".to_string(),
|
|
|
@@ -326,7 +331,7 @@ async fn demo_rest_gate() {
|
|
|
// "0.03888".to_string(),
|
|
|
// "t-my-custom-id-001".to_string(),
|
|
|
// ).await;
|
|
|
- // println!("gate-rest -order{:?}", res_data);
|
|
|
+ // trace!("gate-rest -order{:?}", res_data);
|
|
|
}
|
|
|
|
|
|
async fn demo_rest_ba() {
|
|
|
@@ -336,7 +341,7 @@ async fn demo_rest_ba() {
|
|
|
|
|
|
let ba_exc = BinanceUsdtSwapRest::new(false, btree_map);
|
|
|
let res_data = ba_exc.get_account().await;
|
|
|
- println!("币安-rest-获取账户信息{:?}", res_data);
|
|
|
+ trace!("币安-rest-获取账户信息{:?}", res_data);
|
|
|
}
|
|
|
|
|
|
async fn demo_pub_ws_ba() {
|
|
|
@@ -365,7 +370,7 @@ async fn demo_pub_ws_ba() {
|
|
|
fn demo_get_http_proxy() {
|
|
|
//代理地址
|
|
|
let parsing_detail = proxy::ParsingDetail::parsing_environment_variables();
|
|
|
- println!("----代理信息:{:?}", parsing_detail);
|
|
|
+ trace!("----代理信息:{:?}", parsing_detail);
|
|
|
}
|
|
|
|
|
|
|
|
|
@@ -387,9 +392,9 @@ fn handle_connection(mut stream: TcpStream) {
|
|
|
.map(|result| result.unwrap())
|
|
|
.take_while(|line| !line.is_empty())
|
|
|
.collect();
|
|
|
- println!("Request: {:#?}", http_request);
|
|
|
- println!("Request2: {:#?}", http_request[0]);
|
|
|
- println!("Request3: {:#?}", http_request[1]);
|
|
|
+ trace!("Request: {:#?}", http_request);
|
|
|
+ trace!("Request2: {:#?}", http_request[0]);
|
|
|
+ trace!("Request3: {:#?}", http_request[1]);
|
|
|
|
|
|
let (status_line, filename) = if http_request[0] == "GET / HTTP/1.1" {
|
|
|
("HTTP/1.1 200 OK", "hello.html")
|