mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-22 14:55:16 +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,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)
|
||||
|
|
Loading…
Reference in New Issue
Block a user