1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
// src/utils/finance.rs
//
// Financial calculation utilities for the IG client
use cratePosition;
/// Calculate the Profit and Loss (P&L) for a position based on current market prices
///
/// Thin wrapper over [`Position::pnl_checked`], the single source of truth for
/// position P&L, kept for backwards compatibility.
///
/// # Arguments
///
/// * `position` - The position to calculate P&L for
///
/// # Returns
///
/// * `Option<f64>` - The calculated P&L if market prices are available, None otherwise
///
/// Calculate the percentage return for a position
///
/// # Arguments
///
/// * `position` - The position to calculate percentage return for
///
/// # Returns
///
/// * `Option<f64>` - The calculated percentage return if market prices are available, None otherwise