8000 update test case · coderhxt/bitmax-client-api@9157440 · GitHub
[go: up one dir, main page]

Skip to content

Commit 9157440

Browse files
author
xiaotian.huang
committed
update test case
1 parent f940676 commit 9157440

File tree

6 files changed

+156
-10
lines changed

6 files changed

+156
-10
lines changed
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
package com.bitmax.api.client.domain.event;
2+
3+
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
4+
import com.fasterxml.jackson.annotation.JsonProperty;
5+
import lombok.Getter;
6+
import lombok.Setter;
7+
8+
/**
9+
* @author xiaotian.huang
10+
* @date 2019-05-24
11+
*/
12+
@Setter @Getter
13+
@JsonIgnoreProperties(ignoreUnknown = true)
14+
public class OrderUpdate {
15+
@JsonProperty("m")
16+
private String messageType;
17+
private String execId;
18+
private String coid;
19+
private String origCoid;
20+
private String orderType;
21+
@JsonProperty("s")
22+
private String symbol;
23+
@JsonProperty("t")
24+
private long time;
25+
@JsonProperty("p")
26+
private String orderPrice;
27+
@JsonProperty("q")
28+
private String orderQty;
29+
private String l;
30+
@JsonProperty("f")
31+
private String filledQty;
32+
@JsonProperty("ap")
33+
private String avgPrice;
34+
@JsonProperty("bb")
35+
private String baseAssetTotalBalance;
36+
@JsonProperty("bpb")
37+
private String baseAssetPendingBalance;
38+
@JsonProperty("qb")
39+
private String quoteAssetTotalBalance;
40+
@JsonProperty("qpb")
41+
private String quoteAssetPendingBalance;
42+
private String fee;
43+
@JsonProperty("fa")
44+
private String feeAssset;
45+
private String bc;
46+
private String btmxBal;
47+
private String side;
48+
private String status;
49+
private String errorCode;
50+
@JsonProperty("cat")
51+
private String accountCategory;
52+
@JsonProperty("ei")
53+
private String executionInstruction;
54+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package com.bitmax.api.client.impl;
2+
3+
import com.bitmax.api.client.domain.event.OrderUpdate;
4+
import com.bitmax.api.client.util.ObjectMapperPlus;
5+
import com.fasterxml.jackson.core.type.TypeReference;
6+
import com.fasterxml.jackson.databind.JsonNode;
7+
8+
/**
9+
* @author xiaotian.huang
10+
* @date 2019-05-24
11+
*/
12+
public class BitmaxMsgHandler {
13+
14+
private static final ObjectMapperPlus mapperPlus;
15+
16+
static {
17+
mapperPlus = ObjectMapperPlus.newInstance();
18+
}
19+
20+
public static void handleOrderUpdate(String msg) {
21+
JsonNode node = mapperPlus.findNode(msg, "m");
22+
if (node != null && "order".equals(node.asText())) {
23+
OrderUpdate orderUpdate = mapperPlus.readValue(msg, new TypeReference<OrderUpdate>(){});
24+
System.out.println(mapperPlus.writeValueAsString(orderUpdate));
25+
}
26+
System.out.println("msg: " + msg);
27+
}
28+
}
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
package com.bitmax.api.client.util;
2+
3+
import com.fasterxml.jackson.core.type.TypeReference;
4+
import com.fasterxml.jackson.databind.JsonNode;
5+
import com.fasterxml.jackson.databind.ObjectMapper;
6+
7+
import java.io.IOException;
8+
9+
/**
10+
* @author xiaotian.huang
11+
* @date 2019-05-24
12+
*/
13+
public class ObjectMapperPlus extends ObjectMapper {
14+
15+
private static final ObjectMapperPlus mapperPlus;
16+
17+
static {
18+
mapperPlus = new ObjectMapperPlus();
19+
}
20+
21+
private ObjectMapperPlus() {
22+
}
23+
24+
public static ObjectMapperPlus newInstance() {
25+
if (mapperPlus != null) {
26+
return mapperPlus;
27+
} else {
28+
throw new RuntimeException("plus实例化失败");
29+
}
30+
}
31+
32+
@Override
33+
public String writeValueAsString(Object value) {
34+
String json;
35+
try {
36+
json = super.writeValueAsString(value);
37+
} catch (IOException e) {
38+
throw new RuntimeException("ObjectMapper序列化异常", e);
39+
}
40+
return json;
41+
}
42+
43+
@Override
44+
public <T> T readValue(String content, TypeReference valueTypeRef) {
45+
T t;
46+
try {
47+
t = super.readValue(content, valueTypeRef);
48+
} catch (IOException e) {
49+
throw new RuntimeException("ObjectMapper反序列化异常",e);
50+
}
51+
return t;
52+
}
53+
54+
public JsonNode findNode(String content, String key) {
55+
try {
56+
JsonNode node = super.readTree(content);
57+
return node.findValue(key);
58+
} catch (IOException e) {
59+
throw new RuntimeException("ObjectMapper操作抛出异常", e);
60+
}
61+
}
62+
}

src/test/java/com/bitmax/api/client/impl/BitmaxApiRestClientImplTest.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,18 @@
33
import com.bitmax.api.client.BaseTest;
44
import com.bitmax.api.client.BitmaxApiClientFactory;
55
import com.bitmax.api.client.BitmaxApiRestClient;
6+
import com.bitmax.api.client.domain.DepositAddressResp;
67
import com.bitmax.api.client.domain.*;
78
import com.bitmax.api.client.util.OrderIdWorker;
89
import org.junit.Before;
10+
import org.junit.Ignore;
911
import org.junit.Test;
1012

1113
import java.util.Arrays;
1214
import java.util.List;
1315
import java.util.Map;
1416

17+
@Ignore
1518
public class BitmaxApiRestClientImplTest extends BaseTest {
1619

1720
BitmaxApiRestClient bitmaxApiRestClient;
@@ -129,9 +132,9 @@ public void depositWithdrawHistory() {
129132

130133
@Test
131134
public void placeNewOrder() {
132-
OrderReq orderReq = OrderReq.builder().coid("cash05001")
135+
OrderReq orderReq = OrderReq.builder().coid("cash05003")
133136
.time(System.currentTimeMillis())
134-
.orderPrice("7001")
137+
.orderPrice("7002")
135138
// .stopPrice("15.7")
136139
.orderQty("0.002")
137140
.orderType("limit")
@@ -178,8 +181,8 @@ public void placingMultipleOrdersFromTheCashAccount() {
178181

179182
@Test
180183
public void cancelOrder() {
181-
CancelOrderReq cancelOrderReq = CancelOrderReq.builder().coid("cash123123")
182-
.origCoid("cash05001")
184+
CancelOrderReq cancelOrderReq = CancelOrderReq.builder().coid("cash123126")
185+
.origCoid("cash05002")
183186
.symbol("ETH/BTC")
184187
.time(System.currentTimeMillis())
185188
.build();

src/test/java/com/bitmax/api/client/security/JavaAuthClientTest.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
package com.bitmax.api.client.security;
22

3+
import org.junit.Ignore;
34
import org.junit.Test;
45

6+
@Ignore
57
public class JavaAuthClientTest {
68

79
@Test

src/test/java/com/bitmax/api/client/websocket/BitmaxOrderManageWebSocketExample.java

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import com.bitmax.api.client.BitmaxApiClientFactory;
44
import com.bitmax.api.client.BitmaxApiWebSocketClient;
55
import com.bitmax.api.client.domain.WebSocketType;
6+
import com.bitmax.api.client.impl.BitmaxMsgHandler;
67
import com.bitmax.api.client.impl.BitmaxWebSocketBootStrap;
78

89
/**
@@ -14,14 +15,10 @@ public class BitmaxOrderManageWebSocketExample {
1415
public static void main(String[] args) {
1516
BitmaxApiWebSocketClient socketClient = BitmaxApiClientFactory.newInstance("your-api-key",
1617
"your-secret").newWebSocketClient();
17-
String symbol = "ETH-BTC";
18+
String symbol = "BTC-USDT";
1819
// 订阅order manage
1920
BitmaxWebSocketBootStrap bootStrap = new BitmaxWebSocketBootStrap(WebSocketType.ORDER, socketClient,
20-
symbol, null, 2, response -> {
21-
System.out.println(response);
22-
}, logMsg -> {
23-
System.out.println(logMsg);
24-
});
21+
symbol, null, 2, BitmaxMsgHandler::handleOrderUpdate, System.out::println);
2522
bootStrap.start();
2623
}
2724
}

0 commit comments

Comments
 (0)
0