mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-22 23:05:15 +00:00
bbgo: add session Futures & types: add FuturesExchange
This commit is contained in:
parent
74811abb36
commit
36c6d39612
|
@ -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),
|
||||
|
|
|
@ -4,6 +4,7 @@ import "github.com/c9s/bbgo/pkg/fixedpoint"
|
|||
|
||||
type FuturesExchange interface {
|
||||
UseFutures()
|
||||
UseIsolatedFutures(symbol string)
|
||||
GetFuturesSettings() FuturesSettings
|
||||
}
|
||||
|
||||
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue
Block a user