Skip to content

Commit

Permalink
Fixes on saving fee (#81)
Browse files Browse the repository at this point in the history
  • Loading branch information
grunch committed May 15, 2023
1 parent 6d7798f commit 9a8bc88
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
5 changes: 3 additions & 2 deletions src/db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -209,8 +209,9 @@ pub async fn update_order_event_id_status(
let mut conn = pool.acquire().await?;
let status = status.to_string();
// We calculate the bot fee
let fee = var("FEE").unwrap().parse::<f64>().unwrap() / 2.0;
let fee = fee * amount as f64;
let fee = var("FEE").unwrap().parse::<f32>().unwrap() / 2.0;
let fee = fee * amount as f32;
let fee = fee.round() as i64;

let rows_affected = sqlx::query!(
r#"
Expand Down
7 changes: 4 additions & 3 deletions src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,7 @@ pub async fn show_hold_invoice(
Ok(())
}

/// Set market order sats amount, this used when a buyer take a sell order
pub async fn set_market_order_sats_amount(
order: &mut Order,
buyer_pubkey: XOnlyPublicKey,
Expand All @@ -324,12 +325,12 @@ pub async fn set_market_order_sats_amount(

// We calculate the bot fee
let fee = var("FEE").unwrap().parse::<f64>().unwrap() / 2.0;
let buyer_total_amount = new_sats_amount as f64 - (fee * new_sats_amount as f64);
let buyer_final_amount = new_sats_amount as f64 - (fee * new_sats_amount as f64);

// We send this data related to the buyer
let order_data = SmallOrder::new(
order.id,
buyer_total_amount as i64,
buyer_final_amount as i64,
order.fiat_code.clone(),
order.fiat_amount,
order.payment_method.clone(),
Expand All @@ -350,7 +351,7 @@ pub async fn set_market_order_sats_amount(
send_dm(client, my_keys, &buyer_pubkey, message).await?;

// Update order with new sats value
order.amount = buyer_total_amount as i64;
order.amount = new_sats_amount;
update_order_event(
pool,
client,
Expand Down

0 comments on commit 9a8bc88

Please sign in to comment.