renamed orderstrategy methods, debug in position manager
This commit is contained in:
parent
12c9918d2c
commit
7d639d1b4c
@ -45,10 +45,10 @@ pub trait OrderStrategy: DynClone + Send + Sync {
|
|||||||
fn name(&self) -> String;
|
fn name(&self) -> String;
|
||||||
/// This method is called when the OrderManager checks the open orders on a new tick.
|
/// This method is called when the OrderManager checks the open orders on a new tick.
|
||||||
/// It should manage if some orders have to be closed or keep open.
|
/// It should manage if some orders have to be closed or keep open.
|
||||||
fn on_update(&self);
|
fn on_open_order(&self);
|
||||||
/// This method is called when the OrderManager is requested to close
|
/// This method is called when the OrderManager is requested to close
|
||||||
/// a position that has an open order associated to it.
|
/// a position that has an open order associated to it.
|
||||||
fn on_position_close(
|
fn on_position_order(
|
||||||
&self,
|
&self,
|
||||||
order: &ActiveOrder,
|
order: &ActiveOrder,
|
||||||
open_position: &Position,
|
open_position: &Position,
|
||||||
@ -75,7 +75,7 @@ impl TrailingStop {
|
|||||||
const BREAK_EVEN_PERC: f64 = 0.01;
|
const BREAK_EVEN_PERC: f64 = 0.01;
|
||||||
const MIN_PROFIT_PERC: f64 = TrailingStop::BREAK_EVEN_PERC + 0.03;
|
const MIN_PROFIT_PERC: f64 = TrailingStop::BREAK_EVEN_PERC + 0.03;
|
||||||
const GOOD_PROFIT_PERC: f64 = TrailingStop::MIN_PROFIT_PERC * 2.5;
|
const GOOD_PROFIT_PERC: f64 = TrailingStop::MIN_PROFIT_PERC * 2.5;
|
||||||
const MAX_LOSS_PERC: f64 = -4.0;
|
const MAX_LOSS_PERC: f64 = -0.5;
|
||||||
|
|
||||||
const TAKER_FEE: f64 = 0.2;
|
const TAKER_FEE: f64 = 0.2;
|
||||||
|
|
||||||
@ -86,6 +86,12 @@ impl TrailingStop {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn update_stop_percentage(&mut self, position: &Position) {
|
fn update_stop_percentage(&mut self, position: &Position) {
|
||||||
|
println!(
|
||||||
|
"State: {:?} | PL%: {:0.2}",
|
||||||
|
position.profit_state(),
|
||||||
|
position.pl_perc()
|
||||||
|
);
|
||||||
|
|
||||||
if let Some(profit_state) = position.profit_state() {
|
if let Some(profit_state) = position.profit_state() {
|
||||||
let profit_state_delta = match profit_state {
|
let profit_state_delta = match profit_state {
|
||||||
PositionProfitState::MinimumProfit => Some(Self::MIN_PROFIT_PERC),
|
PositionProfitState::MinimumProfit => Some(Self::MIN_PROFIT_PERC),
|
||||||
@ -94,6 +100,12 @@ impl TrailingStop {
|
|||||||
};
|
};
|
||||||
|
|
||||||
if let Some(profit_state_delta) = profit_state_delta {
|
if let Some(profit_state_delta) = profit_state_delta {
|
||||||
|
println!(
|
||||||
|
"PL%: {} | Delta: {}",
|
||||||
|
position.pl_perc(),
|
||||||
|
profit_state_delta
|
||||||
|
);
|
||||||
|
|
||||||
let current_stop_percentage = position.pl_perc() - profit_state_delta;
|
let current_stop_percentage = position.pl_perc() - profit_state_delta;
|
||||||
|
|
||||||
match profit_state {
|
match profit_state {
|
||||||
@ -224,7 +236,7 @@ impl PositionStrategy for TrailingStop {
|
|||||||
|
|
||||||
// let's check if we surpassed an existing stop percentage
|
// let's check if we surpassed an existing stop percentage
|
||||||
if let Some(existing_stop_percentage) = self.stop_percentages.get(&position.id()) {
|
if let Some(existing_stop_percentage) = self.stop_percentages.get(&position.id()) {
|
||||||
if existing_stop_percentage < &position.pl_perc() {
|
if existing_stop_percentage <= &position.pl_perc() {
|
||||||
return (position, None, Some(vec![close_message]));
|
return (position, None, Some(vec![close_message]));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -261,14 +273,14 @@ impl OrderStrategy for FastOrderStrategy {
|
|||||||
"Fast order strategy".into()
|
"Fast order strategy".into()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn on_update(&self) {
|
fn on_open_order(&self) {
|
||||||
unimplemented!()
|
unimplemented!()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn on_position_close(
|
fn on_position_order(
|
||||||
&self,
|
&self,
|
||||||
order: &ActiveOrder,
|
order: &ActiveOrder,
|
||||||
active_position: &Position,
|
_: &Position,
|
||||||
order_book: &OrderBook,
|
order_book: &OrderBook,
|
||||||
) -> Result<(Option<Vec<Event>>, Option<Vec<Message>>), BoxError> {
|
) -> Result<(Option<Vec<Event>>, Option<Vec<Message>>), BoxError> {
|
||||||
let mut messages = vec![];
|
let mut messages = vec![];
|
||||||
|
Loading…
Reference in New Issue
Block a user