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

dcrdata/exchanges: use EndRate from dcrdex EpochReportRoute as dcr rate #2007

Merged
merged 3 commits into from
Sep 22, 2024
Merged
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
20 changes: 18 additions & 2 deletions exchanges/exchanges.go
Original file line number Diff line number Diff line change
Expand Up @@ -2419,6 +2419,7 @@ type DecredDEX struct {
reqs map[uint64]func(*msgjson.Message)
cacheMtx sync.RWMutex
candleCaches map[uint64]*candleCache
lastRate float64
seq uint64
stamp int64
cfg *DEXConfig
Expand Down Expand Up @@ -2488,9 +2489,13 @@ func (dcr *DecredDEX) Refresh() {
}
}

if dcr.lastRate == 0 {
return // no rate, nothing to do.
}

dcr.Update(&ExchangeState{
BaseState: BaseState{
Price: depth.MidGap(),
Price: dcr.lastRate,
Change: change,
Volume: float64(volume) / 1e8,
Stamp: dcr.lastStamp(),
Expand Down Expand Up @@ -2683,6 +2688,9 @@ func (dcr *DecredDEX) processWsMessage(raw []byte) {
if note.Candle.EndStamp == 0 {
return
}

dcr.lastRate = float64(note.Candle.EndRate) / 1e8

candle := &note.Candle
for binSize, cache := range dcr.candles() {
cache.mtx.Lock()
Expand Down Expand Up @@ -2850,9 +2858,17 @@ func (dcr *DecredDEX) setOrderBook(ob *msgjson.OrderBook) {

depth := dcr.wsDepthSnapshot()

if dcr.lastRate == 0 {
if len(ob.Orders) == 0 {
return // don't send rate update if we don't have a valid rate and there are no orders to get a sane midGap.
}
// Use mid gap as a sane default if the orderbook is not empty.
dcr.lastRate = depth.MidGap()
}

dcr.Update(&ExchangeState{
BaseState: BaseState{
Price: depth.MidGap(),
Price: dcr.lastRate,
ukane-philemon marked this conversation as resolved.
Show resolved Hide resolved
// Change: priceChange, // With candlesticks
Stamp: dcr.stamp,
},
Expand Down
Loading