Skip to content
Open
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
15 changes: 7 additions & 8 deletions v2/margin_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package binance
import (
"context"
"encoding/json"
"fmt"
"net/http"
"strings"
)
Expand Down Expand Up @@ -242,10 +243,15 @@ func (s *MarginBorrowRepayService) Do(ctx context.Context, opts ...RequestOption
m := params{
"asset": s.asset,
"isIsolated": s.isIsolated,
"symbol": s.symbol,
"amount": s.amount,
"type": string(s._type),
}
if s.isIsolated {
if s.symbol == "" {
return nil, fmt.Errorf("symbol is required for isolated margin borrow/repay")
}
m["symbol"] = s.symbol // Only set symbol param when isIsolated is true
}
Comment on lines 243 to 254
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@taobig can you check this comment plz?

Comment on lines 243 to +254
Comment on lines 243 to +254
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pass

r.setFormParams(m)
res = new(TransactionResponse)
data, err := s.c.callAPI(ctx, r, opts...)
Expand Down Expand Up @@ -327,13 +333,6 @@ func (s *ListMarginBorrowRepayService) Do(ctx context.Context, opts ...RequestOp
secType: secTypeSigned,
}
m := params{
//"asset": s.asset,
//"isolatedSymbol": s.isolatedSymbol,
//"txId": s.txId,
//"startTime": s.startTime,
//"endTime": s.endTime,
//"current": s.current,
//"size": s.size,
"type": string(s._type),
}
r.setParams(m)
Expand Down
52 changes: 50 additions & 2 deletions v2/margin_service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,6 @@ func (s *marginTestSuite) TestBorrowRepayBorrow() {
"asset": asset,
"amount": amount,
"isIsolated": false,
"symbol": "",
"type": string(_type),
})
Comment on lines 106 to 110
s.assertRequestEqual(e, r)
Expand Down Expand Up @@ -137,7 +136,6 @@ func (s *marginTestSuite) TestBorrowRepayRepay() {
"asset": asset,
"amount": amount,
"isIsolated": false,
"symbol": "",
"type": string(_type),
})
s.assertRequestEqual(e, r)
Expand All @@ -154,6 +152,56 @@ func (s *marginTestSuite) TestBorrowRepayRepay() {
s.assertTransactionResponseEqual(e, res)
}

func (s *marginTestSuite) TestBorrowRepayBorrowIsolated() {
data := []byte(`{
"tranId": 100000001
}`)
s.mockDo(data, nil)
defer s.assertDo()
asset := "BTC"
amount := "1.000"
symbol := "BTCUSDT"
_type := MarginAccountBorrow
s.assertReq(func(r *request) {
e := newSignedRequest().setFormParams(params{
"asset": asset,
"amount": amount,
"isIsolated": true,
"symbol": symbol,
"type": string(_type),
})
s.assertRequestEqual(e, r)
})
res, err := s.client.NewMarginBorrowRepayService().
Asset(asset).
Amount(amount).
IsIsolated(true).
Symbol(symbol).
Type(_type).
Do(newContext())
s.r().NoError(err)
e := &TransactionResponse{
TranID: 100000001,
}
s.assertTransactionResponseEqual(e, res)
}

func (s *marginTestSuite) TestBorrowRepayBorrowIsolatedWithoutSymbol() {
asset := "BTC"
amount := "1.000"
_type := MarginAccountBorrow
res, err := s.client.NewMarginBorrowRepayService().
Asset(asset).
Amount(amount).
IsIsolated(true).
Type(_type).
Do(newContext())
s.r().Error(err)
s.r().EqualError(err, "symbol is required for isolated margin borrow/repay")
s.r().Nil(res)
s.client.AssertNotCalled(s.T(), "do", anyHTTPRequest())
}

func (s *marginTestSuite) TestListBorrowRepay() {
data := []byte(`{
"rows": [
Expand Down
Loading