(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

@@ -242,8 +242,8 @@ func (h *HitBTC) UpdateTradablePairs(forceUpdate bool) error {
}
// UpdateTicker updates and returns the ticker for a currency pair
func (h *HitBTC) UpdateTicker(currencyPair currency.Pair, assetType asset.Item) (ticker.Price, error) {
var tickerPrice ticker.Price
func (h *HitBTC) UpdateTicker(currencyPair currency.Pair, assetType asset.Item) (*ticker.Price, error) {
tickerPrice := new(ticker.Price)
tick, err := h.GetTickers()
if err != nil {
return tickerPrice, err
@@ -263,7 +263,7 @@ func (h *HitBTC) UpdateTicker(currencyPair currency.Pair, assetType asset.Item)
continue
}
}
tickerPrice := ticker.Price{
tickerPrice := &ticker.Price{
Last: tick[j].Last,
High: tick[j].High,
Low: tick[j].Low,
@@ -275,7 +275,7 @@ func (h *HitBTC) UpdateTicker(currencyPair currency.Pair, assetType asset.Item)
Pair: pairs[i],
LastUpdated: tick[j].Timestamp,
}
err = ticker.ProcessTicker(h.Name, &tickerPrice, assetType)
err = ticker.ProcessTicker(h.Name, tickerPrice, assetType)
if err != nil {
log.Error(log.Ticker, err)
}
@@ -285,7 +285,7 @@ func (h *HitBTC) UpdateTicker(currencyPair currency.Pair, assetType asset.Item)
}
// FetchTicker returns the ticker for a currency pair
func (h *HitBTC) FetchTicker(p currency.Pair, assetType asset.Item) (ticker.Price, error) {
func (h *HitBTC) FetchTicker(p currency.Pair, assetType asset.Item) (*ticker.Price, error) {
tickerNew, err := ticker.GetTicker(h.Name, p, assetType)
if err != nil {
return h.UpdateTicker(p, assetType)
@@ -294,7 +294,7 @@ func (h *HitBTC) FetchTicker(p currency.Pair, assetType asset.Item) (ticker.Pric
}
// FetchOrderbook returns orderbook base on the currency pair
func (h *HitBTC) FetchOrderbook(p currency.Pair, assetType asset.Item) (orderbook.Base, error) {
func (h *HitBTC) FetchOrderbook(p currency.Pair, assetType asset.Item) (*orderbook.Base, error) {
ob, err := orderbook.Get(h.Name, p, assetType)
if err != nil {
return h.UpdateOrderbook(p, assetType)
@@ -303,8 +303,8 @@ func (h *HitBTC) FetchOrderbook(p currency.Pair, assetType asset.Item) (orderboo
}
// UpdateOrderbook updates and returns the orderbook for a currency pair
func (h *HitBTC) UpdateOrderbook(currencyPair currency.Pair, assetType asset.Item) (orderbook.Base, error) {
var orderBook orderbook.Base
func (h *HitBTC) UpdateOrderbook(currencyPair currency.Pair, assetType asset.Item) (*orderbook.Base, error) {
orderBook := new(orderbook.Base)
orderbookNew, err := h.GetOrderbook(h.FormatExchangeCurrency(currencyPair, assetType).String(), 1000)
if err != nil {
return orderBook, err