mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-13 02:23:51 +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
|
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) {
|
func (a *Account) UpdateBalances(balances map[string]Balance) {
|
||||||
a.Lock()
|
a.Lock()
|
||||||
defer a.Unlock()
|
defer a.Unlock()
|
||||||
|
|
Loading…
Reference in New Issue
Block a user