Skip to content

Commit

Permalink
fix: Do not rollover an expired position
Browse files Browse the repository at this point in the history
We need to provide the current timestamp instead of the position expiry, as it would have been otherwise never eligible for rollover.
  • Loading branch information
holzeis committed Sep 19, 2023
1 parent f3fa8db commit 322ab39
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
4 changes: 3 additions & 1 deletion coordinator/src/node/rollover.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,9 @@ async fn check_if_eligible_for_rollover(
if let Some(position) =
positions::Position::get_open_position_by_trader(conn, trader_id.to_string())?
{
if coordinator_commons::is_in_rollover_weekend(position.expiry_timestamp) {
if coordinator_commons::is_in_rollover_weekend(OffsetDateTime::now_utc())
&& !position.is_expired()
{
let next_expiry = coordinator_commons::calculate_next_expiry(OffsetDateTime::now_utc());
if position.expiry_timestamp == next_expiry {
tracing::trace!(%trader_id, position_id=position.id, "Position has already been rolled over");
Expand Down
5 changes: 5 additions & 0 deletions coordinator/src/position/models.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,11 @@ pub struct Position {
}

impl Position {
// Returns true if the position is expired
pub fn is_expired(&self) -> bool {
OffsetDateTime::now_utc() >= self.expiry_timestamp
}

/// Calculates the profit and loss for the coordinator in satoshis
pub fn calculate_coordinator_pnl(&self, quote: Quote) -> Result<i64> {
let closing_price = match self.closing_price {
Expand Down

0 comments on commit 322ab39

Please sign in to comment.