Skip to content

Commit

Permalink
feat(track): add percent information in portfolio info (#35)
Browse files Browse the repository at this point in the history
  • Loading branch information
willyrgf committed Jan 14, 2023
1 parent b265e03 commit c113a96
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 4 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "mfm"
version = "0.1.22"
version = "0.1.23"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
Expand Down
23 changes: 21 additions & 2 deletions src/rebalancer/cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ use std::ops::{Div, Mul};

use crate::{
cmd,
rebalancer::{self, config::Strategy, generate_asset_rebalances, AssetBalances},
rebalancer::{
self, config::Strategy, generate_asset_rebalances, get_total_quoted_balance, AssetBalances,
},
track,
utils::{blockchain::display_amount_to_float, scalar::BigDecimal},
};
Expand Down Expand Up @@ -141,12 +143,14 @@ async fn wrapped_cmd_info(args: &ArgMatches) {

table.add_row(row![
"Asset",
"Percent",
"Price",
"Balance",
"Quoted In",
"Balance in quoted",
"Amount to trade",
"Quoted amount to trade"
"Quoted amount to trade",
"Current Percent"
]);

let asset_rebalances = generate_asset_rebalances(&config)
Expand All @@ -155,6 +159,15 @@ async fn wrapped_cmd_info(args: &ArgMatches) {
tracing::error!(error = %e);
panic!()
});

let assets_balances: Vec<AssetBalances> = asset_rebalances
.clone()
.iter()
.map(|ar| ar.asset_balances.clone())
.collect();

let total_quoted = get_total_quoted_balance(assets_balances.as_slice());

asset_rebalances.clone().iter().for_each(|ar| {
let balance_of = ar.asset_balances.balance;
let asset = ar.asset_balances.asset.clone();
Expand Down Expand Up @@ -190,12 +203,18 @@ async fn wrapped_cmd_info(args: &ArgMatches) {

table.add_row(row![
asset.name(),
ar.asset_balances.percent(),
price,
balance_of_bd.to_f64().unwrap(),
config.quoted_in(),
amount_in_quoted_bd.to_f64().unwrap(),
ar.display_amount_with_sign(ar.asset_amount_to_trade, decimals),
ar.display_amount_with_sign(ar.quoted_amount_to_trade, asset_quoted_decimals),
(amount_in_quoted_bd.to_f64().unwrap()
/ BigDecimal::from_unsigned_u256(&total_quoted, asset_quoted_decimals.into())
.to_f64()
.unwrap())
* 100.0
]);
});

Expand Down

0 comments on commit c113a96

Please sign in to comment.