Skip to content

Commit d58af10

Browse files
Add support for having a quantity >1 for a given entry
1 parent 68cc978 commit d58af10

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

src/main.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ struct Asset {
2424
current_price_cents: u32,
2525
// if sell price is None, it isn't sold
2626
sell_price_cents: Option<u32>,
27+
quantity: u32,
2728
}
2829

2930
fn is_asset_sold(asset: &Asset) -> bool {
@@ -58,6 +59,7 @@ fn print_assets(assets: &Vec<Asset>) {
5859
"Current Price",
5960
"Percent Change",
6061
"Sell Price",
62+
"Quantity"
6163
]);
6264

6365
for asset in assets {
@@ -90,6 +92,7 @@ fn print_assets(assets: &Vec<Asset>) {
9092
} else {
9193
"N/A (currently held)".to_string()
9294
},
95+
asset.quantity.to_string(),
9396
]);
9497
}
9598
println!("{table}");
@@ -113,6 +116,9 @@ fn add_asset(connector: &yf::YahooConnector) -> Option<Asset> {
113116
print!("Enter sell price if sold, otherwise enter 'held': ");
114117
let sell_price_raw: String = read!();
115118

119+
print!("Enter quantity: ");
120+
let n: u32 = read!();
121+
116122
let current_price: Option<u32> = get_current_ticker_price(connector, &symbol);
117123
// if I access a string twice I have to make it owned for some reason - IDK
118124
// what that means or if there is a better way
@@ -125,6 +131,7 @@ fn add_asset(connector: &yf::YahooConnector) -> Option<Asset> {
125131
} else {
126132
Some(sell_price_raw.parse().unwrap())
127133
}),
134+
quantity: n,
128135
})
129136
}
130137

0 commit comments

Comments
 (0)