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

@@ -238,11 +238,16 @@ func (b *Bithumb) GetTransactionHistory(symbol string) (TransactionHistory, erro
return response, nil
}
// GetAccountInformation returns account information
func (b *Bithumb) GetAccountInformation() (Account, error) {
// GetAccountInformation returns account information by singular currency
func (b *Bithumb) GetAccountInformation(currency string) (Account, error) {
response := Account{}
err := b.SendAuthenticatedHTTPRequest(privateAccInfo, nil, &response)
val := url.Values{}
if currency != "" {
val.Set("currency", currency)
}
err := b.SendAuthenticatedHTTPRequest(privateAccInfo, val, &response)
if err != nil {
return response, err
}
@@ -254,18 +259,68 @@ func (b *Bithumb) GetAccountInformation() (Account, error) {
}
// GetAccountBalance returns customer wallet information
func (b *Bithumb) GetAccountBalance() (Balance, error) {
response := Balance{}
func (b *Bithumb) GetAccountBalance(c string) (FullBalance, error) {
var response Balance
var fullBalance = FullBalance{
make(map[string]float64),
make(map[string]float64),
make(map[string]float64),
make(map[string]float64),
make(map[string]float64),
}
err := b.SendAuthenticatedHTTPRequest(privateAccBalance, nil, &response)
vals := url.Values{}
if c != "" {
vals.Set("currency", c)
}
err := b.SendAuthenticatedHTTPRequest(privateAccBalance, vals, &response)
if err != nil {
return response, err
return fullBalance, err
}
if response.Status != noError {
return response, errors.New(response.Message)
return fullBalance, errors.New(response.Message)
}
return response, nil
// Added due to increasing of the usuable currencies on exchange, usually
// without notificatation, so we dont need to update structs later on
for tag, datum := range response.Data {
splitTag := common.SplitStrings(tag, "_")
c := splitTag[len(splitTag)-1]
var val float64
if reflect.TypeOf(datum).String() != "float64" {
val, err = strconv.ParseFloat(datum.(string), 64)
if err != nil {
return fullBalance, err
}
} else {
val = datum.(float64)
}
switch splitTag[0] {
case "available":
fullBalance.Available[c] = val
case "in":
fullBalance.InUse[c] = val
case "total":
fullBalance.Total[c] = val
case "misu":
fullBalance.Misu[c] = val
case "xcoin":
fullBalance.Xcoin[c] = val
default:
return fullBalance, fmt.Errorf("GetAccountBalance error tag name %s unhandled",
splitTag)
}
}
return fullBalance, nil
}
// GetWalletAddress returns customer wallet address

View File

@@ -77,23 +77,23 @@ func TestGetTransactionHistory(t *testing.T) {
}
}
func TestGetAccountInfo(t *testing.T) {
t.Parallel()
_, err := b.GetAccountInfo()
if err == nil {
t.Error("test failed - Bithumb GetAccountInfo() error", err)
}
}
func TestGetAccountBalance(t *testing.T) {
t.Parallel()
_, err := b.GetAccountBalance()
if testAPIKey == "" || testAPISecret == "" {
t.Skip()
}
_, err := b.GetAccountBalance("BTC")
if err == nil {
t.Error("test failed - Bithumb GetAccountBalance() error", err)
}
}
func TestGetWalletAddress(t *testing.T) {
if testAPIKey == "" || testAPISecret == "" {
t.Skip()
}
t.Parallel()
_, err := b.GetWalletAddress("")
if err == nil {
@@ -159,6 +159,9 @@ func TestWithdrawCrypto(t *testing.T) {
func TestRequestKRWDepositDetails(t *testing.T) {
t.Parallel()
if testAPIKey == "" || testAPISecret == "" {
t.Skip()
}
_, err := b.RequestKRWDepositDetails()
if err == nil {
t.Error("test failed - Bithumb RequestKRWDepositDetails() error", err)
@@ -341,3 +344,18 @@ func TestCancelExchangeOrder(t *testing.T) {
t.Errorf("Could not cancel order: %s", err)
}
}
func TestGetAccountInfo(t *testing.T) {
t.Parallel()
if testAPIKey != "" || testAPISecret != "" {
_, err := b.GetAccountInfo()
if err != nil {
t.Error("test failed - Bithumb GetAccountInfo() error", err)
}
} else {
_, err := b.GetAccountInfo()
if err == nil {
t.Error("test failed - Bithumb GetAccountInfo() error")
}
}
}

View File

@@ -79,19 +79,9 @@ type Account struct {
// Balance holds balance details
type Balance struct {
Status string `json:"status"`
Data struct {
TotalBTC float64 `json:"total_btc,string"`
TotalKRW float64 `json:"total_krw"`
InUseBTC float64 `json:"in_use_btc,string"`
InUseKRW float64 `json:"in_use_krw"`
AvailableBTC float64 `json:"available_btc,string"`
AvailableKRW float64 `json:"available_krw"`
MisuKRW float64 `json:"misu_krw"`
MisuBTC float64 `json:"misu_btc,string"`
XcoinLast float64 `json:"xcoin_last,string"`
} `json:"data"`
Message string `json:"message"`
Status string `json:"status"`
Data map[string]interface{} `json:"data"`
Message string `json:"message"`
}
// WalletAddressRes contains wallet address information
@@ -278,3 +268,12 @@ var WithdrawalFees = map[string]float64{
symbol.ENJ: 35,
symbol.PST: 30,
}
// FullBalance defines a return type with full balance data
type FullBalance struct {
InUse map[string]float64
Misu map[string]float64
Total map[string]float64
Xcoin map[string]float64
Available map[string]float64
}

View File

@@ -1,7 +1,6 @@
package bithumb
import (
"errors"
"fmt"
"log"
"sync"
@@ -122,8 +121,30 @@ func (b *Bithumb) UpdateOrderbook(p pair.CurrencyPair, assetType string) (orderb
// GetAccountInfo retrieves balances for all enabled currencies for the
// Bithumb exchange
func (b *Bithumb) GetAccountInfo() (exchange.AccountInfo, error) {
var response exchange.AccountInfo
return response, errors.New("not implemented")
var info exchange.AccountInfo
bal, err := b.GetAccountBalance("ALL")
if err != nil {
return info, err
}
var exchangeBalances []exchange.AccountCurrencyInfo
for key, totalAmount := range bal.Total {
hold, ok := bal.InUse[key]
if !ok {
return info, fmt.Errorf("GetAccountInfo error - in use item not found for currency %s",
key)
}
exchangeBalances = append(exchangeBalances, exchange.AccountCurrencyInfo{
CurrencyName: key,
TotalValue: totalAmount,
Hold: hold,
})
}
info.Currencies = exchangeBalances
info.ExchangeName = b.GetName()
return info, nil
}
// GetFundingHistory returns funding history, deposits and