diff --git a/exchanges/anx/anx.go b/exchanges/anx/anx.go index b77b9240..2a68b5c7 100644 --- a/exchanges/anx/anx.go +++ b/exchanges/anx/anx.go @@ -26,6 +26,7 @@ const ( ANX_RECEIVE_ADDRESS = "receive" ANX_CREATE_ADDRESS = "receive/create" ANX_TICKER = "money/ticker" + ANX_DEPTH = "money/depth" ) type ANX struct { @@ -90,6 +91,15 @@ func (a *ANX) GetTicker(currency string) (ANXTicker, error) { return ticker, nil } +func (a *ANX) GetDepth(currency string) (Depth, error) { + var depth Depth + err := common.SendHTTPGetRequest(fmt.Sprintf("%sapi/2/%s/%s", ANX_API_URL, currency, ANX_TICKER), true, a.Verbose, &depth) + if err != nil { + return depth, err + } + return depth, nil +} + func (a *ANX) GetAPIKey(username, password, otp, deviceID string) (string, string, error) { request := make(map[string]interface{}) request["nonce"] = strconv.FormatInt(time.Now().UnixNano(), 10)[0:13] diff --git a/exchanges/anx/anx_test.go b/exchanges/anx/anx_test.go index cb7ff28f..8b5714c9 100644 --- a/exchanges/anx/anx_test.go +++ b/exchanges/anx/anx_test.go @@ -100,6 +100,17 @@ func TestGetTicker(t *testing.T) { } } +func TestGetDepth(t *testing.T) { + a := ANX{} + ticker, err := a.GetDepth("BTCUSD") + if err != nil { + t.Errorf("Test Failed - ANX GetDepth() error: %s", err) + } + if ticker.Result != "success" { + t.Error("Test Failed - ANX GetDepth() unsuccessful") + } +} + func TestGetAPIKey(t *testing.T) { getAPIKey := ANX{} apiKey, apiSecret, err := getAPIKey.GetAPIKey("userName", "passWord", "", "1337") diff --git a/exchanges/anx/anx_types.go b/exchanges/anx/anx_types.go index 784fe4e9..2b141803 100644 --- a/exchanges/anx/anx_types.go +++ b/exchanges/anx/anx_types.go @@ -51,3 +51,20 @@ type ANXTicker struct { UpdateTime string `json:"dataUpdateTime"` } `json:"data"` } + +type DepthItem struct { + Price float64 `json:"price,string"` + PriceInt float64 `json:"price_int,string"` + Amount float64 `json:"amount,string"` + AmountInt int64 `json:"amount_int,string"` +} + +type Depth struct { + Result string `json:"result"` + Data struct { + Now string `json:"now"` + DataUpdateTime string `json:"dataUpdateTime"` + Asks []DepthItem `json:"asks` + Bids []DepthItem `json:"bids"` + } `json:"data"` +} diff --git a/exchanges/anx/anx_wrapper.go b/exchanges/anx/anx_wrapper.go index cf70d97b..4c775543 100644 --- a/exchanges/anx/anx_wrapper.go +++ b/exchanges/anx/anx_wrapper.go @@ -111,7 +111,21 @@ func (a *ANX) GetOrderbookEx(p pair.CurrencyPair, assetType string) (orderbook.B // UpdateOrderbook updates and returns the orderbook for a currency pair func (a *ANX) UpdateOrderbook(p pair.CurrencyPair, assetType string) (orderbook.Base, error) { var orderBook orderbook.Base - return orderBook, nil + orderbookNew, err := a.GetDepth(exchange.FormatExchangeCurrency(a.GetName(), p).String()) + if err != nil { + return orderBook, err + } + + for x := range orderbookNew.Data.Asks { + orderBook.Asks = append(orderBook.Asks, orderbook.Item{Price: orderbookNew.Data.Asks[x].Price, Amount: orderbookNew.Data.Asks[x].Amount}) + } + + for x := range orderbookNew.Data.Bids { + orderBook.Bids = append(orderBook.Bids, orderbook.Item{Price: orderbookNew.Data.Bids[x].Price, Amount: orderbookNew.Data.Bids[x].Amount}) + } + + orderbook.ProcessOrderbook(a.GetName(), p, orderBook, assetType) + return orderbook.GetOrderbook(a.Name, p, assetType) } //GetExchangeAccountInfo : Retrieves balances for all enabled currencies for the ANX exchange diff --git a/routines.go b/routines.go index 2523cee9..65ebe765 100644 --- a/routines.go +++ b/routines.go @@ -230,11 +230,6 @@ func OrderbookUpdaterRoutine() { if bot.exchanges[x] == nil { continue } - - if bot.exchanges[x].GetName() == "ANX" { - continue - } - exchangeName := bot.exchanges[x].GetName() enabledCurrencies := bot.exchanges[x].GetEnabledCurrencies() var result orderbook.Base