Skip to content

Commit

Permalink
fix settled calc and cancellation display
Browse files Browse the repository at this point in the history
  • Loading branch information
buck54321 authored and chappjc committed Nov 11, 2020
1 parent 81d2ef7 commit b013581
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 31 deletions.
52 changes: 28 additions & 24 deletions client/webserver/site/src/html/order.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,8 @@
{{range $match := $ord.MatchReaders}}
<div class="match-card">
<div class="match-header">
<div class="d-flex justify-content-between align-items-center">
<div class="d-flex justify-content-start align-items-center">
<span class="match-data-label ml-3">Match ID</span>
{{if $match.IsCancel}}<span class="red mr-3">cancellation</span>{{end}}
</div>
<div class="mono mx-3 fs15">{{$match.MatchID}}</div>
</div>
Expand All @@ -115,30 +114,35 @@

</div>

<div class="text-center demi fs20 py-2">
{{$match.FromQuantityString}} {{template "microIcon" $ord.FromSymbol}}
&rarr;
{{$match.ToQuantityString}} {{template "microIcon" $ord.ToSymbol}}
</div>

<div class="row py-2">
<div class="col-10 text-center">
<span class="match-data-label">Rate</span><br>
<span class="fs15">
{{$match.RateString}}
</span>
{{if $match.IsCancel}}
<div class="text-center fs20 red">Cancellation</div>
<div class="text-center fs16">{{$match.FromQuantityString}} {{template "microIcon" $ord.FromSymbol}} ({{$match.OrderPortion}}%)</div>
{{else}}
<div class="text-center demi fs20 py-2">
{{$match.FromQuantityString}} {{template "microIcon" $ord.FromSymbol}}
&rarr;
{{$match.ToQuantityString}} {{template "microIcon" $ord.ToSymbol}}
</div>
<div class="col-7 text-center">
<span class="match-data-label">Side</span><br>
<span class="fs15">{{$match.Side}}</span>
</div>
<div class="col-7 text-center">
<span class="match-data-label">Order Portion</span><br>
<span class="fs15">
{{$match.OrderPortion}}%
</span>

<div class="row py-2">
<div class="col-10 text-center">
<span class="match-data-label">Rate</span><br>
<span class="fs15">
{{$match.RateString}}
</span>
</div>
<div class="col-7 text-center">
<span class="match-data-label">Side</span><br>
<span class="fs15">{{$match.Side}}</span>
</div>
<div class="col-7 text-center">
<span class="match-data-label">Order Portion</span><br>
<span class="fs15">
{{$match.OrderPortion}}%
</span>
</div>
</div>
</div>
{{end}}

<div class="pt-3">
{{if len $match.Swap}}
Expand Down
13 changes: 8 additions & 5 deletions client/webserver/site/src/js/orderutil.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ export const TakerSwapCast = 2
export const MakerRedeemed = 3
export const MatchComplete = 4

/* The match sides are a mirror of dex/order.MatchSide. */
export const Maker = 0
export const Taker = 1

export function sellString (ord) { return ord.sell ? 'sell' : 'buy' }
export function typeString (ord) { return ord.type === Limit ? (ord.tif === ImmediateTiF ? 'limit (i)' : 'limit') : 'market' }
export function rateString (ord) { return ord.type === Market ? 'market' : Doc.formatCoinValue(ord.rate / 1e8) }
Expand Down Expand Up @@ -62,10 +66,9 @@ export function settled (order) {
if (!order.matches) return 0
const qty = isMarketBuy(order) ? m => m.qty * m.rate * 1e-8 : m => m.qty
return order.matches.reduce((settled, match) => {
// >= makerRedeemed is used because the maker never actually goes to
// matchComplete (once at makerRedeemed, nothing left to do), and the taker
// never goes to makerRedeemed, since at that point, they just complete the
// swap.
return (match.status >= MakerRedeemed) ? settled + qty(match) : settled
if (match.isCancel) return settled
const redeemed = (match.side === Maker && match.status >= MakerRedeemed) ||
(match.side === Taker && match.status >= MatchComplete)
return redeemed ? settled + qty(match) : settled
}, 0)
}
11 changes: 9 additions & 2 deletions client/webserver/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,12 +186,12 @@ func (ord *orderReader) SettledPercent() string {

// FilledFrom is the sum filled in units of the outgoing asset.
func (ord *orderReader) FilledFrom() string {
return precision8(ord.sumFrom(filledFilter))
return precision8(ord.sumFrom(filledNonCancelFilter))
}

// FilledTo is the sum filled in units of the incoming asset.
func (ord *orderReader) FilledTo() string {
return precision8(ord.sumTo(filledFilter))
return precision8(ord.sumTo(filledNonCancelFilter))
}

// FilledPercent is the percent of the order that has filled, without percent
Expand All @@ -211,6 +211,9 @@ func (ord *orderReader) percent(filter func(match *core.Match) bool) string {
}

func settledFilter(match *core.Match) bool {
if match.IsCancel {
return false
}
return (match.Side == order.Taker && match.Status == order.MatchComplete) ||
(match.Side == order.Maker && (match.Status == order.MakerRedeemed || match.Status == order.MatchComplete))
}
Expand All @@ -222,6 +225,10 @@ func settlingFilter(match *core.Match) bool {

func filledFilter(match *core.Match) bool { return true }

func filledNonCancelFilter(match *core.Match) bool {
return !match.IsCancel
}

// sumFrom will sum the match quantities in units of the outgoing asset.
func (ord *orderReader) sumFrom(filter func(match *core.Match) bool) uint64 {
var v uint64
Expand Down

0 comments on commit b013581

Please sign in to comment.