all: extend balance field for margin

This commit is contained in:
c9s 2022-04-21 16:23:06 +08:00
parent fbe1906e70
commit cf2e8c9f0a
2 changed files with 11 additions and 8 deletions

View File

@ -234,9 +234,10 @@ func (e *Exchange) queryCrossMarginAccount(ctx context.Context) (*types.Account,
}
a := &types.Account{
AccountType: types.AccountTypeMargin,
MarginInfo: toGlobalMarginAccountInfo(marginAccount), // In binance GO api, Account define marginAccount info which mantain []*AccountAsset and []*AccountPosition.
MarginLevel: fixedpoint.MustNewFromString(marginAccount.MarginLevel),
AccountType: types.AccountTypeMargin,
MarginInfo: toGlobalMarginAccountInfo(marginAccount), // In binance GO api, Account define marginAccount info which mantain []*AccountAsset and []*AccountPosition.
MarginLevel: fixedpoint.MustNewFromString(marginAccount.MarginLevel),
BorrowEnabled: marginAccount.BorrowEnabled,
}
// convert cross margin user assets into balances
@ -276,6 +277,8 @@ func (e *Exchange) queryIsolatedMarginAccount(ctx context.Context) (*types.Accou
userAsset := marginAccount.Assets[0]
a.MarginLevel = fixedpoint.MustNewFromString(userAsset.MarginLevel)
a.BorrowEnabled = userAsset.BaseAsset.BorrowEnabled || userAsset.QuoteAsset.BorrowEnabled
// userAsset.LiquidatePrice
// Convert user assets into balances
balances := types.BalanceMap{}

View File

@ -27,12 +27,11 @@ type Balance struct {
Locked fixedpoint.Value `json:"locked,omitempty"`
// margin related fields
Borrowed fixedpoint.Value `json:"borrowed,omitempty"`
Interest fixedpoint.Value `json:"interest,omitempty"`
Borrowed fixedpoint.Value `json:"borrowed,omitempty"`
Interest fixedpoint.Value `json:"interest,omitempty"`
// NetAsset = (Available + Locked) - Borrowed - Interest
NetAsset fixedpoint.Value `json:"net,omitempty"`
NetAsset fixedpoint.Value `json:"net,omitempty"`
}
func (b Balance) Total() fixedpoint.Value {
@ -245,7 +244,8 @@ type Account struct {
IsolatedMarginInfo *IsolatedMarginAccountInfo
// margin related common field
MarginLevel fixedpoint.Value `json:"marginLevel"`
MarginLevel fixedpoint.Value `json:"marginLevel"`
BorrowEnabled bool `json:"borrowEnabled"`
MakerFeeRate fixedpoint.Value `json:"makerFeeRate,omitempty"`
TakerFeeRate fixedpoint.Value `json:"takerFeeRate,omitempty"`