diff --git a/exchanges/orderbook/orderbook.go b/exchanges/orderbook/orderbook.go index f4e366f4962..f7e024869ee 100644 --- a/exchanges/orderbook/orderbook.go +++ b/exchanges/orderbook/orderbook.go @@ -17,8 +17,7 @@ func Get(exchange string, p currency.Pair, a asset.Item) (*Base, error) { return service.Retrieve(exchange, p, a) } -// GetDepth returns a Depth pointer allowing the caller to stream orderbook -// changes +// GetDepth returns a Depth pointer allowing the caller to stream orderbook changes func GetDepth(exchange string, p currency.Pair, a asset.Item) (*Depth, error) { return service.GetDepth(exchange, p, a) } @@ -202,6 +201,11 @@ func (s *Service) Retrieve(exchange string, p currency.Pair, a asset.Item) (*Bas return book.Retrieve() } +// GetDepth returns the concrete book allowing the caller to stream orderbook changes +func (b *Base) GetDepth() (*Depth, error) { + return service.GetDepth(b.Exchange, b.Pair, b.Asset) +} + // TotalBidsAmount returns the total amount of bids and the total orderbook // bids value func (b *Base) TotalBidsAmount() (amountCollated, total float64) { diff --git a/exchanges/orderbook/orderbook_test.go b/exchanges/orderbook/orderbook_test.go index 016c5298410..b78e8551671 100644 --- a/exchanges/orderbook/orderbook_test.go +++ b/exchanges/orderbook/orderbook_test.go @@ -294,6 +294,34 @@ func TestGetDepth(t *testing.T) { } } +func TestBaseGetDepth(t *testing.T) { + c, err := currency.NewPairFromStrings("BTC", "UST") + if err != nil { + t.Error(err) + } + base := &Base{ + Pair: c, + Asks: []Item{{Price: 100, Amount: 10}}, + Bids: []Item{{Price: 200, Amount: 10}}, + Exchange: "Exchange", + Asset: asset.Spot, + } + + if _, err = base.GetDepth(); !errors.Is(err, errCannotFindOrderbook) { + t.Errorf("expecting %s error but received %v", errCannotFindOrderbook, err) + } + + if err = base.Process(); err != nil { + t.Error(err) + } + + if result, err := base.GetDepth(); err != nil { + t.Errorf("failed to get orderbook. Error %s", err) + } else if !result.pair.Equal(c) { + t.Errorf("Mismatched pairs: %v %v", result.pair, c) + } +} + func TestDeployDepth(t *testing.T) { c, err := currency.NewPairFromStrings("BTC", "USD") if err != nil {