Skip to content

Commit

Permalink
okexapi: add /api/v5/account/account-position-risk api
Browse files Browse the repository at this point in the history
  • Loading branch information
c9s committed Jan 23, 2025
1 parent f792761 commit 13c2f85
Show file tree
Hide file tree
Showing 5 changed files with 317 additions and 2 deletions.
10 changes: 10 additions & 0 deletions pkg/exchange/okex/okexapi/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -440,4 +440,14 @@ func TestClient_Margin(t *testing.T) {
}
}
})

t.Run("get history for manual borrow", func(t *testing.T) {
req := client.NewGetAccountSpotBorrowRepayHistoryRequest()
req.Currency("BTC")
req.EventType(MarginEventTypeManualBorrow)
historyResp, err2 := req.Do(ctx)
if assert.NoError(t, err2) {
t.Logf("history response: %+v", historyResp)
}
})
}
43 changes: 43 additions & 0 deletions pkg/exchange/okex/okexapi/get_account_position_risk_request.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package okexapi

import (
"github.com/c9s/requestgen"
)

//go:generate -command GetRequest requestgen -method GET -responseType .APIResponse -responseDataField Data
//go:generate -command PostRequest requestgen -method POST -responseType .APIResponse -responseDataField Data

type PositionRiskResponse struct {
AdjEq string `json:"adjEq"`
BalData []struct {
Ccy string `json:"ccy"`
DisEq string `json:"disEq"`
Eq string `json:"eq"`
} `json:"balData"`
PosData []struct {
BaseBal string `json:"baseBal"`
Ccy string `json:"ccy"`
InstId string `json:"instId"`
InstType string `json:"instType"`
MgnMode string `json:"mgnMode"`
NotionalCcy string `json:"notionalCcy"`
NotionalUsd string `json:"notionalUsd"`
Pos string `json:"pos"`
PosCcy string `json:"posCcy"`
PosId string `json:"posId"`
PosSide string `json:"posSide"`
QuoteBal string `json:"quoteBal"`
} `json:"posData"`
Ts string `json:"ts"`
}

//go:generate GetRequest -url "/api/v5/account/account-position-risk" -type GetAccountPositionRiskRequest -responseDataType []PositionRiskResponse
type GetAccountPositionRiskRequest struct {
client requestgen.AuthenticatedAPIClient
}

func (c *RestClient) NewGetAccountPositionRiskRequest() *GetAccountPositionRiskRequest {
return &GetAccountPositionRiskRequest{
client: c,
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package okexapi

import (
"time"

"github.com/c9s/requestgen"

"github.com/c9s/bbgo/pkg/fixedpoint"
Expand Down Expand Up @@ -32,6 +34,12 @@ type MarginHistoryEntry struct {
//go:generate GetRequest -url "/api/v5/account/spot-borrow-repay-history" -type GetAccountSpotBorrowRepayHistoryRequest -responseDataType []MarginHistoryEntry
type GetAccountSpotBorrowRepayHistoryRequest struct {
client requestgen.AuthenticatedAPIClient

eventType *MarginEventType `param:"type"`
currency *string `param:"ccy"`
after *time.Time `param:"after,milliseconds"`
before *time.Time `param:"before,milliseconds"`
limit *uint64 `param:"limit" defaultValue:"100"`
}

func (c *RestClient) NewGetAccountSpotBorrowRepayHistoryRequest() *GetAccountSpotBorrowRepayHistoryRequest {
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 13c2f85

Please sign in to comment.