From c507722745632ee051c8489925bcfec5994ed7fd Mon Sep 17 00:00:00 2001 From: austin362667 Date: Tue, 21 Dec 2021 23:56:59 +0800 Subject: [PATCH 1/4] types: add FuturesAccountInfo --- pkg/types/account.go | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/pkg/types/account.go b/pkg/types/account.go index 21ae4640b..31015b0cf 100644 --- a/pkg/types/account.go +++ b/pkg/types/account.go @@ -206,6 +206,7 @@ type Account struct { sync.Mutex `json:"-"` AccountType AccountType `json:"accountType,omitempty"` + FuturesInfo *FuturesAccountInfo MakerFeeRate fixedpoint.Value `json:"makerFeeRate,omitempty"` TakerFeeRate fixedpoint.Value `json:"takerFeeRate,omitempty"` @@ -216,9 +217,30 @@ type Account struct { TotalAccountValue fixedpoint.Value `json:"totalAccountValue,omitempty"` + // Futures fields + CanDeposit bool `json:"canDeposit"` + CanTrade bool `json:"canTrade"` + CanWithdraw bool `json:"canWithdraw"` + balances BalanceMap } +type FuturesAccountInfo struct { + // Futures fields + Assets []FuturesUserAsset `json:"assets"` + FeeTier int `json:"feeTier"` + MaxWithdrawAmount fixedpoint.Value `json:"maxWithdrawAmount"` + Positions PositionMap `json:"positions"` + TotalInitialMargin fixedpoint.Value `json:"totalInitialMargin"` + TotalMaintMargin fixedpoint.Value `json:"totalMaintMargin"` + TotalMarginBalance fixedpoint.Value `json:"totalMarginBalance"` + TotalOpenOrderInitialMargin fixedpoint.Value `json:"totalOpenOrderInitialMargin"` + TotalPositionInitialMargin fixedpoint.Value `json:"totalPositionInitialMargin"` + TotalUnrealizedProfit fixedpoint.Value `json:"totalUnrealizedProfit"` + TotalWalletBalance fixedpoint.Value `json:"totalWalletBalance"` + UpdateTime int64 `json:"updateTime"` +} + func NewAccount() *Account { return &Account{ balances: make(BalanceMap), From cc13ae2aab2a09c7847c6e19e76103315586fa86 Mon Sep 17 00:00:00 2001 From: austin362667 Date: Tue, 21 Dec 2021 23:57:59 +0800 Subject: [PATCH 2/4] types: add FuturesUserAsset --- pkg/types/margin.go | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/pkg/types/margin.go b/pkg/types/margin.go index ede54b700..e8d661583 100644 --- a/pkg/types/margin.go +++ b/pkg/types/margin.go @@ -28,6 +28,19 @@ func (s *FuturesSettings) UseIsolatedFutures(symbol string) { 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 { UseMargin() UseIsolatedMargin(symbol string) From 6c1642eed606925fa8a47c00fce25503dba180dd Mon Sep 17 00:00:00 2001 From: austin362667 Date: Tue, 21 Dec 2021 23:58:57 +0800 Subject: [PATCH 3/4] types: add PositionRisk --- pkg/types/position.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/pkg/types/position.go b/pkg/types/position.go index 8d8a7307d..2c25a61e3 100644 --- a/pkg/types/position.go +++ b/pkg/types/position.go @@ -15,6 +15,11 @@ type ExchangeFee struct { TakerFeeRate fixedpoint.Value } +type PositionRisk struct { + Leverage fixedpoint.Value `json:"leverage"` + LiquidationPrice fixedpoint.Value `json:"liquidationPrice"` +} + type Position struct { Symbol string `json:"symbol"` BaseCurrency string `json:"baseCurrency"` @@ -35,7 +40,6 @@ type Position struct { // Futures data fields Isolated bool `json:"isolated"` - Leverage fixedpoint.Value `json:"leverage"` InitialMargin fixedpoint.Value `json:"initialMargin"` MaintMargin fixedpoint.Value `json:"maintMargin"` OpenOrderInitialMargin fixedpoint.Value `json:"openOrderInitialMargin"` @@ -48,6 +52,7 @@ type Position struct { Notional fixedpoint.Value `json:"notional"` IsolatedWallet fixedpoint.Value `json:"isolatedWallet"` UpdateTime int64 `json:"updateTime"` + PositionRisk PositionRisk sync.Mutex } From df626833136c1651097480f9521221213b86dea8 Mon Sep 17 00:00:00 2001 From: austin362667 Date: Thu, 23 Dec 2021 23:16:20 +0800 Subject: [PATCH 4/4] types: remove exchange specific fields --- pkg/types/account.go | 25 ++++++++++++------------- pkg/types/position.go | 17 +++-------------- 2 files changed, 15 insertions(+), 27 deletions(-) diff --git a/pkg/types/account.go b/pkg/types/account.go index 31015b0cf..8edf10f01 100644 --- a/pkg/types/account.go +++ b/pkg/types/account.go @@ -217,7 +217,6 @@ type Account struct { TotalAccountValue fixedpoint.Value `json:"totalAccountValue,omitempty"` - // Futures fields CanDeposit bool `json:"canDeposit"` CanTrade bool `json:"canTrade"` CanWithdraw bool `json:"canWithdraw"` @@ -227,18 +226,18 @@ type Account struct { type FuturesAccountInfo struct { // Futures fields - Assets []FuturesUserAsset `json:"assets"` - FeeTier int `json:"feeTier"` - MaxWithdrawAmount fixedpoint.Value `json:"maxWithdrawAmount"` - Positions PositionMap `json:"positions"` - TotalInitialMargin fixedpoint.Value `json:"totalInitialMargin"` - TotalMaintMargin fixedpoint.Value `json:"totalMaintMargin"` - TotalMarginBalance fixedpoint.Value `json:"totalMarginBalance"` - TotalOpenOrderInitialMargin fixedpoint.Value `json:"totalOpenOrderInitialMargin"` - TotalPositionInitialMargin fixedpoint.Value `json:"totalPositionInitialMargin"` - TotalUnrealizedProfit fixedpoint.Value `json:"totalUnrealizedProfit"` - TotalWalletBalance fixedpoint.Value `json:"totalWalletBalance"` - UpdateTime int64 `json:"updateTime"` + Assets map[Asset]FuturesUserAsset `json:"assets"` + FeeTier int `json:"feeTier"` + MaxWithdrawAmount fixedpoint.Value `json:"maxWithdrawAmount"` + Positions PositionMap `json:"positions"` + TotalInitialMargin fixedpoint.Value `json:"totalInitialMargin"` + TotalMaintMargin fixedpoint.Value `json:"totalMaintMargin"` + TotalMarginBalance fixedpoint.Value `json:"totalMarginBalance"` + TotalOpenOrderInitialMargin fixedpoint.Value `json:"totalOpenOrderInitialMargin"` + TotalPositionInitialMargin fixedpoint.Value `json:"totalPositionInitialMargin"` + TotalUnrealizedProfit fixedpoint.Value `json:"totalUnrealizedProfit"` + TotalWalletBalance fixedpoint.Value `json:"totalWalletBalance"` + UpdateTime int64 `json:"updateTime"` } func NewAccount() *Account { diff --git a/pkg/types/position.go b/pkg/types/position.go index 2c25a61e3..e7aff235f 100644 --- a/pkg/types/position.go +++ b/pkg/types/position.go @@ -39,20 +39,9 @@ type Position struct { ExchangeFeeRates map[ExchangeName]ExchangeFee `json:"exchangeFeeRates"` // Futures data fields - Isolated bool `json:"isolated"` - InitialMargin fixedpoint.Value `json:"initialMargin"` - MaintMargin fixedpoint.Value `json:"maintMargin"` - OpenOrderInitialMargin fixedpoint.Value `json:"openOrderInitialMargin"` - PositionInitialMargin fixedpoint.Value `json:"positionInitialMargin"` - UnrealizedProfit fixedpoint.Value `json:"unrealizedProfit"` - EntryPrice fixedpoint.Value `json:"entryPrice"` - MaxNotional fixedpoint.Value `json:"maxNotional"` - PositionSide string `json:"positionSide"` - PositionAmt fixedpoint.Value `json:"positionAmt"` - Notional fixedpoint.Value `json:"notional"` - IsolatedWallet fixedpoint.Value `json:"isolatedWallet"` - UpdateTime int64 `json:"updateTime"` - PositionRisk PositionRisk + Isolated bool `json:"isolated"` + UpdateTime int64 `json:"updateTime"` + PositionRisk *PositionRisk sync.Mutex }