Skip to content

Commit

Permalink
exchanges/binance/coin: FuturesAccountInformation now has all positio…
Browse files Browse the repository at this point in the history
…n fields (thrasher-corp#835)

Co-authored-by: Yordan Miladinov <[email protected]>
  • Loading branch information
ydm and Yordan Miladinov authored Nov 23, 2021
1 parent 42b292a commit 6f72838
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 23 deletions.
52 changes: 29 additions & 23 deletions exchanges/binance/cfutures_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,25 @@ type FuturesAccountBalanceData struct {
UpdateTime int64 `json:"updateTime"`
}

// FuturesAccountInformationPositions holds account position data
type FuturesAccountInformationPositions struct {
Symbol string `json:"symbol"`
Amount float64 `json:"positionAmt,string"`
InitialMargin float64 `json:"initialMargin,string"`
MaintMargin float64 `json:"maintMargin,string"`
UnrealizedProfit float64 `json:"unrealizedProfit,string"`
PositionInitialMargin float64 `json:"positionInitialMargin,string"`
OpenOrderInitialMargin float64 `json:"openOrderInitialMargin,string"`
Leverage float64 `json:"leverage,string"`
Isolated bool `json:"isolated"`
PositionSide string `json:"positionSide"`
EntryPrice float64 `json:"entryPrice,string"`
MaxQty float64 `json:"maxQty,string"`
UpdateTime time.Time `json:"updateTime"`
NotionalValue float64 `json:"notionalValue,string"`
IsolatedWallet float64 `json:"isolatedWallet,string"`
}

// FuturesAccountInformation stores account information for futures account
type FuturesAccountInformation struct {
Assets []struct {
Expand All @@ -370,30 +389,17 @@ type FuturesAccountInformation struct {
InitialMargin float64 `json:"initialMargin,string"`
PositionInitialMargin float64 `json:"positionInitialMargin,string"`
OpenOrderInitialMargin float64 `json:"openOrderInitialMargin,string"`
Leverage float64 `json:"leverage,string"`
Isolated bool `json:"isolated"`
PositionSide string `json:"positionSide"`
EntryPrice float64 `json:"entryPrice,string"`
MaxQty float64 `json:"maxQty,string"`
MaxWithdrawAmount float64 `json:"maxWithdrawAmount,string"`
CrossWalletBalance float64 `json:"crossWalletBalance,string"`
CrossUnPNL float64 `json:"crossUnPnl,string"`
AvailableBalance float64 `json:"availableBalance,string"`
} `json:"assets"`
Positions []struct {
Symbol string `json:"symbol"`
InitialMargin float64 `json:"initialMargin,string"`
MaintMargin float64 `json:"maintMargin,string"`
UnrealizedProfit float64 `json:"unrealizedProfit,string"`
PositionInitialMargin float64 `json:"positionInitialMargin,string"`
OpenOrderInitialMargin float64 `json:"openOrderInitialMargin,string"`
Leverage float64 `json:"leverage,string"`
Isolated bool `json:"isolated"`
PositionSide string `json:"positionSide"`
EntryPrice float64 `json:"entryPrice,string"`
MaxQty float64 `json:"maxQty,string"`
} `json:"positions"`
CanDeposit bool `json:"canDeposit"`
CanTrade bool `json:"canTrade"`
CanWithdraw bool `json:"canWithdraw"`
FeeTier int64 `json:"feeTier"`
UpdateTime int64 `json:"updateTime"`
Positions []FuturesAccountInformationPositions `json:"positions"`
CanDeposit bool `json:"canDeposit"`
CanTrade bool `json:"canTrade"`
CanWithdraw bool `json:"canWithdraw"`
FeeTier int64 `json:"feeTier"`
UpdateTime time.Time `json:"updateTime"`
}

// GenericAuthResponse is a general data response for a post auth request
Expand Down
40 changes: 40 additions & 0 deletions exchanges/binance/type_convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -441,3 +441,43 @@ func (u *UFuturesSymbolInfo) UnmarshalJSON(data []byte) error {
u.OnboardDate = aux.OnboardDate.Time()
return nil
}

// UnmarshalJSON deserialises the JSON info, including the timestamp
func (a *FuturesAccountInformationPositions) UnmarshalJSON(data []byte) error {
type Alias FuturesAccountInformationPositions

aux := &struct {
UpdateTime binanceTime `json:"updateTime"`
*Alias
}{
Alias: (*Alias)(a),
}

if err := json.Unmarshal(data, &aux); err != nil {
return err
}

a.UpdateTime = aux.UpdateTime.Time()

return nil
}

// UnmarshalJSON deserialises the JSON info, including the timestamp
func (a *FuturesAccountInformation) UnmarshalJSON(data []byte) error {
type Alias FuturesAccountInformation

aux := &struct {
UpdateTime binanceTime `json:"updateTime"`
*Alias
}{
Alias: (*Alias)(a),
}

if err := json.Unmarshal(data, &aux); err != nil {
return err
}

a.UpdateTime = aux.UpdateTime.Time()

return nil
}

0 comments on commit 6f72838

Please sign in to comment.