Skip to content

Commit

Permalink
Add ANX Depth support
Browse files Browse the repository at this point in the history
  • Loading branch information
thrasher- committed Jan 28, 2018
1 parent 3868379 commit 292d150
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 6 deletions.
10 changes: 10 additions & 0 deletions exchanges/anx/anx.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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]
Expand Down
11 changes: 11 additions & 0 deletions exchanges/anx/anx_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
17 changes: 17 additions & 0 deletions exchanges/anx/anx_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
}
16 changes: 15 additions & 1 deletion exchanges/anx/anx_wrapper.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 0 additions & 5 deletions routines.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 292d150

Please sign in to comment.