Skip to content
This repository was archived by the owner on Oct 30, 2023. It is now read-only.

Commit a7189e2

Browse files
authored
Binance Liquid Swap endpoints
1 parent 8dea186 commit a7189e2

15 files changed

Lines changed: 960 additions & 177 deletions

src/main/java/com/binance/api/client/BinanceApiClientFactory.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,4 +85,11 @@ public BinanceApiMarginRestClient newMarginRestClient() {
8585
public BinanceApiWebSocketClient newWebSocketClient() {
8686
return new BinanceApiWebSocketClientImpl(getSharedClient());
8787
}
88+
89+
/**
90+
* Creates a new synchronous/blocking Swap REST client.
91+
*/
92+
public BinanceApiSwapRestClient newSwapRestClient() {
93+
return new BinanceApiSwapRestClientImpl(apiKey, secret);
94+
}
8895
}
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
package com.binance.api.client;
2+
3+
import com.binance.api.client.domain.SwapRemoveType;
4+
import com.binance.api.client.domain.account.*;
5+
import retrofit2.Call;
6+
import retrofit2.http.Query;
7+
8+
import java.util.List;
9+
10+
public interface BinanceApiSwapRestClient {
11+
12+
/**
13+
* Get metadata about all swap pools.
14+
*
15+
* @return
16+
*/
17+
List<Pool> listAllSwapPools();
18+
19+
/**
20+
* Get liquidity information and user share of a pool.
21+
*
22+
* @param poolId
23+
* @return
24+
*/
25+
Liquidity getPoolLiquidityInfo(String poolId);
26+
27+
/**
28+
* Add liquidity to a pool.
29+
*
30+
* @param poolId
31+
* @param asset
32+
* @param quantity
33+
* @return
34+
*/
35+
LiquidityOperationRecord addLiquidity(String poolId,
36+
String asset,
37+
String quantity);
38+
39+
/**
40+
* Remove liquidity from a pool, type include SINGLE and COMBINATION, asset is mandatory for single asset removal
41+
*
42+
* @param poolId
43+
* @param type
44+
* @param asset
45+
* @param shareAmount
46+
* @return
47+
*/
48+
LiquidityOperationRecord removeLiquidity(String poolId, SwapRemoveType type, List<String> asset, String shareAmount);
49+
50+
/**
51+
* Get liquidity operation (add/remove) records of a pool
52+
*
53+
* @param poolId
54+
* @param limit
55+
* @return
56+
*/
57+
List<LiquidityOperationRecord> getPoolLiquidityOperationRecords(
58+
String poolId,
59+
Integer limit);
60+
61+
/**
62+
* Get liquidity operation (add/remove) record.
63+
*
64+
* @param operationId
65+
* @return
66+
*/
67+
LiquidityOperationRecord getLiquidityOperationRecord(String operationId);
68+
69+
/**
70+
* Request a quote for swap quote asset (selling asset) for base asset (buying asset), essentially price/exchange rates.
71+
*
72+
* @param quoteAsset
73+
* @param baseAsset
74+
* @param quoteQty
75+
* @return
76+
*/
77+
SwapQuote requestQuote(String quoteAsset,
78+
String baseAsset,
79+
String quoteQty);
80+
81+
/**
82+
* Swap quoteAsset for baseAsset
83+
*
84+
* @param quoteAsset
85+
* @param baseAsset
86+
* @param quoteQty
87+
* @return
88+
*/
89+
SwapRecord swap(String quoteAsset,
90+
String baseAsset,
91+
String quoteQty);
92+
93+
SwapHistory getSwapHistory(String swapId);
94+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package com.binance.api.client.domain;
2+
3+
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
4+
5+
@JsonIgnoreProperties(ignoreUnknown = true)
6+
public enum SwapOperationType {
7+
ADD, REMOVE
8+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package com.binance.api.client.domain;
2+
3+
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
4+
5+
@JsonIgnoreProperties(ignoreUnknown = true)
6+
public enum SwapRemoveType {
7+
SINGLE, COMBINATION
8+
}
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
package com.binance.api.client.domain.account;
2+
3+
import java.util.Map;
4+
5+
public class Liquidity {
6+
7+
private String poolId;
8+
private String poolName;
9+
private Long updateTime;
10+
private Map<String, String> liquidity;
11+
private Share share;
12+
13+
public String getPoolId() {
14+
return poolId;
15+
}
16+
17+
public void setPoolId(String poolId) {
18+
this.poolId = poolId;
19+
}
20+
21+
public String getPoolName() {
22+
return poolName;
23+
}
24+
25+
public void setPoolName(String poolName) {
26+
this.poolName = poolName;
27+
}
28+
29+
public Long getUpdateTime() {
30+
return updateTime;
31+
}
32+
33+
public void setUpdateTime(Long updateTime) {
34+
this.updateTime = updateTime;
35+
}
36+
37+
public Map<String, String> getLiquidity() {
38+
return liquidity;
39+
}
40+
41+
public void setLiquidity(Map<String, String> liquidity) {
42+
this.liquidity = liquidity;
43+
}
44+
45+
public Share getShare() {
46+
return share;
47+
}
48+
49+
public void setShare(Share share) {
50+
this.share = share;
51+
}
52+
53+
public static class Share {
54+
private double shareAmount;
55+
private double sharePercentage;
56+
private Map<String, String> asset;
57+
58+
public double getShareAmount() {
59+
return shareAmount;
60+
}
61+
62+
public void setShareAmount(double shareAmount) {
63+
this.shareAmount = shareAmount;
64+
}
65+
66+
public double getSharePercentage() {
67+
return sharePercentage;
68+
}
69+
70+
public void setSharePercentage(double sharePercentage) {
71+
this.sharePercentage = sharePercentage;
72+
}
73+
74+
public Map<String, String> getAsset() {
75+
return asset;
76+
}
77+
78+
public void setAsset(Map<String, String> asset) {
79+
this.asset = asset;
80+
}
81+
82+
@Override
83+
public String toString() {
84+
return "Share{" +
85+
"shareAmount=" + shareAmount +
86+
", sharePercentage=" + sharePercentage +
87+
", asset=" + asset +
88+
'}';
89+
}
90+
}
91+
92+
@Override
93+
public String toString() {
94+
return "Liquidity{" +
95+
"poolId=" + poolId +
96+
", poolName='" + poolName + '\'' +
97+
", updateTime=" + updateTime +
98+
", liquidity=" + liquidity +
99+
", share=" + share +
100+
'}';
101+
}
102+
}
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
package com.binance.api.client.domain.account;
2+
3+
import com.binance.api.client.domain.SwapOperationType;
4+
5+
public class LiquidityOperationRecord {
6+
7+
private String poolId;
8+
private String operationId;
9+
private String updateTime;
10+
private String operation;
11+
private String shareAmount;
12+
private String poolName;
13+
private SwapOperationType status;
14+
15+
public String getPoolId() {
16+
return poolId;
17+
}
18+
19+
public void setPoolId(String poolId) {
20+
this.poolId = poolId;
21+
}
22+
23+
public String getUpdateTime() {
24+
return updateTime;
25+
}
26+
27+
public void setUpdateTime(String updateTime) {
28+
this.updateTime = updateTime;
29+
}
30+
31+
public String getOperation() {
32+
return operation;
33+
}
34+
35+
public void setOperation(String operation) {
36+
this.operation = operation;
37+
}
38+
39+
public String getShareAmount() {
40+
return shareAmount;
41+
}
42+
43+
public void setShareAmount(String shareAmount) {
44+
this.shareAmount = shareAmount;
45+
}
46+
47+
public String getPoolName() {
48+
return poolName;
49+
}
50+
51+
public void setPoolName(String poolName) {
52+
this.poolName = poolName;
53+
}
54+
55+
public SwapOperationType getStatus() {
56+
return status;
57+
}
58+
59+
public void setStatus(SwapOperationType status) {
60+
this.status = status;
61+
}
62+
63+
public String getOperationId() {
64+
return operationId;
65+
}
66+
67+
public void setOperationId(String operationId) {
68+
this.operationId = operationId;
69+
}
70+
71+
@Override
72+
public String toString() {
73+
return "LiquidityOperationRecord{" +
74+
"poolId='" + poolId + '\'' +
75+
", operationId='" + operationId + '\'' +
76+
", updateTime='" + updateTime + '\'' +
77+
", operation='" + operation + '\'' +
78+
", shareAmount='" + shareAmount + '\'' +
79+
", poolName='" + poolName + '\'' +
80+
", status='" + status + '\'' +
81+
'}';
82+
}
83+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
package com.binance.api.client.domain.account;
2+
3+
import java.util.List;
4+
5+
public class Pool {
6+
7+
private String poolId;
8+
private String poolName;
9+
private List<String> assets;
10+
11+
public String getPoolId() {
12+
return poolId;
13+
}
14+
15+
public void setPoolId(String poolId) {
16+
this.poolId = poolId;
17+
}
18+
19+
public List<String> getAssets() {
20+
return assets;
21+
}
22+
23+
public void setAssets(List<String> assets) {
24+
this.assets = assets;
25+
}
26+
27+
public String getPoolName() {
28+
return poolName;
29+
}
30+
31+
public void setPoolName(String poolName) {
32+
this.poolName = poolName;
33+
}
34+
35+
@Override
36+
public String toString() {
37+
return "Pool{" +
38+
"poolId='" + poolId + '\'' +
39+
", poolName='" + poolName + '\'' +
40+
", assets=" + assets +
41+
'}';
42+
}
43+
}

0 commit comments

Comments
 (0)