mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-26 08:45: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"`
|
IsolatedMargin bool `json:"isolatedMargin,omitempty" yaml:"isolatedMargin,omitempty"`
|
||||||
IsolatedMarginSymbol string `json:"isolatedMarginSymbol,omitempty" yaml:"isolatedMarginSymbol,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
|
// 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.Name = name
|
||||||
session.Notifiability = Notifiability{
|
session.Notifiability = Notifiability{
|
||||||
SymbolChannelRouter: NewPatternChannelRouter(nil),
|
SymbolChannelRouter: NewPatternChannelRouter(nil),
|
||||||
|
|
|
@ -4,11 +4,12 @@ import "github.com/c9s/bbgo/pkg/fixedpoint"
|
||||||
|
|
||||||
type FuturesExchange interface {
|
type FuturesExchange interface {
|
||||||
UseFutures()
|
UseFutures()
|
||||||
|
UseIsolatedFutures(symbol string)
|
||||||
GetFuturesSettings() FuturesSettings
|
GetFuturesSettings() FuturesSettings
|
||||||
}
|
}
|
||||||
|
|
||||||
type FuturesSettings struct {
|
type FuturesSettings struct {
|
||||||
IsFutures bool
|
IsFutures bool
|
||||||
IsIsolatedFutures bool
|
IsIsolatedFutures bool
|
||||||
IsolatedFuturesSymbol string
|
IsolatedFuturesSymbol string
|
||||||
}
|
}
|
||||||
|
@ -25,10 +26,8 @@ func (s *FuturesSettings) UseIsolatedFutures(symbol string) {
|
||||||
s.IsFutures = true
|
s.IsFutures = true
|
||||||
s.IsIsolatedFutures = true
|
s.IsIsolatedFutures = true
|
||||||
s.IsolatedFuturesSymbol = symbol
|
s.IsolatedFuturesSymbol = symbol
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
type MarginExchange interface {
|
type MarginExchange interface {
|
||||||
UseMargin()
|
UseMargin()
|
||||||
UseIsolatedMargin(symbol string)
|
UseIsolatedMargin(symbol string)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user