Skip to content

Commit b47247b

Browse files
Merge branch '2.2.0' into 'master'
2.2.0 Improvements(websocket and add examples) See merge request exchange/code/sdk/bitmart-java-sdk-api!22
2 parents 64c8e97 + fe86697 commit b47247b

37 files changed

Lines changed: 972 additions & 374 deletions

CHANGELOG.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,24 @@ Changelog
33
=========================
44

55

6+
### v2.2.0 Release
7+
#### New Features
8+
- New
9+
- `/contract/private/trade-fee-rate` Support querying trade fee rate(KEYED)
10+
#### Improvements
11+
- Add GlobalConst.CLOUD_V2_URL=`https://api-cloud-v2.bitmart.com`
12+
- Optimize websocket
13+
- The ping/pong mechanism of the spot websocket has been modified to support `ping` text
14+
- The `send` function replaces the `subscribe` function and can be used to subscribe and unsubscribe
15+
- Remove the `isDebug` function and `isPrint` variable, and use the `log level` to set debug instead
16+
- Upgrading dependencies with vulnerabilities
17+
- com.squareup.okhttp3 has been upgraded to 4.11.0
18+
- io.netty has been upgraded to 4.1.114.Final
19+
- org.bouncycastle has been upgraded to 1.70
20+
- ch.qos.logback has been upgraded to 1.2.13
21+
22+
---
23+
624
### v2.1.0 Release
725
#### New Features
826
- New

README.md

Lines changed: 127 additions & 93 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ BitMart-Java-SDK-API
44
=========================
55
[![Maven Central](https://img.shields.io/maven-central/v/io.github.bitmartexchange/bitmart-java-sdk-api)](https://repo1.maven.org/maven2/io/github/bitmartexchange/bitmart-java-sdk-api/)
66
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
7+
[![Telegram](https://img.shields.io/badge/Telegram-Join%20Us-blue?logo=Telegram)](https://t.me/bitmart_api)
78

89

910
[BitMart Exchange](https://bitmart.com) official Java client for the BitMart Cloud API.
@@ -16,17 +17,18 @@ Feature
1617
- Efficiency, higher speeds, and lower latencies
1718
- Priority in development and maintenance
1819
- Dedicated and responsive technical support
19-
- Provide webSocket apis calls
2020
- Supported APIs:
2121
- `/spot/*`
2222
- `/contract/*`
2323
- `/account/*`
24+
- Supported websockets:
2425
- Spot WebSocket Market Stream
2526
- Spot User Data Stream
26-
- Contract User Data Stream
27-
- Contract WebSocket Market Stream
27+
- futures User Data Stream
28+
- futures WebSocket Market Stream
2829
- Test cases and examples
2930

31+
3032
Installation
3133
=========================
3234
Copy and paste the following dependency snippet into your `pom.xml` file, replacing `LATEST_VERSION` with the most [recent version](https://mvnrepository.com/artifact/io.github.bitmartexchange/bitmart-java-sdk-api) available:
@@ -68,11 +70,11 @@ public class Market {
6870
System.out.println(cloudResponse.getResponseContent());
6971

7072
// Get Ticker of All Pairs (V3)
71-
cloudResponse =call.callCloud(new V3TickersRequest());
73+
cloudResponse = call.callCloud(new V3TickersRequest());
7274
System.out.println(cloudResponse.getResponseContent());
7375

7476
// Get Depth (V3)
75-
cloudResponse =call.callCloud(new V3DepthRequest().setSymbol("BTC_USDT").setLimit(10));
77+
cloudResponse = call.callCloud(new V3DepthRequest().setSymbol("BTC_USDT").setLimit(10));
7678
System.out.println(cloudResponse.getResponseContent());
7779

7880
// Get Latest K-Line (V3)
@@ -91,6 +93,7 @@ public class Market {
9193
```
9294

9395
#### Spot Trade API Example
96+
9497
```java
9598
import com.bitmart.api.Call;
9699
import com.bitmart.api.CloudContext;
@@ -125,36 +128,43 @@ public class TestSpotTrading {
125128
}
126129
```
127130

128-
* More Spot API Example: [TestSpot.java](https://github.com/bitmartexchange/bitmart-java-sdk-api/blob/master/src/test/java/com/bitmart/api/TestSpot.java)
131+
* Please find [examples/spot](https://github.com/bitmartexchange/bitmart-java-sdk-api/tree/master/src/test/java/com/bitmart/examples/spot) folder to check for more endpoints.
132+
129133

130134
---
131135

132136
#### Spot WebSocket Public Channel Example
133-
```java
134-
public class TestWebSocket {
135137

136-
public static void main(String[] args) throws Exception {
138+
```java
139+
import com.bitmart.api.common.CloudException;
140+
import com.bitmart.api.key.CloudKey;
141+
import com.bitmart.websocket.ContractWebSocket;
142+
import com.bitmart.websocket.OpParam;
143+
import com.bitmart.websocket.WebSocketCallBack;
144+
import com.google.common.collect.ImmutableList;
145+
import lombok.extern.slf4j.Slf4j;
137146

138-
// 1.Connection
139-
WebSocketClient webSocketClient = new WebSocketClient(
140-
"wss://ws-manager-compress.bitmart.com/api?protocol=1.1", new ReceiveMessage());
147+
import static com.bitmart.api.common.GlobalConst.CLOUD_WS_URL;
141148

142-
// 2. send subscribe message
143-
webSocketClient.subscribe(ImmutableList.of(
149+
@Slf4j
150+
public class Ticker {
151+
public static class ReceiveMessage extends WebSocketCallBack {
152+
@Override
153+
public void onMessage(String text) {
154+
log.info("onMessage------>{}", text);
155+
}
156+
}
144157

145-
// public channel
146-
"spot/ticker:BTC_USDT",
147-
"spot/kline1m:BTC_USDT",
148-
"spot/depth5:BTC_USDT",
149-
"spot/trade:BTC_USDT"
150-
));
158+
public static void main(String[] args) {
159+
try {
160+
ContractWebSocket webSocketClient = new ContractWebSocket(CLOUD_WS_URL,
161+
new CloudKey(), new ReceiveMessage());
151162

152-
}
163+
// Ticker Channel
164+
webSocketClient.send(new OpParam().setOp("subscribe").setArgs(ImmutableList.of("spot/ticker:BTC_USDT")));
153165

154-
public class ReceiveMessage extends WebSocketCallBack {
155-
@Override
156-
public void onMessage(String text) {
157-
System.out.println(text);
166+
} catch (CloudException e) {
167+
log.error("CloudException: {}", e.getMessage());
158168
}
159169

160170
}
@@ -163,45 +173,52 @@ public class TestWebSocket {
163173
```
164174

165175
#### Spot WebSocket Private Channel Example
166-
```java
167-
public class TestWebSocket {
168176

169-
private static String API_KEY = "YOUR ACCESS KEY";
170-
private static String API_SECRET = "YOUR SECRET KEY";
171-
private static String API_MEMO = "YOUR MEMO";
177+
```java
178+
import com.bitmart.api.common.CloudException;
179+
import com.bitmart.api.common.GlobalConst;
180+
import com.bitmart.api.key.CloudKey;
181+
import com.bitmart.websocket.OpParam;
182+
import com.bitmart.websocket.WebSocketCallBack;
183+
import com.bitmart.websocket.WebSocketClient;
184+
import com.google.common.collect.ImmutableList;
185+
import lombok.extern.slf4j.Slf4j;
172186

173-
public static void main(String[] args) throws Exception {
187+
@Slf4j
188+
public class BalanceChange {
174189

175-
// 1.Connection
176-
WebSocketClient webSocketClient = new WebSocketClient(
177-
"wss://ws-manager-compress.bitmart.com/user?protocol=1.1", new ReceiveMessage());
190+
private static final String API_KEY = "your_api_key";
191+
private static final String API_SECRET = "your_secret_key";
192+
private static final String API_MEMO = "your_memo";
178193

179-
// 2. login
180-
webSocketClient.login();
194+
public static class ReceiveMessage extends WebSocketCallBack {
195+
@Override
196+
public void onMessage(String text) {
197+
log.info("onMessage------>{}", text);
198+
}
181199

182-
Thread.sleep(2000L); // wait login
200+
}
183201

184-
// 3. send subscribe message
185-
webSocketClient.subscribe(ImmutableList.of(
202+
public static void main(String[] args) {
203+
try {
204+
WebSocketClient webSocketClient = new WebSocketClient(GlobalConst.CLOUD_WS_PRIVATE_URL,
205+
new CloudKey(API_KEY, API_SECRET, API_MEMO), new ReceiveMessage());
186206

187-
// private channel
188-
"spot/user/order:BTC_USDT"
189-
));
207+
// need login
208+
webSocketClient.login();
190209

191-
}
210+
// subscribe private channel
211+
webSocketClient.send(new OpParam().setOp("subscribe").setArgs(ImmutableList.of("spot/user/balance:BALANCE_UPDATE")));
192212

193-
public class ReceiveMessage extends WebSocketCallBack {
194-
@Override
195-
public void onMessage(String text) {
196-
System.out.println(text);
213+
} catch (CloudException e) {
214+
log.error("CloudException: {}", e.getMessage());
197215
}
198216

199217
}
200218
}
201-
202219
```
203220

204-
* More Spot Websocket Example: [TestWebSocket.java](https://github.com/bitmartexchange/bitmart-java-sdk-api/blob/master/src/test/java/com/bitmart/websocket/TestSpotWebSocket.java)
221+
* Please find [examples/spot/websocket](https://github.com/bitmartexchange/bitmart-java-sdk-api/tree/master/src/test/java/com/bitmart/examples/spot/websocket) folder to check for more endpoints.
205222

206223

207224

@@ -249,7 +266,7 @@ public class TestFuturesMarket {
249266
}
250267
```
251268

252-
#### Futures API Example
269+
#### Futures Trade API Example
253270

254271
```java
255272
import com.bitmart.api.Call;
@@ -288,86 +305,103 @@ public class TestFuturesTrading {
288305
}
289306
```
290307

291-
* More Futures API Example: [TestContract.java](https://github.com/bitmartexchange/bitmart-java-sdk-api/blob/master/src/test/java/com/bitmart/api/TestContract.java)
308+
* Please find [examples/futures](https://github.com/bitmartexchange/bitmart-java-sdk-api/tree/master/src/test/java/com/bitmart/examples/futures) folder to check for more endpoints.
309+
292310

293311
---
294312

295313
#### Futures WebSocket Public Channel Example
296314

297315
```java
298-
public class TestContractWebSocket {
299316

300-
public static void main(String[] args) throws Exception {
317+
import com.bitmart.api.common.CloudException;
318+
import com.bitmart.api.key.CloudKey;
319+
import com.bitmart.websocket.ContractWebSocket;
320+
import com.bitmart.websocket.WebSocketCallBack;
321+
import com.bitmart.websocket.contract.ActionParam;
322+
import com.google.common.collect.ImmutableList;
323+
import lombok.extern.slf4j.Slf4j;
301324

302-
// 1.Connection
303-
ContractWebSocket webSocketClient = new ContractWebSocket(
304-
"wss://openapi-ws.bitmart.com/api?protocol=1.1", new ReceiveMessage());
325+
import static com.bitmart.api.common.GlobalConst.CLOUD_CONTRACT_WS_URL;
305326

306-
// 2. send subscribe message
307-
webSocketClient.subscribe(ImmutableList.of(
327+
@Slf4j
328+
public class Ticker {
308329

309-
// public channel
310-
"futures/ticker:BTCUSDT",
311-
"futures/depth20:BTCUSDT",
312-
"futures/trade:BTCUSDT",
313-
"futures/klineBin1m:BTCUSDT"
314-
));
330+
public static class ReceiveMessage extends WebSocketCallBack {
331+
@Override
332+
public void onMessage(String text) {
333+
log.info("onMessage------>{}", text);
334+
}
315335

316336
}
337+
public static void main(String[] args) {
338+
try {
339+
ContractWebSocket webSocketClient = new ContractWebSocket(CLOUD_CONTRACT_WS_URL,
340+
new CloudKey(), new ReceiveMessage());
317341

318-
public class ReceiveMessage extends WebSocketCallBack {
319-
@Override
320-
public void onMessage(String text) {
321-
System.out.println(text);
342+
// Ticker Channel
343+
webSocketClient.send(new ActionParam().setAction("subscribe").setArgs(ImmutableList.of("futures/ticker")));
344+
345+
} catch (CloudException e) {
346+
log.error("CloudException: {}", e.getMessage());
322347
}
323348

324349
}
325350
}
326-
327351
```
328352

329353
#### Futures WebSocket Private Channel Example
330354

331355
```java
332-
public class TestContractWebSocket {
333356

334-
private static String API_KEY = "YOUR ACCESS KEY";
335-
private static String API_SECRET = "YOUR SECRET KEY";
336-
private static String API_MEMO = "YOUR MEMO";
357+
import com.bitmart.api.common.CloudException;
358+
import com.bitmart.api.key.CloudKey;
359+
import com.bitmart.websocket.ContractWebSocket;
360+
import com.bitmart.websocket.WebSocketCallBack;
361+
import com.bitmart.websocket.contract.ActionParam;
362+
import com.google.common.collect.ImmutableList;
363+
import lombok.extern.slf4j.Slf4j;
337364

338-
public static void main(String[] args) throws Exception {
365+
import static com.bitmart.api.common.GlobalConst.CLOUD_CONTRACT_WS_PRIVATE_URL;
339366

340-
// 1.Connection
341-
ContractWebSocket webSocketClient = new ContractWebSocket(
342-
"wss://openapi-ws.bitmart.com/user?protocol=1.1", new ReceiveMessage());
367+
@Slf4j
368+
public class Assets {
343369

344-
// 2. login
345-
webSocketClient.login();
370+
private static final String API_KEY = "your_api_key";
371+
private static final String API_SECRET = "your_secret_key";
372+
private static final String API_MEMO = "your_memo";
346373

347-
Thread.sleep(2000L); // wait login
374+
public static class ReceiveMessage extends WebSocketCallBack {
375+
@Override
376+
public void onMessage(String text) {
377+
log.info("onMessage------>{}", text);
378+
}
348379

349-
// 3. send subscribe message
350-
webSocketClient.subscribe(ImmutableList.of(
380+
}
381+
public static void main(String[] args) {
382+
try {
383+
ContractWebSocket webSocketPrivateClient = new ContractWebSocket(CLOUD_CONTRACT_WS_PRIVATE_URL,
384+
new CloudKey(API_KEY, API_SECRET, API_MEMO), new ReceiveMessage());
351385

352-
// private channel
353-
"futures/asset:BTC",
354-
"futures/position",
355-
"futures/order"
356-
));
386+
// login
387+
webSocketPrivateClient.login();
357388

358-
}
389+
// subscribe private channel
390+
webSocketPrivateClient.send(new ActionParam().setAction("subscribe").setArgs(ImmutableList.of("futures/asset:USDT")));
391+
webSocketPrivateClient.send(new ActionParam().setAction("subscribe").setArgs(ImmutableList.of("futures/position")));
392+
webSocketPrivateClient.send(new ActionParam().setAction("subscribe").setArgs(ImmutableList.of("futures/order")));
359393

360-
public class ReceiveMessage extends WebSocketCallBack {
361-
@Override
362-
public void onMessage(String text) {
363-
System.out.println(text);
394+
} catch (CloudException e) {
395+
log.error("CloudException: {}", e.getMessage());
364396
}
365397

366398
}
367399
}
368400

369401
```
370-
* More Futures Websocket Example: [TestContractWebSocket.java](https://github.com/bitmartexchange/bitmart-java-sdk-api/blob/master/src/test/java/com/bitmart/websocket/TestFuturesWebSocket.java)
402+
403+
* Please find [examples/futures/websocket](https://github.com/bitmartexchange/bitmart-java-sdk-api/tree/master/src/test/java/com/bitmart/examples/futures/websocket) folder to check for more endpoints.
404+
371405

372406

373407
### Logging

0 commit comments

Comments
 (0)