mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-10 09:11:55 +00:00
add lock and unlock functions
This commit is contained in:
parent
f69c87b3a8
commit
5d4680e496
|
@ -52,6 +52,28 @@ func (a *Account) Balance(currency string) (balance Balance, ok bool) {
|
|||
return balance, ok
|
||||
}
|
||||
|
||||
func (a *Account) UnlockBalance(currency string, unlocked float64) bool {
|
||||
a.Lock()
|
||||
balance, ok := a.balances[currency]
|
||||
if ok {
|
||||
balance.Locked -= unlocked
|
||||
balance.Available += unlocked
|
||||
}
|
||||
a.Unlock()
|
||||
return ok
|
||||
}
|
||||
|
||||
func (a *Account) LockBalance(currency string, locked float64) bool {
|
||||
a.Lock()
|
||||
balance, ok := a.balances[currency]
|
||||
if ok {
|
||||
balance.Locked += locked
|
||||
balance.Available -= locked
|
||||
}
|
||||
a.Unlock()
|
||||
return ok
|
||||
}
|
||||
|
||||
func (a *Account) UpdateBalances(balances map[string]Balance) {
|
||||
a.Lock()
|
||||
defer a.Unlock()
|
||||
|
|
Loading…
Reference in New Issue
Block a user