(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

@@ -291,8 +291,8 @@ func (h *HUOBI) UpdateTradablePairs(forceUpdate bool) error {
}
// UpdateTicker updates and returns the ticker for a currency pair
func (h *HUOBI) UpdateTicker(p currency.Pair, assetType asset.Item) (ticker.Price, error) {
var tickerPrice ticker.Price
func (h *HUOBI) UpdateTicker(p currency.Pair, assetType asset.Item) (*ticker.Price, error) {
tickerPrice := new(ticker.Price)
tickers, err := h.GetTickers()
if err != nil {
return tickerPrice, err
@@ -304,7 +304,7 @@ func (h *HUOBI) UpdateTicker(p currency.Pair, assetType asset.Item) (ticker.Pric
if pairFmt != tickers.Data[j].Symbol {
continue
}
tickerPrice := ticker.Price{
tickerPrice := &ticker.Price{
High: tickers.Data[j].High,
Low: tickers.Data[j].Low,
Volume: tickers.Data[j].Volume,
@@ -312,7 +312,7 @@ func (h *HUOBI) UpdateTicker(p currency.Pair, assetType asset.Item) (ticker.Pric
Close: tickers.Data[j].Close,
Pair: pairs[i],
}
err = ticker.ProcessTicker(h.Name, &tickerPrice, assetType)
err = ticker.ProcessTicker(h.Name, tickerPrice, assetType)
if err != nil {
log.Error(log.Ticker, err)
}
@@ -323,7 +323,7 @@ func (h *HUOBI) UpdateTicker(p currency.Pair, assetType asset.Item) (ticker.Pric
}
// FetchTicker returns the ticker for a currency pair
func (h *HUOBI) FetchTicker(p currency.Pair, assetType asset.Item) (ticker.Price, error) {
func (h *HUOBI) 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)
@@ -332,7 +332,7 @@ func (h *HUOBI) FetchTicker(p currency.Pair, assetType asset.Item) (ticker.Price
}
// FetchOrderbook returns orderbook base on the currency pair
func (h *HUOBI) FetchOrderbook(p currency.Pair, assetType asset.Item) (orderbook.Base, error) {
func (h *HUOBI) 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)
@@ -341,8 +341,8 @@ func (h *HUOBI) FetchOrderbook(p currency.Pair, assetType asset.Item) (orderbook
}
// UpdateOrderbook updates and returns the orderbook for a currency pair
func (h *HUOBI) UpdateOrderbook(p currency.Pair, assetType asset.Item) (orderbook.Base, error) {
var orderBook orderbook.Base
func (h *HUOBI) UpdateOrderbook(p currency.Pair, assetType asset.Item) (*orderbook.Base, error) {
orderBook := new(orderbook.Base)
orderbookNew, err := h.GetDepth(OrderBookDataRequestParams{
Symbol: h.FormatExchangeCurrency(p, assetType).String(),
Type: OrderBookDataRequestParamsTypeStep0,