فهرست منبع

添加截取指定精度金额方法和修改coinex下单数量修正

JiahengHe 1 سال پیش
والد
کامیت
218e7c3d33
2فایلهای تغییر یافته به همراه8 افزوده شده و 2 حذف شده
  1. 2 2
      standard/src/coinex_swap.rs
  2. 6 0
      standard/src/utils.rs

+ 2 - 2
standard/src/coinex_swap.rs

@@ -12,7 +12,7 @@ use tokio::spawn;
 use tokio::time::Instant;
 use tracing::{error, info, trace, warn};
 use exchanges::coinex_swap_rest::CoinexSwapRest;
-use crate::{Platform, ExchangeEnum, Account, Position, Ticker, Market, Order, OrderCommand, PositionModeEnum};
+use crate::{Platform, ExchangeEnum, Account, Position, Ticker, Market, Order, OrderCommand, PositionModeEnum, utils};
 use global::trace_stack::TraceStack;
 use crate::utils::get_tick_size;
 
@@ -412,7 +412,7 @@ impl Platform for CoinexSwap {
         let ct_val = self.market.ct_val;
         let order_side;
         let position_side;
-        let size = amount.round_dp(self.market.amount_precision.to_u32().unwrap());
+        let size = utils::truncate_decimal(amount, self.market.amount_precision.to_u32().unwrap());
         if size <= Decimal::ZERO {
             error!("下单数量异常 amount {} amount_precision {} size {}", amount, self.market.amount_precision.to_u32().unwrap(), size);
             return Err(Error::new(ErrorKind::Other, format!("下单数量错误 amount:{}", amount)));

+ 6 - 0
standard/src/utils.rs

@@ -33,6 +33,12 @@ pub fn symbol_enter_mapper(exchange_enum: ExchangeEnum, symbol: &str) -> String
     }
 }
 
+// 截取指定精度的decimal(不会四舍五入)
+pub fn truncate_decimal(amount: Decimal, precision: u32) -> Decimal {
+    let scale = Decimal::new(10i64.pow(precision), 0);
+    (amount * scale).trunc() / scale
+}
+
 // 获取指定精度下的tick_size
 pub fn get_tick_size(precision: u32) -> Decimal {
     return Decimal::new(1, 0) / Decimal::new(10i64.pow(precision), 0);