mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-22 06:53:52 +00:00
Merge pull request #1798 from anywhy/binance_position_risk_api_v3
FEATURE:update binance positionRisk api to v3
This commit is contained in:
commit
a9eb903f01
|
@ -9,13 +9,9 @@ import (
|
|||
|
||||
type FuturesPositionRisk struct {
|
||||
EntryPrice fixedpoint.Value `json:"entryPrice"`
|
||||
MarginType string `json:"marginType"`
|
||||
IsAutoAddMargin string `json:"isAutoAddMargin"`
|
||||
IsolatedMargin string `json:"isolatedMargin"`
|
||||
Leverage fixedpoint.Value `json:"leverage"`
|
||||
LiquidationPrice fixedpoint.Value `json:"liquidationPrice"`
|
||||
MarkPrice fixedpoint.Value `json:"markPrice"`
|
||||
MaxNotionalValue fixedpoint.Value `json:"maxNotionalValue"`
|
||||
PositionAmount fixedpoint.Value `json:"positionAmt"`
|
||||
Notional fixedpoint.Value `json:"notional"`
|
||||
IsolatedWallet string `json:"isolatedWallet"`
|
||||
|
@ -23,9 +19,19 @@ type FuturesPositionRisk struct {
|
|||
UnRealizedProfit fixedpoint.Value `json:"unRealizedProfit"`
|
||||
PositionSide string `json:"positionSide"`
|
||||
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 {
|
||||
client requestgen.AuthenticatedAPIClient
|
||||
|
||||
|
|
|
@ -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
|
||||
|
||||
|
@ -119,6 +119,12 @@ func (f *FuturesGetPositionRisksRequest) GetSlugsMap() (map[string]string, error
|
|||
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) {
|
||||
|
||||
// empty params for GET operation
|
||||
|
@ -128,7 +134,9 @@ func (f *FuturesGetPositionRisksRequest) Do(ctx context.Context) ([]FuturesPosit
|
|||
return nil, err
|
||||
}
|
||||
|
||||
apiURL := "/fapi/v2/positionRisk"
|
||||
var apiURL string
|
||||
|
||||
apiURL = f.GetPath()
|
||||
|
||||
req, err := f.client.NewAuthenticatedRequest(ctx, "GET", apiURL, query, params)
|
||||
if err != nil {
|
||||
|
@ -141,8 +149,32 @@ func (f *FuturesGetPositionRisksRequest) Do(ctx context.Context) ([]FuturesPosit
|
|||
}
|
||||
|
||||
var apiResponse []FuturesPositionRisk
|
||||
if err := response.DecodeJSON(&apiResponse); err != nil {
|
||||
return nil, err
|
||||
|
||||
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 {
|
||||
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
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user