Merge pull request #1798 from anywhy/binance_position_risk_api_v3

FEATURE:update binance positionRisk api to v3
This commit is contained in:
c9s 2024-10-30 14:00:29 +08:00 committed by GitHub
commit a9eb903f01
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 47 additions and 9 deletions

View File

@ -9,13 +9,9 @@ import (
type FuturesPositionRisk struct { type FuturesPositionRisk struct {
EntryPrice fixedpoint.Value `json:"entryPrice"` EntryPrice fixedpoint.Value `json:"entryPrice"`
MarginType string `json:"marginType"`
IsAutoAddMargin string `json:"isAutoAddMargin"`
IsolatedMargin string `json:"isolatedMargin"` IsolatedMargin string `json:"isolatedMargin"`
Leverage fixedpoint.Value `json:"leverage"`
LiquidationPrice fixedpoint.Value `json:"liquidationPrice"` LiquidationPrice fixedpoint.Value `json:"liquidationPrice"`
MarkPrice fixedpoint.Value `json:"markPrice"` MarkPrice fixedpoint.Value `json:"markPrice"`
MaxNotionalValue fixedpoint.Value `json:"maxNotionalValue"`
PositionAmount fixedpoint.Value `json:"positionAmt"` PositionAmount fixedpoint.Value `json:"positionAmt"`
Notional fixedpoint.Value `json:"notional"` Notional fixedpoint.Value `json:"notional"`
IsolatedWallet string `json:"isolatedWallet"` IsolatedWallet string `json:"isolatedWallet"`
@ -23,9 +19,19 @@ type FuturesPositionRisk struct {
UnRealizedProfit fixedpoint.Value `json:"unRealizedProfit"` UnRealizedProfit fixedpoint.Value `json:"unRealizedProfit"`
PositionSide string `json:"positionSide"` PositionSide string `json:"positionSide"`
UpdateTime types.MillisecondTimestamp `json:"updateTime"` UpdateTime types.MillisecondTimestamp `json:"updateTime"`
BreakEvenPrice fixedpoint.Value `json:"breakEvenPrice"`
MarginAsset fixedpoint.Value `json:"marginAsset"`
InitialMargin fixedpoint.Value `json:"initialMargin"`
MaintMargin fixedpoint.Value `json:"maintMargin"`
PositionInitialMargin fixedpoint.Value `json:"positionInitialMargin"`
OpenOrderInitialMargin fixedpoint.Value `json:"openOrderInitialMargin"`
Adl fixedpoint.Value `json:"adl"`
BidNotional fixedpoint.Value `json:"bidNotional"`
AskNotional fixedpoint.Value `json:"askNotional"`
} }
//go:generate requestgen -method GET -url "/fapi/v2/positionRisk" -type FuturesGetPositionRisksRequest -responseType []FuturesPositionRisk //go:generate requestgen -method GET -url "/fapi/v3/positionRisk" -type FuturesGetPositionRisksRequest -responseType []FuturesPositionRisk
type FuturesGetPositionRisksRequest struct { type FuturesGetPositionRisksRequest struct {
client requestgen.AuthenticatedAPIClient client requestgen.AuthenticatedAPIClient

View File

@ -1,4 +1,4 @@
// Code generated by "requestgen -method GET -url /fapi/v2/positionRisk -type FuturesGetPositionRisksRequest -responseType []FuturesPositionRisk"; DO NOT EDIT. // Code generated by "requestgen -method GET -url /fapi/v3/positionRisk -type FuturesGetPositionRisksRequest -responseType []FuturesPositionRisk"; DO NOT EDIT.
package binanceapi package binanceapi
@ -119,6 +119,12 @@ func (f *FuturesGetPositionRisksRequest) GetSlugsMap() (map[string]string, error
return slugs, nil return slugs, nil
} }
// GetPath returns the request path of the API
func (f *FuturesGetPositionRisksRequest) GetPath() string {
return "/fapi/v3/positionRisk"
}
// Do generates the request object and send the request object to the API endpoint
func (f *FuturesGetPositionRisksRequest) Do(ctx context.Context) ([]FuturesPositionRisk, error) { func (f *FuturesGetPositionRisksRequest) Do(ctx context.Context) ([]FuturesPositionRisk, error) {
// empty params for GET operation // empty params for GET operation
@ -128,7 +134,9 @@ func (f *FuturesGetPositionRisksRequest) Do(ctx context.Context) ([]FuturesPosit
return nil, err return nil, err
} }
apiURL := "/fapi/v2/positionRisk" var apiURL string
apiURL = f.GetPath()
req, err := f.client.NewAuthenticatedRequest(ctx, "GET", apiURL, query, params) req, err := f.client.NewAuthenticatedRequest(ctx, "GET", apiURL, query, params)
if err != nil { if err != nil {
@ -141,8 +149,32 @@ func (f *FuturesGetPositionRisksRequest) Do(ctx context.Context) ([]FuturesPosit
} }
var apiResponse []FuturesPositionRisk var apiResponse []FuturesPositionRisk
type responseUnmarshaler interface {
Unmarshal(data []byte) error
}
if unmarshaler, ok := interface{}(&apiResponse).(responseUnmarshaler); ok {
if err := unmarshaler.Unmarshal(response.Body); err != nil {
return nil, err
}
} else {
// The line below checks the content type, however, some API server might not send the correct content type header,
// Hence, this is commented for backward compatibility
// response.IsJSON()
if err := response.DecodeJSON(&apiResponse); err != nil { if err := response.DecodeJSON(&apiResponse); err != nil {
return nil, err return nil, err
} }
}
type responseValidator interface {
Validate() error
}
if validator, ok := interface{}(&apiResponse).(responseValidator); ok {
if err := validator.Validate(); err != nil {
return nil, err
}
}
return apiResponse, nil return apiResponse, nil
} }