mirror of
https://github.com/d0zingcat/gocryptotrader.git
synced 2026-05-14 07:26:47 +00:00
Kraken: Fix Balances reporting 0 free (#1267)
* Kraken: Fix Balances reporting 0 Free This switches to BalancesEx(tended) to get Held assets so we can construct a Total, Held and Free. Without this fix we get 0 balance from GetFree() Haven't added tests because no construct for mocks and it's private data. Considering adding mocks a bridge to far for this fix. * Kraken: Simplify GetBalance
This commit is contained in:
@@ -494,25 +494,17 @@ func (k *Kraken) GetSpread(ctx context.Context, symbol currency.Pair) ([]Spread,
|
||||
}
|
||||
|
||||
// GetBalance returns your balance associated with your keys
|
||||
func (k *Kraken) GetBalance(ctx context.Context) (map[string]float64, error) {
|
||||
func (k *Kraken) GetBalance(ctx context.Context) (map[string]Balance, error) {
|
||||
var response struct {
|
||||
Error []string `json:"error"`
|
||||
Result map[string]string `json:"result"`
|
||||
Error []string `json:"error"`
|
||||
Result map[string]Balance `json:"result"`
|
||||
}
|
||||
|
||||
if err := k.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, krakenBalance, url.Values{}, &response); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
result := make(map[string]float64)
|
||||
for curency, balance := range response.Result {
|
||||
var err error
|
||||
if result[curency], err = strconv.ParseFloat(balance, 64); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
return result, GetError(response.Error)
|
||||
return response.Result, GetError(response.Error)
|
||||
}
|
||||
|
||||
// GetWithdrawInfo gets withdrawal fees
|
||||
|
||||
@@ -18,7 +18,7 @@ const (
|
||||
krakenDepth = "Depth"
|
||||
krakenTrades = "Trades"
|
||||
krakenSpread = "Spread"
|
||||
krakenBalance = "Balance"
|
||||
krakenBalance = "BalanceEx"
|
||||
krakenTradeBalance = "TradeBalance"
|
||||
krakenOpenOrders = "OpenOrders"
|
||||
krakenClosedOrders = "ClosedOrders"
|
||||
@@ -204,6 +204,12 @@ type Spread struct {
|
||||
Ask float64
|
||||
}
|
||||
|
||||
// Balance represents account asset balances
|
||||
type Balance struct {
|
||||
Total float64 `json:"balance,string"`
|
||||
Hold float64 `json:"hold_trade,string"`
|
||||
}
|
||||
|
||||
// TradeBalanceOptions type
|
||||
type TradeBalanceOptions struct {
|
||||
Aclass string
|
||||
|
||||
@@ -613,7 +613,9 @@ func (k *Kraken) UpdateAccountInfo(ctx context.Context, assetType asset.Item) (a
|
||||
}
|
||||
balances = append(balances, account.Balance{
|
||||
Currency: currency.NewCode(translatedCurrency),
|
||||
Total: bal[key],
|
||||
Total: bal[key].Total,
|
||||
Hold: bal[key].Hold,
|
||||
Free: bal[key].Total - bal[key].Hold,
|
||||
})
|
||||
}
|
||||
info.Accounts = append(info.Accounts, account.SubAccount{
|
||||
|
||||
Reference in New Issue
Block a user