qbtrade/pkg/exchange/util.go
2024-06-27 22:42:38 +08:00

38 lines
1.0 KiB
Go

package exchange
import (
"git.qtrade.icu/lychiyu/qbtrade/pkg/exchange/max"
"git.qtrade.icu/lychiyu/qbtrade/pkg/types"
)
func GetSessionAttributes(exchange types.Exchange) (isMargin, isFutures, isIsolated bool, isolatedSymbol string) {
if marginExchange, ok := exchange.(types.MarginExchange); ok {
marginSettings := marginExchange.GetMarginSettings()
isMargin = marginSettings.IsMargin
if isMargin {
isIsolated = marginSettings.IsIsolatedMargin
if marginSettings.IsIsolatedMargin {
isolatedSymbol = marginSettings.IsolatedMarginSymbol
}
}
}
if futuresExchange, ok := exchange.(types.FuturesExchange); ok {
futuresSettings := futuresExchange.GetFuturesSettings()
isFutures = futuresSettings.IsFutures
if isFutures {
isIsolated = futuresSettings.IsIsolatedFutures
if futuresSettings.IsIsolatedFutures {
isolatedSymbol = futuresSettings.IsolatedFuturesSymbol
}
}
}
return isMargin, isFutures, isIsolated, isolatedSymbol
}
func IsMaxExchange(exchange interface{}) bool {
_, res := exchange.(*max.Exchange)
return res
}