Download Jar. Uses 15070K of libraries. Click here for Pure Java version (9272L/52K).
1 | !7 |
2 | |
3 | // from https://github.com/BitgetLimited/v3-bitget-api-sdk/blob/master/bitget-java-sdk-api/src/test/java/com/bitget/openapi/ws/BitgetWsClientTest.java |
4 | |
5 | lib 1400587 // BitGet Java SDK |
6 | |
7 | import com.bitget.openapi.ws.*; |
8 | |
9 | import com.alibaba.fastjson.JSON; |
10 | import com.alibaba.fastjson.JSONObject; |
11 | import com.bitget.openapi.dto.request.ws.SubscribeReq; |
12 | import org.junit.Before; |
13 | import org.junit.Test; |
14 | |
15 | public static final String PUSH_URL = "wss://ws.bitget.com/mix/v1/stream"; |
16 | |
17 | public static String API_KEY = ""; |
18 | public static String SECRET_KEY = ""; |
19 | public static String PASS_PHRASE = ""; |
20 | |
21 | |
22 | p { |
23 | API_KEY = args[0]; |
24 | SECRET_KEY = args[1]; |
25 | PASS_PHRASE = args[2]; |
26 | |
27 | BitgetWsClient client = BitgetWsHandle.builder() |
28 | .pushUrl(PUSH_URL) |
29 | .apiKey(API_KEY) |
30 | .secretKey(SECRET_KEY) |
31 | .passPhrase(PASS_PHRASE) |
32 | .isLogin(true) |
33 | //默认监听处理,如订阅时指定监听,默认不再接收该channel订阅信息 |
34 | .listener(response -> { |
35 | JSONObject json = JSONObject.parseObject(response); |
36 | System.out.println("def:" + json); |
37 | //失败消息的逻辑处理,如:订阅失败 |
38 | }).errorListener(response -> { |
39 | JSONObject json = JSONObject.parseObject(response); |
40 | System.out.println("error:" + json); |
41 | }).build(); |
42 | |
43 | |
44 | List<SubscribeReq> list = new ArrayList<SubscribeReq>() {{ |
45 | add(SubscribeReq.builder().instType("mc").channel("ticker").instId("BTCUSD").build()); |
46 | add(SubscribeReq.builder().instType("SP").channel("candle1W").instId("BTCUSDT").build()); |
47 | }}; |
48 | client.subscribe(list); |
49 | |
50 | List<SubscribeReq> list2 = new ArrayList<SubscribeReq>() {{ |
51 | |
52 | add(SubscribeReq.builder().instType("UMCBL").channel("account").instId("default").build()); |
53 | }}; |
54 | client.subscribe(list2, response -> { |
55 | JSONObject json = JSONObject.parseObject(response); |
56 | System.out.println("appoint:" + json); |
57 | }); |
58 | } |
download show line numbers debug dex old transpilations
Travelled to 2 computer(s): mqqgnosmbjvj, wnsclhtenguj
No comments. add comment
Snippet ID: | #1036024 |
Snippet name: | BitGet Java SDK WebSocket Test |
Eternal ID of this version: | #1036024/8 |
Text MD5: | 125d9c68402a5b627eb82c56e9019cd1 |
Transpilation MD5: | 4a97645559ac1a2b2a44713a561d4a72 |
Author: | stefan |
Category: | javax / networking |
Type: | JavaX source code (desktop) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2022-09-01 14:34:40 |
Source code size: | 2290 bytes / 58 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 233 / 707 |
Version history: | 7 change(s) |
Referenced in: | [show references] |