Skip to content

Commit

Permalink
bbgo: add session Futures & types: add FuturesExchange
Browse files Browse the repository at this point in the history
  • Loading branch information
austin362667 committed Dec 13, 2021
1 parent a53b1d4 commit e66a569
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
17 changes: 17 additions & 0 deletions pkg/bbgo/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,10 @@ type ExchangeSession struct {
IsolatedMargin bool `json:"isolatedMargin,omitempty" yaml:"isolatedMargin,omitempty"`
IsolatedMarginSymbol string `json:"isolatedMarginSymbol,omitempty" yaml:"isolatedMarginSymbol,omitempty"`

Futures bool `json:"futures,omitempty" yaml:"futures"`
IsolatedFutures bool `json:"isolatedFutures,omitempty" yaml:"isolatedFutures,omitempty"`
IsolatedFuturesSymbol string `json:"isolatedFuturesSymbol,omitempty" yaml:"isolatedFuturesSymbol,omitempty"`

// ---------------------------
// Runtime fields
// ---------------------------
Expand Down Expand Up @@ -691,6 +695,19 @@ func InitExchangeSession(name string, session *ExchangeSession) error {
}
}

if session.Futures {
futuresExchange, ok := exchange.(types.FuturesExchange)
if !ok {
return fmt.Errorf("exchange %s does not support futures", exchangeName)
}

if session.IsolatedFutures {
futuresExchange.UseIsolatedFutures(session.IsolatedFuturesSymbol)
} else {
futuresExchange.UseFutures()
}
}

session.Name = name
session.Notifiability = Notifiability{
SymbolChannelRouter: NewPatternChannelRouter(nil),
Expand Down
5 changes: 2 additions & 3 deletions pkg/types/margin.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@ import "github.com/c9s/bbgo/pkg/fixedpoint"

type FuturesExchange interface {
UseFutures()
UseIsolatedFutures(symbol string)
GetFuturesSettings() FuturesSettings
}

type FuturesSettings struct {
IsFutures bool
IsFutures bool
IsIsolatedFutures bool
IsolatedFuturesSymbol string
}
Expand All @@ -25,10 +26,8 @@ func (s *FuturesSettings) UseIsolatedFutures(symbol string) {
s.IsFutures = true
s.IsIsolatedFutures = true
s.IsolatedFuturesSymbol = symbol

}


type MarginExchange interface {
UseMargin()
UseIsolatedMargin(symbol string)
Expand Down

0 comments on commit e66a569

Please sign in to comment.