Files
coin/trade/account.go
2026-01-09 15:48:31 +08:00

48 lines
782 B
Go
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
package trade
import (
"sync"
)
var (
AccountsAssets *Assets
)
type AccountsBalance struct {
AccountEquity float64 // 账户权益(保证金币种)包含未实现盈亏根据mark price计算
Available float64 // 账户可用数量
}
// lock
type Assets struct {
sync.RWMutex
Data map[string]*AccountsBalance
}
func NewAccounts() {
AccountsAssets = &Assets{
Data: make(map[string]*AccountsBalance),
}
}
func (ac *Assets) Set(assets string, balance *AccountsBalance) {
ac.Lock()
defer ac.Unlock()
ac.Data[assets] = balance
}
func (ac *Assets) SetData(data map[string]*AccountsBalance) {
ac.Lock()
defer ac.Unlock()
ac.Data = data
}
func (ac *Assets) Get(assets string) *AccountsBalance {
ac.Lock()
defer ac.Unlock()
return ac.Data[assets]
}