Skip to content

Commit

Permalink
Merge pull request #3507 from xiangxn/fix-3286
Browse files Browse the repository at this point in the history
Fix the margin call price in UI is wrong #3286
  • Loading branch information
xiangxn committed Apr 26, 2022
2 parents 155c606 + f9fb67e commit 72a272b
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 27 deletions.
32 changes: 19 additions & 13 deletions app/components/Account/AccountOrders.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ class AccountOrders extends React.Component {
let base = null;
let quote = null;
let sqr = null;
let mcfr = null;
let feed_price = null;
let bitasset_options = null;

Expand Down Expand Up @@ -103,10 +104,18 @@ class AccountOrders extends React.Component {
"maximum_short_squeeze_ratio"
]);

mcfr = base.getIn([
"bitasset",
"options",
"extensions",
"margin_call_fee_ratio"
]);

feed_price = new FeedPrice({
priceObject: feedPriceRaw,
market_base: marketBaseId,
sqr,
mcfr,
assets
});

Expand Down Expand Up @@ -777,19 +786,16 @@ class AccountOrders extends React.Component {
}
}

AccountOrders = connect(
AccountOrders,
{
listenTo() {
return [SettingsStore];
},
getProps() {
return {
marketDirections: SettingsStore.getState().marketDirections,
viewSettings: SettingsStore.getState().viewSettings
};
}
AccountOrders = connect(AccountOrders, {
listenTo() {
return [SettingsStore];
},
getProps() {
return {
marketDirections: SettingsStore.getState().marketDirections,
viewSettings: SettingsStore.getState().viewSettings
};
}
);
});

export default AccountOrders;
8 changes: 8 additions & 0 deletions app/components/Blockchain/Asset.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,13 @@ class Asset extends React.Component {
"maximum_short_squeeze_ratio"
]);

let mcfr = this.props.asset.getIn([
"bitasset",
"options",
"extensions",
"margin_call_fee_ratio"
]);

let feedPriceRaw = assetUtils.extractRawFeedPrice(this.props.asset);

// if there has been no feed price, settlePrice has 0 amount
Expand Down Expand Up @@ -229,6 +236,7 @@ class Asset extends React.Component {
priceObject: feedPriceRaw,
market_base: this.props.asset.get("id"),
sqr,
mcfr,
assets
});

Expand Down
35 changes: 21 additions & 14 deletions app/lib/common/MarketClasses.js
Original file line number Diff line number Diff line change
Expand Up @@ -367,13 +367,14 @@ class Price {
}

class FeedPrice extends Price {
constructor({priceObject, assets, market_base, sqr, real = false}) {
constructor({priceObject, assets, market_base, sqr, mcfr, real = false}) {
if (
!priceObject ||
typeof priceObject !== "object" ||
!market_base ||
!assets ||
!sqr
!sqr ||
!mcfr
) {
throw new Error("Invalid FeedPrice inputs");
}
Expand Down Expand Up @@ -404,19 +405,25 @@ class FeedPrice extends Price {

this.sqr = parseInt(sqr, 10) / 1000;
this.inverted = inverted;
if (!mcfr) this.mcfr = 0;
else this.mcfr = parseInt(mcfr, 10) / 1000;
}

getSqueezePrice({real = false} = {}) {
if (!this._squeeze_price) {
this._squeeze_price = this.clone();
if (this.inverted) {
this._squeeze_price.base.amount = Math.floor(
this._squeeze_price.base.amount * this.sqr * 1000
this._squeeze_price.base.amount *
(this.sqr - this.mcfr) *
1000
);
this._squeeze_price.quote.amount *= 1000;
} else if (!this.inverted) {
this._squeeze_price.quote.amount = Math.floor(
this._squeeze_price.quote.amount * this.sqr * 1000
this._squeeze_price.quote.amount *
(this.sqr - this.mcfr) *
1000
);
this._squeeze_price.base.amount *= 1000;
}
Expand Down Expand Up @@ -899,25 +906,25 @@ class CallOrder {
let orderDebt = order.iSum
? order.debt
: orderUseCR
? order.max_debt_to_cover.getAmount()
: order.amountToReceive().getAmount();
? order.max_debt_to_cover.getAmount()
: order.amountToReceive().getAmount();
let newOrderDebt = newOrder.iSum
? newOrder.debt
: newOrderUseCR
? newOrder.max_debt_to_cover.getAmount()
: newOrder.amountToReceive().getAmount();
? newOrder.max_debt_to_cover.getAmount()
: newOrder.amountToReceive().getAmount();

/* Determine which collateral values to use */
let orderCollateral = order.iSum
? order.collateral
: orderUseCR
? order.max_collateral_to_sell.getAmount()
: order.amountForSale().getAmount();
? order.max_collateral_to_sell.getAmount()
: order.amountForSale().getAmount();
let newOrderCollateral = newOrder.iSum
? newOrder.collateral
: newOrderUseCR
? newOrder.max_collateral_to_sell.getAmount()
: newOrder.amountForSale().getAmount();
? newOrder.max_collateral_to_sell.getAmount()
: newOrder.amountForSale().getAmount();

newOrder.debt = newOrderDebt + orderDebt;
newOrder.collateral = newOrderCollateral + orderCollateral;
Expand Down Expand Up @@ -1232,8 +1239,8 @@ class FillOrder {
this.className = this.isCall
? "orderHistoryCall"
: this.isBid
? "orderHistoryBid"
: "orderHistoryAsk";
? "orderHistoryBid"
: "orderHistoryAsk";
this.time = fill.time && new Date(utils.makeISODateString(fill.time));
this.block = fill.block;
this.account = fill.op.account || fill.op.account_id;
Expand Down
3 changes: 3 additions & 0 deletions app/lib/common/accountHelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,9 @@ function checkMarginStatus(account) {
sqr:
debtAsset.bitasset.current_feed
.maximum_short_squeeze_ratio,
mcfr:
debtAsset.bitasset.options.extensions
.margin_call_fee_ratio,
assets: assetsMap
});
let current = {
Expand Down
9 changes: 9 additions & 0 deletions app/stores/MarketsStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -755,6 +755,14 @@ class MarketsStore {
"current_feed",
"maximum_short_squeeze_ratio"
]);
let mcfr = this[
this.invertedCalls ? "baseAsset" : "quoteAsset"
].getIn([
"bitasset",
"options",
"extensions",
"margin_call_fee_ratio"
]);

this.is_prediction_market = this[
this.invertedCalls ? "baseAsset" : "quoteAsset"
Expand Down Expand Up @@ -791,6 +799,7 @@ class MarketsStore {
priceObject: feedPriceRaw,
market_base: this.quoteAsset.get("id"),
sqr,
mcfr,
assets
});

Expand Down

0 comments on commit 72a272b

Please sign in to comment.