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

Commit

Permalink
implemented /fapi/v1/leverage and /fapi/v1/marginType
Browse files Browse the repository at this point in the history
  • Loading branch information
mah454 committed Apr 2, 2021
1 parent 00aa240 commit 751820c
Show file tree
Hide file tree
Showing 18 changed files with 306 additions and 21 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.binance.api.client.impl;
package com.binance.api.client.api;

import com.binance.api.client.constant.BinanceApiConstants;
import com.binance.api.client.domain.OrderSide;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
package com.binance.api.client.impl;
package com.binance.api.client.api;

import com.binance.api.client.constant.BinanceApiConstants;
import com.binance.api.client.domain.*;
import com.binance.api.client.domain.account.*;
import com.binance.api.client.domain.account.request.CancelOrderResponse;
import com.binance.api.client.domain.event.ListenKey;
import com.binance.api.client.domain.general.Asset;
import com.binance.api.client.domain.general.ExchangeInfo;
import com.binance.api.client.domain.general.ServerTime;
import com.binance.api.client.domain.market.*;
Expand Down Expand Up @@ -81,18 +80,26 @@ Call<Order> getOrderStatus(@Query("symbol") String symbol, @Query("orderId") Lon

@Headers(BinanceApiConstants.ENDPOINT_SECURITY_TYPE_SIGNED_HEADER)
@DELETE("/fapi/v1/order")
Call<CancelOrderResponse> cancelOrder(@Query("symbol") String symbol, @Query("orderId") Long orderId,
@Query("origClientOrderId") String origClientOrderId, @Query("newClientOrderId") String newClientOrderId,
@Query("recvWindow") Long recvWindow, @Query("timestamp") Long timestamp);
Call<CancelOrderResponse> cancelOrder(@Query("symbol") String symbol,
@Query("orderId") Long orderId,
@Query("origClientOrderId") String origClientOrderId,
@Query("newClientOrderId") String newClientOrderId,
@Query("recvWindow") Long recvWindow,
@Query("timestamp") Long timestamp);

@Headers(BinanceApiConstants.ENDPOINT_SECURITY_TYPE_SIGNED_HEADER)
@GET("/fapi/v1/openOrders")
Call<List<Order>> getOpenOrders(@Query("symbol") String symbol, @Query("recvWindow") Long recvWindow, @Query("timestamp") Long timestamp);
Call<List<Order>> getOpenOrders(@Query("symbol") String symbol,
@Query("recvWindow") Long recvWindow,
@Query("timestamp") Long timestamp);

@Headers(BinanceApiConstants.ENDPOINT_SECURITY_TYPE_SIGNED_HEADER)
@GET("/fapi/v1/allOrders")
Call<List<Order>> getAllOrders(@Query("symbol") String symbol, @Query("orderId") Long orderId,
@Query("limit") Integer limit, @Query("recvWindow") Long recvWindow, @Query("timestamp") Long timestamp);
Call<List<Order>> getAllOrders(@Query("symbol") String symbol,
@Query("orderId") Long orderId,
@Query("limit") Integer limit,
@Query("recvWindow") Long recvWindow,
@Query("timestamp") Long timestamp);

@Headers(BinanceApiConstants.ENDPOINT_SECURITY_TYPE_SIGNED_HEADER)
@GET("/fapi/v2/account")
Expand All @@ -111,4 +118,18 @@ Call<List<Order>> getAllOrders(@Query("symbol") String symbol, @Query("orderId")
@Headers(BinanceApiConstants.ENDPOINT_SECURITY_TYPE_APIKEY_HEADER)
@DELETE("/fapi/v1/listenKey")
Call<Void> closeAliveUserDataStream(@Query("listenKey") String listenKey);

@Headers(BinanceApiConstants.ENDPOINT_SECURITY_TYPE_SIGNED_HEADER)
@POST("/fapi/v1/leverage")
Call<LeverageResponse> changeInitialLeverage(@Query("symbol") String symbol,
@Query("leverage") Integer leverage,
@Query("recvWindow") Long recvWindow,
@Query("timestamp") Long timestamp);

@Headers(BinanceApiConstants.ENDPOINT_SECURITY_TYPE_SIGNED_HEADER)
@POST("/fapi/v1/marginType")
Call<Void> changeMarginType(@Query("symbol") String symbol,
@Query("marginType") MarginType marginType,
@Query("recvWindow") Long recvWindow,
@Query("timestamp") Long timestamp);
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package com.binance.api.client.api.sync;

import com.binance.api.client.domain.account.FuturesAccount;
import com.binance.api.client.domain.account.FuturesNewOrder;
import com.binance.api.client.domain.account.FuturesNewOrderResponse;
import com.binance.api.client.domain.account.*;

public interface BinanceApiFuturesRestClient extends BinanceApiGeneralRestClient {

Expand All @@ -18,4 +16,16 @@ public interface BinanceApiFuturesRestClient extends BinanceApiGeneralRestClient
* @return a response containing details about the newly placed order.
*/
FuturesNewOrderResponse newOrder(FuturesNewOrder order);


/**
* Change leverage
*
* @param leverageRequest
* @return LeverageResponse
*/
LeverageResponse changeInitialLeverage(LeverageRequest leverageRequest);

void changeMarginType(MarginTypeRequest marginTypeRequest);

}
13 changes: 13 additions & 0 deletions src/main/java/com/binance/api/client/domain/MarginType.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.binance.api.client.domain;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;

/**
* Binance futures margin types
*
* @author Mahdi Sheikh Hosseini
*/
@JsonIgnoreProperties(ignoreUnknown = true)
public enum MarginType {
ISOLATED, CROSSED;
}
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,13 @@ public FuturesAssetBalance getAssetBalance(final String symbol) {
.orElse(FuturesAssetBalance.of(symbol));
}

public FuturesPosition getPosition(final String symbol) {
return positions.stream()
.filter(e -> e.getSymbol().equals(symbol))
.findFirst()
.orElse(null);
}

@Override
public String toString() {
return new ToStringBuilder(this, BinanceApiConstants.TO_STRING_BUILDER_STYLE)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
package com.binance.api.client.domain.account;

import com.binance.api.client.constant.BinanceApiConstants;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import org.apache.commons.lang3.builder.ToStringBuilder;

@JsonIgnoreProperties(ignoreUnknown = true)
public class LeverageRequest {

private String symbol;
private int leverage;
private long recvWindow;
private long timestamp;

public LeverageRequest() {
this.timestamp = System.currentTimeMillis();
this.recvWindow = BinanceApiConstants.DEFAULT_RECEIVING_WINDOW;
}

public LeverageRequest(String symbol, int leverage) {
this.symbol = symbol;
this.leverage = leverage;
this.timestamp = System.currentTimeMillis();
this.recvWindow = BinanceApiConstants.DEFAULT_RECEIVING_WINDOW;
}

public String getSymbol() {
return symbol;
}

public void setSymbol(String symbol) {
this.symbol = symbol;
}

public int getLeverage() {
return leverage;
}

public void setLeverage(int leverage) {
this.leverage = leverage;
}

public long getRecvWindow() {
return recvWindow;
}

public void setRecvWindow(long recvWindow) {
this.recvWindow = recvWindow;
}

public long getTimestamp() {
return timestamp;
}

public void setTimestamp(long timestamp) {
this.timestamp = timestamp;
}

@Override
public String toString() {
return new ToStringBuilder(this, BinanceApiConstants.TO_STRING_BUILDER_STYLE)
.append("symbol", symbol)
.append("leverage", leverage)
.append("recvWindow", recvWindow)
.append("timestamp", timestamp)
.toString();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package com.binance.api.client.domain.account;

import com.binance.api.client.constant.BinanceApiConstants;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import org.apache.commons.lang3.builder.ToStringBuilder;

@JsonIgnoreProperties(ignoreUnknown = true)
public class LeverageResponse {

private String symbol;
private int leverage;
private String maxNotionalValue;

public int getLeverage() {
return leverage;
}

public void setLeverage(int leverage) {
this.leverage = leverage;
}

public String getMaxNotionalValue() {
return maxNotionalValue;
}

public void setMaxNotionalValue(String maxNotionalValue) {
this.maxNotionalValue = maxNotionalValue;
}

public String getSymbol() {
return symbol;
}

public void setSymbol(String symbol) {
this.symbol = symbol;
}

@Override
public String toString() {
return new ToStringBuilder(this, BinanceApiConstants.TO_STRING_BUILDER_STYLE)
.append("symbol", symbol)
.append("leverage", leverage)
.append("maxNotionalValue", maxNotionalValue)
.toString();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
package com.binance.api.client.domain.account;

import com.binance.api.client.constant.BinanceApiConstants;
import com.binance.api.client.domain.MarginType;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import org.apache.commons.lang3.builder.ToStringBuilder;

/**
* @author Mahdi Sheikh Hosseini
*/
@JsonIgnoreProperties(ignoreUnknown = true)
public class MarginTypeRequest {

private String symbol;
private MarginType marginType;
private long recvWindow;
private long timestamp;

public MarginTypeRequest() {
this.timestamp = System.currentTimeMillis();
this.recvWindow = BinanceApiConstants.DEFAULT_RECEIVING_WINDOW;
}

public MarginTypeRequest(String symbol, MarginType marginType) {
this.symbol = symbol;
this.marginType = marginType;
this.timestamp = System.currentTimeMillis();
this.recvWindow = BinanceApiConstants.DEFAULT_RECEIVING_WINDOW;
}

public String getSymbol() {
return symbol;
}

public void setSymbol(String symbol) {
this.symbol = symbol;
}

public MarginType getMarginType() {
return marginType;
}

public void setMarginType(MarginType marginType) {
this.marginType = marginType;
}

public long getRecvWindow() {
return recvWindow;
}

public void setRecvWindow(long recvWindow) {
this.recvWindow = recvWindow;
}

public long getTimestamp() {
return timestamp;
}

public void setTimestamp(long timestamp) {
this.timestamp = timestamp;
}

@Override
public String toString() {
return new ToStringBuilder(this, BinanceApiConstants.TO_STRING_BUILDER_STYLE)
.append("symbol", symbol)
.append("marginType", marginType)
.append("recvWindow", recvWindow)
.append("timestamp", timestamp)
.toString();
}

}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.binance.api.client.impl;

import com.binance.api.client.api.BinanceApiError;
import com.binance.api.client.api.BinanceApiService;
import com.binance.api.client.exception.BinanceApiException;
import com.binance.api.client.security.AuthenticationInterceptor;
import okhttp3.Dispatcher;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import com.binance.api.client.domain.account.request.OrderStatusRequest;
import com.binance.api.client.impl.BinanceApiCallbackAdapter;
import com.binance.api.client.impl.BinanceApiServiceGenerator;
import com.binance.api.client.impl.BinanceFuturesApiService;
import com.binance.api.client.api.BinanceFuturesApiService;

import java.util.List;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import com.binance.api.client.domain.account.request.OrderStatusRequest;
import com.binance.api.client.domain.event.ListenKey;
import com.binance.api.client.impl.BinanceApiCallbackAdapter;
import com.binance.api.client.impl.BinanceApiService;
import com.binance.api.client.api.BinanceApiService;
import com.binance.api.client.impl.BinanceApiServiceGenerator;

import java.util.List;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import com.binance.api.client.domain.general.ServerTime;
import com.binance.api.client.domain.market.*;
import com.binance.api.client.impl.BinanceApiCallbackAdapter;
import com.binance.api.client.impl.BinanceApiService;
import com.binance.api.client.api.BinanceApiService;
import com.binance.api.client.impl.BinanceApiServiceGenerator;

import java.util.List;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import com.binance.api.client.domain.SwapRemoveType;
import com.binance.api.client.domain.account.*;
import com.binance.api.client.impl.BinanceApiCallbackAdapter;
import com.binance.api.client.impl.BinanceApiService;
import com.binance.api.client.api.BinanceApiService;
import com.binance.api.client.impl.BinanceApiServiceGenerator;

import java.util.List;
Expand Down
Loading

0 comments on commit 751820c

Please sign in to comment.