ctrader-rs 0.1.2

Rust SDK for the cTrader Open API
Documentation
#![allow(unused)]

/// Convert a pip count to the cTrader relative SL/TP protocol value.
///
/// cTrader relative values are in 1/100000 of a price unit.
/// 1 pip on a 5-decimal pair = 10 points = 0.00010 price units
///         = 0.00010 × 100000 = 10.0 → round to 10000 (because 1 pip = 10 points)
///
/// The simple formula: `pips × 10 × 100` = `pips × 1000` for a standard pair.
///
/// Examples:
/// ```
/// use ctrader::order::pips_to_points;
/// assert_eq!(pips_to_points(50), 500_000);  // 50 pips
/// assert_eq!(pips_to_points(10), 100_000);  // 10 pips
/// ```
///
///
///
pub fn pips_to_points(pips: i64) -> i64 {
    pips * 10 * 1_000
}

/// Convert an absolute price distance to the cTrader relative protocol value.
///
/// `price_distance` — the distance in price units (e.g. 0.0050 for 50 pips on EURUSD).
///
/// Formula: `price_distance × 100_000` rounded to nearest integer.
///
///
///
pub fn price_to_relative(price_distance: f64) -> i64 {
    (price_distance * 100_000.0).round() as i64
}

#[cfg(test)]
mod tests {

    #[tokio::test]
    async fn test() {}
}