JiahengHe 1 vuosi sitten
vanhempi
commit
dc47029705

+ 1 - 1
exchanges/Cargo.toml

@@ -20,7 +20,7 @@ base64 = "0.13"
 tokio = { version = "1.31.0", features = ["full"] }
 chrono = "0.4.26"
 hex = "0.4"
-reqwest = { version = "0.11.14", features = ["json"] }
+reqwest = { version = "0.11.14", features = ["socks", "json"] }
 # 解壓縮數據
 flate2 = "1.0"
 

+ 11 - 3
exchanges/src/phemex_swap_rest.rs

@@ -1,7 +1,7 @@
 use std::collections::BTreeMap;
 
 use chrono::Utc;
-use reqwest::Client;
+use reqwest::{Client, Proxy};
 use reqwest::header::HeaderMap;
 use ring::hmac;
 use rust_decimal::Decimal;
@@ -351,8 +351,16 @@ impl PhemexSwapRest {
 
 
         let client = if is_login {
-            proxy::ParsingDetail::http_enable_proxy(Some("phemex"));
-            Client::new()
+            let params = proxy::ParsingDetail::http_enable_proxy(Some("phemex"));
+            let client_re;
+            if params {
+                let proxy_address = "socks5://127.0.0.1:17890"; // 替换为你的 SOCKS5 代理地址
+                let proxy = Proxy::all(proxy_address).unwrap();
+                client_re = Client::builder().proxy(proxy).build().unwrap();
+            } else {
+                client_re =  Client::new()
+            }
+            client_re
         } else {
             proxy::ParsingDetail::http_enable_proxy(None);
             Client::new()

+ 2 - 2
exchanges/src/proxy.rs

@@ -87,8 +87,8 @@ impl ParsingDetail {
         match proxy_address {
             Ok(value) => {
                 //trace!("环境变量读取成功:key:proxy_address , val:{}", value);
-                env::set_var("http_proxy", value.to_string());
-                env::set_var("https_proxy", value.to_string());
+                // env::set_var("http_proxy", value.to_string());
+                // env::set_var("https_proxy", value.to_string());
 
                 let ip_port: Vec<&str> = value.split(":").collect();
                 let parsing_detail = ParsingDetail::new(ip_port[0].to_string(), ip_port[1].to_string());

+ 11 - 6
standard/src/phemex_swap_handle.rs

@@ -27,9 +27,9 @@ pub fn format_account_info(accounts: &Vec<Value>, symbol: &String) -> Account {
         }
         Some(value) => {
             let coin = value["currency"].as_str().unwrap().to_string();
-            let available_balance = Decimal::from_str(value["accountBalanceRv"].as_str().unwrap()).unwrap();
+            let balance = Decimal::from_str(value["accountBalanceRv"].as_str().unwrap()).unwrap();
             let frozen_balance = Decimal::from_str(value["totalUsedBalanceRv"].as_str().unwrap()).unwrap();
-            let balance = available_balance + frozen_balance;
+            let available_balance = balance - frozen_balance;
             Account {
                 coin,
                 balance,
@@ -46,7 +46,14 @@ pub fn format_account_info(accounts: &Vec<Value>, symbol: &String) -> Account {
 // 处理position信息
 pub fn handle_position(res_data: &ResponseData, ct_val: &Decimal) -> Vec<Position> {
     let res_data_json = res_data.data.as_array().unwrap();
-    res_data_json.iter().map(|item| { format_position_item(item, ct_val) }).collect()
+    return res_data_json.iter().filter_map(|item| {
+        let position = format_position_item(item, ct_val);
+        if position.amount == Decimal::ZERO {
+            None
+        } else {
+            Some(position)
+        }
+    }).collect();
 }
 
 pub fn format_position_item(position: &Value, ct_val: &Decimal) -> Position {
@@ -97,9 +104,7 @@ pub fn format_order_item(order: &Value, ct_val: Decimal) -> Order {
 
     let status = order["ordStatus"].as_str().unwrap();
     let custom_status;
-    if vec!["Rejected"].contains(&status) {
-        custom_status = "NULL".to_string()
-    } else if vec!["Filled", "Canceled"].contains(&status) {
+    if vec!["Rejected", "Filled", "Canceled"].contains(&status) {
         custom_status = "REMOVE".to_string()
     } else if vec!["New", "Init", "Created"].contains(&status) {
         custom_status = "NEW".to_string()

+ 1 - 3
strategy/src/phemex_usdt_swap.rs

@@ -140,8 +140,7 @@ async fn on_private_data(core_arc_clone: Arc<Mutex<Core>>,
             let mut position_res = response.clone();
             position_res.data = position_res.data["positions_p"].clone();
             let positions = standard::handle_info::HandleSwapInfo::handle_position(PhemexSwap, &position_res, &ct_val);
-
-            {
+            if positions.len() > 0 {
                 let mut core = core_arc_clone.lock().await;
                 core.update_position(positions).await;
             }
@@ -193,7 +192,6 @@ async fn on_public_data(core_arc_clone: Arc<Mutex<Core>>,
         }
         let special_depth = standard::handle_info::make_special_depth(label.clone(), depth_asks, depth_bids, depth_format.t, depth_format.create_at);
         trace_stack.on_after_format();
-        println!("深度信息 ask length{} bid length{}", depth_asks.len(), depth_bids.len());
         on_special_depth(core_arc_clone, update_flag_u, &response.label, &mut trace_stack, &special_depth).await;
     } else {
         error!("未知推送类型");