Skip to content

Commit

Permalink
fix: entryPrice divide by 0 (drift-labs#57)
Browse files Browse the repository at this point in the history
  • Loading branch information
jordy25519 authored May 16, 2024
1 parent 071c3c8 commit 18e4125
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,9 @@ impl PerpPosition {
impl From<sdk_types::PerpPosition> for PerpPosition {
fn from(value: sdk_types::PerpPosition) -> Self {
let amount = Decimal::new(value.base_asset_amount, BASE_PRECISION.ilog10());
let average_entry =
Decimal::new(value.quote_entry_amount.abs(), PRICE_DECIMALS) / amount.abs();
let average_entry = Decimal::new(value.quote_entry_amount.abs(), PRICE_DECIMALS)
.checked_div(amount.abs())
.unwrap_or_default();

Self {
amount: amount.normalize(),
Expand Down

0 comments on commit 18e4125

Please sign in to comment.