extracted status printing method in HiddenTrailingStop strategy.
added leverage to stop order in HiddenTrailingStop strategy.
This commit is contained in:
parent
a73e59e0e3
commit
551ca054c6
@ -88,6 +88,30 @@ pub struct HiddenTrailingStop {
|
||||
|
||||
|
||||
impl HiddenTrailingStop {
|
||||
fn print_status(&self, position: &Position) {
|
||||
match self.stop_percentages.get(&position.id()) {
|
||||
None => {
|
||||
info!(
|
||||
"\tState: {:?} | PL: {:0.2}{} ({:0.2}%)",
|
||||
position.profit_state().unwrap(),
|
||||
position.pl(),
|
||||
position.pair().quote(),
|
||||
position.pl_perc()
|
||||
);
|
||||
}
|
||||
Some(stop_percentage) => {
|
||||
info!(
|
||||
"\tState: {:?} | PL: {:0.2}{} ({:0.2}%) | Stop: {:0.2}",
|
||||
position.profit_state().unwrap(),
|
||||
position.pl(),
|
||||
position.pair().quote(),
|
||||
position.pl_perc(),
|
||||
stop_percentage
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn update_stop_percentage(&mut self, position: &Position) {
|
||||
if let Some(profit_state) = position.profit_state() {
|
||||
let profit_state_delta = match profit_state {
|
||||
@ -116,15 +140,6 @@ impl HiddenTrailingStop {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
info!(
|
||||
"\tState: {:?} | PL: {:0.2}{} ({:0.2}%) | Stop: {:0.2}",
|
||||
position.profit_state().unwrap(),
|
||||
position.pl(),
|
||||
position.pair().quote(),
|
||||
position.pl_perc(),
|
||||
self.stop_percentages.get(&position.id()).unwrap_or(&0.0)
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -135,7 +150,7 @@ impl Default for HiddenTrailingStop {
|
||||
|
||||
// in percentage
|
||||
let capital_max_loss = 15.0;
|
||||
let capital_min_profit = 9.0;
|
||||
let capital_min_profit = 1.0;
|
||||
let capital_good_profit = capital_min_profit * 2.0;
|
||||
|
||||
let weighted_min_profit = capital_min_profit / leverage;
|
||||
@ -253,6 +268,8 @@ impl PositionStrategy for HiddenTrailingStop {
|
||||
_: &HashMap<u64, Position>,
|
||||
fees: &Vec<TradingFees>,
|
||||
) -> (Position, Option<Vec<Event>>, Option<Vec<ActionMessage>>) {
|
||||
self.print_status(&position);
|
||||
|
||||
let taker_fee = fees
|
||||
.iter()
|
||||
.filter_map(|x| match x {
|
||||
@ -282,6 +299,7 @@ impl PositionStrategy for HiddenTrailingStop {
|
||||
OrderKind::Stop { price: stop_loss_price },
|
||||
position.platform(),
|
||||
position.amount().neg())
|
||||
.with_leverage(Some(self.leverage))
|
||||
.with_metadata(Some(OrderMetadata::new().with_position_id(Some(position.id()))))
|
||||
};
|
||||
let stop_loss_set = *self.stop_loss_flags.entry(position.id()).or_insert(false);
|
||||
|
Loading…
Reference in New Issue
Block a user