Skip to content

Commit 1dc9fe5

Browse files
authored
Merge pull request VictorFrWu#76 from VictorFrWu/LwBbt
add crypto loan endpoints
2 parents 71ec12a + d99586c commit 1dc9fe5

17 files changed

+991
-0
lines changed
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package com.bybit.api.client.domain.loan;
2+
3+
import lombok.Getter;
4+
5+
@Getter
6+
public enum Direction {
7+
ADD("0"),
8+
REDUCE("1");
9+
10+
private final String directionValue;
11+
12+
Direction(String directionValue) {
13+
this.directionValue = directionValue;
14+
}
15+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package com.bybit.api.client.domain.loan;
2+
3+
import lombok.Getter;
4+
5+
@Getter
6+
public enum LoanTerm {
7+
FLEXIBLE(""),
8+
FIXED_7D("7"),
9+
FIXED_14D("14"),
10+
FIXED_30D("30"),
11+
FIXED_90D("90"),
12+
FIXED_180D("180");
13+
14+
private final String term;
15+
16+
LoanTerm(String term) {
17+
this.term = term;
18+
}
19+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package com.bybit.api.client.domain.loan;
2+
3+
import lombok.Getter;
4+
5+
@Getter
6+
public enum LoanTermType {
7+
FLEXIBLE("2"),
8+
FIXED("1");
9+
10+
private final String termType;
11+
12+
LoanTermType(String termType) {
13+
this.termType = termType;
14+
}
15+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package com.bybit.api.client.domain.loan;
2+
3+
import lombok.Getter;
4+
5+
@Getter
6+
public enum VipLevel {
7+
VIP_0("VIP0"),
8+
VIP_1("VIP1"),
9+
VIP_2("VIP2"),
10+
VIP_3("VIP3"),
11+
VIP_4("VIP4"),
12+
VIP_5("VIP5"),
13+
VIP_SUPREME("VIP99"),
14+
PRO_1("PRO1"),
15+
PRO_2("PRO2"),
16+
PRO_3("PRO3"),
17+
PRO_4("PRO4"),
18+
PRO_5("PRO5"),
19+
PRO_6("PRO6");
20+
21+
private final String level;
22+
23+
VipLevel(String level) {
24+
this.level = level;
25+
}
26+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package com.bybit.api.client.domain.loan.request;
2+
3+
import com.bybit.api.client.domain.loan.Direction;
4+
import com.fasterxml.jackson.annotation.JsonInclude;
5+
import lombok.Builder;
6+
import lombok.Getter;
7+
import lombok.Setter;
8+
import lombok.ToString;
9+
10+
@Getter
11+
@Setter
12+
@ToString
13+
@Builder
14+
@JsonInclude(JsonInclude.Include.NON_NULL)
15+
public class CryptoLoanAdjustLtvRequest {
16+
private String orderId; // mandatory
17+
private String amount; // mandatory
18+
private String direction; // mandatory; ADD: "0", REDUCE: "1"
19+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package com.bybit.api.client.domain.loan.request;
2+
3+
import com.fasterxml.jackson.annotation.JsonInclude;
4+
import lombok.Builder;
5+
import lombok.Getter;
6+
import lombok.Setter;
7+
import lombok.ToString;
8+
9+
@Getter
10+
@Setter
11+
@ToString
12+
@Builder
13+
@JsonInclude(JsonInclude.Include.NON_NULL)
14+
public class CryptoLoanBorrowRequest {
15+
private String loanCurrency; // mandatory
16+
private String loanAmount;
17+
private String loanTerm;
18+
private String collateralCurrency; // mandatory
19+
private String collateralAmount;
20+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package com.bybit.api.client.domain.loan.request;
2+
3+
import com.bybit.api.client.domain.loan.Direction;
4+
import com.bybit.api.client.domain.loan.LoanTerm;
5+
import com.bybit.api.client.domain.loan.LoanTermType;
6+
import com.bybit.api.client.domain.loan.VipLevel;
7+
import com.fasterxml.jackson.annotation.JsonInclude;
8+
import lombok.Builder;
9+
import lombok.Getter;
10+
import lombok.Setter;
11+
import lombok.ToString;
12+
13+
@Getter
14+
@Setter
15+
@ToString
16+
@Builder
17+
@JsonInclude(JsonInclude.Include.NON_NULL)
18+
public class CryptoLoanDataRequest {
19+
private String currency;
20+
private VipLevel vipLevel;
21+
private String loanCurrency;
22+
private String collateralCurrency;
23+
private String loanAmount;
24+
private String collateralAmount;
25+
private LoanTerm loanTerm;
26+
private String orderId;
27+
private String amount; // repay amount or adjust ltv amount
28+
private LoanTermType loanTermType;
29+
private String repayId;
30+
private String adjustId;
31+
private Direction direction;
32+
private String cursor;
33+
private String limit;
34+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package com.bybit.api.client.domain.loan.request;
2+
3+
import com.fasterxml.jackson.annotation.JsonInclude;
4+
import lombok.Builder;
5+
import lombok.Getter;
6+
import lombok.Setter;
7+
import lombok.ToString;
8+
9+
@Getter
10+
@Setter
11+
@ToString
12+
@Builder
13+
@JsonInclude(JsonInclude.Include.NON_NULL)
14+
public class CryptoLoanRepayRequest {
15+
private String orderId; // mandatory
16+
private String amount;// mandatory
17+
}
Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
package com.bybit.api.client.impl;
2+
3+
import com.bybit.api.client.domain.loan.request.CryptoLoanAdjustLtvRequest;
4+
import com.bybit.api.client.domain.loan.request.CryptoLoanBorrowRequest;
5+
import com.bybit.api.client.domain.loan.request.CryptoLoanDataRequest;
6+
import com.bybit.api.client.domain.loan.request.CryptoLoanRepayRequest;
7+
import com.bybit.api.client.restApi.BybitApiAsyncLoanRestClient;
8+
import com.bybit.api.client.restApi.BybitApiCallback;
9+
import com.bybit.api.client.restApi.BybitApiLoanRestClient;
10+
import com.bybit.api.client.restApi.BybitApiService;
11+
import com.bybit.api.client.service.BybitJsonConverter;
12+
13+
import static com.bybit.api.client.service.BybitApiServiceGenerator.createService;
14+
import static com.bybit.api.client.service.BybitApiServiceGenerator.executeSync;
15+
16+
public class BybitApiAsyncLoanRestClientImpl implements BybitApiAsyncLoanRestClient {
17+
private final BybitApiService bybitApiService;
18+
private final BybitJsonConverter converter = new BybitJsonConverter();
19+
20+
public BybitApiAsyncLoanRestClientImpl(String apiKey, String secret, String baseUrl, boolean debugMode, long recvWindow, String logOption) {
21+
bybitApiService = createService(BybitApiService.class, apiKey, secret, baseUrl, debugMode, recvWindow, logOption, "");
22+
}
23+
24+
@Override
25+
public void getCollateralCoins(CryptoLoanDataRequest request, BybitApiCallback<Object> callback) {
26+
bybitApiService.getCollateralCoins(
27+
request.getVipLevel() == null ? null : request.getVipLevel().getLevel(),
28+
request.getCurrency()
29+
).enqueue(new BybitApiCallbackAdapter<>(callback));
30+
}
31+
32+
@Override
33+
public void getBorrowableCoins(CryptoLoanDataRequest request, BybitApiCallback<Object> callback) {
34+
bybitApiService.getBorrowableCoins(
35+
request.getVipLevel() == null ? null : request.getVipLevel().getLevel(),
36+
request.getCurrency()
37+
).enqueue(new BybitApiCallbackAdapter<>(callback));
38+
}
39+
40+
@Override
41+
public void getAcctMortgageLoanLimit(CryptoLoanDataRequest request, BybitApiCallback<Object> callback) {
42+
bybitApiService.getAcctMortgageLoanLimit(
43+
request.getLoanCurrency(),
44+
request.getCollateralCurrency()
45+
).enqueue(new BybitApiCallbackAdapter<>(callback));
46+
}
47+
48+
@Override
49+
public void borrow(CryptoLoanBorrowRequest borrowRequest, BybitApiCallback<Object> callback) {
50+
var request = converter.mapToCryptoLoanBorrowRequest(borrowRequest);
51+
bybitApiService.borrow(request).enqueue(new BybitApiCallbackAdapter<>(callback));
52+
}
53+
54+
@Override
55+
public void repay(CryptoLoanRepayRequest repayRequest, BybitApiCallback<Object> callback) {
56+
var request = converter.mapToCryptoLoanRepayRequest(repayRequest);
57+
bybitApiService.repay(request).enqueue(new BybitApiCallbackAdapter<>(callback));
58+
}
59+
60+
@Override
61+
public void adjustCollateralAmount(CryptoLoanAdjustLtvRequest adjustLtvRequest, BybitApiCallback<Object> callback) {
62+
var request = converter.mapToCryptoLoanAdjustLtvRequest(adjustLtvRequest);
63+
bybitApiService.adjustCollateralAmount(request).enqueue(new BybitApiCallbackAdapter<>(callback));
64+
}
65+
66+
@Override
67+
public void getUnpaidOrders(CryptoLoanDataRequest request, BybitApiCallback<Object> callback) {
68+
bybitApiService.getUnpaidOrders(
69+
request.getOrderId(),
70+
request.getCollateralCurrency(),
71+
request.getLoanCurrency(),
72+
request.getLoanTermType() == null ? null : request.getLoanTermType().getTermType(),
73+
request.getLoanTerm() == null ? null : request.getLoanTerm().getTerm(),
74+
request.getLimit(),
75+
request.getCursor()
76+
).enqueue(new BybitApiCallbackAdapter<>(callback));
77+
}
78+
79+
@Override
80+
public void getCompletedOrders(CryptoLoanDataRequest request, BybitApiCallback<Object> callback) {
81+
bybitApiService.getCompletedOrders(
82+
request.getOrderId(),
83+
request.getCollateralCurrency(),
84+
request.getLoanCurrency(),
85+
request.getLimit(),
86+
request.getCursor()
87+
).enqueue(new BybitApiCallbackAdapter<>(callback));
88+
}
89+
90+
@Override
91+
public void getRepayTransactions(CryptoLoanDataRequest request, BybitApiCallback<Object> callback) {
92+
bybitApiService.getRepayTransactions(
93+
request.getOrderId(),
94+
request.getRepayId(),
95+
request.getLoanCurrency(),
96+
request.getLimit(),
97+
request.getCursor()
98+
).enqueue(new BybitApiCallbackAdapter<>(callback));
99+
}
100+
101+
@Override
102+
public void getLtvAdjustmentHistory(CryptoLoanDataRequest request, BybitApiCallback<Object> callback) {
103+
bybitApiService.getLtvAdjustmentHistory(
104+
request.getOrderId(),
105+
request.getAdjustId(),
106+
request.getCollateralCurrency(),
107+
request.getLimit(),
108+
request.getCursor()
109+
).enqueue(new BybitApiCallbackAdapter<>(callback));
110+
}
111+
112+
@Override
113+
public void getMaxReduceAmount(CryptoLoanDataRequest request, BybitApiCallback<Object> callback) {
114+
bybitApiService.getMaxReduceAmount(
115+
request.getOrderId()
116+
).enqueue(new BybitApiCallbackAdapter<>(callback));
117+
}
118+
}

0 commit comments

Comments
 (0)