use crate::InstrumentId;
use serde::{Deserialize, Serialize};
#[derive(Clone, PartialEq, Eq, Debug, Serialize, Deserialize)]
pub struct TargetPosition {
pub instrument: InstrumentId,
pub target_qty: i128,
pub source_signals: Vec<u64>,
}
impl TargetPosition {
pub fn single(instrument: InstrumentId, target_qty: i128) -> Self {
Self {
instrument,
target_qty,
source_signals: Vec::new(),
}
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn single_target_declares_no_lineage() {
let target = TargetPosition::single(InstrumentId::parse("600000.XSHG").unwrap(), 100);
assert!(target.source_signals.is_empty());
let round_trip: TargetPosition =
serde_json::from_str(&serde_json::to_string(&target).unwrap()).unwrap();
assert_eq!(round_trip, target);
assert!(round_trip.source_signals.is_empty());
}
}