From 8a23f9581722b001c8f6071755c62da6bba592b9 Mon Sep 17 00:00:00 2001
From: eynzhang <2427928+eynzhang@users.noreply.github.com>
Date: Wed, 22 Apr 2020 11:02:37 +0800
Subject: [PATCH] Update to v1.0.13
1. Add performance test
2. Add orders update event (v2)
3. Refactor: rename market full MBP event
4. Delete CHANGE_LOG section in READE as it is duplicate with CHANGE_LOG and Github releases module
---
README.md | 37 +---
pom.xml | 2 +-
.../com/huobi/client/SubscriptionClient.java | 14 +-
.../impl/WebSocketStreamClientImpl.java | 17 +-
.../client/impl/WebsocketRequestImpl.java | 57 +++++-
.../com/huobi/client/impl/utils/Channels.java | 25 ++-
...vent.java => MarketDepthFullMBPEvent.java} | 2 +-
.../model/event/OrdersCancellationEvent.java | 26 +++
.../model/event/OrdersCreationEvent.java | 46 +++++
.../client/model/event/OrdersTradeEvent.java | 76 ++++++++
.../client/model/event/OrdersUpdateEvent.java | 58 ++++++
.../model/request/OrderChangeRequest.java | 15 ++
.../com/huobi/client/PerformanceTest.java | 165 ++++++++++++++++++
.../SubscribeFullMarketMBPEventTest.java | 35 ----
.../examples/SubscribeMarketDepthFullMBP.java | 19 ++
.../client/examples/SubscribeOrderUpdate.java | 15 +-
16 files changed, 514 insertions(+), 95 deletions(-)
rename src/main/java/com/huobi/client/model/event/{FullMarketDepthMBPEvent.java => MarketDepthFullMBPEvent.java} (93%)
create mode 100644 src/main/java/com/huobi/client/model/event/OrdersCancellationEvent.java
create mode 100644 src/main/java/com/huobi/client/model/event/OrdersCreationEvent.java
create mode 100644 src/main/java/com/huobi/client/model/event/OrdersTradeEvent.java
create mode 100644 src/main/java/com/huobi/client/model/event/OrdersUpdateEvent.java
create mode 100644 src/main/java/com/huobi/client/model/request/OrderChangeRequest.java
create mode 100644 src/test/java/com/huobi/client/PerformanceTest.java
delete mode 100644 src/test/java/com/huobi/client/examples/SubscribeFullMarketMBPEventTest.java
create mode 100644 src/test/java/com/huobi/client/examples/SubscribeMarketDepthFullMBP.java
diff --git a/README.md b/README.md
index 802f3972..0558120a 100644
--- a/README.md
+++ b/README.md
@@ -5,39 +5,15 @@ This is Huobi Java SDK, This is a lightweight Java library, you can import to yo
The SDK supports both synchronous and asynchronous RESTful API invoking, and subscribe the market data from the Websocket connection.
+## Huobi Java SDK Releases
-## Huobi Java SDK (change log)
-[Java SDK Change Log](https://github.com/HuobiRDCenter/huobi_Java/blob/master/CHANGE_LOG.md)
-
-
-## Huobi Java SDK Download
-
-- [Huobi Global API Java SDK version 1.0.11](https://github.com/HuobiRDCenter/huobi_Java/releases/tag/1.0.11)
-
-- [Huobi Global API Java SDK version 1.0.10](https://github.com/HuobiRDCenter/huobi_Java/releases/tag/1.0.10)
-
-- [Huobi Global API Java SDK version 1.0.9](https://github.com/HuobiRDCenter/huobi_Java/releases/tag/1.0.9)
-
-- [Huobi Global API Java SDK version 1.0.8](https://github.com/HuobiRDCenter/huobi_Java/releases/tag/1.0.8)
-
-- [Huobi Global API Java SDK version 1.0.7](https://github.com/HuobiRDCenter/huobi_Java/releases/tag/1.0.7)
-
-- [Huobi Global API Java SDK version 1.0.6](https://github.com/HuobiRDCenter/huobi_Java/releases/tag/1.0.6)
-
-- [Huobi Global API Java SDK version 1.0.5](https://github.com/HuobiRDCenter/huobi_Java/releases/tag/1.0.5)
-
-- [Huobi Global API Java SDK version 1.0.4](https://github.com/HuobiRDCenter/huobi_Java/releases/tag/1.0.4)
-
-- [Huobi Global API Java SDK version 1.0.3](https://github.com/HuobiRDCenter/huobi_Java/releases/tag/1.0.3)
-
-- [Huobi Global API Java SDK version 1.0.2](https://github.com/HuobiRDCenter/huobi_Java/releases/tag/1.0.2)
-
-- [Huobi Global API Java SDK version 1.0.1](https://github.com/HuobiRDCenter/huobi_Java/releases/tag/1.0.1)
+Go to [Releases](https://github.com/HuobiRDCenter/huobi_Java/releases) page to view and download each release.
## Table of Contents
- [Beginning](#Beginning)
+
- [Installation](#Installation)
- [Quick Start](#Quick-Start)
- [Request vs. Subscription](#request-vs.-subscription)
@@ -800,11 +776,8 @@ subscriptionClient.subscribeOrderUpdateEvent("btcusdt", (orderEvent) -> {
```java
// Subscribe account change.
-subscriptionClient.subscribeAccountEvent(BalanceMode.AVAILABLE, (accountEvent) -> {
- for (AccountChange change : accountEvent.getData()) {
- System.out.println(change.getAccountType());
- System.out.println("Balance: " + change.getBalance());
- }
+subscriptionClient.subscribeAccountChangeV2Event(AccountChangeModeEnum.TOTAL, (event) -> {
+ System.out.println("===>"+ JSON.toJSONString(event));
});
```
diff --git a/pom.xml b/pom.xml
index eb31578a..8880f7c5 100644
--- a/pom.xml
+++ b/pom.xml
@@ -6,7 +6,7 @@
com.huobi.sdk
huobi-client
- 1.0.12-SNAPSHOT
+ 1.0.13-SNAPSHOT
1.8
diff --git a/src/main/java/com/huobi/client/SubscriptionClient.java b/src/main/java/com/huobi/client/SubscriptionClient.java
index 41740b18..1d4c82c1 100644
--- a/src/main/java/com/huobi/client/SubscriptionClient.java
+++ b/src/main/java/com/huobi/client/SubscriptionClient.java
@@ -11,7 +11,7 @@
import com.huobi.client.model.event.AccountListEvent;
import com.huobi.client.model.event.CandlestickEvent;
import com.huobi.client.model.event.CandlestickReqEvent;
-import com.huobi.client.model.event.FullMarketDepthMBPEvent;
+import com.huobi.client.model.event.MarketDepthFullMBPEvent;
import com.huobi.client.model.event.MarketBBOEvent;
import com.huobi.client.model.event.MarketDepthMBPEvent;
import com.huobi.client.model.event.OrderListEvent;
@@ -21,6 +21,7 @@
import com.huobi.client.model.event.TradeClearingEvent;
import com.huobi.client.model.event.TradeEvent;
import com.huobi.client.model.event.TradeStatisticsEvent;
+import com.huobi.client.model.event.OrdersUpdateEvent;
import com.huobi.client.model.request.OrdersRequest;
/***
@@ -467,7 +468,16 @@ void request24HTradeStatisticsEvent(String symbols, boolean autoClose,
void requestAccountListEvent(boolean autoClose, SubscriptionListener callback,
SubscriptionErrorHandler errorHandler);
- void subscribeFullMarketDepthMBP(String symbol, MBPLevelEnums level, SubscriptionListener callback);
+ /**
+ * when the order status is changed, the order change event will be triggered
+ * @param symbol
+ * @param listener
+ * @param errorHandler
+ */
+ void subscribeOrderChangeEvent(String symbol, SubscriptionListener listener,
+ SubscriptionErrorHandler errorHandler);
+
+ void subscribeMarketDepthFullMBP(String symbol, MBPLevelEnums level, SubscriptionListener callback);
void subscribeMarketDepthMBP(String symbol, MBPLevelEnums level, SubscriptionListener callback);
diff --git a/src/main/java/com/huobi/client/impl/WebSocketStreamClientImpl.java b/src/main/java/com/huobi/client/impl/WebSocketStreamClientImpl.java
index ff61b41a..909574d4 100644
--- a/src/main/java/com/huobi/client/impl/WebSocketStreamClientImpl.java
+++ b/src/main/java/com/huobi/client/impl/WebSocketStreamClientImpl.java
@@ -19,7 +19,7 @@
import com.huobi.client.model.event.AccountListEvent;
import com.huobi.client.model.event.CandlestickEvent;
import com.huobi.client.model.event.CandlestickReqEvent;
-import com.huobi.client.model.event.FullMarketDepthMBPEvent;
+import com.huobi.client.model.event.MarketDepthFullMBPEvent;
import com.huobi.client.model.event.MarketBBOEvent;
import com.huobi.client.model.event.MarketDepthMBPEvent;
import com.huobi.client.model.event.OrderListEvent;
@@ -29,6 +29,7 @@
import com.huobi.client.model.event.TradeClearingEvent;
import com.huobi.client.model.event.TradeEvent;
import com.huobi.client.model.event.TradeStatisticsEvent;
+import com.huobi.client.model.event.OrdersUpdateEvent;
import com.huobi.client.model.request.OrdersRequest;
public class WebSocketStreamClientImpl implements SubscriptionClient {
@@ -394,8 +395,16 @@ public void requestMarketDepthMBP(String symbol, MBPLevelEnums level, Subscripti
}
@Override
- public void subscribeFullMarketDepthMBP(String symbol, MBPLevelEnums level,
- SubscriptionListener callback) {
- createConnection(requestImpl.subscribeFullMarketDepthMBPEvent(symbol, level, callback, null));
+ public void subscribeMarketDepthFullMBP(String symbol, MBPLevelEnums level,
+ SubscriptionListener callback) {
+ createConnection(requestImpl.subscribeMarketDepthFullMBPEvent(symbol, level, callback, null));
}
+
+ @Override
+ public void subscribeOrderChangeEvent(String symbol, SubscriptionListener listener,
+ SubscriptionErrorHandler errorHandler) {
+ createConnection(requestImpl.subscribeOrderChangeEvent(symbol, listener, errorHandler));
+ }
+
+
}
diff --git a/src/main/java/com/huobi/client/impl/WebsocketRequestImpl.java b/src/main/java/com/huobi/client/impl/WebsocketRequestImpl.java
index af93afb8..cc099964 100644
--- a/src/main/java/com/huobi/client/impl/WebsocketRequestImpl.java
+++ b/src/main/java/com/huobi/client/impl/WebsocketRequestImpl.java
@@ -3,8 +3,12 @@
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
+import java.util.Optional;
+import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
+import com.alibaba.fastjson.TypeReference;
+
import org.apache.commons.lang.time.DateFormatUtils;
import com.huobi.client.SubscriptionErrorHandler;
@@ -46,7 +50,7 @@
import com.huobi.client.model.event.AccountListEvent;
import com.huobi.client.model.event.CandlestickEvent;
import com.huobi.client.model.event.CandlestickReqEvent;
-import com.huobi.client.model.event.FullMarketDepthMBPEvent;
+import com.huobi.client.model.event.MarketDepthFullMBPEvent;
import com.huobi.client.model.event.MarketBBOEvent;
import com.huobi.client.model.event.MarketDepthMBPEvent;
import com.huobi.client.model.event.OrderListEvent;
@@ -56,6 +60,10 @@
import com.huobi.client.model.event.TradeClearingEvent;
import com.huobi.client.model.event.TradeEvent;
import com.huobi.client.model.event.TradeStatisticsEvent;
+import com.huobi.client.model.event.OrdersUpdateEvent;
+import com.huobi.client.model.event.OrdersCancellationEvent;
+import com.huobi.client.model.event.OrdersCreationEvent;
+import com.huobi.client.model.event.OrdersTradeEvent;
import com.huobi.client.model.request.OrdersRequest;
import static com.huobi.client.impl.utils.InternalUtils.await;
@@ -847,18 +855,18 @@ WebsocketRequest requestOrderDetailEvent(
return request;
}
- WebsocketRequest subscribeFullMarketDepthMBPEvent(String symbol, MBPLevelEnums level,
- SubscriptionListener subscriptionListener, SubscriptionErrorHandler errorHandler) {
- WebsocketRequest request = new WebsocketRequest(
+ WebsocketRequest subscribeMarketDepthFullMBPEvent(String symbol, MBPLevelEnums level,
+ SubscriptionListener subscriptionListener, SubscriptionErrorHandler errorHandler) {
+ WebsocketRequest request = new WebsocketRequest(
subscriptionListener, errorHandler);
request.connectionHandler = (connection) -> {
- connection.send(Channels.fullMarketDepthMBPChannel(symbol, level));
+ connection.send(Channels.marketDepthFullMBPChannel(symbol, level));
};
request.jsonParser = (jsonWrapper) -> {
JsonWrapper data = jsonWrapper.getJsonObject("tick");
- FullMarketDepthMBPEvent event = new FullMarketDepthMBPEvent();
+ MarketDepthFullMBPEvent event = new MarketDepthFullMBPEvent();
event.setSeqNum(data.getLong("seqNum"));
List bidList = new LinkedList<>();
@@ -965,5 +973,42 @@ WebsocketRequest requestMarketDepthMBPEvent(String symbol,
return request;
}
+
+ WebsocketRequest subscribeOrderChangeEvent(String symbol, SubscriptionListener listener,
+ SubscriptionErrorHandler errorHandler) {
+ WebsocketRequest request = new WebsocketRequest<>(listener, errorHandler);
+
+ request.name = "Order Change Event";
+ // 新版本需设置版本号
+ request.signatureVersion = ApiSignatureV2.SIGNATURE_VERSION_VALUE;
+ request.authHandler = (connection) -> {
+ connection.send(Channels.orderChangeChannel(symbol));
+ };
+ request.jsonParser = (jsonWrapper) -> {
+ JsonWrapper data = jsonWrapper.getJsonObject("data");
+ return Optional.ofNullable(data).map(a -> {
+ String eventType = data.getString("eventType");
+ OrdersUpdateEvent result = null;
+ switch (eventType) {
+ case "creation":
+ result = JSON.parseObject(data.getJson().toString(), new TypeReference(){});
+ break;
+ case "trade":
+ result = JSON.parseObject(data.getJson().toString(), new TypeReference(){});
+ break;
+ case "cancellation":
+ result = JSON.parseObject(data.getJson().toString(), new TypeReference(){});
+ break;
+
+ default:
+ break;
+ }
+
+ return result;
+ }).orElse(null);
+ };
+
+ return request;
+ }
}
diff --git a/src/main/java/com/huobi/client/impl/utils/Channels.java b/src/main/java/com/huobi/client/impl/utils/Channels.java
index 035c109d..fb5ae50a 100644
--- a/src/main/java/com/huobi/client/impl/utils/Channels.java
+++ b/src/main/java/com/huobi/client/impl/utils/Channels.java
@@ -125,24 +125,31 @@ public static String requestAccountListChannel() {
public static String marketDepthMBPChannel(String symbol, MBPLevelEnums level) {
return marketDepthMBPChannel(OP_SUB, symbol, level);
}
-
- public static String fullMarketDepthMBPChannel(String symbol, MBPLevelEnums level) {
- JSONObject json = new JSONObject();
- String topic = "market." + symbol + ".mbp.refresh." + level.getLevels();
- json.put(OP_SUB, topic);
- json.put("id", System.currentTimeMillis() + "");
- return json.toJSONString();
- }
public static String requestMarketDepthMBPChannel(String symbol, MBPLevelEnums level) {
return marketDepthMBPChannel(OP_REQ, symbol, level);
}
- public static String marketDepthMBPChannel(String op, String symbol, MBPLevelEnums level) {
+ private static String marketDepthMBPChannel(String op, String symbol, MBPLevelEnums level) {
JSONObject json = new JSONObject();
String topic = "market." + symbol + ".mbp." + level.getLevels();
json.put(op, topic);
json.put("cid", System.currentTimeMillis() + "");
return json.toJSONString();
}
+
+ public static String marketDepthFullMBPChannel(String symbol, MBPLevelEnums level) {
+ JSONObject json = new JSONObject();
+ String topic = "market." + symbol + ".mbp.refresh." + level.getLevels();
+ json.put(OP_SUB, topic);
+ json.put("id", System.currentTimeMillis() + "");
+ return json.toJSONString();
+ }
+
+ public static String orderChangeChannel(String symbol) {
+ JSONObject json = new JSONObject();
+ json.put("action", OP_SUB);
+ json.put("ch", "orders#".concat(symbol));
+ return json.toJSONString();
+ }
}
diff --git a/src/main/java/com/huobi/client/model/event/FullMarketDepthMBPEvent.java b/src/main/java/com/huobi/client/model/event/MarketDepthFullMBPEvent.java
similarity index 93%
rename from src/main/java/com/huobi/client/model/event/FullMarketDepthMBPEvent.java
rename to src/main/java/com/huobi/client/model/event/MarketDepthFullMBPEvent.java
index da2b2d94..59213e6d 100644
--- a/src/main/java/com/huobi/client/model/event/FullMarketDepthMBPEvent.java
+++ b/src/main/java/com/huobi/client/model/event/MarketDepthFullMBPEvent.java
@@ -4,7 +4,7 @@
import com.huobi.client.model.DepthEntry;
-public class FullMarketDepthMBPEvent {
+public class MarketDepthFullMBPEvent {
private Long seqNum;
diff --git a/src/main/java/com/huobi/client/model/event/OrdersCancellationEvent.java b/src/main/java/com/huobi/client/model/event/OrdersCancellationEvent.java
new file mode 100644
index 00000000..f43cfbe8
--- /dev/null
+++ b/src/main/java/com/huobi/client/model/event/OrdersCancellationEvent.java
@@ -0,0 +1,26 @@
+package com.huobi.client.model.event;
+
+@SuppressWarnings("serial")
+public class OrdersCancellationEvent extends OrdersUpdateEvent {
+
+ private String remainAmt;
+
+ private Long lastActTime;
+
+ public String getRemainAmt() {
+ return remainAmt;
+ }
+
+ public void setRemainAmt(String remainAmt) {
+ this.remainAmt = remainAmt;
+ }
+
+ public Long getLastActTime() {
+ return lastActTime;
+ }
+
+ public void setLastActTime(Long lastActTime) {
+ this.lastActTime = lastActTime;
+ }
+
+}
diff --git a/src/main/java/com/huobi/client/model/event/OrdersCreationEvent.java b/src/main/java/com/huobi/client/model/event/OrdersCreationEvent.java
new file mode 100644
index 00000000..79b7f4f8
--- /dev/null
+++ b/src/main/java/com/huobi/client/model/event/OrdersCreationEvent.java
@@ -0,0 +1,46 @@
+package com.huobi.client.model.event;
+
+@SuppressWarnings("serial")
+public class OrdersCreationEvent extends OrdersUpdateEvent {
+
+ private String orderPrice;
+
+ private String orderSize;
+
+ private String type;
+
+ private Long orderCreateTime;
+
+ public String getOrderPrice() {
+ return orderPrice;
+ }
+
+ public void setOrderPrice(String orderPrice) {
+ this.orderPrice = orderPrice;
+ }
+
+ public String getOrderSize() {
+ return orderSize;
+ }
+
+ public void setOrderSize(String orderSize) {
+ this.orderSize = orderSize;
+ }
+
+ public String getType() {
+ return type;
+ }
+
+ public void setType(String type) {
+ this.type = type;
+ }
+
+ public Long getOrderCreateTime() {
+ return orderCreateTime;
+ }
+
+ public void setOrderCreateTime(Long orderCreateTime) {
+ this.orderCreateTime = orderCreateTime;
+ }
+
+}
diff --git a/src/main/java/com/huobi/client/model/event/OrdersTradeEvent.java b/src/main/java/com/huobi/client/model/event/OrdersTradeEvent.java
new file mode 100644
index 00000000..57058ba1
--- /dev/null
+++ b/src/main/java/com/huobi/client/model/event/OrdersTradeEvent.java
@@ -0,0 +1,76 @@
+package com.huobi.client.model.event;
+
+@SuppressWarnings("serial")
+public class OrdersTradeEvent extends OrdersUpdateEvent {
+
+ private Long tradeId;
+
+ private String tradePrice;
+
+ private String tradeVolume;
+
+ private Long tradeTime;
+
+ private Boolean aggressor;
+
+ private String execAmt;
+
+ private String remainAmt;
+
+ public Long getTradeId() {
+ return tradeId;
+ }
+
+ public void setTradeId(Long tradeId) {
+ this.tradeId = tradeId;
+ }
+
+ public String getTradePrice() {
+ return tradePrice;
+ }
+
+ public void setTradePrice(String tradePrice) {
+ this.tradePrice = tradePrice;
+ }
+
+ public String getTradeVolume() {
+ return tradeVolume;
+ }
+
+ public void setTradeVolume(String tradeVolume) {
+ this.tradeVolume = tradeVolume;
+ }
+
+ public Long getTradeTime() {
+ return tradeTime;
+ }
+
+ public void setTradeTime(Long tradeTime) {
+ this.tradeTime = tradeTime;
+ }
+
+ public Boolean getAggressor() {
+ return aggressor;
+ }
+
+ public void setAggressor(Boolean aggressor) {
+ this.aggressor = aggressor;
+ }
+
+ public String getExecAmt() {
+ return execAmt;
+ }
+
+ public void setExecAmt(String execAmt) {
+ this.execAmt = execAmt;
+ }
+
+ public String getRemainAmt() {
+ return remainAmt;
+ }
+
+ public void setRemainAmt(String remainAmt) {
+ this.remainAmt = remainAmt;
+ }
+
+}
diff --git a/src/main/java/com/huobi/client/model/event/OrdersUpdateEvent.java b/src/main/java/com/huobi/client/model/event/OrdersUpdateEvent.java
new file mode 100644
index 00000000..6b6f53e9
--- /dev/null
+++ b/src/main/java/com/huobi/client/model/event/OrdersUpdateEvent.java
@@ -0,0 +1,58 @@
+package com.huobi.client.model.event;
+
+import java.io.Serializable;
+
+@SuppressWarnings("serial")
+public class OrdersUpdateEvent implements Serializable {
+
+ String eventType;
+
+ String symbol;
+
+ Long orderId;
+
+ String clientOrderId;
+
+ String orderStatus;
+
+ public String getEventType() {
+ return eventType;
+ }
+
+ public void setEventType(String eventType) {
+ this.eventType = eventType;
+ }
+
+ public String getSymbol() {
+ return symbol;
+ }
+
+ public void setSymbol(String symbol) {
+ this.symbol = symbol;
+ }
+
+ public Long getOrderId() {
+ return orderId;
+ }
+
+ public void setOrderId(Long orderId) {
+ this.orderId = orderId;
+ }
+
+ public String getClientOrderId() {
+ return clientOrderId;
+ }
+
+ public void setClientOrderId(String clientOrderId) {
+ this.clientOrderId = clientOrderId;
+ }
+
+ public String getOrderStatus() {
+ return orderStatus;
+ }
+
+ public void setOrderStatus(String orderStatus) {
+ this.orderStatus = orderStatus;
+ }
+
+}
diff --git a/src/main/java/com/huobi/client/model/request/OrderChangeRequest.java b/src/main/java/com/huobi/client/model/request/OrderChangeRequest.java
new file mode 100644
index 00000000..68b44ab5
--- /dev/null
+++ b/src/main/java/com/huobi/client/model/request/OrderChangeRequest.java
@@ -0,0 +1,15 @@
+package com.huobi.client.model.request;
+
+public class OrderChangeRequest {
+
+ private String symbol;
+
+ public String getSymbol() {
+ return symbol;
+ }
+
+ public void setSymbol(String symbol) {
+ this.symbol = symbol;
+ }
+
+}
diff --git a/src/test/java/com/huobi/client/PerformanceTest.java b/src/test/java/com/huobi/client/PerformanceTest.java
new file mode 100644
index 00000000..484f7d4c
--- /dev/null
+++ b/src/test/java/com/huobi/client/PerformanceTest.java
@@ -0,0 +1,165 @@
+package com.huobi.client;
+
+import java.math.BigDecimal;
+import java.util.Map;
+
+import com.huobi.client.examples.constants.Constants;
+import com.huobi.client.impl.RestApiInvoker;
+import com.huobi.client.model.enums.AccountType;
+import com.huobi.client.model.enums.CandlestickInterval;
+import com.huobi.client.model.enums.OrderState;
+import com.huobi.client.model.request.AccountLedgerRequest;
+import com.huobi.client.model.request.CandlestickRequest;
+import com.huobi.client.model.request.MatchResultRequest;
+import com.huobi.client.model.request.NewOrderRequest;
+import com.huobi.client.model.request.OpenOrderRequest;
+import com.huobi.client.model.request.OrdersRequest;
+
+public class PerformanceTest {
+
+
+ public static void main(String[] args) {
+
+ for (int i = 0; i < 10; i++) {
+ test();
+ System.out.println("============finish execute " + i + "============");
+ }
+
+ }
+
+ public static void test() {
+ String symbol = "adausdt";
+ String currency = "ada";
+ // 开启性能测试的开关
+ RestApiInvoker.enablePerformanceSwitch(true);
+
+ RequestOptions options = new RequestOptions();
+ options.setUrl("https://api.huobi.de.com");
+ SyncRequestClient client = SyncRequestClient.create(Constants.API_KEY, Constants.SECRET_KEY, options);
+
+ Long startTime = null;
+ Long endTime = null;
+
+ // Timestamp
+ startTime = System.currentTimeMillis();
+ client.getExchangeTimestamp();
+ endTime = System.currentTimeMillis();
+ printTime("timestamp", startTime, endTime, RestApiInvoker.EXECUTE_COST_MAP);
+
+ // currencys
+ startTime = System.currentTimeMillis();
+ client.getCurrencies();
+ endTime = System.currentTimeMillis();
+ printTime("currencys", startTime, endTime, RestApiInvoker.EXECUTE_COST_MAP);
+
+ // symbols
+ startTime = System.currentTimeMillis();
+ client.getSymbols();
+ endTime = System.currentTimeMillis();
+ printTime("symbols", startTime, endTime, RestApiInvoker.EXECUTE_COST_MAP);
+
+ // currency info
+ startTime = System.currentTimeMillis();
+ client.getCurrencyInfo(currency, true);
+ endTime = System.currentTimeMillis();
+ printTime("currency_info", startTime, endTime, RestApiInvoker.EXECUTE_COST_MAP);
+
+ // K线
+ startTime = System.currentTimeMillis();
+ client.getCandlestick(new CandlestickRequest(symbol, CandlestickInterval.MIN15, null, null, 1));
+ endTime = System.currentTimeMillis();
+ printTime("kline", startTime, endTime, RestApiInvoker.EXECUTE_COST_MAP);
+
+ // 深度
+ startTime = System.currentTimeMillis();
+ client.getPriceDepth(symbol, 5);
+ endTime = System.currentTimeMillis();
+ printTime("depth", startTime, endTime, RestApiInvoker.EXECUTE_COST_MAP);
+
+ // 成交
+ startTime = System.currentTimeMillis();
+ client.getTrade(symbol);
+ endTime = System.currentTimeMillis();
+ printTime("trade", startTime, endTime, RestApiInvoker.EXECUTE_COST_MAP);
+
+ // 历史成交
+ startTime = System.currentTimeMillis();
+ client.getHistoricalTrade(symbol, 1);
+ endTime = System.currentTimeMillis();
+ printTime("history_trade", startTime, endTime, RestApiInvoker.EXECUTE_COST_MAP);
+
+ // Ticker
+ startTime = System.currentTimeMillis();
+ client.getBestQuote(symbol);
+ endTime = System.currentTimeMillis();
+ printTime("ticker", startTime, endTime, RestApiInvoker.EXECUTE_COST_MAP);
+
+ // 24h ticker
+ startTime = System.currentTimeMillis();
+ client.get24HTradeStatistics(symbol);
+ endTime = System.currentTimeMillis();
+ printTime("ticker", startTime, endTime, RestApiInvoker.EXECUTE_COST_MAP);
+
+ // 下单
+ startTime = System.currentTimeMillis();
+ Long orderId = client.createOrder(NewOrderRequest.spotBuyLimit(symbol, new BigDecimal("0.01"), new BigDecimal("500")));
+ endTime = System.currentTimeMillis();
+ printTime("place_order", startTime, endTime, RestApiInvoker.EXECUTE_COST_MAP);
+
+ // 开仓订单
+ startTime = System.currentTimeMillis();
+ client.getOpenOrders(new OpenOrderRequest(symbol, AccountType.SPOT, null, 1));
+ endTime = System.currentTimeMillis();
+ printTime("get_open_order", startTime, endTime, RestApiInvoker.EXECUTE_COST_MAP);
+
+ // 撤单
+ startTime = System.currentTimeMillis();
+ client.cancelOrder(symbol, orderId);
+ endTime = System.currentTimeMillis();
+ printTime("cancel_order", startTime, endTime, RestApiInvoker.EXECUTE_COST_MAP);
+
+ // 查询订单
+ startTime = System.currentTimeMillis();
+ client.getOrder(symbol, orderId);
+ endTime = System.currentTimeMillis();
+ printTime("get_order", startTime, endTime, RestApiInvoker.EXECUTE_COST_MAP);
+
+ // 查询历史订单
+ startTime = System.currentTimeMillis();
+ client.getOrders(new OrdersRequest(symbol, OrderState.CANCELED, null, null, null, null, 1, null));
+ endTime = System.currentTimeMillis();
+ printTime("get_orders", startTime, endTime, RestApiInvoker.EXECUTE_COST_MAP);
+
+ // 查询成交
+ startTime = System.currentTimeMillis();
+ client.getMatchResults(symbol, orderId);
+ endTime = System.currentTimeMillis();
+ printTime("get_matchresult", startTime, endTime, RestApiInvoker.EXECUTE_COST_MAP);
+
+ // 查询历史成交
+ startTime = System.currentTimeMillis();
+ client.getMatchResults(new MatchResultRequest(symbol, null, null, null, 1, null));
+ endTime = System.currentTimeMillis();
+ printTime("get_matchresults", startTime, endTime, RestApiInvoker.EXECUTE_COST_MAP);
+
+ // 查询账户财务流水
+ startTime = System.currentTimeMillis();
+ client.getAccountLedgers(new AccountLedgerRequest(12477272L));
+ endTime = System.currentTimeMillis();
+ printTime("getAccountLedgers", startTime, endTime, RestApiInvoker.EXECUTE_COST_MAP);
+ }
+
+
+ public static void printTime(String key, Long startTime, Long endTime, Map executeTimeMap) {
+
+ Long executeStartTime = executeTimeMap.get(RestApiInvoker.START_TIME_KEY);
+ Long executeEndTime = executeTimeMap.get(RestApiInvoker.END_TIME_KEY);
+ Long totalCost = endTime - startTime;
+ Long executeCost = executeEndTime - executeStartTime;
+ Long innerCost = totalCost - executeCost;
+
+ System.out.println("| " + key + " |" + totalCost + " | " + executeCost + "|" + innerCost + " |");
+
+ }
+
+}
diff --git a/src/test/java/com/huobi/client/examples/SubscribeFullMarketMBPEventTest.java b/src/test/java/com/huobi/client/examples/SubscribeFullMarketMBPEventTest.java
deleted file mode 100644
index 0915e36b..00000000
--- a/src/test/java/com/huobi/client/examples/SubscribeFullMarketMBPEventTest.java
+++ /dev/null
@@ -1,35 +0,0 @@
-package com.huobi.client.examples;
-
-import java.util.concurrent.TimeUnit;
-
-import org.junit.Test;
-
-import com.huobi.client.SubscriptionClient;
-import com.huobi.client.SubscriptionOptions;
-import com.huobi.client.SyncRequestClient;
-import com.huobi.client.examples.constants.Constants;
-import com.huobi.client.model.enums.MBPLevelEnums;
-
-public class SubscribeFullMarketMBPEventTest {
-
- @Test
- public void testSubscribeFullMarketMBPEvent() {
- String symbol = "btcusdt";
- SubscriptionOptions options = new SubscriptionOptions();
- SubscriptionClient client = SubscriptionClient.create(Constants.API_KEY, Constants.SECRET_KEY, options);
- client.subscribeFullMarketDepthMBP(symbol, MBPLevelEnums.LEVEL10, event -> {
- System.out.println(event.getAsks());
- });
- try {
- TimeUnit.SECONDS.sleep(10l);
- } catch (InterruptedException e) {
- e.printStackTrace();
- }
- }
-
- @Test
- public void testGetSystemStatus() {
- SyncRequestClient client = SyncRequestClient.create(Constants.API_KEY, Constants.SECRET_KEY);
- System.out.println(client.getSystemStatus());
- }
-}
diff --git a/src/test/java/com/huobi/client/examples/SubscribeMarketDepthFullMBP.java b/src/test/java/com/huobi/client/examples/SubscribeMarketDepthFullMBP.java
new file mode 100644
index 00000000..6faac5aa
--- /dev/null
+++ b/src/test/java/com/huobi/client/examples/SubscribeMarketDepthFullMBP.java
@@ -0,0 +1,19 @@
+package com.huobi.client.examples;
+
+import com.alibaba.fastjson.JSON;
+import com.huobi.client.SubscriptionClient;
+import com.huobi.client.model.enums.MBPLevelEnums;
+
+public class SubscribeMarketDepthFullMBP {
+
+ public static void main(String[] args) {
+
+ String symbol = "htusdt";
+ SubscriptionClient subscriptionClient = SubscriptionClient.create();
+
+ subscriptionClient.subscribeMarketDepthFullMBP(symbol, MBPLevelEnums.LEVEL5, (event) -> {
+
+ System.out.println("callback:" + JSON.toJSONString(event));
+ });
+ }
+}
diff --git a/src/test/java/com/huobi/client/examples/SubscribeOrderUpdate.java b/src/test/java/com/huobi/client/examples/SubscribeOrderUpdate.java
index 5aa88eb3..d78156fd 100644
--- a/src/test/java/com/huobi/client/examples/SubscribeOrderUpdate.java
+++ b/src/test/java/com/huobi/client/examples/SubscribeOrderUpdate.java
@@ -18,7 +18,7 @@ public class SubscribeOrderUpdate {
public static void main(String[] args) {
- String symbol = "htusdt";
+ String symbol = "hthusd";
SubscriptionClient client = SubscriptionClient.create(Constants.API_KEY, Constants.SECRET_KEY);
/**
* subscribe order updateEvent ,old interface
@@ -37,6 +37,7 @@ public static void main(String[] args) {
System.out.println(JSON.toJSONString(event));
}));
+
/**
* request order list event
*/
@@ -53,9 +54,9 @@ public static void main(String[] args) {
Date today = new Date();
Date startDate = DateUtils.addDays(today, -2);
- long startOrderId = 48909764277L;
+ long startOrderId = 81964355440L;
- OrdersRequest ordersRequest = new OrdersRequest(symbol, stateList, typeList, startDate, today, startOrderId, 20, QueryDirection.PREV);
+ OrdersRequest ordersRequest = new OrdersRequest(symbol, stateList, typeList, startDate, today, 0L, 20, QueryDirection.PREV);
client.requestOrderListEvent(ordersRequest, orderListEvent -> {
System.out.println("=================Request Order List======================");
@@ -64,8 +65,6 @@ public static void main(String[] args) {
});
});
- System.out.println("------------------------------------------");
-
/**
* request order detail event
*/
@@ -76,6 +75,12 @@ public static void main(String[] args) {
});
});
+ /**
+ * subscribe order update v2
+ */
+ client.subscribeOrderChangeEvent(symbol, (event) -> {
+ System.out.println(JSON.toJSONString(event));
+ }, null);
}
}