From 2af39f7009024b3c139cb8a32d7c64400b94b956 Mon Sep 17 00:00:00 2001 From: Philemon Ukane Date: Fri, 20 Sep 2024 21:09:58 +0100 Subject: [PATCH] don't send dex update if we don't have sane value Signed-off-by: Philemon Ukane --- exchanges/exchanges.go | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/exchanges/exchanges.go b/exchanges/exchanges.go index ee3f26c72..03a9d5b47 100644 --- a/exchanges/exchanges.go +++ b/exchanges/exchanges.go @@ -2489,9 +2489,8 @@ func (dcr *DecredDEX) Refresh() { } } - // Use mid gap if we are yet to get an epoch report notification. if dcr.lastRate == 0 { - dcr.lastRate = depth.MidGap() + return // no rate, nothing to do. } dcr.Update(&ExchangeState{ @@ -2859,6 +2858,15 @@ func (dcr *DecredDEX) setOrderBook(ob *msgjson.OrderBook) { depth := dcr.wsDepthSnapshot() + if dcr.lastRate == 0 { + // Use mid gap as a sane default if the orderbook is not empty. + midGap := depth.MidGap() + if midGap == 1 { + return // don't send rate update if we don't have a valid rate. + } + dcr.lastRate = midGap + } + dcr.Update(&ExchangeState{ BaseState: BaseState{ Price: dcr.lastRate,