瀏覽代碼

币安初版格式化

gepangpang 1 年之前
父節點
當前提交
0c9c6d20b6
共有 2 個文件被更改,包括 34 次插入7 次删除
  1. 28 6
      standard/src/binance_swap.rs
  2. 6 1
      standard/tests/exchange_test.rs

+ 28 - 6
standard/src/binance_swap.rs

@@ -9,7 +9,7 @@ use rust_decimal_macros::dec;
 use serde_json::{json, Value};
 use tokio::sync::mpsc::Sender;
 use tokio::time::Instant;
-use tracing::{error, warn};
+use tracing::{error, info, warn};
 use crate::{Platform, ExchangeEnum, Account, Position, Ticker, Market, Order, OrderCommand, utils, PositionModeEnum};
 use exchanges::binance_swap_rest::BinanceSwapRest;
 use global::trace_stack::TraceStack;
@@ -40,6 +40,28 @@ impl BinanceSwap {
             order_sender,
             error_sender,
         };
+
+        // 修改持仓模式
+        let mode_result = binance_swap.set_dual_mode("", false).await;
+        match mode_result {
+            Ok(ok) => {
+                info!("Binance:设置持仓模式成功!{:?}", ok);
+            }
+            Err(error) => {
+                error!("Binance:设置持仓模式失败!mode_result={}", error)
+            }
+        }
+        // 设置持仓杠杆
+        let lever_rate_result = binance_swap.set_dual_leverage("1").await;
+        match lever_rate_result {
+            Ok(ok) => {
+                info!("Binance:设置持仓杠杆成功!{:?}", ok);
+            }
+            Err(error) => {
+                error!("Binance:设置持仓杠杆失败!{:?}", error)
+            }
+        }
+        // 获取市场信息
         binance_swap.market = BinanceSwap::get_market(&mut binance_swap).await.unwrap_or(binance_swap.market);
         return binance_swap;
     }
@@ -344,15 +366,15 @@ impl Platform for BinanceSwap {
         let mut params = json!({
             "newClientOrderId": custom_id.to_string(),
             "symbol": symbol_format,
-            "price": price.to_string(),
         });
         let size = (amount / ct_val).floor();
         params["quantity"] = json!(size);
         if price.eq(&Decimal::ZERO) {
-            params["orderType"] = json!("MARKET");
+            params["type"] = json!("MARKET");
         } else {
             params["price"] = json!(price.to_string());
-            params["orderType"] = json!("LIMIT");
+            params["type"] = json!("LIMIT");
+            params["timeInForce"] = json!("GTC");
         };
         match origin_side {
             "kd" => {
@@ -364,11 +386,11 @@ impl Platform for BinanceSwap {
                 params["positionSide"] = json!("LONG");
             }
             "kk" => {
-                params["side"] = json!("BUY");
+                params["side"] = json!("SELL");
                 params["positionSide"] = json!("SHORT");
             }
             "pk" => {
-                params["side"] = json!("SELL");
+                params["side"] = json!("BUY");
                 params["positionSide"] = json!("SHORT");
             }
             _ => { error!("下单参数错误"); }

+ 6 - 1
standard/tests/exchange_test.rs

@@ -220,7 +220,12 @@ where
                 api_secret: "".to_string(),
             };
 
-            let mut exchange_wss = BinanceSwapWs::new_label(name, false, Option::from(params), BinanceSwapWsType::PublicAndPrivate);
+
+            let mut exchange_wss = if ["depth", "ticker"].contains(&mold) {
+                BinanceSwapWs::new_label(name, false, Option::from(params), BinanceSwapWsType::Public).await
+            } else {
+                BinanceSwapWs::new_label(name, false, Option::from(params), BinanceSwapWsType::Private).await
+            };
             exchange_wss.set_symbols(vec![symbol_format.clone()]);
             exchange_wss.set_subscribe(subscriber_type.into());
             let bool_v3_clone = Arc::clone(&is_shutdown_arc);