Expose stock account accessors
This commit is contained in:
@@ -104,6 +104,7 @@ pub struct OrderRuntimeView {
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct PortfolioRuntimeView {
|
||||
pub account_type: &'static str,
|
||||
pub starting_cash: f64,
|
||||
pub units: f64,
|
||||
pub cash: f64,
|
||||
@@ -359,6 +360,7 @@ impl StrategyContext<'_> {
|
||||
let cash = self.portfolio.cash();
|
||||
let total_equity = self.portfolio.total_equity();
|
||||
PortfolioRuntimeView {
|
||||
account_type: "STOCK",
|
||||
starting_cash: self.portfolio.starting_cash(),
|
||||
units: self.portfolio.units(),
|
||||
cash,
|
||||
@@ -386,6 +388,26 @@ impl StrategyContext<'_> {
|
||||
self.portfolio_view()
|
||||
}
|
||||
|
||||
pub fn stock_account(&self) -> PortfolioRuntimeView {
|
||||
self.portfolio_view()
|
||||
}
|
||||
|
||||
pub fn future_account(&self) -> Option<PortfolioRuntimeView> {
|
||||
None
|
||||
}
|
||||
|
||||
pub fn account_by_type(&self, account_type: &str) -> Option<PortfolioRuntimeView> {
|
||||
if account_type.eq_ignore_ascii_case("STOCK") {
|
||||
Some(self.stock_account())
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
pub fn accounts(&self) -> BTreeMap<String, PortfolioRuntimeView> {
|
||||
BTreeMap::from([("STOCK".to_string(), self.stock_account())])
|
||||
}
|
||||
|
||||
pub fn frozen_cash(&self) -> f64 {
|
||||
self.open_orders
|
||||
.iter()
|
||||
|
||||
Reference in New Issue
Block a user