diff --git a/src/future/table_mgmt.rs b/src/future/table_mgmt.rs index f1ddff6..65a6e1e 100644 --- a/src/future/table_mgmt.rs +++ b/src/future/table_mgmt.rs @@ -202,24 +202,23 @@ async fn update_repeat_task( let exit_trade_fee = decimal_mul(decimal_mul(position_size, element.current_price), trade_fee); let fee_total = decimal_add(entry_trade_fee, exit_trade_fee); let initial_margin = decimal_add(decimal_mul(position_size, element.entry_price), entry_trade_fee); - - let mut profit = Decimal::new(0, 8); + let mut unrealized_pnl = Decimal::new(0, 8); if element.position.contains("Long") { - profit = decimal_sub(decimal_sub(element.current_price, element.entry_price),fee_total); + unrealized_pnl = decimal_sub(decimal_mul(decimal_sub(element.current_price, element.entry_price), position_size), fee_total); } else { - profit = decimal_sub(decimal_sub(element.entry_price, element.current_price),fee_total); + unrealized_pnl = decimal_sub(decimal_mul(decimal_sub(element.entry_price, element.current_price), position_size), fee_total); } - let mut pure_profit_percent = (profit.to_f64().unwrap() - / initial_margin.to_f64().unwrap()) + let mut pure_profit_percent = (unrealized_pnl.to_f64().unwrap() + / decimal_add(initial_margin, unrealized_pnl).to_f64().unwrap()) * 100.0; pure_profit_percent = (pure_profit_percent * 100.0).round() / 100.0; // Rounding update_record_build.push(element.id.to_string()); // id update_record_build.push(price.to_string()); // current_price - update_record_build.push(decimal_add(profit, element.used_usdt).to_string()); //expected_get_usdt - update_record_build.push(profit.to_string()); // expected_usdt_profit + update_record_build.push(decimal_add(unrealized_pnl, element.used_usdt).to_string()); //expected_get_usdt + update_record_build.push(unrealized_pnl.to_string()); // expected_usdt_profit update_record_build.push(pure_profit_percent.to_string()); // pure_profit_percent if element.minimum_profit_percent > pure_profit_percent {