(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

@@ -176,8 +176,8 @@ func (y *Yobit) UpdateTradablePairs(forceUpdate bool) error {
}
// UpdateTicker updates and returns the ticker for a currency pair
func (y *Yobit) UpdateTicker(p currency.Pair, assetType asset.Item) (ticker.Price, error) {
var tickerPrice ticker.Price
func (y *Yobit) UpdateTicker(p currency.Pair, assetType asset.Item) (*ticker.Price, error) {
tickerPrice := new(ticker.Price)
pairsCollated, err := y.FormatExchangeCurrencies(y.GetEnabledPairs(assetType), assetType)
if err != nil {
return tickerPrice, err
@@ -195,7 +195,7 @@ func (y *Yobit) UpdateTicker(p currency.Pair, assetType asset.Item) (ticker.Pric
continue
}
resultCurr := result[curr]
var tickerPrice ticker.Price
tickerPrice := new(ticker.Price)
tickerPrice.Pair = enabledPairs[i]
tickerPrice.Last = resultCurr.Last
tickerPrice.Ask = resultCurr.Sell
@@ -205,7 +205,7 @@ func (y *Yobit) UpdateTicker(p currency.Pair, assetType asset.Item) (ticker.Pric
tickerPrice.QuoteVolume = resultCurr.VolumeCurrent
tickerPrice.Volume = resultCurr.Vol
err = ticker.ProcessTicker(y.Name, &tickerPrice, assetType)
err = ticker.ProcessTicker(y.Name, tickerPrice, assetType)
if err != nil {
log.Error(log.Ticker, err)
}
@@ -214,7 +214,7 @@ func (y *Yobit) UpdateTicker(p currency.Pair, assetType asset.Item) (ticker.Pric
}
// FetchTicker returns the ticker for a currency pair
func (y *Yobit) FetchTicker(p currency.Pair, assetType asset.Item) (ticker.Price, error) {
func (y *Yobit) FetchTicker(p currency.Pair, assetType asset.Item) (*ticker.Price, error) {
tick, err := ticker.GetTicker(y.Name, p, assetType)
if err != nil {
return y.UpdateTicker(p, assetType)
@@ -223,7 +223,7 @@ func (y *Yobit) FetchTicker(p currency.Pair, assetType asset.Item) (ticker.Price
}
// FetchOrderbook returns the orderbook for a currency pair
func (y *Yobit) FetchOrderbook(p currency.Pair, assetType asset.Item) (orderbook.Base, error) {
func (y *Yobit) FetchOrderbook(p currency.Pair, assetType asset.Item) (*orderbook.Base, error) {
ob, err := orderbook.Get(y.Name, p, assetType)
if err != nil {
return y.UpdateOrderbook(p, assetType)
@@ -232,8 +232,8 @@ func (y *Yobit) FetchOrderbook(p currency.Pair, assetType asset.Item) (orderbook
}
// UpdateOrderbook updates and returns the orderbook for a currency pair
func (y *Yobit) UpdateOrderbook(p currency.Pair, assetType asset.Item) (orderbook.Base, error) {
var orderBook orderbook.Base
func (y *Yobit) UpdateOrderbook(p currency.Pair, assetType asset.Item) (*orderbook.Base, error) {
orderBook := new(orderbook.Base)
orderbookNew, err := y.GetDepth(y.FormatExchangeCurrency(p, assetType).String())
if err != nil {
return orderBook, err