GetAccountInfo wrapper update (#220)

* Added untested [cloudflare issue] changes to accountinfo for ANX

* Add alphapoint comment for future implementation

* Adds GetAccountInfo for Binance

* Adds GetAccountInfo update for Bithumb

* Updates GetAccountInfo for GateIO.
Adds error handling feature for authenticated requests.

* Updates GetAccountInfo function for Huobi.
Adds function for getting account ID.

* Updates GetAccountInfo function
Adds GetAccountID function

* Updates GetAccountInfo [un-tested, no access to keys at this time]

* Updates GetAccountInfo for Kraken

* Updates GetAccountInfo func for OKEX

* Updates GetAccountInfo for exchange ZB

* Updates GetAccountInfo func for Bitmex

* Updates GetAccountInfo func for Coinut

* Updates GetAccountInfo for ANX exchange

* Fixes incorrect hold currency issue

* Fixes type name

* Fixes issue with unneeded code in wrapper for Bithumb

* Change strings to type symbol string

* Fixes nit for Gateio

* Fixes GetAccountInfo issue
Fixes SpotCancelOrder issue
This commit is contained in:
Ryan O'Hara-Reid
2018-12-13 16:53:19 +11:00
committed by Adrian Gallagher
parent 05f9f40723
commit 4ca3fd5b00
40 changed files with 981 additions and 143 deletions

View File

@@ -2,6 +2,7 @@ package itbit
import (
"bytes"
"encoding/json"
"errors"
"fmt"
"log"
@@ -326,6 +327,10 @@ func (i *ItBit) SendAuthenticatedHTTPRequest(method string, path string, params
return fmt.Errorf(exchange.WarningAuthenticatedRequestWithoutCredentialsSet, i.Name)
}
if i.ClientID == "" {
return errors.New("client ID not set")
}
request := make(map[string]interface{})
url := i.APIUrl + path
@@ -368,7 +373,29 @@ func (i *ItBit) SendAuthenticatedHTTPRequest(method string, path string, params
headers["X-Auth-Nonce"] = nonce
headers["Content-Type"] = "application/json"
return i.SendPayload(method, url, headers, bytes.NewBuffer([]byte(PayloadJSON)), result, true, i.Verbose)
var intermediary json.RawMessage
errCheck := struct {
Code int `json:"code"`
Description string `json:"description"`
RequestID string `json:"requestId"`
}{}
err = i.SendPayload(method, url, headers, bytes.NewBuffer([]byte(PayloadJSON)), &intermediary, true, i.Verbose)
if err != nil {
return err
}
err = common.JSONDecode(intermediary, &errCheck)
if err == nil {
if errCheck.Code != 0 || errCheck.Description != "" {
return fmt.Errorf("itbit.go SendAuthRequest error code: %d description: %s",
errCheck.Code,
errCheck.Description)
}
}
return common.JSONDecode(intermediary, result)
}
// GetFee returns an estimate of fee based on type of transaction

View File

@@ -302,3 +302,12 @@ func TestCancelExchangeOrder(t *testing.T) {
t.Errorf("Could not cancel order: %s", err)
}
}
func TestGetAccountInfo(t *testing.T) {
if apiKey != "" || apiSecret != "" || clientID != "" {
_, err := i.GetAccountInfo()
if err == nil {
t.Error("Test Failed - GetAccountInfo() error")
}
}
}

View File

@@ -3,6 +3,7 @@ package itbit
import (
"fmt"
"log"
"net/url"
"strconv"
"sync"
@@ -107,12 +108,45 @@ func (i *ItBit) UpdateOrderbook(p pair.CurrencyPair, assetType string) (orderboo
return orderbook.GetOrderbook(i.Name, p, assetType)
}
// GetAccountInfo retrieves balances for all enabled currencies for the
//ItBit exchange - to-do
// GetAccountInfo retrieves balances for all enabled currencies
func (i *ItBit) GetAccountInfo() (exchange.AccountInfo, error) {
var response exchange.AccountInfo
response.ExchangeName = i.GetName()
return response, nil
var info exchange.AccountInfo
info.ExchangeName = i.GetName()
wallets, err := i.GetWallets(url.Values{})
if err != nil {
return info, err
}
type balance struct {
TotalValue float64
Hold float64
}
var amounts = make(map[string]*balance)
for _, wallet := range wallets {
for _, cb := range wallet.Balances {
if _, ok := amounts[cb.Currency]; !ok {
amounts[cb.Currency] = &balance{}
}
amounts[cb.Currency].TotalValue += cb.TotalBalance
amounts[cb.Currency].Hold += cb.TotalBalance - cb.AvailableBalance
}
}
var fullBalance []exchange.AccountCurrencyInfo
for key, data := range amounts {
fullBalance = append(fullBalance, exchange.AccountCurrencyInfo{
CurrencyName: key,
TotalValue: data.TotalValue,
Hold: data.Hold,
})
}
return info, nil
}
// GetFundingHistory returns funding history, deposits and