Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MINOR: [binance] update borrow/repay api changes #1524

Merged
merged 1 commit into from
Feb 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading