Skip to content

Commit c916c2c

Browse files
authored
Merge pull request binance-exchange#285 from truonghatsts/features/bswap
Binance Liquid Swap endpoints
2 parents 120aff0 + c9ff0d9 commit c916c2c

File tree

130 files changed

+8180
-6012
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

130 files changed

+8180
-6012
lines changed
Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
package com.binance.api.client;
2+
3+
import com.binance.api.client.domain.TransferType;
4+
import com.binance.api.client.domain.account.*;
5+
import com.binance.api.client.domain.account.request.CancelOrderRequest;
6+
import com.binance.api.client.domain.account.request.CancelOrderResponse;
7+
import com.binance.api.client.domain.account.request.OrderRequest;
8+
import com.binance.api.client.domain.account.request.OrderStatusRequest;
9+
import com.binance.api.client.domain.event.ListenKey;
10+
11+
import java.util.List;
12+
13+
/**
14+
* Binance API façade, supporting asynchronous/non-blocking access Binance's Margin REST API.
15+
*/
16+
public interface BinanceApiAsyncMarginRestClient {
17+
18+
// Account endpoints
19+
20+
/**
21+
* Get current margin account information (async).
22+
*/
23+
void getAccount(Long recvWindow, Long timestamp, BinanceApiCallback<MarginAccount> callback);
24+
25+
/**
26+
* Get current margin account information using default parameters (async).
27+
*/
28+
void getAccount(BinanceApiCallback<MarginAccount> callback);
29+
30+
/**
31+
* Get all open orders on margin account for a symbol (async).
32+
*
33+
* @param orderRequest order request parameters
34+
* @param callback the callback that handles the response
35+
*/
36+
void getOpenOrders(OrderRequest orderRequest, BinanceApiCallback<List<Order>> callback);
37+
38+
/**
39+
* Send in a new margin order (async).
40+
*
41+
* @param order the new order to submit.
42+
* @return a response containing details about the newly placed order.
43+
*/
44+
void newOrder(NewOrder order, BinanceApiCallback<NewOrderResponse> callback);
45+
46+
/**
47+
* Cancel an active margin order (async).
48+
*
49+
* @param cancelOrderRequest order status request parameters
50+
*/
51+
void cancelOrder(CancelOrderRequest cancelOrderRequest, BinanceApiCallback<CancelOrderResponse> callback);
52+
53+
/**
54+
* Check margin order's status (async).
55+
*
56+
* @param orderStatusRequest order status request options/filters
57+
* @return an order
58+
*/
59+
void getOrderStatus(OrderStatusRequest orderStatusRequest, BinanceApiCallback<Order> callback);
60+
61+
/**
62+
* Get margin trades for a specific symbol (async).
63+
*
64+
* @param symbol symbol to get trades from
65+
* @return a list of trades
66+
*/
67+
void getMyTrades(String symbol, BinanceApiCallback<List<Trade>> callback);
68+
69+
// User stream endpoints
70+
71+
/**
72+
* Start a new user data stream (async).
73+
*
74+
* @return a listen key that can be used with data streams
75+
*/
76+
void startUserDataStream(BinanceApiCallback<ListenKey> callback);
77+
78+
/**
79+
* PING a user data stream to prevent a time out (async).
80+
*
81+
* @param listenKey listen key that identifies a data stream
82+
*/
83+
void keepAliveUserDataStream(String listenKey, BinanceApiCallback<Void> callback);
84+
85+
/**
86+
* Execute transfer between spot account and margin account
87+
* @param asset asset to repay
88+
* @param amount amount to repay
89+
* @return transaction id
90+
*/
91+
void transfer(String asset, String amount, TransferType type, BinanceApiCallback<MarginTransaction> callback);
92+
93+
/**
94+
* Apply for a loan
95+
* @param asset asset to repay
96+
* @param amount amount to repay
97+
* @return transaction id
98+
*/
99+
void borrow(String asset, String amount, BinanceApiCallback<MarginTransaction> callback);
100+
101+
/**
102+
* Repay loan for margin account
103+
* @param asset asset to repay
104+
* @param amount amount to repay
105+
* @return transaction id
106+
*/
107+
void repay(String asset, String amount, BinanceApiCallback<MarginTransaction> callback);
108+
109+
}

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

100644100755
File mode changed.
Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,24 @@
1-
package com.binance.api.client;
2-
3-
/**
4-
* BinanceApiCallback is a functional interface used together with the BinanceApiAsyncClient to provide a non-blocking REST client.
5-
*
6-
* @param <T> the return type from the callback
7-
*/
8-
@FunctionalInterface
9-
public interface BinanceApiCallback<T> {
10-
11-
/**
12-
* Called whenever a response comes back from the Binance API.
13-
*
14-
* @param response the expected response object
15-
*/
16-
void onResponse(T response);
17-
18-
/**
19-
* Called whenever an error occurs.
20-
*
21-
* @param cause the cause of the failure
22-
*/
23-
default void onFailure(Throwable cause) {}
1+
package com.binance.api.client;
2+
3+
/**
4+
* BinanceApiCallback is a functional interface used together with the BinanceApiAsyncClient to provide a non-blocking REST client.
5+
*
6+
* @param <T> the return type from the callback
7+
*/
8+
@FunctionalInterface
9+
public interface BinanceApiCallback<T> {
10+
11+
/**
12+
* Called whenever a response comes back from the Binance API.
13+
*
14+
* @param response the expected response object
15+
*/
16+
void onResponse(T response);
17+
18+
/**
19+
* Called whenever an error occurs.
20+
*
21+
* @param cause the cause of the failure
22+
*/
23+
default void onFailure(Throwable cause) {}
2424
}
Lines changed: 95 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -1,75 +1,95 @@
1-
package com.binance.api.client;
2-
3-
import com.binance.api.client.impl.BinanceApiAsyncRestClientImpl;
4-
import com.binance.api.client.impl.BinanceApiRestClientImpl;
5-
import com.binance.api.client.impl.BinanceApiWebSocketClientImpl;
6-
7-
import static com.binance.api.client.impl.BinanceApiServiceGenerator.getSharedClient;
8-
9-
/**
10-
* A factory for creating BinanceApi client objects.
11-
*/
12-
public class BinanceApiClientFactory {
13-
14-
/**
15-
* API Key
16-
*/
17-
private String apiKey;
18-
19-
/**
20-
* Secret.
21-
*/
22-
private String secret;
23-
24-
/**
25-
* Instantiates a new binance api client factory.
26-
*
27-
* @param apiKey the API key
28-
* @param secret the Secret
29-
*/
30-
private BinanceApiClientFactory(String apiKey, String secret) {
31-
this.apiKey = apiKey;
32-
this.secret = secret;
33-
}
34-
35-
/**
36-
* New instance.
37-
*
38-
* @param apiKey the API key
39-
* @param secret the Secret
40-
*
41-
* @return the binance api client factory
42-
*/
43-
public static BinanceApiClientFactory newInstance(String apiKey, String secret) {
44-
return new BinanceApiClientFactory(apiKey, secret);
45-
}
46-
47-
/**
48-
* New instance without authentication.
49-
*
50-
* @return the binance api client factory
51-
*/
52-
public static BinanceApiClientFactory newInstance() {
53-
return new BinanceApiClientFactory(null, null);
54-
}
55-
56-
/**
57-
* Creates a new synchronous/blocking REST client.
58-
*/
59-
public BinanceApiRestClient newRestClient() {
60-
return new BinanceApiRestClientImpl(apiKey, secret);
61-
}
62-
63-
/**
64-
* Creates a new asynchronous/non-blocking REST client.
65-
*/
66-
public BinanceApiAsyncRestClient newAsyncRestClient() {return new BinanceApiAsyncRestClientImpl(apiKey, secret);
67-
}
68-
69-
/**
70-
* Creates a new web socket client used for handling data streams.
71-
*/
72-
public BinanceApiWebSocketClient newWebSocketClient() {
73-
return new BinanceApiWebSocketClientImpl(getSharedClient());
74-
}
75-
}
1+
package com.binance.api.client;
2+
3+
import com.binance.api.client.impl.*;
4+
5+
import static com.binance.api.client.impl.BinanceApiServiceGenerator.getSharedClient;
6+
7+
/**
8+
* A factory for creating BinanceApi client objects.
9+
*/
10+
public class BinanceApiClientFactory {
11+
12+
/**
13+
* API Key
14+
*/
15+
private String apiKey;
16+
17+
/**
18+
* Secret.
19+
*/
20+
private String secret;
21+
22+
/**
23+
* Instantiates a new binance api client factory.
24+
*
25+
* @param apiKey the API key
26+
* @param secret the Secret
27+
*/
28+
private BinanceApiClientFactory(String apiKey, String secret) {
29+
this.apiKey = apiKey;
30+
this.secret = secret;
31+
}
32+
33+
/**
34+
* New instance.
35+
*
36+
* @param apiKey the API key
37+
* @param secret the Secret
38+
*
39+
* @return the binance api client factory
40+
*/
41+
public static BinanceApiClientFactory newInstance(String apiKey, String secret) {
42+
return new BinanceApiClientFactory(apiKey, secret);
43+
}
44+
45+
/**
46+
* New instance without authentication.
47+
*
48+
* @return the binance api client factory
49+
*/
50+
public static BinanceApiClientFactory newInstance() {
51+
return new BinanceApiClientFactory(null, null);
52+
}
53+
54+
/**
55+
* Creates a new synchronous/blocking REST client.
56+
*/
57+
public BinanceApiRestClient newRestClient() {
58+
return new BinanceApiRestClientImpl(apiKey, secret);
59+
}
60+
61+
/**
62+
* Creates a new asynchronous/non-blocking REST client.
63+
*/
64+
public BinanceApiAsyncRestClient newAsyncRestClient() {
65+
return new BinanceApiAsyncRestClientImpl(apiKey, secret);
66+
}
67+
68+
/**
69+
* Creates a new asynchronous/non-blocking Margin REST client.
70+
*/
71+
public BinanceApiAsyncMarginRestClient newAsyncMarginRestClient() {
72+
return new BinanceApiAsyncMarginRestClientImpl(apiKey, secret);
73+
}
74+
75+
/**
76+
* Creates a new synchronous/blocking Margin REST client.
77+
*/
78+
public BinanceApiMarginRestClient newMarginRestClient() {
79+
return new BinanceApiMarginRestClientImpl(apiKey, secret);
80+
}
81+
82+
/**
83+
* Creates a new web socket client used for handling data streams.
84+
*/
85+
public BinanceApiWebSocketClient newWebSocketClient() {
86+
return new BinanceApiWebSocketClientImpl(getSharedClient());
87+
}
88+
89+
/**
90+
* Creates a new synchronous/blocking Swap REST client.
91+
*/
92+
public BinanceApiSwapRestClient newSwapRestClient() {
93+
return new BinanceApiSwapRestClientImpl(apiKey, secret);
94+
}
95+
}

0 commit comments

Comments
 (0)