You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

56 lines
1.2 KiB

package types
import (
"sig-pub/api/pb"
"sig-pub/pkg/utils/collect"
)
var SupportedExchanges = []pb.ExchangeType{
pb.ExchangeType_OKX,
}
func IsSupportExchange(exchange pb.ExchangeType) bool {
for _, se := range SupportedExchanges {
if se == exchange {
return true
}
}
return false
}
type ExchangeState[T any] struct {
state []T
}
func NewExchangeState[T any]() *ExchangeState[T] {
return NewExchangeState0[T](func() (v T) { return })
}
func NewExchangeState0[T any](newer func() T) *ExchangeState[T] {
maxExchange := collect.MustMax(SupportedExchanges, func(e pb.ExchangeType) int32 { return int32(e) })
es := &ExchangeState[T]{
state: make([]T, maxExchange+1),
}
for _, exchange := range SupportedExchanges {
es.Set(exchange, newer())
}
return es
}
func (s *ExchangeState[T]) IsSupport(exchange pb.ExchangeType) bool {
return IsSupportExchange(exchange)
}
func (s *ExchangeState[T]) Get(exchange pb.ExchangeType) T {
return s.state[exchange]
}
func (s *ExchangeState[T]) Set(exchange pb.ExchangeType, v T) {
s.state[exchange] = v
}
func (s *ExchangeState[T]) Range(f func(exchange pb.ExchangeType, v T)) {
for _, exchange := range SupportedExchanges {
f(exchange, s.state[exchange])
}
}