mirror of
https://github.com/d0zingcat/gocryptotrader.git
synced 2026-05-13 23:16:45 +00:00
Account: Add account.Balance.Available() method (#777)
* add account.Balance.Available() method that returns the amount of an asset not locked/held * account: comment Balance.Available() * account: test Balance.Available()
This commit is contained in:
@@ -93,3 +93,9 @@ func (s *Service) Update(a *Holdings) error {
|
||||
|
||||
return s.mux.Publish([]uuid.UUID{acc.ID}, acc.h)
|
||||
}
|
||||
|
||||
// Available returns the amount you can use immediately. E.g. if you have $100, but $20
|
||||
// are held (locked) because of a limit buy order, your available balance is $80.
|
||||
func (b Balance) Available() float64 {
|
||||
return b.TotalValue - b.Hold
|
||||
}
|
||||
|
||||
@@ -134,3 +134,29 @@ func TestHoldings(t *testing.T) {
|
||||
|
||||
wg.Wait()
|
||||
}
|
||||
|
||||
func TestBalance_Available(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
b := Balance{
|
||||
CurrencyName: currency.BTC,
|
||||
TotalValue: 16,
|
||||
Hold: 0,
|
||||
}
|
||||
|
||||
if have := b.Available(); have != 16 {
|
||||
t.Errorf("have %f, want 16", have)
|
||||
}
|
||||
|
||||
b.Hold = 8
|
||||
|
||||
if have := b.Available(); have != 8 {
|
||||
t.Errorf("have %f, want 8", have)
|
||||
}
|
||||
|
||||
b.Hold = 16
|
||||
|
||||
if have := b.Available(); have != 0 {
|
||||
t.Errorf("have %f, want 0", have)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user