Skip to content

Commit 14b3573

Browse files
committed
update read me & message handler
1 parent 39517e1 commit 14b3573

Some content is hidden

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

44 files changed

+887
-30
lines changed

README.md

Lines changed: 36 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -40,29 +40,25 @@ Maven Example
4040
<dependency>
4141
<groupId>io.github.wuhewuhe</groupId>
4242
<artifactId>bybit-java-api</artifactId>
43-
<version>1.2.3</version>
43+
<version>1.2.4</version>
4444
</dependency>
4545
```
4646
Gradle Example
4747
```java
48-
implementation group: 'io.github.wuhewuhe', name: 'bybit-java-api', version: '1.2.3'
48+
implementation group: 'io.github.wuhewuhe', name: 'bybit-java-api', version: '1.2.4'
4949
```
5050
Furthermore, build tool, please check [sonar type central repository](https://central.sonatype.com/artifact/io.github.wuhewuhe/bybit-java-api/1.2.3)
5151

5252
## Release-Notes
53-
### HTTP Sync & Async Request
54-
- Position new endpoints: Move Positions and Get Move Positions History
55-
- Account new endpoint: Batch Set Collateral Coin
56-
- TradeOrderRequest add a new parameter: marketUnit
53+
### Websockets
54+
- Add WebSocketMessage handler class to all public and private channels
5755

5856
### Improvements
59-
- Fix Switch Position Mode Issue
57+
- public and private websocket channel set message handler
6058

6159
### Change Log
62-
- C:\Net\GithubProjects\open-api-sdk\bybit-java-api
63-
- Set Tp/SL and Set Risk Limit endpoints are deprecated
64-
- GetExecutionList move from PositionService to TradeService and rename to GetTradeHistory
65-
60+
- Spot Margin Trade endpoints are decrypted for classical users
61+
-
6662
## Usage
6763
Note: Replace placeholders (like YOUR_API_KEY, links, or other details) with the actual information. You can also customize this template to better fit the actual state and details of your Java API.
6864
### HttP Client Factory & Websocket Client
@@ -224,16 +220,42 @@ client.getPublicChannelStream(List.of("orderbook.50.BTCUSDT"), BybitApiConfig.V5
224220
client.getPublicChannelStream(List.of("orderbook.50.BTCUSDT","orderbook.1.ETHUSDT"), BybitApiConfig.V5_PUBLIC_LINEAR);
225221
```
226222

223+
- Ticker Subscribe
224+
```java
225+
var client = BybitApiClientFactory.newInstance(BybitApiConfig.STREAM_MAINNET_DOMAIN, true).newWebsocketClient();
226+
227+
client.setMessageHandler(message -> {
228+
var tickerData = (new ObjectMapper()).readValue(message, WebSocketTickerMessage.class);
229+
// Process message data here
230+
System.out.println("Websocket Message Data: " + tickerData.getData().toString());
231+
});
232+
233+
// Ticker
234+
client.getPublicChannelStream(List.of("tickers.BTCUSDT"), BybitApiConfig.V5_PUBLIC_LINEAR);
235+
```
236+
227237
### Websocket private channel
228-
- Order Subscribe
238+
- Position Subscribe
229239
```java
230-
var client = BybitApiClientFactory.newInstance("YOUR_API_KEY", "YOUR_API_SECRET", BybitApiConfig.STREAM_TESTNET_DOMAIN).newWebsocketClient(5, "60s", (message) -> System.out.println("Handle message :" + message));
240+
var client = BybitApiClientFactory.newInstance("YOUR_API_KEY", "YOUR_API_SECRET", BybitApiConfig.STREAM_TESTNET_DOMAIN).newWebsocketClient();
241+
231242
// Position
232-
// client.getOrderBookStream(List.of("position.linear"), BybitApiConfig.V5_PRIVATE);
243+
client.getPrivateChannelStream(List.of("position"), BybitApiConfig.V5_PRIVATE);
244+
```
245+
246+
- Order Channel active Message Handler & Max Alive Time & Ping Interval
247+
```java
248+
var client = BybitApiClientFactory.newInstance("YOUR_API_KEY", "YOUR_API_SECRET", BybitApiConfig.STREAM_TESTNET_DOMAIN, true)
249+
.newWebsocketClient(5, "60s", (message) -> {
250+
var orderMessage = (new ObjectMapper()).readValue(message, WebSocketOrderMessage.class);
251+
// Process message data here
252+
System.out.println("Websocket Message Data: " + orderMessage.getData().toString());
253+
});
233254

234255
// Order
235256
client.getPrivateChannelStream(List.of("order"), BybitApiConfig.V5_PRIVATE);
236257
```
258+
237259
## Contact
238260
For support, join our Bybit API community on [Telegram](https://t.me/Bybitapi).
239261

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
<groupId>io.github.wuhewuhe</groupId>
88
<artifactId>bybit-java-api</artifactId>
9-
<version>1.2.3</version>
9+
<version>1.2.4-SNAPSHOT</version>
1010
<name>bybit-java-api</name>
1111
<url>https://github.com/wuhewuhe/bybit-java-api</url>
1212

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package com.bybit.api.client.domain.websocket_message.private_channel;
2+
3+
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
4+
import lombok.Data;
5+
import lombok.NoArgsConstructor;
6+
7+
@Data
8+
@NoArgsConstructor
9+
@JsonIgnoreProperties(ignoreUnknown = true)
10+
public class CoinData {
11+
private String coin;
12+
private String equity;
13+
private String usdValue;
14+
private String walletBalance;
15+
private String free;
16+
private String locked;
17+
private String spotHedgingQty;
18+
private String borrowAmount;
19+
private String availableToBorrow;
20+
private String availableToWithdraw;
21+
private String accruedInterest;
22+
private String totalOrderIM;
23+
private String totalPositionIM;
24+
private String totalPositionMM;
25+
private String unrealisedPnl;
26+
private String cumRealisedPnl;
27+
private String bonus;
28+
private Boolean collateralSwitch;
29+
private Boolean marginCollateral;
30+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
package com.bybit.api.client.domain.websocket_message.private_channel;
2+
3+
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
4+
import lombok.Data;
5+
import lombok.NoArgsConstructor;
6+
7+
@Data
8+
@NoArgsConstructor
9+
@JsonIgnoreProperties(ignoreUnknown = true)
10+
public class ExecutionData {
11+
private String category;
12+
private String symbol;
13+
private String isLeverage;
14+
private String orderId;
15+
private String orderLinkId;
16+
private String side;
17+
private String orderPrice;
18+
private String orderQty;
19+
private String leavesQty;
20+
private String createType;
21+
private String orderType;
22+
private String stopOrderType;
23+
private String execFee;
24+
private String execId;
25+
private String execPrice;
26+
private String execQty;
27+
private String execType;
28+
private String execValue;
29+
private String execTime;
30+
private Boolean isMaker;
31+
private String feeRate;
32+
private String tradeIv;
33+
private String markIv;
34+
private String markPrice;
35+
private String indexPrice;
36+
private String underlyingPrice;
37+
private String blockTradeId;
38+
private String closedSize;
39+
private Long seq;
40+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package com.bybit.api.client.domain.websocket_message.private_channel;
2+
3+
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
4+
import lombok.Data;
5+
import lombok.NoArgsConstructor;
6+
7+
@Data
8+
@NoArgsConstructor
9+
@JsonIgnoreProperties(ignoreUnknown = true)
10+
public class GreekData {
11+
private String baseCoin;
12+
private String totalDelta;
13+
private String totalGamma;
14+
private String totalVega;
15+
private String totalTheta;
16+
}
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
package com.bybit.api.client.domain.websocket_message.private_channel;
2+
3+
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
4+
import lombok.Data;
5+
import lombok.NoArgsConstructor;
6+
7+
@Data
8+
@NoArgsConstructor
9+
@JsonIgnoreProperties(ignoreUnknown = true)
10+
public class OrderData {
11+
private String category;
12+
private String orderId;
13+
private String orderLinkId;
14+
private String isLeverage;
15+
private String blockTradeId;
16+
private String symbol;
17+
private String price;
18+
private String qty;
19+
private String side;
20+
private Integer positionIdx;
21+
private String orderStatus;
22+
private String createType;
23+
private String cancelType;
24+
private String rejectReason;
25+
private String avgPrice;
26+
private String leavesQty;
27+
private String leavesValue;
28+
private String cumExecQty;
29+
private String cumExecValue;
30+
private String cumExecFee;
31+
private String feeCurrency;
32+
private String timeInForce;
33+
private String orderType;
34+
private String stopOrderType;
35+
private String ocoTriggerType;
36+
private String orderIv;
37+
private String marketUnit;
38+
private String triggerPrice;
39+
private String takeProfit;
40+
private String stopLoss;
41+
private String tpslMode;
42+
private String tpLimitPrice;
43+
private String slLimitPrice;
44+
private String tpTriggerBy;
45+
private String slTriggerBy;
46+
private Integer triggerDirection;
47+
private String triggerBy;
48+
private String lastPriceOnCreated;
49+
private Boolean reduceOnly;
50+
private Boolean closeOnTrigger;
51+
private String placeType;
52+
private String smpType;
53+
private Integer smpGroup;
54+
private String smpOrderId;
55+
private String createdTime;
56+
private String updatedTime;
57+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
package com.bybit.api.client.domain.websocket_message.private_channel;
2+
3+
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
4+
import lombok.Data;
5+
import lombok.NoArgsConstructor;
6+
7+
@Data
8+
@NoArgsConstructor
9+
@JsonIgnoreProperties(ignoreUnknown = true)
10+
public class PositionData {
11+
private String category;
12+
private String symbol;
13+
private String side;
14+
private String size;
15+
private Integer positionIdx;
16+
private Integer tradeMode;
17+
private String positionValue;
18+
private Integer riskId;
19+
private String riskLimitValue;
20+
private String entryPrice;
21+
private String markPrice;
22+
private String leverage;
23+
private String positionBalance;
24+
private Integer autoAddMargin;
25+
private String positionMM;
26+
private String positionIM;
27+
private String liqPrice;
28+
private String bustPrice;
29+
private String tpslMode;
30+
private String takeProfit;
31+
private String stopLoss;
32+
private String trailingStop;
33+
private String unrealisedPnl;
34+
private String cumRealisedPnl;
35+
private String positionStatus;
36+
private Integer adlRankIndicator;
37+
private Boolean isReduceOnly;
38+
private String mmrSysUpdatedTime;
39+
private String leverageSysUpdatedTime;
40+
private String createdTime;
41+
private String updatedTime;
42+
private Long seq;
43+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package com.bybit.api.client.domain.websocket_message.private_channel;
2+
3+
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
4+
import lombok.Data;
5+
import lombok.NoArgsConstructor;
6+
7+
import java.util.List;
8+
9+
@Data
10+
@NoArgsConstructor
11+
@JsonIgnoreProperties(ignoreUnknown = true)
12+
public class WalletData {
13+
private String accountType;
14+
private String accountLTV;
15+
private String accountIMRate;
16+
private String accountMMRate;
17+
private String totalEquity;
18+
private String totalWalletBalance;
19+
private String totalMarginBalance;
20+
private String totalAvailableBalance;
21+
private String totalPerpUPL;
22+
private String totalInitialMargin;
23+
private String totalMaintenanceMargin;
24+
private List<CoinData> coin;
25+
26+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package com.bybit.api.client.domain.websocket_message.private_channel;
2+
3+
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
4+
import lombok.Data;
5+
6+
import java.util.List;
7+
8+
@Data
9+
@JsonIgnoreProperties(ignoreUnknown = true)
10+
public class WebSocketExecutionMessage {
11+
private String id;
12+
private String topic;
13+
private Long creationTime;
14+
private List<ExecutionData> data; // Assuming 'data' is an array of KlineData objects
15+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package com.bybit.api.client.domain.websocket_message.private_channel;
2+
3+
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
4+
import lombok.Data;
5+
6+
import java.util.List;
7+
8+
@Data
9+
@JsonIgnoreProperties(ignoreUnknown = true)
10+
public class WebSocketGreekMessage {
11+
private String id;
12+
private String topic;
13+
private Long creationTime;
14+
private List<GreekData> data; // Assuming 'data' is an array of KlineData objects
15+
}

0 commit comments

Comments
 (0)