(Exchange Interface) Convert Fetch & Update orderbook/ticker methods to return pointers (#398)

* moved order and ticker fetching to return a pointer

* return nil instead of empty struct

* fixed incorrect nil

* general cleanup
This commit is contained in:
Andrew
2019-12-17 15:54:09 +11:00
committed by Adrian Gallagher
parent 44aa1e306c
commit 75ac5ee791
42 changed files with 320 additions and 348 deletions

View File

@@ -202,8 +202,8 @@ func (a *ANX) FetchTradablePairs(asset asset.Item) ([]string, error) {
}
// UpdateTicker updates and returns the ticker for a currency pair
func (a *ANX) UpdateTicker(p currency.Pair, assetType asset.Item) (ticker.Price, error) {
var tickerPrice ticker.Price
func (a *ANX) UpdateTicker(p currency.Pair, assetType asset.Item) (*ticker.Price, error) {
tickerPrice := new(ticker.Price)
tick, err := a.GetTicker(a.FormatExchangeCurrency(p, assetType).String())
if err != nil {
return tickerPrice, err
@@ -215,7 +215,7 @@ func (a *ANX) UpdateTicker(p currency.Pair, assetType asset.Item) (ticker.Price,
ask, _ := convert.FloatFromString(tick.Data.Sell.Value)
volume, _ := convert.FloatFromString(tick.Data.Volume.Value)
tickerPrice = ticker.Price{
tickerPrice = &ticker.Price{
Last: last,
High: high,
Low: low,
@@ -226,7 +226,7 @@ func (a *ANX) UpdateTicker(p currency.Pair, assetType asset.Item) (ticker.Price,
LastUpdated: time.Unix(0, tick.Data.UpdateTime),
}
err = ticker.ProcessTicker(a.Name, &tickerPrice, assetType)
err = ticker.ProcessTicker(a.Name, tickerPrice, assetType)
if err != nil {
return tickerPrice, err
}
@@ -235,7 +235,7 @@ func (a *ANX) UpdateTicker(p currency.Pair, assetType asset.Item) (ticker.Price,
}
// FetchTicker returns the ticker for a currency pair
func (a *ANX) FetchTicker(p currency.Pair, assetType asset.Item) (ticker.Price, error) {
func (a *ANX) FetchTicker(p currency.Pair, assetType asset.Item) (*ticker.Price, error) {
tickerNew, err := ticker.GetTicker(a.Name, p, assetType)
if err != nil {
return a.UpdateTicker(p, assetType)
@@ -244,7 +244,7 @@ func (a *ANX) FetchTicker(p currency.Pair, assetType asset.Item) (ticker.Price,
}
// FetchOrderbook returns the orderbook for a currency pair
func (a *ANX) FetchOrderbook(p currency.Pair, assetType asset.Item) (orderbook.Base, error) {
func (a *ANX) FetchOrderbook(p currency.Pair, assetType asset.Item) (*orderbook.Base, error) {
ob, err := orderbook.Get(a.Name, p, assetType)
if err != nil {
return a.UpdateOrderbook(p, assetType)
@@ -253,8 +253,8 @@ func (a *ANX) FetchOrderbook(p currency.Pair, assetType asset.Item) (orderbook.B
}
// UpdateOrderbook updates and returns the orderbook for a currency pair
func (a *ANX) UpdateOrderbook(p currency.Pair, assetType asset.Item) (orderbook.Base, error) {
var orderBook orderbook.Base
func (a *ANX) UpdateOrderbook(p currency.Pair, assetType asset.Item) (*orderbook.Base, error) {
orderBook := new(orderbook.Base)
orderbookNew, err := a.GetDepth(a.FormatExchangeCurrency(p, assetType).String())
if err != nil {
return orderBook, err