From b000f572b4ad70c55a8f36fbb34efcd3508bfe6a Mon Sep 17 00:00:00 2001 From: austin362667 Date: Thu, 30 Dec 2021 21:40:57 +0800 Subject: [PATCH] types: add FuturesPosition --- pkg/types/account.go | 3 ++- pkg/types/position.go | 21 +++++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/pkg/types/account.go b/pkg/types/account.go index 8edf10f01..3b3e9a6f9 100644 --- a/pkg/types/account.go +++ b/pkg/types/account.go @@ -121,6 +121,7 @@ func (m AssetMap) SlackAttachment() slack.Attachment { type BalanceMap map[string]Balance type PositionMap map[string]Position +type FuturesPositionMap map[string]FuturesPosition func (m BalanceMap) String() string { var ss []string @@ -229,7 +230,7 @@ type FuturesAccountInfo struct { Assets map[Asset]FuturesUserAsset `json:"assets"` FeeTier int `json:"feeTier"` MaxWithdrawAmount fixedpoint.Value `json:"maxWithdrawAmount"` - Positions PositionMap `json:"positions"` + Positions FuturesPositionMap `json:"positions"` TotalInitialMargin fixedpoint.Value `json:"totalInitialMargin"` TotalMaintMargin fixedpoint.Value `json:"totalMaintMargin"` TotalMarginBalance fixedpoint.Value `json:"totalMarginBalance"` diff --git a/pkg/types/position.go b/pkg/types/position.go index d3996d137..638d05c12 100644 --- a/pkg/types/position.go +++ b/pkg/types/position.go @@ -39,6 +39,27 @@ type Position struct { FeeRate *ExchangeFee `json:"feeRate,omitempty"` ExchangeFeeRates map[ExchangeName]ExchangeFee `json:"exchangeFeeRates"` + sync.Mutex +} + +type FuturesPosition struct { + Symbol string `json:"symbol"` + BaseCurrency string `json:"baseCurrency"` + QuoteCurrency string `json:"quoteCurrency"` + + Market Market `json:"market"` + + Base fixedpoint.Value `json:"base"` + Quote fixedpoint.Value `json:"quote"` + AverageCost fixedpoint.Value `json:"averageCost"` + + // ApproximateAverageCost adds the computed fee in quote in the average cost + // This is used for calculating net profit + ApproximateAverageCost fixedpoint.Value `json:"approximateAverageCost"` + + FeeRate *ExchangeFee `json:"feeRate,omitempty"` + ExchangeFeeRates map[ExchangeName]ExchangeFee `json:"exchangeFeeRates"` + // Futures data fields Isolated bool `json:"isolated"` UpdateTime int64 `json:"updateTime"`