mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-22 06:53:52 +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
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (session *ExchangeSession) MarginType() string {
|
func (session *ExchangeSession) MarginType() types.MarginType {
|
||||||
margin := "none"
|
|
||||||
if session.Margin {
|
if session.Margin {
|
||||||
margin = "margin"
|
|
||||||
if session.IsolatedMargin {
|
if session.IsolatedMargin {
|
||||||
margin = "isolated"
|
return types.MarginTypeIsolatedMargin
|
||||||
|
} else {
|
||||||
|
return types.MarginTypeCrossMargin
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return margin
|
|
||||||
|
return types.MarginTypeSpot
|
||||||
}
|
}
|
||||||
|
|
||||||
func (session *ExchangeSession) metricsBalancesUpdater(balances types.BalanceMap) {
|
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"
|
"github.com/c9s/bbgo/pkg/fixedpoint"
|
||||||
)
|
)
|
||||||
|
|
||||||
type FuturesExchange interface {
|
type MarginType string
|
||||||
UseFutures()
|
|
||||||
UseIsolatedFutures(symbol string)
|
|
||||||
GetFuturesSettings() FuturesSettings
|
|
||||||
}
|
|
||||||
|
|
||||||
type FuturesSettings struct {
|
const (
|
||||||
IsFutures bool
|
MarginTypeSpot MarginType = "spot"
|
||||||
IsIsolatedFutures bool
|
MarginTypeCrossMargin MarginType = "cross_margin"
|
||||||
IsolatedFuturesSymbol string
|
MarginTypeIsolatedMargin MarginType = "isolated_margin"
|
||||||
}
|
)
|
||||||
|
|
||||||
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"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type MarginExchange interface {
|
type MarginExchange interface {
|
||||||
UseMargin()
|
UseMargin()
|
||||||
|
|
Loading…
Reference in New Issue
Block a user