types: add marginType

This commit is contained in:
c9s 2024-08-21 15:24:43 +08:00
parent 055cfbb3ff
commit 40d3a40277
No known key found for this signature in database
GPG Key ID: 7385E7E464CB0A54
3 changed files with 54 additions and 42 deletions

View File

@ -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) {

42
pkg/types/futures.go Normal file
View File

@ -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"`
}

View File

@ -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()