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

client/{core,mm}: Rebalance on EpochMatchSummary instead of new epoch #2517

Merged
merged 1 commit into from
Sep 12, 2023
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
17 changes: 10 additions & 7 deletions client/core/bookie.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,13 +184,16 @@ func (b *bookie) logEpochReport(note *msgjson.EpochReportNote) error {

marketID := marketName(b.base, b.quote)
matchSummaries := b.AddRecentMatches(note.MatchSummary, note.EndStamp)
if len(note.MatchSummary) > 0 {
b.send(&BookUpdate{
Action: EpochMatchSummary,
MarketID: marketID,
Payload: matchSummaries,
})
}

b.send(&BookUpdate{
Action: EpochMatchSummary,
MarketID: marketID,
Payload: &EpochMatchSummaryPayload{
MatchSummaries: matchSummaries,
Epoch: note.Epoch,
},
})

for durStr, cache := range b.candleCaches {
c, ok := cache.addCandle(&note.Candle)
if !ok {
Expand Down
4 changes: 4 additions & 0 deletions client/core/core_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1500,6 +1500,7 @@ func TestBookFeed(t *testing.T) {
dc := rig.dc

checkAction := func(feed BookFeed, action string) {
t.Helper()
select {
case u := <-feed.Next():
if u.Action != action {
Expand Down Expand Up @@ -1728,6 +1729,8 @@ func TestBookFeed(t *testing.T) {
t.Fatalf("handleEpochReportMsg error: %v", err)
}

checkAction(feed2, EpochMatchSummary)

// We'll only receive 1 candle update, since we only synced one set of
// candles so far.
checkAction(feed2, CandleUpdateAction)
Expand All @@ -1743,6 +1746,7 @@ func TestBookFeed(t *testing.T) {
if err := handleEpochReportMsg(tCore, dc, epochReport); err != nil {
t.Fatalf("handleEpochReportMsg error: %v", err)
}
checkAction(feed2, EpochMatchSummary)
checkAction(feed2, CandleUpdateAction)
checkAction(feed2, CandleUpdateAction)

Expand Down
5 changes: 5 additions & 0 deletions client/core/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -743,6 +743,11 @@ type CandlesPayload struct {
Candles []msgjson.Candle `json:"candles"`
}

type EpochMatchSummaryPayload struct {
MatchSummaries []*orderbook.MatchSummary `json:"matchSummaries"`
Epoch uint64 `json:"epoch"`
}

// dexAccount is the core type to represent the client's account information for
// a DEX.
type dexAccount struct {
Expand Down
12 changes: 5 additions & 7 deletions client/mm/mm_basic.go
Original file line number Diff line number Diff line change
Expand Up @@ -716,8 +716,6 @@ func (m *basicMarketMaker) handleNotification(note core.Notification) {
return
}
m.processTrade(ord)
case *core.EpochNotification:
go m.rebalance(n.Epoch)
case *core.FiatRatesNote:
go m.processFiatRates(n.FiatRates)
}
Expand Down Expand Up @@ -803,11 +801,11 @@ func (m *basicMarketMaker) run() {
defer wg.Done()
for {
select {
case <-bookFeed.Next():
// Really nothing to do with the updates. We just need to keep
// the subscription live in order to get a mid-gap rate when
// needed. We could use this to trigger rebalances mid-epoch
// though, which I think would provide some advantage.
case n := <-bookFeed.Next():
if n.Action == core.EpochMatchSummary {
payload := n.Payload.(*core.EpochMatchSummaryPayload)
m.rebalance(payload.Epoch + 1)
}
case <-m.ctx.Done():
return
}
Expand Down
2 changes: 1 addition & 1 deletion client/webserver/site/src/html/bodybuilder.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@
{{end}}

{{define "bottom"}}
<script src="/js/entry.js?v=0a518229|5c5461e5"></script>
<script src="/js/entry.js?v=faadd923|2e83f47d"></script>
</body>
</html>
{{end}}
2 changes: 1 addition & 1 deletion client/webserver/site/src/js/markets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1812,7 +1812,7 @@ export default class MarketsPage extends BasePage {
}

handleEpochMatchSummary (data: BookUpdate) {
this.addRecentMatches(data.payload)
this.addRecentMatches(data.payload.matchSummaries)
this.refreshRecentMatchesTable()
}

Expand Down