11package services
22
33import (
4+ "log"
45 "math/big"
56 "time"
67
@@ -187,7 +188,10 @@ func (s *InfoService) GetExchangeStats() (*types.ExchangeStats, error) {
187188 for _ , t := range tradeData {
188189 if t .AddressCode () == p .AddressCode () {
189190 totalTrades = totalTrades + int (t .Count .Int64 ())
190- totalVolume = totalVolume + t .ConvertedVolume (& p , rates [p .BaseTokenSymbol ])
191+
192+ if exchangeRate := rates [p .BaseTokenSymbol ]; exchangeRate != 0 {
193+ totalVolume = totalVolume + t .ConvertedVolume (& p , rates [p .BaseTokenSymbol ])
194+ }
191195
192196 pairTradeCounts [p .Name ()] = int (t .Count .Int64 ())
193197 tokenTradeCounts [p .BaseTokenSymbol ] = tokenTradeCounts [p .BaseTokenSymbol ] + int (t .Count .Int64 ())
@@ -197,15 +201,19 @@ func (s *InfoService) GetExchangeStats() (*types.ExchangeStats, error) {
197201 for _ , o := range bidsData {
198202 if o .AddressCode () == p .AddressCode () {
199203 // change and replace by equivalent dollar volume instead of order count
200- totalBuyOrderAmount = totalBuyOrderAmount + o .ConvertedVolume (& p , rates [p .BaseTokenSymbol ])
204+ if exchangeRate := rates [p .BaseTokenSymbol ]; exchangeRate != 0 {
205+ totalBuyOrderAmount = totalBuyOrderAmount + o .ConvertedVolume (& p , rates [p .BaseTokenSymbol ])
206+ }
201207 totalBuyOrders = totalBuyOrders + int (o .OrderCount .Int64 ())
202208 }
203209 }
204210
205211 for _ , o := range asksData {
206212 if o .AddressCode () == p .AddressCode () {
207213 // change and replace by equivalent dollar volume instead of order count
208- totalSellOrderAmount = totalSellOrderAmount + o .ConvertedVolume (& p , rates [p .BaseTokenSymbol ])
214+ if exchangeRate := rates [p .BaseTokenSymbol ]; exchangeRate != 0 {
215+ totalSellOrderAmount = totalSellOrderAmount + o .ConvertedVolume (& p , rates [p .BaseTokenSymbol ])
216+ }
209217 totalSellOrders = totalSellOrders + int (o .OrderCount .Int64 ())
210218 }
211219 }
@@ -235,6 +243,8 @@ func (s *InfoService) GetExchangeStats() (*types.ExchangeStats, error) {
235243 TradeSuccessRatio : tradeSuccessRatio ,
236244 }
237245
246+ log .Printf ("%+v\n " , stats )
247+
238248 return stats , nil
239249}
240250
@@ -412,7 +422,10 @@ func (s *InfoService) GetExchangeData() (*types.ExchangeData, error) {
412422 pairData .AverageTradeAmount = math .Div (t .Volume , t .Count )
413423
414424 totalTrades = totalTrades + int (t .Count .Int64 ())
415- totalVolume = totalVolume + t .ConvertedVolume (& p , rates [p .BaseTokenSymbol ])
425+
426+ if exchangeRate := rates [p .BaseTokenSymbol ]; exchangeRate != 0 {
427+ totalVolume = totalVolume + t .ConvertedVolume (& p , rates [p .BaseTokenSymbol ])
428+ }
416429
417430 pairTradeCounts [p .Name ()] = int (t .Count .Int64 ())
418431 tokenTradeCounts [p .BaseTokenSymbol ] = tokenTradeCounts [p .BaseTokenSymbol ] + int (t .Count .Int64 ())
@@ -426,8 +439,10 @@ func (s *InfoService) GetExchangeData() (*types.ExchangeData, error) {
426439 pairData .BidPrice = o .BestPrice
427440 pairData .AverageOrderAmount = math .Div (pairData .OrderVolume , pairData .OrderCount )
428441
429- // change and replace by equivalent dollar volume instead of order count
430- totalBuyOrderAmount = totalBuyOrderAmount + o .ConvertedVolume (& p , rates [p .BaseTokenSymbol ])
442+ if exchangeRate := rates [p .BaseTokenSymbol ]; exchangeRate != 0 {
443+ totalBuyOrderAmount = totalBuyOrderAmount + o .ConvertedVolume (& p , rates [p .BaseTokenSymbol ])
444+ }
445+
431446 totalBuyOrders = totalBuyOrders + int (o .OrderCount .Int64 ())
432447 }
433448 }
@@ -439,8 +454,10 @@ func (s *InfoService) GetExchangeData() (*types.ExchangeData, error) {
439454 pairData .AskPrice = o .BestPrice
440455 pairData .AverageOrderAmount = math .Div (pairData .OrderVolume , pairData .OrderCount )
441456
442- // change and replace by equivalent dollar volume instead of order count
443- totalSellOrderAmount = totalSellOrderAmount + o .ConvertedVolume (& p , rates [p .BaseTokenSymbol ])
457+ if exchangeRate := rates [p .BaseTokenSymbol ]; exchangeRate != 0 {
458+ totalSellOrderAmount = totalSellOrderAmount + o .ConvertedVolume (& p , rates [p .BaseTokenSymbol ])
459+ }
460+
444461 totalSellOrders = totalSellOrders + int (o .OrderCount .Int64 ())
445462
446463 //TODO change price into orderbook price
0 commit comments