diff --git a/v2/margin_service.go b/v2/margin_service.go index 4c67e3e7..09ef9516 100644 --- a/v2/margin_service.go +++ b/v2/margin_service.go @@ -3,6 +3,7 @@ package binance import ( "context" "encoding/json" + "fmt" "net/http" "strings" ) @@ -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 + } r.setFormParams(m) res = new(TransactionResponse) data, err := s.c.callAPI(ctx, r, opts...) @@ -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) diff --git a/v2/margin_service_test.go b/v2/margin_service_test.go index c1de34ab..db133e0e 100644 --- a/v2/margin_service_test.go +++ b/v2/margin_service_test.go @@ -106,7 +106,6 @@ func (s *marginTestSuite) TestBorrowRepayBorrow() { "asset": asset, "amount": amount, "isIsolated": false, - "symbol": "", "type": string(_type), }) s.assertRequestEqual(e, r) @@ -137,7 +136,6 @@ func (s *marginTestSuite) TestBorrowRepayRepay() { "asset": asset, "amount": amount, "isIsolated": false, - "symbol": "", "type": string(_type), }) s.assertRequestEqual(e, r) @@ -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": [