Skip to content

Commit

Permalink
1.2.3
Browse files Browse the repository at this point in the history
  • Loading branch information
VictorFrWu committed Jan 31, 2024
1 parent 6242110 commit 2ce2535
Show file tree
Hide file tree
Showing 12 changed files with 144 additions and 35 deletions.
8 changes: 5 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,24 +40,26 @@ Maven Example
<dependency>
<groupId>io.github.wuhewuhe</groupId>
<artifactId>bybit-java-api</artifactId>
<version>1.1.5</version>
<version>1.2.3</version>
</dependency>
```
Gradle Example
```java
implementation group: 'io.github.wuhewuhe', name: 'bybit-java-api', version: '1.1.5'
implementation group: 'io.github.wuhewuhe', name: 'bybit-java-api', version: '1.2.3'
```
Furthermore, build tool, please check [sonar type central repository](https://central.sonatype.com/artifact/io.github.wuhewuhe/bybit-java-api/1.1.5)
Furthermore, build tool, please check [sonar type central repository](https://central.sonatype.com/artifact/io.github.wuhewuhe/bybit-java-api/1.2.3)

## Release-Notes
### HTTP Sync & Async Request
- Position new endpoints: Move Positions and Get Move Positions History
- Account new endpoint: Batch Set Collateral Coin
- TradeOrderRequest add a new parameter: marketUnit

### Improvements
- Fix Switch Position Mode Issue

### Change Log
- C:\Net\GithubProjects\open-api-sdk\bybit-java-api
- Set Tp/SL and Set Risk Limit endpoints are deprecated
- GetExecutionList move from PositionService to TradeService and rename to GetTradeHistory

Expand Down
36 changes: 18 additions & 18 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>io.github.wuhewuhe</groupId>
<artifactId>bybit-java-api</artifactId>
<version>1.1.5</version>
<version>1.2.3</version>
<name>bybit-java-api</name>
<url>https://github.com/wuhewuhe/bybit-java-api</url>

Expand Down Expand Up @@ -148,22 +148,22 @@
</dependencies>

<distributionManagement>

<repository>
<id>github</id>
<name>GitHub Packages Repository</name>
<url>https://maven.pkg.github.com/wuhewuhe/bybit-java-api</url>
</repository>
<!--
<snapshotRepository>
<id>ossrh</id>
<url>https://s01.oss.sonatype.org/content/repositories/snapshots</url>
</snapshotRepository>
<repository>
<id>ossrh</id>
<url>https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/</url>
</repository>
-->
<repository>
<id>github</id>
<name>GitHub Packages Repository</name>
<url>https://maven.pkg.github.com/wuhewuhe/bybit-java-api</url>
</repository>
-->
<snapshotRepository>
<id>ossrh</id>
<url>https://s01.oss.sonatype.org/content/repositories/snapshots</url>
</snapshotRepository>
<repository>
<id>ossrh</id>
<url>https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/</url>
</repository>

</distributionManagement>

<build>
Expand All @@ -185,7 +185,7 @@
</configuration>
</plugin>

<!-- Sonar Maven Central Package Management
<!-- Sonar Maven Central Package Management -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-release-plugin</artifactId>
Expand Down Expand Up @@ -253,7 +253,7 @@
</execution>
</executions>
</plugin>
-->

</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,6 @@ public class PlaceOrderRequest {
private String slLimitPrice;
private String tpOrderType;
private String slOrderType;
private String marketUnit;
}

Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,5 @@ public class TradeOrderRequest {
private OrderStatus orderStatus;
private Integer timeWindow; // only to Disconnect Cancel All options
private ExecType execType;
private String marketUnit;
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ public BybitApiTradeAsyncRestClientImpl(String apiKey, String secret, String bas
}

@Override
public void getHistoryOrderResult(TradeOrderRequest orderHistoryRequest, BybitApiCallback<Object> callback) {
bybitApiService.getHistoryOrderResult(
public void getOrderHistory(TradeOrderRequest orderHistoryRequest, BybitApiCallback<Object> callback) {
bybitApiService.getOrderHistory(
orderHistoryRequest.getCategory().getCategoryTypeId(),
orderHistoryRequest.getSymbol(),
orderHistoryRequest.getBaseCoin(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ public Object getBorrowQuota(TradeOrderRequest borrowQuotaRequest) {
}

@Override
public Object getHistoryOrderResult(TradeOrderRequest orderHistoryRequest) {
return executeSync(bybitApiService.getHistoryOrderResult(
public Object getOrderHistory(TradeOrderRequest orderHistoryRequest) {
return executeSync(bybitApiService.getOrderHistory(
orderHistoryRequest.getCategory().getCategoryTypeId(),
orderHistoryRequest.getSymbol(),
orderHistoryRequest.getBaseCoin(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

public interface BybitApiAsyncTradeRestClient {
// Trade
void getHistoryOrderResult(TradeOrderRequest orderHistoryRequest, BybitApiCallback<Object> callback);
void getOrderHistory(TradeOrderRequest orderHistoryRequest, BybitApiCallback<Object> callback);
void setDisconnectCancelAllTime(TradeOrderRequest tradeOrderRequest, BybitApiCallback<Object> callback);
void getBorrowQuota(TradeOrderRequest borrowQuotaRequest, BybitApiCallback<Object> callback);
void getOpenOrders(TradeOrderRequest order, BybitApiCallback<Object> callback);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -771,7 +771,7 @@ Call<Object> getMarketAccountRatio(@Query("category") String category,
*/
@Headers(BybitApiConstants.ENDPOINT_SECURITY_TYPE_SIGNED_HEADER)
@GET("/v5/order/history")
Call<Object> getHistoryOrderResult(@Query("category") String category,
Call<Object> getOrderHistory(@Query("category") String category,
@Query("symbol") String symbol,
@Query("baseCoin") String baseCoin,
@Query("settleCoin") String settleCoin,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
public interface BybitApiTradeRestClient {

// Trade
Object getHistoryOrderResult(TradeOrderRequest orderHistoryRequest);
Object getOrderHistory(TradeOrderRequest orderHistoryRequest);
Object setDisconnectCancelAllTime(TradeOrderRequest setDcpRequest);
Object getBorrowQuota(TradeOrderRequest borrowQuotaRequest);
Object getOpenOrders(TradeOrderRequest order);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ private TradeOrderRequest getTradeOrderRequest(Map<String, Object> orderMap, Str
.slLimitPrice((String) orderMap.getOrDefault("slLimitPrice", null)) // Optional
.tpOrderType(orderMap.containsKey("tpOrderType") ? TradeOrderType.valueOf(orderMap.get("tpOrderType").toString().toUpperCase()) : null) // Optional, default to Market
.slOrderType(orderMap.containsKey("slOrderType") ? TradeOrderType.valueOf(orderMap.get("slOrderType").toString().toUpperCase()) : null) // Optional, default to Market
.marketUnit((String)orderMap.getOrDefault("marketUnit", null))
.build();
}

Expand Down Expand Up @@ -131,6 +132,7 @@ public TradeOrderRequest getTradeOrderRequest(JsonNode requestNode, String categ
.slLimitPrice(requestNode.has("slLimitPrice") ? requestNode.get("slLimitPrice").asText() : null)
.tpOrderType(requestNode.has("tpOrderType") ? TradeOrderType.valueOf(requestNode.get("tpOrderType").asText().toUpperCase()) : null)
.slOrderType(requestNode.has("slOrderType") ? TradeOrderType.valueOf(requestNode.get("slOrderType").asText().toUpperCase()) : null)
.marketUnit(requestNode.has("marketUnit") ? requestNode.get("marketUnit").asText() : null)
.build();
}

Expand Down Expand Up @@ -305,6 +307,7 @@ public PlaceOrderRequest convertTradeToPlaceOrderRequest(TradeOrderRequest trade
.slLimitPrice(tradeOrderRequest.getSlLimitPrice()) // Optional
.tpOrderType(tradeOrderRequest.getTpOrderType() == null ? null : tradeOrderRequest.getTpOrderType().getOType()) // Optional, default to Market
.slOrderType(tradeOrderRequest.getSlOrderType() == null ? null : tradeOrderRequest.getSlOrderType().getOType()) // Optional, default to Market
.marketUnit(tradeOrderRequest.getMarketUnit())
.build();
}

Expand Down
97 changes: 97 additions & 0 deletions src/test/java/com/bybit/api/domain/trade/OpenOrderTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
package com.bybit.api.domain.trade;

import com.bybit.api.client.config.BybitApiConfig;
import com.bybit.api.client.domain.CategoryType;
import com.bybit.api.client.domain.TradeOrderType;
import com.bybit.api.client.domain.trade.Side;
import com.bybit.api.client.domain.trade.TimeInForce;
import com.bybit.api.client.domain.trade.request.TradeOrderRequest;
import com.bybit.api.client.restApi.BybitApiTradeRestClient;
import com.bybit.api.client.service.BybitApiClientFactory;
import org.junit.Test;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.TimeUnit;

public class OpenOrderTest {
BybitApiTradeRestClient client = BybitApiClientFactory.newInstance("8wYkmpLsMg10eNQyPm", "Ouxc34myDnXvei54XsBZgoQzfGxO4bkr2Zsj", BybitApiConfig.TESTNET_DOMAIN).newTradeRestClient();

@Test
public void Test_PlaceLinearOrder() throws InterruptedException {
/*
List<String> orderLinkIdList = new ArrayList<>();
var newSpotOrderRequest = TradeOrderRequest.builder().category(CategoryType.SPOT).symbol("XRPUSDT").side(Side.BUY).price("0.1").orderType(TradeOrderType.LIMIT).qty("10").timeInForce(TimeInForce.IOC);
// place 510 spot orders in canceled status
int lastIdx = 510;
for (int i = 0; i < lastIdx; i++) {
String orderCustomId = "hwu_test_spot_order_link_id_" + String.valueOf(i + 1);
var newOrder = client.createOrder(newSpotOrderRequest.orderLinkId(orderCustomId).build());
System.out.println("order " + (i + 1));
System.out.println(newOrder);
orderLinkIdList.add(orderCustomId);
}
// place 510 linear orders in filled status
var newLinearOrderRequest = TradeOrderRequest.builder().category(CategoryType.LINEAR).symbol("XRPUSDT").side(Side.BUY).orderType(TradeOrderType.MARKET).qty("2").timeInForce(TimeInForce.IOC);
for (int i = 0; i < lastIdx; i++) {
String orderCustomId = "hwu_test_linear_order_link_Id_" + String.valueOf(i + 1);
var newOrder = client.createOrder(newLinearOrderRequest.orderLinkId(orderCustomId).build());
System.out.println("order " + (i + 1));
System.out.println(newOrder);
orderLinkIdList.add(orderCustomId);
}
// place 510 linear orders in filled status
var newInverseOrderRequest = TradeOrderRequest.builder().category(CategoryType.INVERSE).symbol("BTCUSD").side(Side.BUY).orderType(TradeOrderType.MARKET).qty("1").timeInForce(TimeInForce.IOC);
for (int i = 0; i < lastIdx; i++) {
String orderCustomId = "hwu_test_inverse_order_link_Id_" + String.valueOf(i + 1);
var newOrder = client.createOrder(newInverseOrderRequest.orderLinkId(orderCustomId).build());
System.out.println("order " + (i + 1));
System.out.println(newOrder);
orderLinkIdList.add(orderCustomId);
}
// after 10 seconds
TimeUnit.SECONDS.sleep(10);
var openOrderRequest = TradeOrderRequest.builder();
//get spot open orders
var openSpotOrdersResult = client.getOpenOrders(openOrderRequest.category(CategoryType.SPOT).openOnly(1).build());
System.out.println(openSpotOrdersResult);
//test spot order
String lastSpotOrderLinkId = orderLinkIdList.get(lastIdx - 1), firstSpotOrderLinkId = orderLinkIdList.get(0);
//get 510th spot order
var lastSpotOrderResult = client.getOpenOrders(openOrderRequest.category(CategoryType.SPOT).orderLinkId(lastSpotOrderLinkId).build());
System.out.println(lastSpotOrderResult);
//get 1st spot order
var firstSpotOrderResult = client.getOpenOrders(openOrderRequest.category(CategoryType.SPOT).orderLinkId(firstSpotOrderLinkId).build());
System.out.println(firstSpotOrderResult);
//get linear open orders
var openLinearOrdersResult = client.getOpenOrders(openOrderRequest.category(CategoryType.LINEAR).openOnly(1).build());
System.out.println(openLinearOrdersResult);
//test linear order
String lastLinearOrderLinkId = orderLinkIdList.get(lastIdx * 2 - 1), firstLinearOrderLinkId = orderLinkIdList.get(lastIdx);
//get 510th linear order
var lastLinearOrderResult = client.getOpenOrders(openOrderRequest.category(CategoryType.LINEAR).orderLinkId(lastLinearOrderLinkId).build());
System.out.println(lastLinearOrderResult);
//get 1st linear order
var firstLinearOrderResult = client.getOpenOrders(openOrderRequest.category(CategoryType.LINEAR).orderLinkId(firstLinearOrderLinkId).build());
System.out.println(firstLinearOrderResult);
//get linear open orders
var openInverseOrdersResult = client.getOpenOrders(openOrderRequest.category(CategoryType.INVERSE).openOnly(2).build());
System.out.println(openInverseOrdersResult);
//test inverse order
String lastInverseOrderLinkId = orderLinkIdList.get(lastIdx * 3 - 1), firstInverseOrderLinkId = orderLinkIdList.get(lastIdx * 2);
//get 510th inverse order
var lastInverseOrderResult = client.getOpenOrders(openOrderRequest.category(CategoryType.INVERSE).orderLinkId(lastInverseOrderLinkId).build());
System.out.println(lastInverseOrderResult);
//get 1st inverse order
var firInverseOrderResult = client.getOpenOrders(openOrderRequest.category(CategoryType.INVERSE).orderLinkId(firstInverseOrderLinkId).build());
System.out.println(firInverseOrderResult);
*/
}
}
19 changes: 12 additions & 7 deletions src/test/java/com/bybit/api/examples/http/sync/TradeExample.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
package com.bybit.api.examples.http.sync;

import com.bybit.api.client.config.BybitApiConfig;
import com.bybit.api.client.domain.position.request.PositionDataRequest;
import com.bybit.api.client.domain.position.ExecType;
import com.bybit.api.client.domain.trade.request.TradeOrderRequest;
import com.bybit.api.client.restApi.BybitApiTradeRestClient;
import com.bybit.api.client.domain.*;
import com.bybit.api.client.domain.trade.*;
import com.bybit.api.client.service.BybitApiClientFactory;
Expand All @@ -18,8 +17,7 @@ public static void main(String[] args) {

// Getting a list of history order between 2 years
var orderHistory = TradeOrderRequest.builder().category(CategoryType.LINEAR).limit(10).build();
var allOrders = client.getHistoryOrderResult(orderHistory);
System.out.println(allOrders);
System.out.println(client.getOrderHistory(orderHistory));

// Get all real time orders
var openOrderRequest = TradeOrderRequest.builder().category(CategoryType.SPOT).build();
Expand All @@ -45,8 +43,15 @@ public static void main(String[] args) {
System.out.println(canceledOrder);

// Get Trade History
var executionRequest = TradeOrderRequest.builder().category(CategoryType.SPOT).build();
var executionData = client.getTradeHistory(executionRequest);
System.out.println(executionData);
var tradeHistoryRequest = TradeOrderRequest.builder().category(CategoryType.LINEAR).symbol("BTCUSDT").execType(ExecType.Trade).limit(100).build();
System.out.println(client.getTradeHistory(tradeHistoryRequest));

// Set DCP Options
var setDcpOptionsRequest = TradeOrderRequest.builder().timeWindow(40).build();
System.out.println(client.setDisconnectCancelAllTime(setDcpOptionsRequest));

// Get Borrow Quota
var getBorrowQuotaRequest = TradeOrderRequest.builder().category(CategoryType.SPOT).symbol("BTCUSDT").side(Side.BUY).build();
System.out.println(client.getBorrowQuota(getBorrowQuotaRequest));
}
}

0 comments on commit 2ce2535

Please sign in to comment.