diff --git a/pkg/bbgo/session.go b/pkg/bbgo/session.go index 8a9bef426..c6647bc4f 100644 --- a/pkg/bbgo/session.go +++ b/pkg/bbgo/session.go @@ -886,15 +886,16 @@ func (session *ExchangeSession) InitExchange(name string, ex types.Exchange) err return nil } -func (session *ExchangeSession) MarginType() string { - margin := "none" +func (session *ExchangeSession) MarginType() types.MarginType { if session.Margin { - margin = "margin" if session.IsolatedMargin { - margin = "isolated" + return types.MarginTypeIsolatedMargin + } else { + return types.MarginTypeCrossMargin } } - return margin + + return types.MarginTypeSpot } func (session *ExchangeSession) metricsBalancesUpdater(balances types.BalanceMap) { diff --git a/pkg/types/futures.go b/pkg/types/futures.go new file mode 100644 index 000000000..ef19e0a2d --- /dev/null +++ b/pkg/types/futures.go @@ -0,0 +1,42 @@ +package types + +import "github.com/c9s/bbgo/pkg/fixedpoint" + +type FuturesExchange interface { + UseFutures() + UseIsolatedFutures(symbol string) + GetFuturesSettings() FuturesSettings +} + +type FuturesSettings struct { + IsFutures bool + IsIsolatedFutures bool + IsolatedFuturesSymbol string +} + +func (s FuturesSettings) GetFuturesSettings() FuturesSettings { + return s +} + +func (s *FuturesSettings) UseFutures() { + s.IsFutures = true +} + +func (s *FuturesSettings) UseIsolatedFutures(symbol string) { + s.IsFutures = true + s.IsIsolatedFutures = true + s.IsolatedFuturesSymbol = symbol +} + +// FuturesUserAsset define cross/isolated futures account asset +type FuturesUserAsset struct { + Asset string `json:"asset"` + InitialMargin fixedpoint.Value `json:"initialMargin"` + MaintMargin fixedpoint.Value `json:"maintMargin"` + MarginBalance fixedpoint.Value `json:"marginBalance"` + MaxWithdrawAmount fixedpoint.Value `json:"maxWithdrawAmount"` + OpenOrderInitialMargin fixedpoint.Value `json:"openOrderInitialMargin"` + PositionInitialMargin fixedpoint.Value `json:"positionInitialMargin"` + UnrealizedProfit fixedpoint.Value `json:"unrealizedProfit"` + WalletBalance fixedpoint.Value `json:"walletBalance"` +} diff --git a/pkg/types/margin.go b/pkg/types/margin.go index a546f2d69..97875fccf 100644 --- a/pkg/types/margin.go +++ b/pkg/types/margin.go @@ -7,44 +7,13 @@ import ( "github.com/c9s/bbgo/pkg/fixedpoint" ) -type FuturesExchange interface { - UseFutures() - UseIsolatedFutures(symbol string) - GetFuturesSettings() FuturesSettings -} +type MarginType string -type FuturesSettings struct { - IsFutures bool - IsIsolatedFutures bool - IsolatedFuturesSymbol string -} - -func (s FuturesSettings) GetFuturesSettings() FuturesSettings { - return s -} - -func (s *FuturesSettings) UseFutures() { - s.IsFutures = true -} - -func (s *FuturesSettings) UseIsolatedFutures(symbol string) { - s.IsFutures = true - s.IsIsolatedFutures = true - s.IsolatedFuturesSymbol = symbol -} - -// FuturesUserAsset define cross/isolated futures account asset -type FuturesUserAsset struct { - Asset string `json:"asset"` - InitialMargin fixedpoint.Value `json:"initialMargin"` - MaintMargin fixedpoint.Value `json:"maintMargin"` - MarginBalance fixedpoint.Value `json:"marginBalance"` - MaxWithdrawAmount fixedpoint.Value `json:"maxWithdrawAmount"` - OpenOrderInitialMargin fixedpoint.Value `json:"openOrderInitialMargin"` - PositionInitialMargin fixedpoint.Value `json:"positionInitialMargin"` - UnrealizedProfit fixedpoint.Value `json:"unrealizedProfit"` - WalletBalance fixedpoint.Value `json:"walletBalance"` -} +const ( + MarginTypeSpot MarginType = "spot" + MarginTypeCrossMargin MarginType = "cross_margin" + MarginTypeIsolatedMargin MarginType = "isolated_margin" +) type MarginExchange interface { UseMargin()