Account and properties
This commit is contained in:
+23
-2
@@ -1,4 +1,4 @@
|
|||||||
use crate::types::{ActivePosition, WatchListItem};
|
use crate::types::{Account, ActivePosition, WatchListItem};
|
||||||
|
|
||||||
pub trait Formatted {
|
pub trait Formatted {
|
||||||
fn get_formatted(&self) -> Vec<String>;
|
fn get_formatted(&self) -> Vec<String>;
|
||||||
@@ -40,6 +40,27 @@ impl Formatted for ActivePosition {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub struct Property(&'static str, String);
|
||||||
|
|
||||||
|
impl Formatted for Account {
|
||||||
|
fn get_formatted(&self) -> Vec<String> {
|
||||||
|
vec![
|
||||||
|
Property("Equity", format_f64(self.equity)),
|
||||||
|
Property("Liquid", format_f64(self.liquid)),
|
||||||
|
Property("Unreal", format_f64(self.unreal)),
|
||||||
|
Property("Realized", format_f64(self.realized)),
|
||||||
|
Property("Margin", format_f64(self.margin)),
|
||||||
|
]
|
||||||
|
.get_formatted()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Formatted for Property {
|
||||||
|
fn get_formatted(&self) -> Vec<String> {
|
||||||
|
vec![format!("\x1b[91m{}\x1b[0m", self.0), self.1.clone()]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl<T: Formatted> Formatted for Vec<T> {
|
impl<T: Formatted> Formatted for Vec<T> {
|
||||||
fn get_formatted(&self) -> Vec<String> {
|
fn get_formatted(&self) -> Vec<String> {
|
||||||
let mut output = Vec::new();
|
let mut output = Vec::new();
|
||||||
@@ -66,7 +87,7 @@ impl<T: Formatted> Formatted for Vec<T> {
|
|||||||
for (col_idx, col) in row.iter().enumerate() {
|
for (col_idx, col) in row.iter().enumerate() {
|
||||||
let width = widths[col_idx];
|
let width = widths[col_idx];
|
||||||
|
|
||||||
row_out.push_str(&format!("{:>width$}", col, width = width));
|
row_out.push_str(&format!("{:<width$}", col, width = width));
|
||||||
|
|
||||||
if col_idx + 1 != row.len() {
|
if col_idx + 1 != row.len() {
|
||||||
row_out.push_str(" ");
|
row_out.push_str(" ");
|
||||||
|
|||||||
+14
-12
@@ -17,13 +17,15 @@ use pulse_ui::{
|
|||||||
};
|
};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
formatting::{Formatted, apply_padding}, types::{ActivePosition, WatchListItem},
|
formatting::{Formatted, apply_padding},
|
||||||
|
types::{Account, ActivePosition, WatchListItem},
|
||||||
};
|
};
|
||||||
|
|
||||||
pub struct PulseTradeApp {
|
pub struct PulseTradeApp {
|
||||||
command: State<InputState>,
|
command: State<InputState>,
|
||||||
watch_list: State<Vec<WatchListItem>>,
|
watch_list: State<Vec<WatchListItem>>,
|
||||||
active_positions: State<Vec<ActivePosition>>,
|
active_positions: State<Vec<ActivePosition>>,
|
||||||
|
account: State<Account>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl App for PulseTradeApp {
|
impl App for PulseTradeApp {
|
||||||
@@ -147,17 +149,10 @@ impl App for PulseTradeApp {
|
|||||||
),
|
),
|
||||||
(
|
(
|
||||||
LayoutItem::Widget(Size::Flex(1)),
|
LayoutItem::Widget(Size::Flex(1)),
|
||||||
Box::new(
|
Box::new(format![
|
||||||
vec![
|
" ACCOUNT\n{}",
|
||||||
" ACCOUNT",
|
apply_padding(self.account.lock().await.get_formatted()).join("\n")
|
||||||
" Equity: $25,483.21",
|
]),
|
||||||
" Liquid: $11,928.43",
|
|
||||||
" Unreal: +$483.12",
|
|
||||||
" Realized: +$2,182.49",
|
|
||||||
" Margin: 0.00%",
|
|
||||||
]
|
|
||||||
.join("\n"),
|
|
||||||
),
|
|
||||||
),
|
),
|
||||||
]),
|
]),
|
||||||
);
|
);
|
||||||
@@ -207,6 +202,13 @@ async fn main() {
|
|||||||
command: ctx.use_state(InputState::new()),
|
command: ctx.use_state(InputState::new()),
|
||||||
watch_list: ctx.use_state(Vec::new()),
|
watch_list: ctx.use_state(Vec::new()),
|
||||||
active_positions: ctx.use_state(Vec::new()),
|
active_positions: ctx.use_state(Vec::new()),
|
||||||
|
account: ctx.use_state(Account {
|
||||||
|
equity: 25_483.21,
|
||||||
|
liquid: 11_928.43,
|
||||||
|
unreal: 483.12,
|
||||||
|
realized: 2_182.49,
|
||||||
|
margin: 0.0,
|
||||||
|
}),
|
||||||
})
|
})
|
||||||
.await;
|
.await;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user