Skip to content

Commit

Permalink
Fix #758, sort My Open Orders by price
Browse files Browse the repository at this point in the history
  • Loading branch information
svk31 committed Mar 3, 2016
1 parent df2075d commit d6800ba
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 21 deletions.
6 changes: 3 additions & 3 deletions web/app/assets/locales/locale-en.js
Expand Up @@ -646,8 +646,8 @@
market: "Market",
price_history: "Price Chart",
order_depth: "Market Depth",
history: "All History",
my_history: "My History",
history: "Market trades",
my_history: "My trades",
balance: "Balance",
lowest_ask: "Lowest ask",
highest_bid: "Highest bid",
Expand Down Expand Up @@ -690,7 +690,7 @@
index: "Index",
my_bids: "My bids",
my_asks: "My asks",
my_orders: "My orders",
my_orders: "My open orders",
settle_orders: "Settle orders",
asks: "Sell orders",
bids: "Buy orders",
Expand Down
34 changes: 25 additions & 9 deletions web/app/components/Exchange/Exchange.jsx
Expand Up @@ -658,9 +658,11 @@ class Exchange extends React.Component {
return ((satAmount / price.quote.amount) * price.base.amount) / totalPrecision;
}

getBuyAmount(price, total = 0) {
getBuyAmount(price, total = 0, satAmount) {
let amountPrecision = utils.get_asset_precision(this.props.quoteAsset.get("precision"));
let satAmount = utils.get_satoshi_amount(total, this.props.baseAsset);
if (!satAmount) {
satAmount = utils.get_satoshi_amount(total, this.props.baseAsset);
}

return ((satAmount / price.quote.amount) * price.base.amount) / amountPrecision;
}
Expand Down Expand Up @@ -739,27 +741,41 @@ class Exchange extends React.Component {
if (type === "bid") {

let displaySellPrice = this._getDisplayPrice("ask", order.sell_price);
let sellAmount = this.getSellAmount(order.sell_price, null, order.for_sale);
let sellAmount = market_utils.limitByPrecision(this.getSellAmount(order.sell_price, null, order.totalForSale), quote);

this.setState({
displaySellPrice: displaySellPrice,
sellPrice: order.sell_price,
sellAmount: value,
sellTotal: utils.get_asset_amount(order.for_sale, base)
sellAmount: sellAmount,
sellTotal: utils.get_asset_amount(order.totalForSale, base),
displayBuyPrice: displaySellPrice,
buyPrice: {
quote: order.sell_price.base,
base: order.sell_price.quote
},
buyAmount: null,
buyTotal: null
});

} else if (type === "ask") {

let displayBuyPrice = this._getDisplayPrice("bid", order.sell_price);

// Calculate total
let total = this.getBuyTotal(order.sell_price, null, order.for_sale);
// let total = this.getBuyTotal(order.sell_price, null, order.totalForSale);
let buyAmount = market_utils.limitByPrecision(this.getBuyAmount(order.sell_price, null, order.totalValue), quote);

this.setState({
displayBuyPrice: displayBuyPrice,
buyPrice: order.sell_price,
buyAmount: utils.get_asset_amount(order.for_sale, quote),
buyTotal: market_utils.limitByPrecision(total, base)
buyAmount: buyAmount,
buyTotal: utils.get_asset_amount(order.totalValue, base),
displaySellPrice: displayBuyPrice,
sellPrice: {
quote: order.sell_price.base,
base: order.sell_price.quote
},
sellAmount: null,
sellTotal: null
});
}
}
Expand Down
8 changes: 5 additions & 3 deletions web/app/components/Exchange/MyOpenOrders.jsx
Expand Up @@ -126,7 +126,8 @@ class MyOpenOrders extends React.Component {

return b_price.full - a_price.full;
}).map((order, index) => {
return <OrderRow date={new Date(order.expiration).getTime()} ref="orderRow" key={order.id} order={order} base={base} quote={quote} cancel_text={cancel} onCancel={this.props.onCancel.bind(this, order.id)}/>;
let {price} = market_utils.parseOrder(order, base, quote);
return <OrderRow price={price.full} ref="orderRow" key={order.id} order={order} base={base} quote={quote} cancel_text={cancel} onCancel={this.props.onCancel.bind(this, order.id)}/>;
}).toArray();

asks = orders.filter(a => {
Expand All @@ -137,7 +138,8 @@ class MyOpenOrders extends React.Component {

return a_price.full - b_price.full;
}).map(order => {
return <OrderRow date={new Date(order.expiration).getTime()} key={order.id} order={order} base={base} quote={quote} cancel_text={cancel} onCancel={this.props.onCancel.bind(this, order.id)}/>;
let {price} = market_utils.parseOrder(order, base, quote);
return <OrderRow price={price.full} key={order.id} order={order} base={base} quote={quote} cancel_text={cancel} onCancel={this.props.onCancel.bind(this, order.id)}/>;
}).toArray();

} else {
Expand Down Expand Up @@ -169,7 +171,7 @@ class MyOpenOrders extends React.Component {
}

rows.sort((a, b) => {
return b.props.date - a.props.date;
return a.props.price - b.props.price;
})

// if (bids.length === 0 && asks.length ===0) {
Expand Down
34 changes: 28 additions & 6 deletions web/app/components/Exchange/OrderBook.jsx
Expand Up @@ -51,14 +51,29 @@ class OrderBookRowHorizontal extends React.Component {
let {order, quote, base, type} = this.props;

let integerClass = type === "bid" ? "orderHistoryBid" : type === "ask" ? "orderHistoryAsk" : "orderHistoryCall" ;

return (
<tr onClick={this.props.onClick} >
<td className={integerClass}>
<PriceText preFormattedPrice={order.price} />
</td>
<td>{utils.format_number(order.amount, quote.get("precision"))}</td>
<td>{utils.format_number(order.value, base.get("precision"))}</td>
<td>{utils.format_number(order.totalValue, base.get("precision"))}</td>
<td>{type === "bid" ?
utils.format_number(order.amount, quote.get("precision")) :
utils.format_asset(order.for_sale, quote, true)
}
</td>
<td>{type === "bid" ?
utils.format_asset(order.for_sale, base, true) :
utils.format_number(order.value, base.get("precision"))
}
</td>
<td>{type === "bid" ?
utils.format_asset(order.totalForSale, base, true) :
utils.format_asset(order.totalValue, base, true)

}

</td>

</tr>
)
Expand Down Expand Up @@ -226,7 +241,7 @@ class OrderBook extends React.Component {
let totalBidValue = 0;
let totalAskAmount = 0;

let totalAsks = 0, totalBids = 0;
let totalAsks = 0, totalBids = 0, totalBidForSale = 0;

if(base && quote) {
let totalBidAmount = 0;
Expand All @@ -250,8 +265,11 @@ class OrderBook extends React.Component {
totalBidAmount = market_utils.limitByPrecision(totalBidAmount + order.amount, base);

totalBidValue += order.value;
totalBidForSale += order.for_sale;

order.totalValue = totalBidValue;
order.totalAmount = totalBidAmount;
order.totalForSale = totalBidForSale;

return (horizontal ?
<OrderBookRowHorizontal
Expand Down Expand Up @@ -287,7 +305,7 @@ class OrderBook extends React.Component {
return total > a.price_full ? a.price_full : total;
}, null) : 0;

let totalAskValue = 0;
let totalAskValue = 0, totalAskForSale = 0;

askRows = combinedAsks.sort((a, b) => {
return a.price_full - b.price_full;
Expand All @@ -299,9 +317,13 @@ class OrderBook extends React.Component {
}).map((order, index) => {
totalAskAmount = market_utils.limitByPrecision(totalAskAmount + order.amount, base);
// totalAskAmount += order.amount;
totalAskValue += order.value;
totalAskValue += (order.sell_price.quote.amount * order.for_sale / order.sell_price.base.amount);
totalAskForSale += order.for_sale;
// console.log("order:", order);
// console.log(order.sell_price.quote.amount * order.for_sale / order.sell_price.base.amount);
order.totalValue = totalAskValue;
order.totalAmount = totalAskAmount;
order.totalForSale = totalAskForSale;

return (horizontal ?

Expand Down

0 comments on commit d6800ba

Please sign in to comment.