-
Notifications
You must be signed in to change notification settings - Fork 236
Expand file tree
/
Copy pathBitgetWsClientTest.java
More file actions
46 lines (41 loc) · 1.97 KB
/
Copy pathBitgetWsClientTest.java
File metadata and controls
46 lines (41 loc) · 1.97 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
package com.bitget.openapi.ws;
import com.alibaba.fastjson.JSONObject;
import com.bitget.openapi.common.enums.SignTypeEnum;
import com.bitget.openapi.dto.request.ws.SubscribeReq;
import java.net.InetSocketAddress;
import java.net.Proxy;
import java.util.ArrayList;
import java.util.List;
public class BitgetWsClientTest {
public static final String PUSH_URL = "wss://wspap.bitget.com/mix/v1/stream";
public static final String API_KEY = "";
public static final String SECRET_KEY = "";
public static final String PASS_PHRASE = "";
public static final String PROXY_HOST = "localhost";
public static final int PROXY_PORT = 10808;
public static void main(String[] args) {
BitgetWsClient client = BitgetWsHandle.builder()
.pushUrl(PUSH_URL)
.apiKey(API_KEY)
.secretKey(SECRET_KEY)
.passPhrase(PASS_PHRASE)
.proxy(Proxy.Type.HTTP,PROXY_HOST, PROXY_PORT)
// .signType(SignTypeEnum.RSA)
.isLogin(true)
//默认监听处理,如订阅时指定监听,默认不再接收该channel订阅信息
.listener(response -> {
JSONObject json = JSONObject.parseObject(response);
System.out.println("def:" + json);
//失败消息的逻辑处理,如:订阅失败
}).errorListener(response -> {
JSONObject json = JSONObject.parseObject(response);
System.out.println("error:" + json);
}).build();
List<SubscribeReq> list = new ArrayList<SubscribeReq>() {{
// add(SubscribeReq.builder().instType("UMCBL").channel("positions").instId("default").build());
add(SubscribeReq.builder().instType("mc").channel("ticker").instId("ETHUSDT").build());
// add(SubscribeReq.builder().instType("SP").channel("candle1W").instId("BTCUSDT").build());
}};
client.subscribe(list);
}
}