mirror of
https://github.com/d0zingcat/gocryptotrader.git
synced 2026-05-17 23:16:52 +00:00
bugfix: don't index or range over data if length is zero
This commit is contained in:
@@ -126,7 +126,7 @@ func (c *CoinbasePro) UpdateOrderbook(p pair.CurrencyPair, assetType string) (or
|
||||
}
|
||||
|
||||
for x := range obNew.Asks {
|
||||
orderBook.Asks = append(orderBook.Asks, orderbook.Item{Amount: obNew.Bids[x].Amount, Price: obNew.Bids[x].Price})
|
||||
orderBook.Asks = append(orderBook.Asks, orderbook.Item{Amount: obNew.Asks[x].Amount, Price: obNew.Asks[x].Price})
|
||||
}
|
||||
|
||||
orderbook.ProcessOrderbook(c.GetName(), p, orderBook, assetType)
|
||||
|
||||
@@ -200,6 +200,10 @@ func (g *Gateio) GetOrderbook(symbol string) (Orderbook, error) {
|
||||
|
||||
var ob Orderbook
|
||||
|
||||
if len(resp.Asks) == 0 {
|
||||
return ob, errors.New("asks are empty")
|
||||
}
|
||||
|
||||
// Asks are in reverse order
|
||||
for x := len(resp.Asks) - 1; x != 0; x-- {
|
||||
data := resp.Asks[x]
|
||||
@@ -217,6 +221,10 @@ func (g *Gateio) GetOrderbook(symbol string) (Orderbook, error) {
|
||||
ob.Asks = append(ob.Asks, OrderbookItem{Price: price, Amount: amount})
|
||||
}
|
||||
|
||||
if len(resp.Bids) == 0 {
|
||||
return ob, errors.New("bids are empty")
|
||||
}
|
||||
|
||||
for x := range resp.Bids {
|
||||
data := resp.Bids[x]
|
||||
|
||||
|
||||
@@ -95,8 +95,15 @@ func (h *HUOBI) UpdateTicker(p pair.CurrencyPair, assetType string) (ticker.Pric
|
||||
tickerPrice.Last = tick.Close
|
||||
tickerPrice.Volume = tick.Volume
|
||||
tickerPrice.High = tick.High
|
||||
tickerPrice.Ask = tick.Ask[0]
|
||||
tickerPrice.Bid = tick.Bid[0]
|
||||
|
||||
if len(tick.Ask) > 0 {
|
||||
tickerPrice.Ask = tick.Ask[0]
|
||||
}
|
||||
|
||||
if len(tick.Bid) > 0 {
|
||||
tickerPrice.Bid = tick.Bid[0]
|
||||
}
|
||||
|
||||
ticker.ProcessTicker(h.GetName(), p, tickerPrice, assetType)
|
||||
return ticker.GetTicker(h.Name, p, assetType)
|
||||
}
|
||||
|
||||
@@ -59,8 +59,15 @@ func (h *HUOBIHADAX) UpdateTicker(p pair.CurrencyPair, assetType string) (ticker
|
||||
tickerPrice.Last = tick.Close
|
||||
tickerPrice.Volume = tick.Volume
|
||||
tickerPrice.High = tick.High
|
||||
tickerPrice.Ask = tick.Ask[0]
|
||||
tickerPrice.Bid = tick.Bid[0]
|
||||
|
||||
if len(tick.Ask) > 0 {
|
||||
tickerPrice.Ask = tick.Ask[0]
|
||||
}
|
||||
|
||||
if len(tick.Bid) > 0 {
|
||||
tickerPrice.Bid = tick.Bid[0]
|
||||
}
|
||||
|
||||
ticker.ProcessTicker(h.GetName(), p, tickerPrice, assetType)
|
||||
return ticker.GetTicker(h.Name, p, assetType)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user