Skip to content

Commit 792c694

Browse files
committed
fix: guard against sending empty symbol in isolated margin
1 parent a9f964d commit 792c694

2 files changed

Lines changed: 71 additions & 16 deletions

File tree

v2/margin_service.go

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -242,12 +242,11 @@ func (s *MarginBorrowRepayService) Do(ctx context.Context, opts ...RequestOption
242242
m := params{
243243
"asset": s.asset,
244244
"isIsolated": s.isIsolated,
245-
//"symbol": s.symbol,
246-
"amount": s.amount,
247-
"type": string(s._type),
245+
"amount": s.amount,
246+
"type": string(s._type),
248247
}
249-
if s.isIsolated {
250-
m["symbol"] = s.symbol // set symbol param only when isIsolated is true
248+
if s.isIsolated && s.symbol != "" {
249+
m["symbol"] = s.symbol // Only set symbol param when isIsolated is true
251250
}
252251
r.setFormParams(m)
253252
res = new(TransactionResponse)
@@ -330,13 +329,6 @@ func (s *ListMarginBorrowRepayService) Do(ctx context.Context, opts ...RequestOp
330329
secType: secTypeSigned,
331330
}
332331
m := params{
333-
//"asset": s.asset,
334-
//"isolatedSymbol": s.isolatedSymbol,
335-
//"txId": s.txId,
336-
//"startTime": s.startTime,
337-
//"endTime": s.endTime,
338-
//"current": s.current,
339-
//"size": s.size,
340332
"type": string(s._type),
341333
}
342334
r.setParams(m)

v2/margin_service_test.go

Lines changed: 67 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -106,8 +106,7 @@ func (s *marginTestSuite) TestBorrowRepayBorrow() {
106106
"asset": asset,
107107
"amount": amount,
108108
"isIsolated": false,
109-
//"symbol": "",
110-
"type": string(_type),
109+
"type": string(_type),
111110
})
112111
s.assertRequestEqual(e, r)
113112
})
@@ -137,8 +136,7 @@ func (s *marginTestSuite) TestBorrowRepayRepay() {
137136
"asset": asset,
138137
"amount": amount,
139138
"isIsolated": false,
140-
//"symbol": "",
141-
"type": string(_type),
139+
"type": string(_type),
142140
})
143141
s.assertRequestEqual(e, r)
144142
})
@@ -154,6 +152,71 @@ func (s *marginTestSuite) TestBorrowRepayRepay() {
154152
s.assertTransactionResponseEqual(e, res)
155153
}
156154

155+
func (s *marginTestSuite) TestBorrowRepayBorrowIsolated() {
156+
data := []byte(`{
157+
"tranId": 100000001
158+
}`)
159+
s.mockDo(data, nil)
160+
defer s.assertDo()
161+
asset := "BTC"
162+
amount := "1.000"
163+
symbol := "BTCUSDT"
164+
_type := MarginAccountBorrow
165+
s.assertReq(func(r *request) {
166+
e := newSignedRequest().setFormParams(params{
167+
"asset": asset,
168+
"amount": amount,
169+
"isIsolated": true,
170+
"symbol": symbol,
171+
"type": string(_type),
172+
})
173+
s.assertRequestEqual(e, r)
174+
})
175+
res, err := s.client.NewMarginBorrowRepayService().
176+
Asset(asset).
177+
Amount(amount).
178+
IsIsolated(true).
179+
Symbol(symbol).
180+
Type(_type).
181+
Do(newContext())
182+
s.r().NoError(err)
183+
e := &TransactionResponse{
184+
TranID: 100000001,
185+
}
186+
s.assertTransactionResponseEqual(e, res)
187+
}
188+
189+
func (s *marginTestSuite) TestBorrowRepayBorrowIsolatedWithoutSymbol() {
190+
data := []byte(`{
191+
"tranId": 100000001
192+
}`)
193+
s.mockDo(data, nil)
194+
defer s.assertDo()
195+
asset := "BTC"
196+
amount := "1.000"
197+
_type := MarginAccountBorrow
198+
s.assertReq(func(r *request) {
199+
e := newSignedRequest().setFormParams(params{
200+
"asset": asset,
201+
"amount": amount,
202+
"isIsolated": true,
203+
"type": string(_type),
204+
})
205+
s.assertRequestEqual(e, r)
206+
})
207+
res, err := s.client.NewMarginBorrowRepayService().
208+
Asset(asset).
209+
Amount(amount).
210+
IsIsolated(true).
211+
Type(_type).
212+
Do(newContext())
213+
s.r().NoError(err)
214+
e := &TransactionResponse{
215+
TranID: 100000001,
216+
}
217+
s.assertTransactionResponseEqual(e, res)
218+
}
219+
157220
func (s *marginTestSuite) TestListBorrowRepay() {
158221
data := []byte(`{
159222
"rows": [

0 commit comments

Comments
 (0)