rust #10
@ -1,8 +1,8 @@
|
||||
use dyn_clone::DynClone;
|
||||
use log::debug;
|
||||
use std::collections::HashMap;
|
||||
use std::fmt::{Debug, Formatter};
|
||||
|
||||
use dyn_clone::DynClone;
|
||||
|
||||
use crate::events::{Event, EventKind, EventMetadata, Message};
|
||||
use crate::managers::{OrderManager, PositionManager, TrackedPositionsMap};
|
||||
use crate::models::{ExecutedOrder, OrderForm, Position, PositionProfitState};
|
||||
@ -86,7 +86,7 @@ impl PositionStrategy for TrailingStop {
|
||||
position: Position,
|
||||
manager: &PositionManager,
|
||||
) -> (Position, Option<Vec<Event>>, Option<Vec<Message>>) {
|
||||
let mut signals = vec![];
|
||||
let mut messages = vec![];
|
||||
let events = vec![];
|
||||
|
||||
let pl_perc = TrailingStop::net_pl_percentage(position.pl_perc(), TrailingStop::TAKER_FEE);
|
||||
@ -103,7 +103,8 @@ impl PositionStrategy for TrailingStop {
|
||||
} else if TrailingStop::MAX_LOSS_PERC < pl_perc && pl_perc < 0.0 {
|
||||
PositionProfitState::Loss
|
||||
} else {
|
||||
signals.push(Message::ClosePosition {
|
||||
debug!("Inserting close position message...");
|
||||
messages.push(Message::ClosePosition {
|
||||
position: position.clone(),
|
||||
});
|
||||
PositionProfitState::Critical
|
||||
@ -120,7 +121,7 @@ impl PositionStrategy for TrailingStop {
|
||||
return (
|
||||
new_position,
|
||||
(!events.is_empty()).then_some(events),
|
||||
(!signals.is_empty()).then_some(signals),
|
||||
(!messages.is_empty()).then_some(messages),
|
||||
);
|
||||
}
|
||||
}
|
||||
@ -128,7 +129,7 @@ impl PositionStrategy for TrailingStop {
|
||||
return (
|
||||
new_position,
|
||||
(!events.is_empty()).then_some(events),
|
||||
(!signals.is_empty()).then_some(signals),
|
||||
(!messages.is_empty()).then_some(messages),
|
||||
)
|
||||
}
|
||||
};
|
||||
@ -174,7 +175,7 @@ impl PositionStrategy for TrailingStop {
|
||||
return (
|
||||
new_position,
|
||||
(!events.is_empty()).then_some(events),
|
||||
(!signals.is_empty()).then_some(signals),
|
||||
(!messages.is_empty()).then_some(messages),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user