mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-10 09:11:55 +00:00
types: add marginType
This commit is contained in:
parent
055cfbb3ff
commit
40d3a40277
|
@ -886,15 +886,16 @@ func (session *ExchangeSession) InitExchange(name string, ex types.Exchange) err
|
|||
return nil
|
||||
}
|
||||
|
||||
func (session *ExchangeSession) MarginType() string {
|
||||
margin := "none"
|
||||
func (session *ExchangeSession) MarginType() types.MarginType {
|
||||
if session.Margin {
|
||||
margin = "margin"
|
||||
if session.IsolatedMargin {
|
||||
margin = "isolated"
|
||||
return types.MarginTypeIsolatedMargin
|
||||
} else {
|
||||
return types.MarginTypeCrossMargin
|
||||
}
|
||||
}
|
||||
return margin
|
||||
|
||||
return types.MarginTypeSpot
|
||||
}
|
||||
|
||||
func (session *ExchangeSession) metricsBalancesUpdater(balances types.BalanceMap) {
|
||||
|
|
42
pkg/types/futures.go
Normal file
42
pkg/types/futures.go
Normal file
|
@ -0,0 +1,42 @@
|
|||
package types
|
||||
|
||||
import "github.com/c9s/bbgo/pkg/fixedpoint"
|
||||
|
||||
type FuturesExchange interface {
|
||||
UseFutures()
|
||||
UseIsolatedFutures(symbol string)
|
||||
GetFuturesSettings() FuturesSettings
|
||||
}
|
||||
|
||||
type FuturesSettings struct {
|
||||
IsFutures bool
|
||||
IsIsolatedFutures bool
|
||||
IsolatedFuturesSymbol string
|
||||
}
|
||||
|
||||
func (s FuturesSettings) GetFuturesSettings() FuturesSettings {
|
||||
return s
|
||||
}
|
||||
|
||||
func (s *FuturesSettings) UseFutures() {
|
||||
s.IsFutures = true
|
||||
}
|
||||
|
||||
func (s *FuturesSettings) UseIsolatedFutures(symbol string) {
|
||||
s.IsFutures = true
|
||||
s.IsIsolatedFutures = true
|
||||
s.IsolatedFuturesSymbol = symbol
|
||||
}
|
||||
|
||||
// FuturesUserAsset define cross/isolated futures account asset
|
||||
type FuturesUserAsset struct {
|
||||
Asset string `json:"asset"`
|
||||
InitialMargin fixedpoint.Value `json:"initialMargin"`
|
||||
MaintMargin fixedpoint.Value `json:"maintMargin"`
|
||||
MarginBalance fixedpoint.Value `json:"marginBalance"`
|
||||
MaxWithdrawAmount fixedpoint.Value `json:"maxWithdrawAmount"`
|
||||
OpenOrderInitialMargin fixedpoint.Value `json:"openOrderInitialMargin"`
|
||||
PositionInitialMargin fixedpoint.Value `json:"positionInitialMargin"`
|
||||
UnrealizedProfit fixedpoint.Value `json:"unrealizedProfit"`
|
||||
WalletBalance fixedpoint.Value `json:"walletBalance"`
|
||||
}
|
|
@ -7,44 +7,13 @@ import (
|
|||
"github.com/c9s/bbgo/pkg/fixedpoint"
|
||||
)
|
||||
|
||||
type FuturesExchange interface {
|
||||
UseFutures()
|
||||
UseIsolatedFutures(symbol string)
|
||||
GetFuturesSettings() FuturesSettings
|
||||
}
|
||||
type MarginType string
|
||||
|
||||
type FuturesSettings struct {
|
||||
IsFutures bool
|
||||
IsIsolatedFutures bool
|
||||
IsolatedFuturesSymbol string
|
||||
}
|
||||
|
||||
func (s FuturesSettings) GetFuturesSettings() FuturesSettings {
|
||||
return s
|
||||
}
|
||||
|
||||
func (s *FuturesSettings) UseFutures() {
|
||||
s.IsFutures = true
|
||||
}
|
||||
|
||||
func (s *FuturesSettings) UseIsolatedFutures(symbol string) {
|
||||
s.IsFutures = true
|
||||
s.IsIsolatedFutures = true
|
||||
s.IsolatedFuturesSymbol = symbol
|
||||
}
|
||||
|
||||
// FuturesUserAsset define cross/isolated futures account asset
|
||||
type FuturesUserAsset struct {
|
||||
Asset string `json:"asset"`
|
||||
InitialMargin fixedpoint.Value `json:"initialMargin"`
|
||||
MaintMargin fixedpoint.Value `json:"maintMargin"`
|
||||
MarginBalance fixedpoint.Value `json:"marginBalance"`
|
||||
MaxWithdrawAmount fixedpoint.Value `json:"maxWithdrawAmount"`
|
||||
OpenOrderInitialMargin fixedpoint.Value `json:"openOrderInitialMargin"`
|
||||
PositionInitialMargin fixedpoint.Value `json:"positionInitialMargin"`
|
||||
UnrealizedProfit fixedpoint.Value `json:"unrealizedProfit"`
|
||||
WalletBalance fixedpoint.Value `json:"walletBalance"`
|
||||
}
|
||||
const (
|
||||
MarginTypeSpot MarginType = "spot"
|
||||
MarginTypeCrossMargin MarginType = "cross_margin"
|
||||
MarginTypeIsolatedMargin MarginType = "isolated_margin"
|
||||
)
|
||||
|
||||
type MarginExchange interface {
|
||||
UseMargin()
|
||||
|
|
Loading…
Reference in New Issue
Block a user