Skip to content

Commit

Permalink
dcrdata/exchanges: use EndRate from dcrdex EpochReportRoute as dc…
Browse files Browse the repository at this point in the history
…r rate

- Use EndRate from dcrdex EpochReportRoute as dcr rate

---------

Signed-off-by: Philemon Ukane <ukanephilemon@gmail.com>
  • Loading branch information
ukane-philemon authored Sep 22, 2024
1 parent ae8f5c2 commit 14d6940
Showing 1 changed file with 18 additions and 2 deletions.
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,
// Change: priceChange, // With candlesticks
Stamp: dcr.stamp,
},
Expand Down

0 comments on commit 14d6940

Please sign in to comment.