Documentation
use std::collections::VecDeque;
use crate::strategy_engine::Strategy;


#[derive(Debug, Clone)]
pub struct Scalping {
    prices: VecDeque<f64>,
}

impl Scalping {
    pub fn new() -> Self {
        Self {
            prices: VecDeque::new(),
        }
    }

    pub fn update_price(&mut self, price: f64) {
        self.prices.push_back(price);
    }
}

impl Strategy for Scalping {
    fn evaluate(&self, price: &f64) -> f64 {
        if self.prices.len() < 2 {
            return 0.0;
        }

        let last_price = self.prices[self.prices.len() - 2];
        if *price > last_price {
            1.0 // 买入信号
        } else if *price < last_price {
            -1.0 // 卖出信号
        } else {
            0.0 // 无信号
        }
    }

    fn calculate_indicator(&self, prices: &Vec<f64>) -> f64 {
        // 计算交易次数作为指标
        let mut trades = 0;
        for i in 1..prices.len() {
            if prices[i] != prices[i - 1] {
                trades += 1;
            }
        }
        trades as f64
    }
}