Skip to content

Commit b182d5c

Browse files
authored
program: check limit price when setting auction for limit order (#1650)
* program: check limit price after applying buffer in trigger limit order auction * program: reduce duplicate code * program: check limit price when setting limit auction params
1 parent e46686d commit b182d5c

File tree

2 files changed

+25
-2
lines changed

2 files changed

+25
-2
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1414
- sdk: fix to getMaxTradeSizeUSDCForPerp which was previously overshooting max allowed size due to IMF factor
1515
- program: add existing position fields to order records ([#1614](https://github.com/drift-labs/protocol-v2/pull/1614))
1616
- program: check limit price after applying buffer in trigger limit order ([#1648](https://github.com/drift-labs/protocol-v2/pull/1648))
17+
- program: check limit price when setting auction for limit order ([#1650](https://github.com/drift-labs/protocol-v2/pull/1650))
1718

1819
### Breaking
1920

programs/drift/src/state/order_params.rs

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ impl OrderParams {
200200
if is_oracle_offset_oracle {
201201
msg!(
202202
"Updating oracle limit auction start price to {}",
203-
new_auction_start_price
203+
auction_start_price_offset
204204
);
205205
self.auction_start_price = Some(auction_start_price_offset);
206206
} else {
@@ -216,7 +216,7 @@ impl OrderParams {
216216
if is_oracle_offset_oracle {
217217
msg!(
218218
"Updating oracle limit auction start price to {}",
219-
new_auction_start_price
219+
auction_start_price_offset
220220
);
221221
self.auction_start_price = Some(auction_start_price_offset);
222222
} else {
@@ -243,6 +243,28 @@ impl OrderParams {
243243
}
244244
}
245245

246+
let worst_price = if is_oracle_offset_oracle {
247+
oracle_price_offset as i64
248+
} else {
249+
self.price as i64
250+
};
251+
252+
if self.direction == PositionDirection::Long {
253+
if let Some(auction_start_price) = self.auction_start_price {
254+
self.auction_start_price = Some(auction_start_price.min(worst_price));
255+
}
256+
if let Some(auction_end_price) = self.auction_end_price {
257+
self.auction_end_price = Some(auction_end_price.min(worst_price));
258+
}
259+
} else {
260+
if let Some(auction_start_price) = self.auction_start_price {
261+
self.auction_start_price = Some(auction_start_price.max(worst_price));
262+
}
263+
if let Some(auction_end_price) = self.auction_end_price {
264+
self.auction_end_price = Some(auction_end_price.max(worst_price));
265+
}
266+
}
267+
246268
let auction_duration_before = self.auction_duration;
247269
let new_auction_duration = get_auction_duration(
248270
self.auction_end_price

0 commit comments

Comments
 (0)