Skip to content

Commit

Permalink
bugfix: don't index or range over data if length is zero
Browse files Browse the repository at this point in the history
  • Loading branch information
thrasher- committed Sep 20, 2018
1 parent fb4e2d1 commit 042c4bf
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 5 deletions.
2 changes: 1 addition & 1 deletion exchanges/coinbasepro/coinbasepro_wrapper.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
8 changes: 8 additions & 0 deletions exchanges/gateio/gateio.go
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -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]

Expand Down
11 changes: 9 additions & 2 deletions exchanges/huobi/huobi_wrapper.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
11 changes: 9 additions & 2 deletions exchanges/huobihadax/huobihadax_wrapper.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down

0 comments on commit 042c4bf

Please sign in to comment.