Files
gocryptotrader/common/key/key.go
Jun 1b7fa2259a account: refactor for save holdings (#1846)
* account: refactor for save holdings

Signed-off-by: Ye Sijun <junnplus@gmail.com>

* Update exchanges/account/account.go

Co-authored-by: Gareth Kirwan <gbjkirwan@gmail.com>

* Update exchanges/account/account.go

Co-authored-by: Scott <gloriousCode@users.noreply.github.com>

* account: minor changes

Signed-off-by: Ye Sijun <junnplus@gmail.com>

---------

Signed-off-by: Ye Sijun <junnplus@gmail.com>
Co-authored-by: Gareth Kirwan <gbjkirwan@gmail.com>
Co-authored-by: Scott <gloriousCode@users.noreply.github.com>
2025-04-02 12:32:23 +11:00

78 lines
2.0 KiB
Go

package key
import (
"strings"
"github.com/thrasher-corp/gocryptotrader/currency"
"github.com/thrasher-corp/gocryptotrader/exchanges/asset"
)
// ExchangePairAsset is a unique map key signature for exchange, currency pair and asset
type ExchangePairAsset struct {
Exchange string
Base *currency.Item
Quote *currency.Item
Asset asset.Item
}
// ExchangeAsset is a unique map key signature for exchange and asset
type ExchangeAsset struct {
Exchange string
Asset asset.Item
}
// PairAsset is a unique map key signature for currency pair and asset
type PairAsset struct {
Base *currency.Item
Quote *currency.Item
Asset asset.Item
}
// SubAccountAsset is a unique map key signature for subaccount and asset
type SubAccountAsset struct {
SubAccount string
Asset asset.Item
}
// Pair combines the base and quote into a pair
func (k *PairAsset) Pair() currency.Pair {
if k == nil || (k.Base == nil && k.Quote == nil) {
return currency.EMPTYPAIR
}
return currency.NewPair(k.Base.Currency(), k.Quote.Currency())
}
// Pair combines the base and quote into a pair
func (k *ExchangePairAsset) Pair() currency.Pair {
if k == nil || (k.Base == nil && k.Quote == nil) {
return currency.EMPTYPAIR
}
return currency.NewPair(k.Base.Currency(), k.Quote.Currency())
}
// MatchesExchangeAsset checks if the key matches the exchange and asset
func (k *ExchangePairAsset) MatchesExchangeAsset(exch string, item asset.Item) bool {
if k == nil {
return false
}
return strings.EqualFold(k.Exchange, exch) && k.Asset == item
}
// MatchesPairAsset checks if the key matches the pair and asset
func (k *ExchangePairAsset) MatchesPairAsset(pair currency.Pair, item asset.Item) bool {
if k == nil {
return false
}
return k.Base == pair.Base.Item &&
k.Quote == pair.Quote.Item &&
k.Asset == item
}
// MatchesExchange checks if the exchange matches
func (k *ExchangePairAsset) MatchesExchange(exch string) bool {
if k == nil {
return false
}
return strings.EqualFold(k.Exchange, exch)
}