Skip to content

Commit

Permalink
Merge pull request #1524 from c9s/edwin/binance-update-api-changes-2
Browse files Browse the repository at this point in the history
MINOR: [binance] update borrow/repay api changes
  • Loading branch information
c9s authored Feb 5, 2024
2 parents aad3f89 + f77d03d commit 565cdef
Show file tree
Hide file tree
Showing 10 changed files with 177 additions and 449 deletions.
21 changes: 21 additions & 0 deletions pkg/exchange/binance/binanceapi/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,3 +176,24 @@ func TestClient_NewTransferAssetRequest(t *testing.T) {
assert.NotEmpty(t, res)
t.Logf("result: %+v", res)
}

func TestClient_GetMarginBorrowRepayHistoryRequest(t *testing.T) {
client := getTestClientOrSkip(t)
ctx := context.Background()

err := client.SetTimeOffsetFromServer(ctx)
assert.NoError(t, err)

req := client.NewGetMarginBorrowRepayHistoryRequest()
end := time.Now()
start := end.Add(-24 * time.Hour * 30)
req.StartTime(start)
req.EndTime(end)
req.Asset("BTC")
req.SetBorrowRepayType(BorrowRepayTypeBorrow)
res, err := req.Do(ctx)
assert.NoError(t, err)
assert.NotNil(t, res)
assert.NotEmpty(t, res)
t.Logf("result: %+v", res)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
package binanceapi

import (
"time"

"github.com/c9s/requestgen"

"github.com/c9s/bbgo/pkg/fixedpoint"
"github.com/c9s/bbgo/pkg/types"
)

// one of PENDING (pending execution), CONFIRMED (successfully loaned), FAILED (execution failed, nothing happened to your account);
type MarginBorrowStatus string

const (
BorrowRepayStatusPending MarginBorrowStatus = "PENDING"
BorrowRepayStatusConfirmed MarginBorrowStatus = "CONFIRMED"
BorrowRepayStatusFailed MarginBorrowStatus = "FAILED"
)

type BorrowRepayType string

const (
BorrowRepayTypeBorrow BorrowRepayType = "BORROW"
BorrowRepayTypeRepay BorrowRepayType = "REPAY"
)

type MarginBorrowRepayRecord struct {
IsolatedSymbol string `json:"isolatedSymbol"`
Amount fixedpoint.Value `json:"amount"`
Asset string `json:"asset"`
Interest fixedpoint.Value `json:"interest"`
Principal fixedpoint.Value `json:"principal"`
Status MarginBorrowStatus `json:"status"`
Timestamp types.MillisecondTimestamp `json:"timestamp"`
TxId uint64 `json:"txId"`
}

// GetMarginBorrowRepayHistoryRequest
//
// txId or startTime must be sent. txId takes precedence.
// Response in descending order
// If isolatedSymbol is not sent, crossed margin data will be returned
// The max interval between startTime and endTime is 30 days.
// If startTime and endTime not sent, return records of the last 7 days by default
// Set archived to true to query data from 6 months ago
//
//go:generate requestgen -method GET -url "/sapi/v1/margin/borrow-repay" -type GetMarginBorrowRepayHistoryRequest -responseType .RowsResponse -responseDataField Rows -responseDataType []MarginBorrowRepayRecord
type GetMarginBorrowRepayHistoryRequest struct {
client requestgen.AuthenticatedAPIClient

asset string `param:"asset"`
startTime *time.Time `param:"startTime,milliseconds"`
endTime *time.Time `param:"endTime,milliseconds"`
isolatedSymbol *string `param:"isolatedSymbol"`
archived *bool `param:"archived"`
size *int `param:"size"`
current *int `param:"current"`
BorrowRepayType BorrowRepayType `param:"type"`
}

func (c *RestClient) NewGetMarginBorrowRepayHistoryRequest() *GetMarginBorrowRepayHistoryRequest {
return &GetMarginBorrowRepayHistoryRequest{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
Expand Up @@ -15,7 +15,7 @@ func Test_GetMarginLoanHistoryRequest(t *testing.T) {
err := client.SetTimeOffsetFromServer(ctx)
assert.NoError(t, err)

req := client.NewGetMarginLoanHistoryRequest()
req := client.NewGetMarginBorrowRepayHistoryRequest()
req.Asset("USDT")
req.IsolatedSymbol("DOTUSDT")
req.StartTime(time.Date(2022, time.February, 1, 0, 0, 0, 0, time.UTC))
Expand Down
54 changes: 0 additions & 54 deletions pkg/exchange/binance/binanceapi/get_margin_loan_history_request.go

This file was deleted.

Loading

0 comments on commit 565cdef

Please sign in to comment.