Explorar el Código

1、关闭设置持仓模式(无接口) 2、处理推送空数组仓位

JiahengHe hace 1 año
padre
commit
1c552ac536
Se han modificado 2 ficheros con 29 adiciones y 17 borrados
  1. 15 14
      standard/src/bitmart_swap.rs
  2. 14 3
      strategy/src/bitmart_usdt_swap.rs

+ 15 - 14
standard/src/bitmart_swap.rs

@@ -45,25 +45,25 @@ impl BitmartSwap {
         };
         bitmart_swap.market = BitmartSwap::get_market(&mut bitmart_swap).await.unwrap();
         // 修改持仓模式
-        let mode_result = bitmart_swap.set_dual_mode("", true).await;
-        match mode_result {
-            Ok(ok) => {
-                info!("BitmartSwap:设置持仓模式成功!{:?}", ok);
-            }
-            Err(error) => {
-                error!("BitmartSwap:设置持仓模式失败!{:?}", error)
-            }
-        }
-        // 设置持仓杠杆
-        // let lever_rate_result = bitmart_swap.set_dual_leverage("10").await;
-        // match lever_rate_result {
+        // let mode_result = bitmart_swap.set_dual_mode("", true).await;
+        // match mode_result {
         //     Ok(ok) => {
-        //         info!("BitmartSwap:设置持仓杠杆成功!{:?}", ok);
+        //         info!("BitmartSwap:设置持仓模式成功!{:?}", ok);
         //     }
         //     Err(error) => {
-        //         error!("BitmartSwap:设置持仓杠杆失败!{:?}", error)
+        //         error!("BitmartSwap:设置持仓模式失败!{:?}", error)
         //     }
         // }
+        // 设置持仓杠杆
+        let lever_rate_result = bitmart_swap.set_dual_leverage("10").await;
+        match lever_rate_result {
+            Ok(ok) => {
+                info!("BitmartSwap:设置持仓杠杆成功!{:?}", ok);
+            }
+            Err(error) => {
+                error!("BitmartSwap:设置持仓杠杆失败!{:?}", error)
+            }
+        }
 
         return bitmart_swap;
     }
@@ -496,6 +496,7 @@ impl Platform for BitmartSwap {
                         // result_sd.send(result).await.unwrap();
                     }
                     Err(error) => {
+                        info!("撤单失败 order_id {} custom_id {} err {}", order_id, custom_id, error);
                         // 取消失败去查订单。
                         let query_rst = self_clone.get_order_detail(&order_id, &custom_id).await;
                         match query_rst {

+ 14 - 3
strategy/src/bitmart_usdt_swap.rs

@@ -112,14 +112,25 @@ async fn on_private_data(core_arc_clone: Arc<Mutex<Core>>,
 
             // bitmart如果没有仓位不会给0,会给个空数组
             if positions.is_empty() {
+                info!("仓位推送空数组,自行组装空仓位:response: {:?}", response);
                 positions.push(Position {
                     symbol: run_symbol.replace("_", "").to_uppercase(),
                     margin_level: Default::default(),
-                    amount: Default::default(),
+                    amount: Decimal::ZERO,
                     frozen_amount: Default::default(),
-                    price: Default::default(),
+                    price: Decimal::ZERO,
                     profit: Default::default(),
-                    position_mode: PositionModeEnum::Both,
+                    position_mode: PositionModeEnum::Short,
+                    margin: Default::default(),
+                });
+                positions.push(Position {
+                    symbol: run_symbol.replace("_", "").to_uppercase(),
+                    margin_level: Default::default(),
+                    amount: Decimal::ZERO,
+                    frozen_amount: Default::default(),
+                    price: Decimal::ZERO,
+                    profit: Default::default(),
+                    position_mode: PositionModeEnum::Long,
                     margin: Default::default(),
                 });
             }