Add ANX Depth support

This commit is contained in:
Adrian Gallagher
2018-01-28 20:21:44 +11:00
parent 386837900c
commit 292d150595
5 changed files with 53 additions and 6 deletions

View File

@@ -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]

View File

@@ -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")

View File

@@ -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"`
}

View File

@@ -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

View File

@@ -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