@@ -64,6 +64,7 @@ type TransactionResponse struct {
64
64
}
65
65
66
66
// MarginLoanService apply for a loan
67
+ // Deprecated: use MarginBorrowRepayService instead
67
68
type MarginLoanService struct {
68
69
c * Client
69
70
asset string
@@ -128,6 +129,7 @@ func (s *MarginLoanService) Do(ctx context.Context, opts ...RequestOption) (res
128
129
}
129
130
130
131
// MarginRepayService repay loan for margin account
132
+ // Deprecated: use MarginBorrowRepayService instead
131
133
type MarginRepayService struct {
132
134
c * Client
133
135
asset string
@@ -191,6 +193,77 @@ func (s *MarginRepayService) Do(ctx context.Context, opts ...RequestOption) (res
191
193
return res , nil
192
194
}
193
195
196
+ // MarginBorrowRepayService borrow/repay for margin account
197
+ type MarginBorrowRepayService struct {
198
+ c * Client
199
+ asset string // Mandatory:YES
200
+ amount string // Mandatory:YES
201
+ isIsolated bool // Mandatory:YES, TRUE for Isolated Margin, FALSE for Cross Margin, Default FALSE
202
+ symbol string // Mandatory:YES, Only for Isolated margin
203
+ _type MarginAccountBorrowRepayType // Mandatory:YES, BORROW or REPAY
204
+ }
205
+
206
+ // Asset set asset being transferred, e.g., BTC
207
+ func (s * MarginBorrowRepayService ) Asset (asset string ) * MarginBorrowRepayService {
208
+ s .asset = asset
209
+ return s
210
+ }
211
+
212
+ // Amount the amount to be transferred
213
+ func (s * MarginBorrowRepayService ) Amount (amount string ) * MarginBorrowRepayService {
214
+ s .amount = amount
215
+ return s
216
+ }
217
+
218
+ // IsIsolated is for isolated margin or not, "TRUE", "FALSE",default "FALSE"
219
+ func (s * MarginBorrowRepayService ) IsIsolated (isIsolated bool ) * MarginBorrowRepayService {
220
+ s .isIsolated = isIsolated
221
+ return s
222
+ }
223
+
224
+ // Symbol set isolated symbol
225
+ func (s * MarginBorrowRepayService ) Symbol (symbol string ) * MarginBorrowRepayService {
226
+ s .symbol = symbol
227
+ return s
228
+ }
229
+
230
+ func (s * MarginBorrowRepayService ) Type (marginBorrowRepayType MarginAccountBorrowRepayType ) * MarginBorrowRepayService {
231
+ s ._type = marginBorrowRepayType
232
+ return s
233
+ }
234
+
235
+ // Do send request
236
+ func (s * MarginBorrowRepayService ) Do (ctx context.Context , opts ... RequestOption ) (res * TransactionResponse , err error ) {
237
+ r := & request {
238
+ method : http .MethodPost ,
239
+ endpoint : "/sapi/v1/margin/borrow-repay" ,
240
+ secType : secTypeSigned ,
241
+ }
242
+ m := params {
243
+ "asset" : s .asset ,
244
+ "amount" : s .amount ,
245
+ "type" : string (s ._type ),
246
+ }
247
+ r .setFormParams (m )
248
+ if s .isIsolated {
249
+ r .setParam ("isIsolated" , "TRUE" )
250
+ }
251
+ if s .symbol != "" {
252
+ r .setParam ("symbol" , s .symbol )
253
+ }
254
+
255
+ res = new (TransactionResponse )
256
+ data , err := s .c .callAPI (ctx , r , opts ... )
257
+ if err != nil {
258
+ return nil , err
259
+ }
260
+ err = json .Unmarshal (data , res )
261
+ if err != nil {
262
+ return nil , err
263
+ }
264
+ return res , nil
265
+ }
266
+
194
267
// ListMarginLoansService list loan record
195
268
type ListMarginLoansService struct {
196
269
c * Client
0 commit comments