Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix the margin call price in UI is wrong #3286 #3507

Merged
merged 1 commit into from
Apr 26, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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"
]);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if mcfr of an asset is undefined? I think the default value is 0?


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