Skip to content

Commit

Permalink
Start on portfolio historyA
Browse files Browse the repository at this point in the history
  • Loading branch information
d-e-s-o committed Jan 8, 2023
1 parent 6e1d090 commit c477c05
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 3 deletions.
55 changes: 55 additions & 0 deletions src/api/v2/account_portfolio.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
// Copyright (C) 2023 The apca Developers
// SPDX-License-Identifier: GPL-3.0-or-later

use num_decimal::Num;


pub struct History {
/// Basis in dollar of the profit loss calculation.
pub base_value: Num,

// - name: timestamp
// type: array of epoch int (in seconds)
// desc: time of each data element, left-labeled (the beginning of time window)
// - name: equity
// type: array of number
// desc: equity value of the account in dollar amount as of the end of each time window
// - name: profit_loss
// type: array of number
// desc: profit/loss in dollar from the base value
// - name: profit_loss_pct
// type: array of number
// desc: profit/loss in percentage from the base value
// - name: base_value
// type: number
// desc: basis in dollar of the profit loss calculation
// - name: timeframe
// desc: time window size of each data element
}


#[cfg(test)]
mod tests {
use super::*;

use serde_json::from_slice as from_json;


/// Make sure that we can parse the reference portfolio history
/// object.
#[test]
fn parse_reference_portfolio_history() {
let serialized = r#"{
"timestamp": [1580826600000, 1580827500000, 1580828400000],
"equity": [27423.73, 27408.19, 27515.97],
"profit_loss": [11.8, -3.74, 104.04],
"profit_loss_pct": [0.000430469507254688, -0.0001364369455197062, 0.0037954277571845543],
"base_value": 27411.93,
"timeframe": "15Min"
}"#;

let history = from_json::<History>(serialized).unwrap();
todo!()
//assert_eq!(amount, Amount::notional(Num::from_str("15.12").unwrap()));
}
}
4 changes: 3 additions & 1 deletion src/api/v2/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (C) 2019-2022 The apca Developers
// Copyright (C) 2019-2023 The apca Developers
// SPDX-License-Identifier: GPL-3.0-or-later

/// Definitions pertaining the user's account.
Expand All @@ -7,6 +7,8 @@ pub mod account;
pub mod account_activities;
/// Definitions pertaining the user's account configuration.
pub mod account_config;
/// Definitions pertaining the account portfolio.
pub mod account_portfolio;
/// Definitions surrounding assets.
pub mod asset;
/// Functionality for listing available assets.
Expand Down
2 changes: 0 additions & 2 deletions src/api/v2/order.rs
Original file line number Diff line number Diff line change
Expand Up @@ -825,8 +825,6 @@ mod tests {

use futures::TryFutureExt;

use serde_json::from_slice as from_json;

use test_log::test;

use uuid::Uuid;
Expand Down

0 comments on commit c477c05

Please sign in to comment.