Merge pull request #385 from austin362667/refactor/futures-account

types: add global structs for futures
This commit is contained in:
Yo-An Lin 2021-12-24 00:33:27 +08:00 committed by GitHub
commit d1c5e93e4f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 42 additions and 14 deletions

View File

@ -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,29 @@ type Account struct {
TotalAccountValue fixedpoint.Value `json:"totalAccountValue,omitempty"`
CanDeposit bool `json:"canDeposit"`
CanTrade bool `json:"canTrade"`
CanWithdraw bool `json:"canWithdraw"`
balances BalanceMap
}
type FuturesAccountInfo struct {
// Futures fields
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 {
return &Account{
balances: make(BalanceMap),

View File

@ -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)

View File

@ -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"`
@ -34,20 +39,9 @@ type Position struct {
ExchangeFeeRates map[ExchangeName]ExchangeFee `json:"exchangeFeeRates"`
// 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"`
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"`
Isolated bool `json:"isolated"`
UpdateTime int64 `json:"updateTime"`
PositionRisk *PositionRisk
sync.Mutex
}