Skip to content

Commit

Permalink
safeguard: Make minimum required gain configurable
Browse files Browse the repository at this point in the history
This change also makes the minimum required gain that a position must
have in order to be considered for stop-loss order creation
configurable. We keep the default of 5%.
  • Loading branch information
d-e-s-o committed Feb 16, 2024
1 parent 9abf3a9 commit fb90f37
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions ext/safeguard.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,6 @@ use tracing_subscriber::fmt::time::SystemTime;
use tracing_subscriber::FmtSubscriber;


/// The minimum total unrealized gain on a position to consider creating
/// a stop-loss order.
const MIN_GAIN_PERCENT: usize = 5;
/// The minimum markup for the limit price, expressed in basis points
/// (i.e., 100th of a percent).
const LIMIT_ORDER_MARKUP: usize = 10;
Expand All @@ -67,6 +64,10 @@ struct Args {
/// creation.
#[clap(short, long)]
min_value: Option<usize>,
/// The minimum gain a position needs to have for it to be considered
/// for stop-loss order creation.
#[clap(short = 'g', long, default_value = "5")]
min_gain_percent: usize,
/// Increase verbosity (can be supplied multiple times).
#[clap(short = 'v', long = "verbose", global = true, parse(from_occurrences))]
verbosity: usize,
Expand Down Expand Up @@ -169,10 +170,10 @@ fn evaluate_position(
.clone()
.unwrap_or_default()
* 100;
if total_gain < Num::from(MIN_GAIN_PERCENT) {
if total_gain < Num::from(args.min_gain_percent) {
info!(
"total gain ({:.2}%) is below {}%",
total_gain, MIN_GAIN_PERCENT
total_gain, args.min_gain_percent
);
return Ok(())
}
Expand Down

0 comments on commit fb90f37

Please sign in to comment.