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

Commit

Permalink
Merge pull request #285 from truonghatsts/features/bswap
Browse files Browse the repository at this point in the history
Binance Liquid Swap endpoints
  • Loading branch information
joaopsilva authored Oct 4, 2020
2 parents 120aff0 + c9ff0d9 commit c916c2c
Show file tree
Hide file tree
Showing 130 changed files with 8,180 additions and 6,012 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
package com.binance.api.client;

import com.binance.api.client.domain.TransferType;
import com.binance.api.client.domain.account.*;
import com.binance.api.client.domain.account.request.CancelOrderRequest;
import com.binance.api.client.domain.account.request.CancelOrderResponse;
import com.binance.api.client.domain.account.request.OrderRequest;
import com.binance.api.client.domain.account.request.OrderStatusRequest;
import com.binance.api.client.domain.event.ListenKey;

import java.util.List;

/**
* Binance API façade, supporting asynchronous/non-blocking access Binance's Margin REST API.
*/
public interface BinanceApiAsyncMarginRestClient {

// Account endpoints

/**
* Get current margin account information (async).
*/
void getAccount(Long recvWindow, Long timestamp, BinanceApiCallback<MarginAccount> callback);

/**
* Get current margin account information using default parameters (async).
*/
void getAccount(BinanceApiCallback<MarginAccount> callback);

/**
* Get all open orders on margin account for a symbol (async).
*
* @param orderRequest order request parameters
* @param callback the callback that handles the response
*/
void getOpenOrders(OrderRequest orderRequest, BinanceApiCallback<List<Order>> callback);

/**
* Send in a new margin order (async).
*
* @param order the new order to submit.
* @return a response containing details about the newly placed order.
*/
void newOrder(NewOrder order, BinanceApiCallback<NewOrderResponse> callback);

/**
* Cancel an active margin order (async).
*
* @param cancelOrderRequest order status request parameters
*/
void cancelOrder(CancelOrderRequest cancelOrderRequest, BinanceApiCallback<CancelOrderResponse> callback);

/**
* Check margin order's status (async).
*
* @param orderStatusRequest order status request options/filters
* @return an order
*/
void getOrderStatus(OrderStatusRequest orderStatusRequest, BinanceApiCallback<Order> callback);

/**
* Get margin trades for a specific symbol (async).
*
* @param symbol symbol to get trades from
* @return a list of trades
*/
void getMyTrades(String symbol, BinanceApiCallback<List<Trade>> callback);

// User stream endpoints

/**
* Start a new user data stream (async).
*
* @return a listen key that can be used with data streams
*/
void startUserDataStream(BinanceApiCallback<ListenKey> callback);

/**
* PING a user data stream to prevent a time out (async).
*
* @param listenKey listen key that identifies a data stream
*/
void keepAliveUserDataStream(String listenKey, BinanceApiCallback<Void> callback);

/**
* Execute transfer between spot account and margin account
* @param asset asset to repay
* @param amount amount to repay
* @return transaction id
*/
void transfer(String asset, String amount, TransferType type, BinanceApiCallback<MarginTransaction> callback);

/**
* Apply for a loan
* @param asset asset to repay
* @param amount amount to repay
* @return transaction id
*/
void borrow(String asset, String amount, BinanceApiCallback<MarginTransaction> callback);

/**
* Repay loan for margin account
* @param asset asset to repay
* @param amount amount to repay
* @return transaction id
*/
void repay(String asset, String amount, BinanceApiCallback<MarginTransaction> callback);

}
Empty file.
46 changes: 23 additions & 23 deletions src/main/java/com/binance/api/client/BinanceApiCallback.java
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
package com.binance.api.client;

/**
* BinanceApiCallback is a functional interface used together with the BinanceApiAsyncClient to provide a non-blocking REST client.
*
* @param <T> the return type from the callback
*/
@FunctionalInterface
public interface BinanceApiCallback<T> {

/**
* Called whenever a response comes back from the Binance API.
*
* @param response the expected response object
*/
void onResponse(T response);

/**
* Called whenever an error occurs.
*
* @param cause the cause of the failure
*/
default void onFailure(Throwable cause) {}
package com.binance.api.client;

/**
* BinanceApiCallback is a functional interface used together with the BinanceApiAsyncClient to provide a non-blocking REST client.
*
* @param <T> the return type from the callback
*/
@FunctionalInterface
public interface BinanceApiCallback<T> {

/**
* Called whenever a response comes back from the Binance API.
*
* @param response the expected response object
*/
void onResponse(T response);

/**
* Called whenever an error occurs.
*
* @param cause the cause of the failure
*/
default void onFailure(Throwable cause) {}
}
170 changes: 95 additions & 75 deletions src/main/java/com/binance/api/client/BinanceApiClientFactory.java
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,75 +1,95 @@
package com.binance.api.client;

import com.binance.api.client.impl.BinanceApiAsyncRestClientImpl;
import com.binance.api.client.impl.BinanceApiRestClientImpl;
import com.binance.api.client.impl.BinanceApiWebSocketClientImpl;

import static com.binance.api.client.impl.BinanceApiServiceGenerator.getSharedClient;

/**
* A factory for creating BinanceApi client objects.
*/
public class BinanceApiClientFactory {

/**
* API Key
*/
private String apiKey;

/**
* Secret.
*/
private String secret;

/**
* Instantiates a new binance api client factory.
*
* @param apiKey the API key
* @param secret the Secret
*/
private BinanceApiClientFactory(String apiKey, String secret) {
this.apiKey = apiKey;
this.secret = secret;
}

/**
* New instance.
*
* @param apiKey the API key
* @param secret the Secret
*
* @return the binance api client factory
*/
public static BinanceApiClientFactory newInstance(String apiKey, String secret) {
return new BinanceApiClientFactory(apiKey, secret);
}

/**
* New instance without authentication.
*
* @return the binance api client factory
*/
public static BinanceApiClientFactory newInstance() {
return new BinanceApiClientFactory(null, null);
}

/**
* Creates a new synchronous/blocking REST client.
*/
public BinanceApiRestClient newRestClient() {
return new BinanceApiRestClientImpl(apiKey, secret);
}

/**
* Creates a new asynchronous/non-blocking REST client.
*/
public BinanceApiAsyncRestClient newAsyncRestClient() {return new BinanceApiAsyncRestClientImpl(apiKey, secret);
}

/**
* Creates a new web socket client used for handling data streams.
*/
public BinanceApiWebSocketClient newWebSocketClient() {
return new BinanceApiWebSocketClientImpl(getSharedClient());
}
}
package com.binance.api.client;

import com.binance.api.client.impl.*;

import static com.binance.api.client.impl.BinanceApiServiceGenerator.getSharedClient;

/**
* A factory for creating BinanceApi client objects.
*/
public class BinanceApiClientFactory {

/**
* API Key
*/
private String apiKey;

/**
* Secret.
*/
private String secret;

/**
* Instantiates a new binance api client factory.
*
* @param apiKey the API key
* @param secret the Secret
*/
private BinanceApiClientFactory(String apiKey, String secret) {
this.apiKey = apiKey;
this.secret = secret;
}

/**
* New instance.
*
* @param apiKey the API key
* @param secret the Secret
*
* @return the binance api client factory
*/
public static BinanceApiClientFactory newInstance(String apiKey, String secret) {
return new BinanceApiClientFactory(apiKey, secret);
}

/**
* New instance without authentication.
*
* @return the binance api client factory
*/
public static BinanceApiClientFactory newInstance() {
return new BinanceApiClientFactory(null, null);
}

/**
* Creates a new synchronous/blocking REST client.
*/
public BinanceApiRestClient newRestClient() {
return new BinanceApiRestClientImpl(apiKey, secret);
}

/**
* Creates a new asynchronous/non-blocking REST client.
*/
public BinanceApiAsyncRestClient newAsyncRestClient() {
return new BinanceApiAsyncRestClientImpl(apiKey, secret);
}

/**
* Creates a new asynchronous/non-blocking Margin REST client.
*/
public BinanceApiAsyncMarginRestClient newAsyncMarginRestClient() {
return new BinanceApiAsyncMarginRestClientImpl(apiKey, secret);
}

/**
* Creates a new synchronous/blocking Margin REST client.
*/
public BinanceApiMarginRestClient newMarginRestClient() {
return new BinanceApiMarginRestClientImpl(apiKey, secret);
}

/**
* Creates a new web socket client used for handling data streams.
*/
public BinanceApiWebSocketClient newWebSocketClient() {
return new BinanceApiWebSocketClientImpl(getSharedClient());
}

/**
* Creates a new synchronous/blocking Swap REST client.
*/
public BinanceApiSwapRestClient newSwapRestClient() {
return new BinanceApiSwapRestClientImpl(apiKey, secret);
}
}
Loading

0 comments on commit c916c2c

Please sign in to comment.