bbgo: add session Futures & types: add FuturesExchange

This commit is contained in:
austin362667 2021-12-13 23:16:58 +08:00
parent 74811abb36
commit 36c6d39612
2 changed files with 19 additions and 3 deletions

View File

@ -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
// ---------------------------
@ -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),

View File

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