fix: set symbol param only when isIsolated is true#813
Open
taobig wants to merge 2 commits into
Open
Conversation
Collaborator
|
@taobig thanks for your fix we will merge it soon |
Contributor
There was a problem hiding this comment.
Pull request overview
This PR updates the v2 margin borrow/repay request builder to stop sending symbol= when isIsolated=false, addressing a backend change that now rejects requests when an empty symbol parameter is present (causing -1022 signature errors).
Changes:
- Make
symbolconditional onisIsolatedfor/sapi/v1/margin/borrow-repay. - Update unit tests to reflect the absence of
symbolfor cross margin requests.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
v2/margin_service.go |
Stops including symbol in form params for cross margin borrow/repay requests. |
v2/margin_service_test.go |
Adjusts expected form params for borrow/repay tests to no longer include symbol when cross margin. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
242
to
251
| m := params{ | ||
| "asset": s.asset, | ||
| "isIsolated": s.isIsolated, | ||
| "symbol": s.symbol, | ||
| "amount": s.amount, | ||
| "type": string(s._type), | ||
| //"symbol": s.symbol, | ||
| "amount": s.amount, | ||
| "type": string(s._type), | ||
| } | ||
| if s.isIsolated { | ||
| m["symbol"] = s.symbol // set symbol param only when isIsolated is true | ||
| } |
Comment on lines
105
to
111
| e := newSignedRequest().setFormParams(params{ | ||
| "asset": asset, | ||
| "amount": amount, | ||
| "isIsolated": false, | ||
| "symbol": "", | ||
| "type": string(_type), | ||
| //"symbol": "", | ||
| "type": string(_type), | ||
| }) |
Comment on lines
135
to
142
| s.assertReq(func(r *request) { | ||
| e := newSignedRequest().setFormParams(params{ | ||
| "asset": asset, | ||
| "amount": amount, | ||
| "isIsolated": false, | ||
| "symbol": "", | ||
| "type": string(_type), | ||
| //"symbol": "", | ||
| "type": string(_type), | ||
| }) |
Comment on lines
95
to
113
| func (s *marginTestSuite) TestBorrowRepayBorrow() { | ||
| data := []byte(`{ | ||
| "tranId": 100000001 | ||
| }`) | ||
| s.mockDo(data, nil) | ||
| defer s.assertDo() | ||
| asset := "BTC" | ||
| amount := "1.000" | ||
| _type := MarginAccountBorrow | ||
| s.assertReq(func(r *request) { | ||
| e := newSignedRequest().setFormParams(params{ | ||
| "asset": asset, | ||
| "amount": amount, | ||
| "isIsolated": false, | ||
| "symbol": "", | ||
| "type": string(_type), | ||
| //"symbol": "", | ||
| "type": string(_type), | ||
| }) | ||
| s.assertRequestEqual(e, r) | ||
| }) |
Comment on lines
+248
to
+250
| if s.isIsolated { | ||
| m["symbol"] = s.symbol // set symbol param only when isIsolated is true | ||
| } |
Comment on lines
106
to
110
| "asset": asset, | ||
| "amount": amount, | ||
| "isIsolated": false, | ||
| "symbol": "", | ||
| "type": string(_type), | ||
| }) |
cb72bd0 to
792c694
Compare
Comment on lines
242
to
+250
| m := params{ | ||
| "asset": s.asset, | ||
| "isIsolated": s.isIsolated, | ||
| "symbol": s.symbol, | ||
| "amount": s.amount, | ||
| "type": string(s._type), | ||
| } | ||
| if s.isIsolated && s.symbol != "" { | ||
| m["symbol"] = s.symbol // Only set symbol param when isIsolated is true | ||
| } |
Comment on lines
+189
to
+213
| func (s *marginTestSuite) TestBorrowRepayBorrowIsolatedWithoutSymbol() { | ||
| data := []byte(`{ | ||
| "tranId": 100000001 | ||
| }`) | ||
| s.mockDo(data, nil) | ||
| defer s.assertDo() | ||
| asset := "BTC" | ||
| amount := "1.000" | ||
| _type := MarginAccountBorrow | ||
| s.assertReq(func(r *request) { | ||
| e := newSignedRequest().setFormParams(params{ | ||
| "asset": asset, | ||
| "amount": amount, | ||
| "isIsolated": true, | ||
| "type": string(_type), | ||
| }) | ||
| s.assertRequestEqual(e, r) | ||
| }) | ||
| res, err := s.client.NewMarginBorrowRepayService(). | ||
| Asset(asset). | ||
| Amount(amount). | ||
| IsIsolated(true). | ||
| Type(_type). | ||
| Do(newContext()) | ||
| s.r().NoError(err) |
Comment on lines
+248
to
+250
| if s.isIsolated && s.symbol != "" { | ||
| m["symbol"] = s.symbol // Only set symbol param when isIsolated is true | ||
| } |
Comment on lines
243
to
+254
| 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 | ||
| } |
| import ( | ||
| "context" | ||
| "encoding/json" | ||
| "fmt" |
| } | ||
| if s.isIsolated { | ||
| if s.symbol == "" { | ||
| return nil, fmt.Errorf("symbol is required for isolated margin borrow/repay") |
| Type(_type). | ||
| Do(newContext()) | ||
| s.r().Error(err) | ||
| s.r().EqualError(err, "symbol is required for isolated margin borrow/repay") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
fix: stop sending symbol="" when isIsolated=false as backend upgrade now rejects it
<APIError> code=-1022, msg=Signature for this request is not valid.