mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-10 09:11:55 +00:00
account: check if balance exists
This commit is contained in:
parent
5949c7587e
commit
ce70bbbc4a
|
@ -145,7 +145,12 @@ func (a *Account) UseLockedBalance(currency string, fund fixedpoint.Value) error
|
|||
defer a.Unlock()
|
||||
|
||||
balance, ok := a.balances[currency]
|
||||
if ok && balance.Locked.Compare(fund) >= 0 {
|
||||
if !ok {
|
||||
return fmt.Errorf("account balance %s does not exist", currency)
|
||||
}
|
||||
|
||||
// simple case, using fund less than locked
|
||||
if balance.Locked.Compare(fund) >= 0 {
|
||||
balance.Locked = balance.Locked.Sub(fund)
|
||||
a.balances[currency] = balance
|
||||
return nil
|
||||
|
|
Loading…
Reference in New Issue
Block a user