├── .gitignore
├── huobi-client-examples
├── pom.xml
└── src
│ └── main
│ ├── java
│ └── org
│ │ └── oxerr
│ │ └── huobi
│ │ └── examples
│ │ ├── fix
│ │ ├── MarketClient.java
│ │ ├── TradeClient.java
│ │ └── package-info.java
│ │ ├── rest
│ │ ├── AccountInfoDemo.java
│ │ ├── MarketDataDemo.java
│ │ ├── OpenOrderDemo.java
│ │ └── package-info.java
│ │ ├── websocket
│ │ ├── WebSocketDemo.java
│ │ └── package-info.java
│ │ └── xchange
│ │ ├── HuobiSocketIOServiceDemo.java
│ │ └── package-info.java
│ └── resources
│ ├── logback.xml
│ └── org
│ └── oxerr
│ └── huobi
│ └── examples
│ └── fix
│ ├── market.cfg
│ └── trade.cfg
├── huobi-client-fix
├── pom.xml
└── src
│ └── main
│ └── java
│ └── org
│ └── oxerr
│ └── huobi
│ └── fix
│ ├── HuobiApplication.java
│ ├── MarketApplication.java
│ ├── MarketDataRequests.java
│ ├── TradeApplication.java
│ ├── TradeRequests.java
│ ├── field
│ ├── AccReqID.java
│ ├── AvailableBtc.java
│ ├── AvailableCny.java
│ ├── AvailableLtc.java
│ ├── Fee.java
│ ├── FrozenBtc.java
│ ├── FrozenCny.java
│ ├── FrozenLtc.java
│ ├── ProcessedAmount.java
│ ├── ProcessedPrice.java
│ ├── Total.java
│ ├── Vot.java
│ └── package-info.java
│ ├── fix44
│ ├── AccountInfoRequest.java
│ ├── AccountInfoResponse.java
│ ├── HuobiMessageFactory.java
│ ├── HuobiOrderInfoResponse.java
│ └── package-info.java
│ └── package-info.java
├── huobi-client-rest
├── pom.xml
└── src
│ ├── main
│ ├── java
│ │ └── org
│ │ │ └── oxerr
│ │ │ └── huobi
│ │ │ └── rest
│ │ │ ├── HttpClient.java
│ │ │ ├── Huobi.java
│ │ │ ├── HuobiAdapters.java
│ │ │ ├── HuobiClient.java
│ │ │ ├── HuobiClientException.java
│ │ │ ├── HuobiExchange.java
│ │ │ ├── LoginRequiredException.java
│ │ │ ├── domain
│ │ │ ├── AbstractObject.java
│ │ │ ├── Delegation.java
│ │ │ ├── Depth.java
│ │ │ ├── Funds.java
│ │ │ ├── LoginResult.java
│ │ │ ├── MyTradeInfo.java
│ │ │ ├── TradeResult.java
│ │ │ ├── Type.java
│ │ │ └── package-info.java
│ │ │ ├── dto
│ │ │ ├── account
│ │ │ │ ├── AccountInfo.java
│ │ │ │ └── package-info.java
│ │ │ ├── marketdata
│ │ │ │ ├── Depth.java
│ │ │ │ ├── OrderBookObject.java
│ │ │ │ ├── OrderBookTAS.java
│ │ │ │ ├── Ticker.java
│ │ │ │ ├── TickerObject.java
│ │ │ │ ├── TopObject.java
│ │ │ │ ├── TradeObject.java
│ │ │ │ └── package-info.java
│ │ │ ├── package-info.java
│ │ │ └── trade
│ │ │ │ ├── CancelOrderResult.java
│ │ │ │ ├── HuobiError.java
│ │ │ │ ├── Order.java
│ │ │ │ ├── PlaceOrderResult.java
│ │ │ │ └── package-info.java
│ │ │ ├── package-info.java
│ │ │ ├── service
│ │ │ ├── HuobiDigest.java
│ │ │ └── polling
│ │ │ │ ├── HuobiAccountService.java
│ │ │ │ ├── HuobiAccountServiceRaw.java
│ │ │ │ ├── HuobiBasePollingService.java
│ │ │ │ ├── HuobiBaseTradeService.java
│ │ │ │ ├── HuobiMarketDataService.java
│ │ │ │ ├── HuobiMarketDataServiceRaw.java
│ │ │ │ ├── HuobiTradeService.java
│ │ │ │ ├── HuobiTradeServiceRaw.java
│ │ │ │ └── package-info.java
│ │ │ └── valuereader
│ │ │ ├── DelegationReader.java
│ │ │ ├── HTMLReader.java
│ │ │ ├── JsonValueReader.java
│ │ │ ├── JsonValueTypeRefReader.java
│ │ │ ├── LoginResultReader.java
│ │ │ ├── ValueReader.java
│ │ │ ├── VoidValueReader.java
│ │ │ └── package-info.java
│ └── resources
│ │ └── huobi.json
│ └── test
│ ├── java
│ └── org
│ │ └── oxerr
│ │ └── huobi
│ │ └── rest
│ │ ├── HuobiAdaptersTest.java
│ │ ├── domain
│ │ ├── MyTradeInfoTest.java
│ │ ├── TradeResultTest.java
│ │ └── TypeTest.java
│ │ ├── dto
│ │ ├── account
│ │ │ └── AccountInfoTest.java
│ │ ├── marketdata
│ │ │ ├── DepthTest.java
│ │ │ ├── OHLCVTest.java
│ │ │ ├── OrderBookTASTest.java
│ │ │ ├── TickerTest.java
│ │ │ └── UnmarshalTest.java
│ │ └── trade
│ │ │ ├── HuobiErrorTest.java
│ │ │ ├── HuobiOrderTest.java
│ │ │ └── HuobiPlaceOrderResultTest.java
│ │ └── valuereader
│ │ └── DelegationReaderTest.java
│ └── resources
│ └── org
│ └── oxerr
│ └── huobi
│ └── rest
│ ├── domain
│ ├── cancel.json
│ ├── my_trade_info.json
│ ├── tradeResult0.json
│ └── tradeResult2.json
│ ├── dto
│ ├── account
│ │ └── account-info.json
│ ├── marketdata
│ │ ├── depth.json
│ │ ├── detail.json
│ │ ├── ohlcv.json
│ │ └── ticker.json
│ └── trade
│ │ ├── error.json
│ │ ├── order.json
│ │ ├── orders.json
│ │ └── place-order-result.json
│ └── valuereader
│ └── delegation.html
├── huobi-client-websocket
├── pom.xml
└── src
│ ├── main
│ └── java
│ │ └── org
│ │ └── oxerr
│ │ └── huobi
│ │ └── websocket
│ │ ├── HuobiSocket.java
│ │ ├── HuobiSocketClient.java
│ │ ├── dto
│ │ ├── Depth.java
│ │ ├── DepthDiff.java
│ │ ├── GsonFactory.java
│ │ ├── InstantAdapter.java
│ │ ├── Percent.java
│ │ ├── Period.java
│ │ ├── TradeDetail.java
│ │ ├── package-info.java
│ │ ├── request
│ │ │ ├── AbstractSymbolIdListRequest.java
│ │ │ ├── AbstractSymbolIdRequest.java
│ │ │ ├── Request.java
│ │ │ ├── historydata
│ │ │ │ ├── ReqKLineRequest.java
│ │ │ │ ├── ReqMarketDepthRequest.java
│ │ │ │ ├── ReqMarketDepthTopRequest.java
│ │ │ │ ├── ReqMarketDetailRequest.java
│ │ │ │ ├── ReqTimeLineRequest.java
│ │ │ │ ├── ReqTradeDetailTopRequest.java
│ │ │ │ └── package-info.java
│ │ │ ├── marketdata
│ │ │ │ ├── AbstractPush.java
│ │ │ │ ├── LastKLine.java
│ │ │ │ ├── LastTimeLine.java
│ │ │ │ ├── MarketDepthDiff.java
│ │ │ │ ├── MarketDepthTopDiff.java
│ │ │ │ ├── MarketDetail.java
│ │ │ │ ├── MarketOverview.java
│ │ │ │ ├── Message.java
│ │ │ │ ├── PushType.java
│ │ │ │ ├── TradeDetail.java
│ │ │ │ └── package-info.java
│ │ │ ├── package-info.java
│ │ │ └── service
│ │ │ │ ├── ReqMsgSubscribeRequest.java
│ │ │ │ ├── ReqMsgUnsubscribeRequest.java
│ │ │ │ ├── ReqSymbolDetailRequest.java
│ │ │ │ ├── ReqSymbolListRequest.java
│ │ │ │ └── package-info.java
│ │ └── response
│ │ │ ├── ErrorResponse.java
│ │ │ ├── ReqResponse.java
│ │ │ ├── Response.java
│ │ │ ├── ResponseFactory.java
│ │ │ ├── historydata
│ │ │ ├── ReqKLineResponse.java
│ │ │ ├── ReqMarketDepthResponse.java
│ │ │ ├── ReqMarketDepthTopResponse.java
│ │ │ ├── ReqMarketDetailResponse.java
│ │ │ ├── ReqTimeLineResponse.java
│ │ │ ├── ReqTradeDetailTopResponse.java
│ │ │ └── package-info.java
│ │ │ ├── marketdata
│ │ │ ├── LastKLine.java
│ │ │ ├── LastTimeLine.java
│ │ │ ├── MarketDepthDiff.java
│ │ │ ├── MarketDepthTopDiff.java
│ │ │ ├── MarketDetail.java
│ │ │ ├── MarketOverview.java
│ │ │ ├── Message.java
│ │ │ ├── TradeDetail.java
│ │ │ ├── package-info.java
│ │ │ └── payload
│ │ │ │ ├── LastKLinePayload.java
│ │ │ │ ├── LastTimeLinePayload.java
│ │ │ │ ├── MarketDepthDiffPayload.java
│ │ │ │ ├── MarketDepthTopDiffPayload.java
│ │ │ │ ├── MarketDetailPayload.java
│ │ │ │ ├── MarketOverviewPayload.java
│ │ │ │ ├── TradeDetailPayload.java
│ │ │ │ ├── Update.java
│ │ │ │ └── package-info.java
│ │ │ ├── package-info.java
│ │ │ ├── payload
│ │ │ ├── AbstractPayload.java
│ │ │ ├── Orders.java
│ │ │ ├── Payload.java
│ │ │ ├── ReqKLinePayload.java
│ │ │ ├── ReqMarketDepthPayload.java
│ │ │ ├── ReqMarketDepthTopPayload.java
│ │ │ ├── ReqMarketDetailPayload.java
│ │ │ ├── ReqSymbolDetailPayload.java
│ │ │ ├── ReqSymbolListPayload.java
│ │ │ ├── ReqTimeLinePayload.java
│ │ │ ├── ReqTradeDetailTopPayload.java
│ │ │ ├── Trades.java
│ │ │ ├── VoidPayload.java
│ │ │ └── package-info.java
│ │ │ └── service
│ │ │ ├── ReqMsgSubscribeResponse.java
│ │ │ ├── ReqMsgUnsubscribeResponse.java
│ │ │ ├── ReqSymbolDetailResponse.java
│ │ │ ├── ReqSymbolListResponse.java
│ │ │ └── package-info.java
│ │ ├── event
│ │ ├── HuobiSocketAdapter.java
│ │ ├── HuobiSocketListener.java
│ │ ├── ResponseAdapter.java
│ │ ├── ResponseListener.java
│ │ └── package-info.java
│ │ └── package-info.java
│ └── test
│ ├── java
│ └── org
│ │ └── oxerr
│ │ └── huobi
│ │ └── websocket
│ │ └── dto
│ │ ├── request
│ │ └── historydata
│ │ │ └── ReqTimeLineRequestTest.java
│ │ └── response
│ │ ├── AbstractResponseTest.java
│ │ ├── ErrorResponseTest.java
│ │ ├── ReqKLineResponseTest.java
│ │ ├── ReqMarketDepthResponseTest.java
│ │ ├── ReqMarketDepthTopResponseTest.java
│ │ ├── ReqMarketDetailResponseTest.java
│ │ ├── ReqMsgSubscribeResponseTest.java
│ │ ├── ReqMsgUnsubscribeResponseTest.java
│ │ ├── ReqSymbolDetailResponseTest.java
│ │ ├── ReqSymbolListResponseTest.java
│ │ ├── ReqTimeLineResponseTest.java
│ │ ├── ReqTradeDetailTopResponseTest.java
│ │ ├── message
│ │ ├── LastKLineTest.java
│ │ ├── LastTimeLineTest.java
│ │ ├── MarketDepthDiffTest.java
│ │ ├── MarketDepthTopDiffTest.java
│ │ ├── MarketDetailTest.java
│ │ ├── MarketOverviewTest.java
│ │ └── TradeDetailTest.java
│ │ └── payload
│ │ └── ReqMarketDepthTopPayloadTest.java
│ └── resources
│ └── org
│ └── oxerr
│ └── huobi
│ └── websocket
│ └── dto
│ └── response
│ ├── error-601.json
│ ├── message
│ ├── lastKLine.json
│ ├── lastTimeLine.json
│ ├── marketDepthDiff.json
│ ├── marketDepthTopDiff.json
│ ├── marketDetail.json
│ ├── marketOverview.json
│ └── tradeDetail.json
│ ├── payload
│ ├── 1416496077000
│ │ ├── marketDepthDiff.json
│ │ └── reqMarketDepth.json
│ └── 1416498909000
│ │ ├── marketDepthDiff1.json
│ │ ├── marketDepthDiff2.json
│ │ └── reqMarketDepth.json
│ ├── reqKLine.json
│ ├── reqMarketDepth.json
│ ├── reqMarketDepthTop.json
│ ├── reqMarketDetail.json
│ ├── reqMsgSubscribe.json
│ ├── reqMsgUnsubscribe.json
│ ├── reqSymbolDetail-btccny,ltccny.json
│ ├── reqSymbolDetail-btccny.json
│ ├── reqSymbolList.json
│ ├── reqTimeLine.json
│ └── reqTradeDetailTop.json
├── huobi-client-xchange
├── pom.xml
└── src
│ ├── main
│ └── java
│ │ └── org
│ │ └── oxerr
│ │ └── huobi
│ │ └── xchange
│ │ ├── HuobiExchange.java
│ │ ├── package-info.java
│ │ └── service
│ │ ├── package-info.java
│ │ └── streaming
│ │ ├── HuobiExchangeEvent.java
│ │ ├── HuobiExchangeEventListener.java
│ │ ├── HuobiSocketIOAdapters.java
│ │ ├── HuobiSocketIOService.java
│ │ ├── HuobiStreamingConfiguration.java
│ │ └── package-info.java
│ └── test
│ └── java
│ └── org
│ └── oxerr
│ └── huobi
│ └── xchange
│ └── service
│ └── streaming
│ └── HuobiAdaptersTest.java
├── pom.xml
└── src
└── site
└── site.xml
/.gitignore:
--------------------------------------------------------------------------------
1 | target/
2 | .project
3 | .classpath
4 | .settings/
5 | .DS_Store
6 | /huobi-client-examples/src/main/resources/org/oxerr/huobi/examples/fix/FIX44.xml
7 | /huobi-client-examples/src/main/resources/org/oxerr/huobi/examples/fix/HuoBiFixCA-Client.keystore
8 |
--------------------------------------------------------------------------------
/huobi-client-examples/pom.xml:
--------------------------------------------------------------------------------
1 |
5 | 4.0.0
6 |
7 |
8 | org.oxerr
9 | huobi-client
10 | 2.1.0-SNAPSHOT
11 |
12 |
13 | huobi-client-examples
14 |
15 | Huobi Client - Examples
16 | Examples demonstrate how to use this library.
17 |
18 |
19 |
20 | org.slf4j
21 | jul-to-slf4j
22 | 1.7.7
23 |
24 |
25 | ch.qos.logback
26 | logback-classic
27 | true
28 |
29 |
30 | ${project.groupId}
31 | huobi-client-websocket
32 | ${project.version}
33 |
34 |
35 | ${project.groupId}
36 | huobi-client-fix
37 | ${project.version}
38 |
39 |
40 | ${project.groupId}
41 | huobi-client-xchange
42 | ${project.version}
43 |
44 |
45 |
46 |
--------------------------------------------------------------------------------
/huobi-client-examples/src/main/java/org/oxerr/huobi/examples/fix/package-info.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Demonstrations for FIX API.
3 | */
4 | package org.oxerr.huobi.examples.fix;
5 |
--------------------------------------------------------------------------------
/huobi-client-examples/src/main/java/org/oxerr/huobi/examples/rest/AccountInfoDemo.java:
--------------------------------------------------------------------------------
1 | package org.oxerr.huobi.examples.rest;
2 |
3 | import java.io.IOException;
4 |
5 | import org.oxerr.huobi.xchange.HuobiExchange;
6 | import org.slf4j.Logger;
7 | import org.slf4j.LoggerFactory;
8 |
9 | import com.xeiam.xchange.Exchange;
10 | import com.xeiam.xchange.ExchangeFactory;
11 | import com.xeiam.xchange.ExchangeSpecification;
12 | import com.xeiam.xchange.dto.account.AccountInfo;
13 | import com.xeiam.xchange.service.polling.account.PollingAccountService;
14 |
15 | public class AccountInfoDemo {
16 |
17 | private static final Logger log = LoggerFactory.getLogger(AccountInfoDemo.class);
18 |
19 | public static void main(String[] args) throws IOException {
20 | final String accessKey = args[0], secretKey = args[1];
21 |
22 | ExchangeSpecification spec = new ExchangeSpecification(HuobiExchange.class);
23 | spec.setApiKey(accessKey);
24 | spec.setSecretKey(secretKey);
25 |
26 | Exchange tradeExchange = ExchangeFactory.INSTANCE.createExchange(spec);
27 | PollingAccountService accountService = tradeExchange.getPollingAccountService();
28 |
29 | // Account info
30 | AccountInfo accountInfo = accountService.getAccountInfo();
31 | log.info("Account info: {}", accountInfo);
32 | }
33 |
34 | }
35 |
--------------------------------------------------------------------------------
/huobi-client-examples/src/main/java/org/oxerr/huobi/examples/rest/MarketDataDemo.java:
--------------------------------------------------------------------------------
1 | package org.oxerr.huobi.examples.rest;
2 |
3 | import java.io.IOException;
4 | import java.math.BigDecimal;
5 |
6 | import org.oxerr.huobi.xchange.HuobiExchange;
7 | import org.slf4j.Logger;
8 | import org.slf4j.LoggerFactory;
9 |
10 | import com.xeiam.xchange.Exchange;
11 | import com.xeiam.xchange.ExchangeFactory;
12 | import com.xeiam.xchange.currency.CurrencyPair;
13 | import com.xeiam.xchange.dto.marketdata.OrderBook;
14 | import com.xeiam.xchange.dto.marketdata.Ticker;
15 | import com.xeiam.xchange.dto.marketdata.Trades;
16 | import com.xeiam.xchange.service.polling.marketdata.PollingMarketDataService;
17 |
18 | public class MarketDataDemo {
19 |
20 | private static final Logger log = LoggerFactory.getLogger(MarketDataDemo.class);
21 |
22 | public static void main(String[] args) throws IOException {
23 | Exchange exchange = ExchangeFactory.INSTANCE.createExchange(HuobiExchange.class.getName());
24 | PollingMarketDataService marketDataService = exchange.getPollingMarketDataService();
25 |
26 | // Ticker
27 | Ticker ticker = marketDataService.getTicker(CurrencyPair.BTC_CNY);
28 | log.info("BTC ticker: {}", ticker);
29 |
30 | ticker = marketDataService.getTicker(CurrencyPair.LTC_CNY);
31 | log.info("LTC ticker: {}", ticker);
32 |
33 | // Depth
34 | OrderBook depth = marketDataService.getOrderBook(CurrencyPair.BTC_CNY);
35 | log.info("BTC depth: {}", depth);
36 | if (depth.getBids().size() >= 2) {
37 | BigDecimal bid0 = depth.getBids().get(0).getLimitPrice();
38 | BigDecimal bid1 = depth.getBids().get(1).getLimitPrice();
39 | if (bid0.compareTo(bid1) <= 0) {
40 | throw new RuntimeException("bids in depth should be ordered from highest to lowest.");
41 | }
42 | }
43 | if (depth.getAsks().size() >= 2) {
44 | BigDecimal ask0 = depth.getAsks().get(0).getLimitPrice();
45 | BigDecimal ask1 = depth.getAsks().get(1).getLimitPrice();
46 | if (ask0.compareTo(ask1) >= 0) {
47 | throw new RuntimeException("asks in depth should be ordered from lowest to highest.");
48 | }
49 | }
50 |
51 | depth = marketDataService.getOrderBook(CurrencyPair.LTC_CNY);
52 | log.info("LTC depth: {}", depth);
53 |
54 | // Trades
55 | Trades trades = marketDataService.getTrades(CurrencyPair.BTC_CNY);
56 | log.info("BTC trades: {}", trades);
57 |
58 | // trades = marketDataService.getTrades(CurrencyPair.LTC_CNY);
59 | // log.info("LTC trades: {}", trades);
60 | }
61 |
62 | }
63 |
--------------------------------------------------------------------------------
/huobi-client-examples/src/main/java/org/oxerr/huobi/examples/rest/OpenOrderDemo.java:
--------------------------------------------------------------------------------
1 | package org.oxerr.huobi.examples.rest;
2 |
3 | import java.io.IOException;
4 | import java.util.Arrays;
5 |
6 | import org.oxerr.huobi.xchange.HuobiExchange;
7 | import org.slf4j.Logger;
8 | import org.slf4j.LoggerFactory;
9 |
10 | import com.xeiam.xchange.Exchange;
11 | import com.xeiam.xchange.ExchangeFactory;
12 | import com.xeiam.xchange.ExchangeSpecification;
13 | import com.xeiam.xchange.currency.CurrencyPair;
14 | import com.xeiam.xchange.dto.trade.OpenOrders;
15 | import com.xeiam.xchange.exceptions.ExchangeException;
16 | import com.xeiam.xchange.exceptions.NotAvailableFromExchangeException;
17 | import com.xeiam.xchange.exceptions.NotYetImplementedForExchangeException;
18 | import com.xeiam.xchange.service.polling.trade.PollingTradeService;
19 |
20 | public class OpenOrderDemo {
21 |
22 | private static final Logger log = LoggerFactory
23 | .getLogger(OpenOrderDemo.class);
24 |
25 | public static void main(String[] args) throws ExchangeException,
26 | NotAvailableFromExchangeException,
27 | NotYetImplementedForExchangeException, IOException {
28 | String accessKey = args[0], secretKey = args[1];
29 |
30 | ExchangeSpecification spec = new ExchangeSpecification(
31 | HuobiExchange.class);
32 | spec.setApiKey(accessKey);
33 | spec.setSecretKey(secretKey);
34 | spec.setExchangeSpecificParametersItem(HuobiExchange.SYMBOLS_PARAMETER,
35 | Arrays.asList(CurrencyPair.BTC_CNY));
36 |
37 | Exchange exchange = ExchangeFactory.INSTANCE.createExchange(spec);
38 | PollingTradeService tradeService = exchange.getPollingTradeService();
39 |
40 | OpenOrders openOrders = tradeService.getOpenOrders();
41 | log.info("open orders: {}", openOrders);
42 | }
43 |
44 | }
45 |
--------------------------------------------------------------------------------
/huobi-client-examples/src/main/java/org/oxerr/huobi/examples/rest/package-info.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Demonstrations for RESTful API.
3 | */
4 | package org.oxerr.huobi.examples.rest;
5 |
--------------------------------------------------------------------------------
/huobi-client-examples/src/main/java/org/oxerr/huobi/examples/websocket/package-info.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Demonstrations for WebSocket API.
3 | */
4 | package org.oxerr.huobi.examples.websocket;
5 |
--------------------------------------------------------------------------------
/huobi-client-examples/src/main/java/org/oxerr/huobi/examples/xchange/HuobiSocketIOServiceDemo.java:
--------------------------------------------------------------------------------
1 | package org.oxerr.huobi.examples.xchange;
2 |
3 | import java.util.concurrent.TimeUnit;
4 |
5 | import org.oxerr.huobi.xchange.HuobiExchange;
6 | import org.oxerr.huobi.xchange.service.streaming.HuobiSocketIOService;
7 | import org.slf4j.Logger;
8 | import org.slf4j.LoggerFactory;
9 | import org.slf4j.bridge.SLF4JBridgeHandler;
10 |
11 | import com.xeiam.xchange.Exchange;
12 | import com.xeiam.xchange.ExchangeFactory;
13 | import com.xeiam.xchange.service.streaming.ExchangeEvent;
14 | import com.xeiam.xchange.service.streaming.StreamingExchangeService;
15 |
16 | /**
17 | * Demonstration for {@link HuobiSocketIOService}.
18 | */
19 | public class HuobiSocketIOServiceDemo {
20 |
21 | private static final Logger log = LoggerFactory
22 | .getLogger(HuobiSocketIOServiceDemo.class);
23 |
24 | public static void main(String[] args) throws InterruptedException {
25 | // Bridge/route all JUL log records to the SLF4J API.
26 | SLF4JBridgeHandler.removeHandlersForRootLogger();
27 | SLF4JBridgeHandler.install();
28 |
29 | final Exchange exchange = ExchangeFactory.INSTANCE
30 | .createExchange(HuobiExchange.class.getName());
31 | final StreamingExchangeService streamingExchangeService = exchange
32 | .getStreamingExchangeService(null);
33 |
34 | final Thread consumer = new Thread("consumer") {
35 |
36 | @Override
37 | public void run() {
38 |
39 | while (!isInterrupted()) {
40 | try {
41 | ExchangeEvent event = streamingExchangeService
42 | .getNextEvent();
43 | log.info("status: {}, type: {}, data: {}, payload: {}",
44 | streamingExchangeService.getWebSocketStatus(),
45 | event.getEventType(), event.getData(),
46 | event.getPayload());
47 | } catch (InterruptedException e) {
48 | this.interrupt();
49 | }
50 | }
51 | }
52 |
53 | };
54 |
55 | // Start consumer.
56 | consumer.start();
57 | log.info("Consumer started.");
58 |
59 | // Start streaming service.
60 | streamingExchangeService.connect();
61 |
62 | // Demonstrate for 1 minute.
63 | TimeUnit.MINUTES.sleep(1);
64 |
65 | // Disconnect streaming service.
66 | streamingExchangeService.disconnect();
67 |
68 | // Interrupt consumer to exit.
69 | consumer.interrupt();
70 | log.info("Consumer interrupted.");
71 | }
72 |
73 | }
74 |
--------------------------------------------------------------------------------
/huobi-client-examples/src/main/java/org/oxerr/huobi/examples/xchange/package-info.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Demonstrations for XChange API.
3 | */
4 | package org.oxerr.huobi.examples.xchange;
5 |
--------------------------------------------------------------------------------
/huobi-client-examples/src/main/resources/logback.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 | INFO
8 |
9 |
10 | %d{HH:mm:ss.SSS} [%t] %-5p [%c{16}#%M:%3L] - %m%n
11 |
12 |
13 |
14 |
15 | target/huobi-client-examples.log
16 |
17 | UTF-8
18 | %d [%t] %-5p [%c{16}#%M:%3L] - %m%n
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
--------------------------------------------------------------------------------
/huobi-client-examples/src/main/resources/org/oxerr/huobi/examples/fix/market.cfg:
--------------------------------------------------------------------------------
1 | [DEFAULT]
2 | FileStorePath=target/data/huobi_fix_market_client
3 | FileLogPath=target/data/huobi_market_client_log
4 | ConnectionType=initiator
5 | BeginString=FIX.4.4
6 | HeartBtInt=30
7 | LogonTimeout=120
8 | StartTime=00:00:00
9 | EndTime=00:00:00
10 | UseDataDictionary=Y
11 | # Download from https://news.huobi.com/download/huobifix_pack.zip
12 | DataDictionary=org/oxerr/huobi/examples/fix/FIX44.xml
13 | ValidateSequenceNumbers=N
14 | ReconnectInterval=5
15 | SenderCompID=huobiuid
16 | TargetCompID=huobi
17 | SocketConnectHost=106.38.234.75
18 |
19 | [SESSION]
20 | SessionQualifier=market
21 | SocketConnectPort=5000
22 |
--------------------------------------------------------------------------------
/huobi-client-examples/src/main/resources/org/oxerr/huobi/examples/fix/trade.cfg:
--------------------------------------------------------------------------------
1 | [DEFAULT]
2 | FileStorePath=target/data/huobi_fix_trade_client
3 | FileLogPath=target/data/huobi_trade_client_log
4 | ConnectionType=initiator
5 | BeginString=FIX.4.4
6 | HeartBtInt=30
7 | StartTime=00:00:00
8 | EndTime=00:00:00
9 | UseDataDictionary=Y
10 | # Download from https://news.huobi.com/download/huobifix_pack.zip
11 | DataDictionary=org/oxerr/huobi/examples/fix/FIX44.xml
12 | ValidateSequenceNumbers=N
13 | ReconnectInterval=5
14 | SenderCompID=huobiuid
15 | TargetCompID=huobi
16 | SocketConnectHost=103.10.87.52
17 |
18 | [SESSION]
19 | SessionQualifier=trade
20 | SocketConnectPort=5001
21 | SocketUseSSL=Y
22 | # Download from https://news.huobi.com/download/huobifix_pack.zip
23 | SocketKeyStore=org/oxerr/huobi/examples/fix/HuoBiFixCA-Client.keystore
24 | SocketKeyStorePassword=BEDA14BE-908D-B30B-2934-E01F15886852
25 |
--------------------------------------------------------------------------------
/huobi-client-fix/pom.xml:
--------------------------------------------------------------------------------
1 |
5 | 4.0.0
6 |
7 |
8 | org.oxerr
9 | huobi-client
10 | 2.1.0-SNAPSHOT
11 |
12 |
13 | huobi-client-fix
14 |
15 | Huobi Client - FIX
16 |
17 | Huobi FIX API.
19 | ]]>
20 |
21 |
22 |
23 | org.slf4j
24 | slf4j-api
25 |
26 |
27 | quickfixj
28 | quickfixj-core
29 |
30 |
31 | quickfixj
32 | quickfixj-msg-fix44
33 |
34 |
35 | org.apache.mina
36 | mina-core
37 |
38 |
39 | org.apache.mina
40 | mina-filter-ssl
41 |
42 |
43 |
44 |
--------------------------------------------------------------------------------
/huobi-client-fix/src/main/java/org/oxerr/huobi/fix/HuobiApplication.java:
--------------------------------------------------------------------------------
1 | package org.oxerr.huobi.fix;
2 |
3 | import java.util.concurrent.ExecutorService;
4 | import java.util.concurrent.Executors;
5 |
6 | import org.slf4j.Logger;
7 | import org.slf4j.LoggerFactory;
8 |
9 | import quickfix.Application;
10 | import quickfix.DoNotSend;
11 | import quickfix.FieldNotFound;
12 | import quickfix.IncorrectDataFormat;
13 | import quickfix.IncorrectTagValue;
14 | import quickfix.Message;
15 | import quickfix.RejectLogon;
16 | import quickfix.Session;
17 | import quickfix.SessionID;
18 | import quickfix.UnsupportedMessageType;
19 | import quickfix.fix44.MessageCracker;
20 |
21 | /**
22 | * Abstract {@link Application} for Huobi.
23 | */
24 | public abstract class HuobiApplication extends MessageCracker implements
25 | Application {
26 |
27 | private final Logger log = LoggerFactory.getLogger(HuobiApplication.class);
28 | private final ExecutorService executorService;
29 |
30 | public HuobiApplication() {
31 | executorService = Executors.newFixedThreadPool(Runtime.getRuntime()
32 | .availableProcessors() * 2 + 1);
33 | }
34 |
35 | /**
36 | * {@inheritDoc}
37 | */
38 | @Override
39 | public void onCreate(SessionID sessionId) {
40 | }
41 |
42 | /**
43 | * {@inheritDoc}
44 | */
45 | @Override
46 | public void onLogon(SessionID sessionId) {
47 | }
48 |
49 | /**
50 | * {@inheritDoc}
51 | */
52 | @Override
53 | public void onLogout(SessionID sessionId) {
54 | }
55 |
56 | /**
57 | * {@inheritDoc}
58 | */
59 | @Override
60 | public void toAdmin(Message message, SessionID sessionId) {
61 | log.trace("toAdmin: {}", message);
62 | }
63 |
64 | /**
65 | * {@inheritDoc}
66 | */
67 | @Override
68 | public void fromAdmin(Message message, SessionID sessionId)
69 | throws FieldNotFound, IncorrectDataFormat, IncorrectTagValue,
70 | RejectLogon {
71 | log.trace("fromAdmin: {}", message);
72 | }
73 |
74 | /**
75 | * {@inheritDoc}
76 | */
77 | @Override
78 | public void toApp(Message message, SessionID sessionId)
79 | throws DoNotSend {
80 | log.trace("toApp: {}", message);
81 | }
82 |
83 | /**
84 | * {@inheritDoc}
85 | */
86 | @Override
87 | public void fromApp(Message message, SessionID sessionId)
88 | throws FieldNotFound, IncorrectDataFormat, IncorrectTagValue,
89 | UnsupportedMessageType {
90 | log.trace("fromApp: {}", message);
91 | crack(message, sessionId);
92 | }
93 |
94 | public void sendMessage(final Message message, final SessionID sessionId) {
95 | log.trace("sending message: {}", message);
96 |
97 | executorService.execute(new Runnable() {
98 |
99 | @Override
100 | public void run() {
101 | Session.lookupSession(sessionId).send(message);
102 | }
103 |
104 | });
105 | }
106 |
107 | }
108 |
--------------------------------------------------------------------------------
/huobi-client-fix/src/main/java/org/oxerr/huobi/fix/MarketApplication.java:
--------------------------------------------------------------------------------
1 | package org.oxerr.huobi.fix;
2 |
3 | import org.slf4j.Logger;
4 | import org.slf4j.LoggerFactory;
5 |
6 | import quickfix.FieldNotFound;
7 | import quickfix.IncorrectTagValue;
8 | import quickfix.SessionID;
9 | import quickfix.UnsupportedMessageType;
10 | import quickfix.fix44.MarketDataSnapshotFullRefresh;
11 | import quickfix.fix44.Reject;
12 |
13 | public class MarketApplication extends HuobiApplication {
14 |
15 | private final Logger log = LoggerFactory.getLogger(MarketApplication.class);
16 |
17 | @Override
18 | public void onMessage(MarketDataSnapshotFullRefresh message,
19 | SessionID sessionId) throws FieldNotFound, UnsupportedMessageType,
20 | IncorrectTagValue {
21 | log.info("{}", message);
22 | }
23 |
24 | @Override
25 | public void onMessage(Reject message, SessionID sessionId)
26 | throws FieldNotFound, UnsupportedMessageType, IncorrectTagValue {
27 | log.error("{}", message);
28 | }
29 |
30 | }
31 |
--------------------------------------------------------------------------------
/huobi-client-fix/src/main/java/org/oxerr/huobi/fix/MarketDataRequests.java:
--------------------------------------------------------------------------------
1 | package org.oxerr.huobi.fix;
2 |
3 | import quickfix.field.MDEntryType;
4 | import quickfix.field.MDReqID;
5 | import quickfix.field.MarketDepth;
6 | import quickfix.field.SubscriptionRequestType;
7 | import quickfix.field.Symbol;
8 | import quickfix.fix44.MarketDataRequest;
9 | import quickfix.fix44.MarketDataRequest.NoMDEntryTypes;
10 | import quickfix.fix44.MarketDataRequest.NoRelatedSym;
11 |
12 | public final class MarketDataRequests {
13 |
14 | private MarketDataRequests() {
15 | }
16 |
17 | public static MarketDataRequest buildMarketDataRequest(
18 | String mdReqId,
19 | String symbol,
20 | char subscriptionRequestType,
21 | int marketDepth,
22 | int mdUpdateType,
23 | char... mdEntryTypes) {
24 | MarketDataRequest message = new MarketDataRequest();
25 |
26 | NoRelatedSym symGroup = new NoRelatedSym();
27 | symGroup.set(new Symbol(symbol));
28 | message.addGroup(symGroup);
29 |
30 | message.set(new MDReqID(mdReqId));
31 | message.set(new SubscriptionRequestType(subscriptionRequestType));
32 | message.set(new MarketDepth(marketDepth));
33 | // message.set(new MDUpdateType(mdUpdateType));
34 |
35 | for (char mdEntryType : mdEntryTypes) {
36 | NoMDEntryTypes entryTypesGroup = new NoMDEntryTypes();
37 | entryTypesGroup.set(new MDEntryType(mdEntryType));
38 | message.addGroup(entryTypesGroup);
39 | }
40 |
41 | return message;
42 | }
43 |
44 | }
45 |
--------------------------------------------------------------------------------
/huobi-client-fix/src/main/java/org/oxerr/huobi/fix/field/AccReqID.java:
--------------------------------------------------------------------------------
1 | package org.oxerr.huobi.fix.field;
2 |
3 | import quickfix.StringField;
4 |
5 | public class AccReqID extends StringField {
6 |
7 | private static final long serialVersionUID = 20141101L;
8 |
9 | public static final int FIELD = 1622;
10 |
11 | public AccReqID() {
12 | super(FIELD);
13 | }
14 |
15 | public AccReqID(String data) {
16 | super(FIELD, data);
17 | }
18 |
19 | }
20 |
--------------------------------------------------------------------------------
/huobi-client-fix/src/main/java/org/oxerr/huobi/fix/field/AvailableBtc.java:
--------------------------------------------------------------------------------
1 | package org.oxerr.huobi.fix.field;
2 |
3 | import java.math.BigDecimal;
4 |
5 | import quickfix.DecimalField;
6 |
7 | public class AvailableBtc extends DecimalField {
8 |
9 | private static final long serialVersionUID = 20141101L;
10 |
11 | public static final int FIELD = 1624;
12 |
13 | public AvailableBtc() {
14 | super(FIELD);
15 | }
16 |
17 | public AvailableBtc(BigDecimal data) {
18 | super(FIELD, data);
19 | }
20 |
21 | public AvailableBtc(double data) {
22 | super(FIELD, new BigDecimal(data));
23 | }
24 |
25 | }
26 |
--------------------------------------------------------------------------------
/huobi-client-fix/src/main/java/org/oxerr/huobi/fix/field/AvailableCny.java:
--------------------------------------------------------------------------------
1 | package org.oxerr.huobi.fix.field;
2 |
3 | import java.math.BigDecimal;
4 |
5 | import quickfix.DecimalField;
6 |
7 | public class AvailableCny extends DecimalField {
8 |
9 | private static final long serialVersionUID = 20141101L;
10 |
11 | public static final int FIELD = 1623;
12 |
13 | public AvailableCny() {
14 | super(FIELD);
15 | }
16 |
17 | public AvailableCny(BigDecimal data) {
18 | super(FIELD, data);
19 | }
20 |
21 | public AvailableCny(double data) {
22 | super(FIELD, new BigDecimal(data));
23 | }
24 |
25 | }
26 |
--------------------------------------------------------------------------------
/huobi-client-fix/src/main/java/org/oxerr/huobi/fix/field/AvailableLtc.java:
--------------------------------------------------------------------------------
1 | package org.oxerr.huobi.fix.field;
2 |
3 | import java.math.BigDecimal;
4 |
5 | import quickfix.DecimalField;
6 |
7 | public class AvailableLtc extends DecimalField {
8 |
9 | private static final long serialVersionUID = 20141101L;
10 |
11 | public static final int FIELD = 1625;
12 |
13 | public AvailableLtc() {
14 | super(FIELD);
15 | }
16 |
17 | public AvailableLtc(BigDecimal data) {
18 | super(FIELD, data);
19 | }
20 |
21 | public AvailableLtc(double data) {
22 | super(FIELD, new BigDecimal(data));
23 | }
24 |
25 | }
26 |
--------------------------------------------------------------------------------
/huobi-client-fix/src/main/java/org/oxerr/huobi/fix/field/Fee.java:
--------------------------------------------------------------------------------
1 | package org.oxerr.huobi.fix.field;
2 |
3 | import java.math.BigDecimal;
4 |
5 | import quickfix.DecimalField;
6 |
7 | public class Fee extends DecimalField {
8 |
9 | private static final long serialVersionUID = 20141102L;
10 |
11 | public static final int FIELD = 1633;
12 |
13 | public Fee() {
14 | super(FIELD);
15 | }
16 |
17 | public Fee(BigDecimal data) {
18 | super(FIELD, data);
19 | }
20 |
21 | public Fee(double data) {
22 | super(FIELD, new BigDecimal(data));
23 | }
24 |
25 | }
26 |
--------------------------------------------------------------------------------
/huobi-client-fix/src/main/java/org/oxerr/huobi/fix/field/FrozenBtc.java:
--------------------------------------------------------------------------------
1 | package org.oxerr.huobi.fix.field;
2 |
3 | import java.math.BigDecimal;
4 |
5 | import quickfix.DecimalField;
6 |
7 | public class FrozenBtc extends DecimalField {
8 |
9 | private static final long serialVersionUID = 20141101L;
10 |
11 | public static final int FIELD = 1627;
12 |
13 | public FrozenBtc() {
14 | super(FIELD);
15 | }
16 |
17 | public FrozenBtc(BigDecimal data) {
18 | super(FIELD, data);
19 | }
20 |
21 | public FrozenBtc(double data) {
22 | super(FIELD, new BigDecimal(data));
23 | }
24 |
25 | }
26 |
--------------------------------------------------------------------------------
/huobi-client-fix/src/main/java/org/oxerr/huobi/fix/field/FrozenCny.java:
--------------------------------------------------------------------------------
1 | package org.oxerr.huobi.fix.field;
2 |
3 | import java.math.BigDecimal;
4 |
5 | import quickfix.DecimalField;
6 |
7 | public class FrozenCny extends DecimalField {
8 |
9 | private static final long serialVersionUID = 20141101L;
10 |
11 | public static final int FIELD = 1628;
12 |
13 | public FrozenCny() {
14 | super(FIELD);
15 | }
16 |
17 | public FrozenCny(BigDecimal data) {
18 | super(FIELD, data);
19 | }
20 |
21 | public FrozenCny(double data) {
22 | super(FIELD, new BigDecimal(data));
23 | }
24 |
25 | }
26 |
--------------------------------------------------------------------------------
/huobi-client-fix/src/main/java/org/oxerr/huobi/fix/field/FrozenLtc.java:
--------------------------------------------------------------------------------
1 | package org.oxerr.huobi.fix.field;
2 |
3 | import java.math.BigDecimal;
4 |
5 | import quickfix.DecimalField;
6 |
7 | public class FrozenLtc extends DecimalField {
8 |
9 | private static final long serialVersionUID = 20141101L;
10 |
11 | public static final int FIELD = 1626;
12 |
13 | public FrozenLtc() {
14 | super(FIELD);
15 | }
16 |
17 | public FrozenLtc(BigDecimal data) {
18 | super(FIELD, data);
19 | }
20 |
21 | public FrozenLtc(double data) {
22 | super(FIELD, new BigDecimal(data));
23 | }
24 |
25 | }
26 |
--------------------------------------------------------------------------------
/huobi-client-fix/src/main/java/org/oxerr/huobi/fix/field/ProcessedAmount.java:
--------------------------------------------------------------------------------
1 | package org.oxerr.huobi.fix.field;
2 |
3 | import java.math.BigDecimal;
4 |
5 | import quickfix.DecimalField;
6 |
7 | public class ProcessedAmount extends DecimalField {
8 |
9 | private static final long serialVersionUID = 20141102L;
10 |
11 | public static final int FIELD = 1631;
12 |
13 | public ProcessedAmount() {
14 | super(FIELD);
15 | }
16 |
17 | public ProcessedAmount(BigDecimal data) {
18 | super(FIELD, data);
19 | }
20 |
21 | public ProcessedAmount(double data) {
22 | super(FIELD, new BigDecimal(data));
23 | }
24 |
25 | }
26 |
--------------------------------------------------------------------------------
/huobi-client-fix/src/main/java/org/oxerr/huobi/fix/field/ProcessedPrice.java:
--------------------------------------------------------------------------------
1 | package org.oxerr.huobi.fix.field;
2 |
3 | import java.math.BigDecimal;
4 |
5 | import quickfix.DecimalField;
6 |
7 | public class ProcessedPrice extends DecimalField {
8 |
9 | private static final long serialVersionUID = 20141102L;
10 |
11 | public static final int FIELD = 1630;
12 |
13 | public ProcessedPrice() {
14 | super(FIELD);
15 | }
16 |
17 | public ProcessedPrice(BigDecimal data) {
18 | super(FIELD, data);
19 | }
20 |
21 | public ProcessedPrice(double data) {
22 | super(FIELD, new BigDecimal(data));
23 | }
24 |
25 | }
26 |
--------------------------------------------------------------------------------
/huobi-client-fix/src/main/java/org/oxerr/huobi/fix/field/Total.java:
--------------------------------------------------------------------------------
1 | package org.oxerr.huobi.fix.field;
2 |
3 | import java.math.BigDecimal;
4 |
5 | import quickfix.DecimalField;
6 |
7 | public class Total extends DecimalField {
8 |
9 | private static final long serialVersionUID = 20141102L;
10 |
11 | public static final int FIELD = 1634;
12 |
13 | public Total() {
14 | super(FIELD);
15 | }
16 |
17 | public Total(BigDecimal data) {
18 | super(FIELD, data);
19 | }
20 |
21 | public Total(double data) {
22 | super(FIELD, new BigDecimal(data));
23 | }
24 |
25 | }
26 |
--------------------------------------------------------------------------------
/huobi-client-fix/src/main/java/org/oxerr/huobi/fix/field/Vot.java:
--------------------------------------------------------------------------------
1 | package org.oxerr.huobi.fix.field;
2 |
3 | import java.math.BigDecimal;
4 |
5 | import quickfix.DecimalField;
6 |
7 | public class Vot extends DecimalField {
8 |
9 | private static final long serialVersionUID = 20141102L;
10 |
11 | public static final int FIELD = 1632;
12 |
13 | public Vot() {
14 | super(FIELD);
15 | }
16 |
17 | public Vot(BigDecimal data) {
18 | super(FIELD, data);
19 | }
20 |
21 | public Vot(double data) {
22 | super(FIELD, new BigDecimal(data));
23 | }
24 |
25 | }
26 |
--------------------------------------------------------------------------------
/huobi-client-fix/src/main/java/org/oxerr/huobi/fix/field/package-info.java:
--------------------------------------------------------------------------------
1 | /**
2 | * User Defined Fields for Huobi.
3 | */
4 | package org.oxerr.huobi.fix.field;
5 |
--------------------------------------------------------------------------------
/huobi-client-fix/src/main/java/org/oxerr/huobi/fix/fix44/AccountInfoRequest.java:
--------------------------------------------------------------------------------
1 | package org.oxerr.huobi.fix.fix44;
2 |
3 | import org.oxerr.huobi.fix.field.AccReqID;
4 |
5 | import quickfix.FieldNotFound;
6 | import quickfix.field.Account;
7 | import quickfix.field.MsgType;
8 | import quickfix.field.Symbol;
9 |
10 | /**
11 | * The request message for account info.
12 | */
13 | public class AccountInfoRequest extends quickfix.fix44.Message {
14 |
15 | private static final long serialVersionUID = 20141101L;
16 |
17 | public static final String MSGTYPE = "Z1000";
18 |
19 | public AccountInfoRequest() {
20 | getHeader().setField(new MsgType(MSGTYPE));
21 | }
22 |
23 | public void set(Account value) {
24 | setField(value);
25 | }
26 |
27 | public Account get(Account value) throws FieldNotFound {
28 | getField(value);
29 | return value;
30 | }
31 |
32 | public Account getAccount() throws FieldNotFound {
33 | Account value = new Account();
34 | getField(value);
35 | return value;
36 | }
37 |
38 | public boolean isSet(Account field) {
39 | return isSetField(field);
40 | }
41 |
42 | public boolean isSetAccount() {
43 | return isSetField(Account.FIELD);
44 | }
45 |
46 | public void set(AccReqID value) {
47 | setField(value);
48 | }
49 |
50 | public AccReqID get(AccReqID value) throws FieldNotFound {
51 | getField(value);
52 | return value;
53 | }
54 |
55 | public AccReqID getAccReqID() throws FieldNotFound {
56 | AccReqID value = new AccReqID();
57 | getField(value);
58 | return value;
59 | }
60 |
61 | public boolean isSet(AccReqID field) {
62 | return isSetField(field);
63 | }
64 |
65 | public boolean isSetAccReqID() {
66 | return isSetField(AccReqID.FIELD);
67 | }
68 |
69 | public void set(Symbol value) {
70 | setField(value);
71 | }
72 |
73 | public Symbol get(Symbol value) throws FieldNotFound {
74 | getField(value);
75 | return value;
76 | }
77 |
78 | public Symbol getSymbol() throws FieldNotFound {
79 | Symbol value = new Symbol();
80 | getField(value);
81 | return value;
82 | }
83 |
84 | public boolean isSet(Symbol field) {
85 | return isSetField(field);
86 | }
87 |
88 | public boolean isSetSymbol() {
89 | return isSetField(Symbol.FIELD);
90 | }
91 |
92 | }
93 |
--------------------------------------------------------------------------------
/huobi-client-fix/src/main/java/org/oxerr/huobi/fix/fix44/HuobiMessageFactory.java:
--------------------------------------------------------------------------------
1 | package org.oxerr.huobi.fix.fix44;
2 |
3 | import quickfix.Message;
4 | import quickfix.MessageFactory;
5 |
6 | /**
7 | * {@link MessageFactory} that added Huobi customized message support.
8 | */
9 | public class HuobiMessageFactory extends quickfix.fix44.MessageFactory {
10 |
11 | @Override
12 | public Message create(String beginString, String msgType) {
13 | if (AccountInfoResponse.MSGTYPE.equals(msgType)) {
14 | return new AccountInfoResponse();
15 | }
16 |
17 | if (HuobiOrderInfoResponse.MSGTYPE.equals(msgType)) {
18 | return new HuobiOrderInfoResponse();
19 | }
20 |
21 | return super.create(beginString, msgType);
22 | }
23 |
24 | }
25 |
--------------------------------------------------------------------------------
/huobi-client-fix/src/main/java/org/oxerr/huobi/fix/fix44/package-info.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Huobi customized FIX messages.
3 | */
4 | package org.oxerr.huobi.fix.fix44;
5 |
--------------------------------------------------------------------------------
/huobi-client-fix/src/main/java/org/oxerr/huobi/fix/package-info.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Implementation for Huobi FIX API v2.
3 | */
4 | package org.oxerr.huobi.fix;
5 |
--------------------------------------------------------------------------------
/huobi-client-rest/pom.xml:
--------------------------------------------------------------------------------
1 |
5 | 4.0.0
6 |
7 |
8 | org.oxerr
9 | huobi-client
10 | 2.1.0-SNAPSHOT
11 |
12 |
13 | huobi-client-rest
14 |
15 | Huobi Client - REST
16 |
17 | Huobi RESTful API.
19 | ]]>
20 |
21 |
22 |
23 | org.apache.commons
24 | commons-lang3
25 |
26 |
27 | org.apache.httpcomponents
28 | httpclient
29 |
30 |
31 | org.slf4j
32 | slf4j-api
33 |
34 |
35 | net.sourceforge.nekohtml
36 | nekohtml
37 |
38 |
39 | com.fasterxml.jackson.core
40 | jackson-core
41 |
42 |
43 | com.fasterxml.jackson.core
44 | jackson-databind
45 |
46 |
47 | com.xeiam.xchange
48 | xchange-core
49 |
50 |
51 | ch.qos.logback
52 | logback-classic
53 | true
54 |
55 |
56 | commons-io
57 | commons-io
58 |
59 |
60 |
61 |
--------------------------------------------------------------------------------
/huobi-client-rest/src/main/java/org/oxerr/huobi/rest/HuobiClientException.java:
--------------------------------------------------------------------------------
1 | package org.oxerr.huobi.rest;
2 |
3 | import java.io.IOException;
4 |
5 | public class HuobiClientException extends IOException {
6 |
7 | private static final long serialVersionUID = 2014010401L;
8 |
9 | public HuobiClientException() {
10 | }
11 |
12 | public HuobiClientException(String message) {
13 | super(message);
14 | }
15 |
16 | public HuobiClientException(String message, Throwable cause) {
17 | super(message, cause);
18 | }
19 |
20 | public HuobiClientException(Throwable cause) {
21 | super(cause);
22 | }
23 |
24 | }
25 |
--------------------------------------------------------------------------------
/huobi-client-rest/src/main/java/org/oxerr/huobi/rest/HuobiExchange.java:
--------------------------------------------------------------------------------
1 | package org.oxerr.huobi.rest;
2 |
3 | import java.util.Arrays;
4 | import java.util.List;
5 |
6 | import org.oxerr.huobi.rest.service.polling.HuobiAccountService;
7 | import org.oxerr.huobi.rest.service.polling.HuobiMarketDataService;
8 | import org.oxerr.huobi.rest.service.polling.HuobiTradeService;
9 |
10 | import si.mazi.rescu.SynchronizedValueFactory;
11 |
12 | import com.xeiam.xchange.BaseExchange;
13 | import com.xeiam.xchange.Exchange;
14 | import com.xeiam.xchange.ExchangeSpecification;
15 | import com.xeiam.xchange.currency.CurrencyPair;
16 |
17 | /**
18 | * Entry point to the XChange APIs.
19 | */
20 | public class HuobiExchange extends BaseExchange implements Exchange {
21 |
22 | /**
23 | * The parameter name of the symbols that will focus on.
24 | */
25 | public static final String SYMBOLS_PARAMETER = "symbols";
26 |
27 | public static final String TRADE_PASSWORD_PARAMETER = "trade_password";
28 |
29 | private static final List SYMBOLS = Arrays.asList(
30 | CurrencyPair.BTC_CNY,
31 | CurrencyPair.LTC_CNY);
32 |
33 | @Override
34 | public void applySpecification(ExchangeSpecification exchangeSpecification) {
35 | super.applySpecification(exchangeSpecification);
36 | pollingMarketDataService = new HuobiMarketDataService(this);
37 | if (exchangeSpecification.getApiKey() != null) {
38 | pollingAccountService = new HuobiAccountService(this);
39 | pollingTradeService = new HuobiTradeService(this);
40 | }
41 | }
42 |
43 | /**
44 | * {@inheritDoc}
45 | */
46 | @Override
47 | public ExchangeSpecification getDefaultExchangeSpecification() {
48 | ExchangeSpecification spec = new ExchangeSpecification(getClass());
49 | spec.setExchangeName("Huobi");
50 | spec.setExchangeDescription(
51 | "Huobi.com is the leading platform in cryptocurrency transactions, "
52 | + "which committed in providing professional, secure, "
53 | + "trustworthy services for investors around the world.");
54 | spec.setPlainTextUri("http://market.huobi.com/staticmarket");
55 | spec.setSslUri("https://api.huobi.com");
56 | spec.setExchangeSpecificParametersItem(SYMBOLS_PARAMETER, SYMBOLS);
57 | return spec;
58 | }
59 |
60 | /**
61 | * {@inheritDoc}
62 | */
63 | @Override
64 | public SynchronizedValueFactory getNonceFactory() {
65 | return null;
66 | }
67 |
68 | }
69 |
--------------------------------------------------------------------------------
/huobi-client-rest/src/main/java/org/oxerr/huobi/rest/LoginRequiredException.java:
--------------------------------------------------------------------------------
1 | package org.oxerr.huobi.rest;
2 |
3 | public class LoginRequiredException extends HuobiClientException {
4 |
5 | private static final long serialVersionUID = 2014010401L;
6 |
7 | }
8 |
--------------------------------------------------------------------------------
/huobi-client-rest/src/main/java/org/oxerr/huobi/rest/domain/AbstractObject.java:
--------------------------------------------------------------------------------
1 | package org.oxerr.huobi.rest.domain;
2 |
3 | import java.io.Serializable;
4 |
5 | import org.apache.commons.lang3.builder.ToStringBuilder;
6 |
7 | abstract class AbstractObject implements Serializable {
8 |
9 | private static final long serialVersionUID = 2014010201L;
10 |
11 | @Override
12 | public String toString() {
13 | return ToStringBuilder.reflectionToString(this);
14 | }
15 |
16 | }
17 |
--------------------------------------------------------------------------------
/huobi-client-rest/src/main/java/org/oxerr/huobi/rest/domain/Delegation.java:
--------------------------------------------------------------------------------
1 | package org.oxerr.huobi.rest.domain;
2 |
3 | import java.math.BigDecimal;
4 | import java.util.Date;
5 |
6 | public class Delegation extends AbstractObject {
7 |
8 | private static final long serialVersionUID = 2014010401L;
9 |
10 | /**
11 | * Delegation ID.
12 | */
13 | private long id;
14 |
15 | /**
16 | * 委托时间
17 | */
18 | private Date date;
19 |
20 | /**
21 | * 类别
22 | */
23 | private Type type;
24 |
25 | /**
26 | * 价格
27 | */
28 | private BigDecimal price;
29 |
30 | /**
31 | * 数量
32 | */
33 | private BigDecimal amount;
34 |
35 | /**
36 | * 交易额
37 | */
38 | private BigDecimal trading;
39 |
40 | /**
41 | * 手续费
42 | */
43 | private BigDecimal fee;
44 |
45 | /**
46 | * 总金额
47 | */
48 | private BigDecimal total;
49 |
50 | public long getId() {
51 | return id;
52 | }
53 |
54 | public void setId(long id) {
55 | this.id = id;
56 | }
57 |
58 | public Date getDate() {
59 | return date;
60 | }
61 |
62 | public void setDate(Date date) {
63 | this.date = date;
64 | }
65 |
66 | public Type getType() {
67 | return type;
68 | }
69 |
70 | public void setType(Type type) {
71 | this.type = type;
72 | }
73 |
74 | public BigDecimal getPrice() {
75 | return price;
76 | }
77 |
78 | public void setPrice(BigDecimal price) {
79 | this.price = price;
80 | }
81 |
82 | public BigDecimal getAmount() {
83 | return amount;
84 | }
85 |
86 | public void setAmount(BigDecimal amount) {
87 | this.amount = amount;
88 | }
89 |
90 | public BigDecimal getTrading() {
91 | return trading;
92 | }
93 |
94 | public void setTrading(BigDecimal trading) {
95 | this.trading = trading;
96 | }
97 |
98 | public BigDecimal getFee() {
99 | return fee;
100 | }
101 |
102 | public void setFee(BigDecimal fee) {
103 | this.fee = fee;
104 | }
105 |
106 | public BigDecimal getTotal() {
107 | return total;
108 | }
109 |
110 | public void setTotal(BigDecimal total) {
111 | this.total = total;
112 | }
113 |
114 | }
115 |
--------------------------------------------------------------------------------
/huobi-client-rest/src/main/java/org/oxerr/huobi/rest/domain/Depth.java:
--------------------------------------------------------------------------------
1 | package org.oxerr.huobi.rest.domain;
2 |
3 | import java.math.BigDecimal;
4 |
5 | import org.oxerr.huobi.rest.domain.Depth.Marketdepth.Data;
6 |
7 | /**
8 | * @deprecated Use {@link Depth} instead.
9 | */
10 | @Deprecated
11 | public class Depth extends AbstractObject {
12 |
13 | private static final long serialVersionUID = 2014010201L;
14 |
15 | private Marketdepth[] marketdepth;
16 |
17 | public Data[] getBids() {
18 | return marketdepth[0].getData();
19 | }
20 |
21 | public Data[] getAsks() {
22 | return marketdepth[1].getData();
23 | }
24 |
25 | public void setMarketdepth(Marketdepth[] marketdepth) {
26 | this.marketdepth = marketdepth;
27 | }
28 |
29 | public static class Marketdepth extends AbstractObject {
30 |
31 | private static final long serialVersionUID = 2014010201L;
32 |
33 | private String name;
34 |
35 | private Data[] data;
36 |
37 | public String getName() {
38 | return name;
39 | }
40 |
41 | public void setName(String name) {
42 | this.name = name;
43 | }
44 |
45 | public Data[] getData() {
46 | return data;
47 | }
48 |
49 | public void setData(BigDecimal[][] data) {
50 | this.data = new Data[data.length];
51 | for (int i = 0; i < data.length; i++) {
52 | this.data[i] = new Data(data[i]);
53 | }
54 | }
55 |
56 | public static class Data extends AbstractObject {
57 |
58 | private static final long serialVersionUID = 2014010201L;
59 |
60 | private BigDecimal[] points;
61 |
62 | public Data(BigDecimal[] points) {
63 | this.points = points;
64 | }
65 |
66 | public BigDecimal getPrice() {
67 | return points[0];
68 | }
69 |
70 | public BigDecimal getTotal() {
71 | return points[1];
72 | }
73 |
74 | public BigDecimal getAmount() {
75 | return points[2];
76 | }
77 |
78 | }
79 | }
80 | }
81 |
82 |
--------------------------------------------------------------------------------
/huobi-client-rest/src/main/java/org/oxerr/huobi/rest/domain/LoginResult.java:
--------------------------------------------------------------------------------
1 | package org.oxerr.huobi.rest.domain;
2 |
3 | public class LoginResult extends AbstractObject {
4 |
5 | private static final long serialVersionUID = 2014010201L;
6 |
7 | private String level;
8 |
9 | private Funds funds;
10 |
11 | public String getLevel() {
12 | return level;
13 | }
14 |
15 | public void setLevel(String level) {
16 | this.level = level;
17 | }
18 |
19 | public Funds getFunds() {
20 | return funds;
21 | }
22 |
23 | public void setFunds(Funds funds) {
24 | this.funds = funds;
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/huobi-client-rest/src/main/java/org/oxerr/huobi/rest/domain/TradeResult.java:
--------------------------------------------------------------------------------
1 | package org.oxerr.huobi.rest.domain;
2 |
3 | public class TradeResult extends AbstractObject {
4 |
5 | private static final long serialVersionUID = 2014010401L;
6 |
7 | private int code;
8 |
9 | private String msg;
10 |
11 | public int getCode() {
12 | return code;
13 | }
14 |
15 | public void setCode(int code) {
16 | this.code = code;
17 | }
18 |
19 | public String getMsg() {
20 | return msg;
21 | }
22 |
23 | public void setMsg(String msg) {
24 | this.msg = msg;
25 | }
26 |
27 | }
28 |
--------------------------------------------------------------------------------
/huobi-client-rest/src/main/java/org/oxerr/huobi/rest/domain/Type.java:
--------------------------------------------------------------------------------
1 | package org.oxerr.huobi.rest.domain;
2 |
3 | public enum Type {
4 |
5 | BUY("do_buy", "买入"), SELL("do_sell", "卖出");
6 |
7 | public static Type toType(String typeString) {
8 | for (Type type : Type.values()) {
9 | if (type.type.equals(typeString)) {
10 | return type;
11 | }
12 | }
13 |
14 | throw new IllegalArgumentException("Unexpected type: " + typeString);
15 | }
16 |
17 | public static Type delegationToType(String delegationTypeString) {
18 | for (Type type : Type.values()) {
19 | if (type.delegationType.equals(delegationTypeString)) {
20 | return type;
21 | }
22 | }
23 |
24 | throw new IllegalArgumentException("Unexpected delegation type: "
25 | + delegationTypeString);
26 | }
27 |
28 | private String type;
29 |
30 | private String delegationType;
31 |
32 | Type(String type, String delegationType) {
33 | this.type = type;
34 | this.delegationType = delegationType;
35 | }
36 |
37 | /**
38 | * @return the delegationType
39 | */
40 | public String getDelegationType() {
41 | return delegationType;
42 | }
43 |
44 | /**
45 | * {@inheritDoc}
46 | */
47 | @Override
48 | public String toString() {
49 | return type;
50 | }
51 |
52 | }
53 |
--------------------------------------------------------------------------------
/huobi-client-rest/src/main/java/org/oxerr/huobi/rest/domain/package-info.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Domain Objects.
3 | */
4 | package org.oxerr.huobi.rest.domain;
5 |
--------------------------------------------------------------------------------
/huobi-client-rest/src/main/java/org/oxerr/huobi/rest/dto/account/package-info.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Data transfer objects for account.
3 | */
4 | package org.oxerr.huobi.rest.dto.account;
5 |
--------------------------------------------------------------------------------
/huobi-client-rest/src/main/java/org/oxerr/huobi/rest/dto/marketdata/Depth.java:
--------------------------------------------------------------------------------
1 | package org.oxerr.huobi.rest.dto.marketdata;
2 |
3 | import java.math.BigDecimal;
4 |
5 | import com.fasterxml.jackson.annotation.JsonProperty;
6 |
7 | public class Depth {
8 |
9 | private final BigDecimal[][] asks;
10 | private final BigDecimal[][] bids;
11 |
12 | public Depth(
13 | @JsonProperty("asks") final BigDecimal[][] asks,
14 | @JsonProperty("bids") final BigDecimal[][] bids) {
15 | this.asks = asks;
16 | this.bids = bids;
17 | }
18 |
19 | public BigDecimal[][] getAsks() {
20 | return asks;
21 | }
22 |
23 | public BigDecimal[][] getBids() {
24 | return bids;
25 | }
26 |
27 | }
28 |
--------------------------------------------------------------------------------
/huobi-client-rest/src/main/java/org/oxerr/huobi/rest/dto/marketdata/OrderBookObject.java:
--------------------------------------------------------------------------------
1 | package org.oxerr.huobi.rest.dto.marketdata;
2 |
3 | import java.math.BigDecimal;
4 |
5 | import com.fasterxml.jackson.annotation.JsonProperty;
6 |
7 | public class OrderBookObject {
8 |
9 | private final BigDecimal price;
10 | private final BigDecimal level;
11 | private final BigDecimal amount;
12 |
13 | public OrderBookObject(
14 | @JsonProperty("price") final BigDecimal price,
15 | @JsonProperty("level") final BigDecimal level,
16 | @JsonProperty("amount") final BigDecimal amount) {
17 | this.price = price;
18 | this.level = level;
19 | this.amount = amount;
20 | }
21 |
22 | public BigDecimal getPrice() {
23 | return price;
24 | }
25 |
26 | public BigDecimal getLevel() {
27 | return level;
28 | }
29 |
30 | public BigDecimal getAmount() {
31 | return amount;
32 | }
33 |
34 | }
35 |
--------------------------------------------------------------------------------
/huobi-client-rest/src/main/java/org/oxerr/huobi/rest/dto/marketdata/Ticker.java:
--------------------------------------------------------------------------------
1 | package org.oxerr.huobi.rest.dto.marketdata;
2 |
3 | import com.fasterxml.jackson.annotation.JsonProperty;
4 |
5 | public class Ticker {
6 |
7 | private final TickerObject ticker;
8 |
9 | public Ticker(@JsonProperty("ticker") final TickerObject ticker) {
10 | this.ticker = ticker;
11 | }
12 |
13 | public TickerObject getTicker() {
14 | return ticker;
15 | }
16 |
17 | }
18 |
--------------------------------------------------------------------------------
/huobi-client-rest/src/main/java/org/oxerr/huobi/rest/dto/marketdata/TickerObject.java:
--------------------------------------------------------------------------------
1 | package org.oxerr.huobi.rest.dto.marketdata;
2 |
3 | import java.math.BigDecimal;
4 |
5 | import com.fasterxml.jackson.annotation.JsonProperty;
6 |
7 | public class TickerObject {
8 |
9 | private final BigDecimal high;
10 | private final BigDecimal low;
11 | private final BigDecimal last;
12 | private final BigDecimal vol;
13 | private final BigDecimal buy;
14 | private final BigDecimal sell;
15 |
16 | public TickerObject(
17 | @JsonProperty("high") final BigDecimal high,
18 | @JsonProperty("low") final BigDecimal low,
19 | @JsonProperty("last") final BigDecimal last,
20 | @JsonProperty("vol") final BigDecimal vol,
21 | @JsonProperty("buy") final BigDecimal buy,
22 | @JsonProperty("sell") final BigDecimal sell) {
23 | this.high = high;
24 | this.low = low;
25 | this.last = last;
26 | this.vol = vol;
27 | this.buy = buy;
28 | this.sell = sell;
29 | }
30 |
31 | public BigDecimal getHigh() {
32 | return high;
33 | }
34 |
35 | public BigDecimal getLow() {
36 | return low;
37 | }
38 |
39 | public BigDecimal getLast() {
40 | return last;
41 | }
42 |
43 | public BigDecimal getVol() {
44 | return vol;
45 | }
46 |
47 | public BigDecimal getBuy() {
48 | return buy;
49 | }
50 |
51 | public BigDecimal getSell() {
52 | return sell;
53 | }
54 |
55 | }
56 |
--------------------------------------------------------------------------------
/huobi-client-rest/src/main/java/org/oxerr/huobi/rest/dto/marketdata/TopObject.java:
--------------------------------------------------------------------------------
1 | package org.oxerr.huobi.rest.dto.marketdata;
2 |
3 | import java.math.BigDecimal;
4 |
5 | import com.fasterxml.jackson.annotation.JsonProperty;
6 |
7 | public class TopObject {
8 |
9 | private final BigDecimal price;
10 | private final BigDecimal level;
11 | private final BigDecimal amount;
12 | private final BigDecimal accu;
13 |
14 | public TopObject(
15 | @JsonProperty("price") final BigDecimal price,
16 | @JsonProperty("level") final BigDecimal level,
17 | @JsonProperty("amount") final BigDecimal amount,
18 | @JsonProperty("accu") final BigDecimal accu) {
19 | this.price = price;
20 | this.level = level;
21 | this.amount = amount;
22 | this.accu = accu;
23 | }
24 |
25 | public BigDecimal getPrice() {
26 | return price;
27 | }
28 |
29 | public BigDecimal getLevel() {
30 | return level;
31 | }
32 |
33 | public BigDecimal getAmount() {
34 | return amount;
35 | }
36 |
37 | public BigDecimal getAccu() {
38 | return accu;
39 | }
40 |
41 | }
42 |
--------------------------------------------------------------------------------
/huobi-client-rest/src/main/java/org/oxerr/huobi/rest/dto/marketdata/TradeObject.java:
--------------------------------------------------------------------------------
1 | package org.oxerr.huobi.rest.dto.marketdata;
2 |
3 | import java.math.BigDecimal;
4 |
5 | import com.fasterxml.jackson.annotation.JsonProperty;
6 |
7 | public class TradeObject {
8 |
9 | private final String time;
10 | private final BigDecimal price;
11 | private final BigDecimal amount;
12 | private final String type;
13 |
14 | public TradeObject(
15 | @JsonProperty("time") final String time,
16 | @JsonProperty("price") final BigDecimal price,
17 | @JsonProperty("amount") final BigDecimal amount,
18 | @JsonProperty("type") final String type) {
19 | this.time = time;
20 | this.price = price;
21 | this.amount = amount;
22 | this.type = type;
23 | }
24 |
25 | public String getTime() {
26 | return time;
27 | }
28 |
29 | public BigDecimal getPrice() {
30 | return price;
31 | }
32 |
33 | public BigDecimal getAmount() {
34 | return amount;
35 | }
36 |
37 | public String getType() {
38 | return type;
39 | }
40 |
41 | }
42 |
--------------------------------------------------------------------------------
/huobi-client-rest/src/main/java/org/oxerr/huobi/rest/dto/marketdata/package-info.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Data transfer objects for market data.
3 | */
4 | package org.oxerr.huobi.rest.dto.marketdata;
5 |
--------------------------------------------------------------------------------
/huobi-client-rest/src/main/java/org/oxerr/huobi/rest/dto/package-info.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Data transfer objects.
3 | */
4 | package org.oxerr.huobi.rest.dto;
5 |
--------------------------------------------------------------------------------
/huobi-client-rest/src/main/java/org/oxerr/huobi/rest/dto/trade/CancelOrderResult.java:
--------------------------------------------------------------------------------
1 | package org.oxerr.huobi.rest.dto.trade;
2 |
3 | import com.fasterxml.jackson.annotation.JsonProperty;
4 |
5 | public class CancelOrderResult extends HuobiError {
6 |
7 | private final String result;
8 |
9 | public CancelOrderResult(
10 | @JsonProperty("code") final int code,
11 | @JsonProperty("msg") final String msg,
12 | @JsonProperty("time") final long time,
13 | @JsonProperty("result") final String result) {
14 | super(code, msg, time);
15 | this.result = result;
16 | }
17 |
18 | public String getResult() {
19 | return result;
20 | }
21 |
22 | }
23 |
--------------------------------------------------------------------------------
/huobi-client-rest/src/main/java/org/oxerr/huobi/rest/dto/trade/HuobiError.java:
--------------------------------------------------------------------------------
1 | package org.oxerr.huobi.rest.dto.trade;
2 |
3 | import com.fasterxml.jackson.annotation.JsonProperty;
4 |
5 | public class HuobiError {
6 |
7 | public static final int ORDER_NOT_EXIST = 26;
8 |
9 | private final int code;
10 | private final String msg;
11 | private final long time;
12 |
13 | public HuobiError(
14 | @JsonProperty("code") final int code,
15 | @JsonProperty("msg") final String msg,
16 | @JsonProperty("time") final long time) {
17 | this.code = code;
18 | this.msg = msg;
19 | this.time = time;
20 | }
21 |
22 | public int getCode() {
23 | return code;
24 | }
25 |
26 | public String getMsg() {
27 | return msg;
28 | }
29 |
30 | public long getTime() {
31 | return time;
32 | }
33 |
34 | }
35 |
--------------------------------------------------------------------------------
/huobi-client-rest/src/main/java/org/oxerr/huobi/rest/dto/trade/PlaceOrderResult.java:
--------------------------------------------------------------------------------
1 | package org.oxerr.huobi.rest.dto.trade;
2 |
3 | import com.fasterxml.jackson.annotation.JsonProperty;
4 |
5 | public class PlaceOrderResult extends HuobiError {
6 |
7 | private final String result;
8 | private final long id;
9 |
10 | public PlaceOrderResult(
11 | @JsonProperty("code") final int code,
12 | @JsonProperty("msg") final String msg,
13 | @JsonProperty("time") final long time,
14 | @JsonProperty("result") final String result,
15 | @JsonProperty("id") final long id) {
16 | super(code, msg, time);
17 | this.result = result;
18 | this.id = id;
19 | }
20 |
21 | public String getResult() {
22 | return result;
23 | }
24 |
25 | public long getId() {
26 | return id;
27 | }
28 |
29 | }
30 |
--------------------------------------------------------------------------------
/huobi-client-rest/src/main/java/org/oxerr/huobi/rest/dto/trade/package-info.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Data transfer objects for trading.
3 | */
4 | package org.oxerr.huobi.rest.dto.trade;
5 |
--------------------------------------------------------------------------------
/huobi-client-rest/src/main/java/org/oxerr/huobi/rest/package-info.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Client for HUOBI.
3 | */
4 | package org.oxerr.huobi.rest;
5 |
--------------------------------------------------------------------------------
/huobi-client-rest/src/main/java/org/oxerr/huobi/rest/service/HuobiDigest.java:
--------------------------------------------------------------------------------
1 | package org.oxerr.huobi.rest.service;
2 |
3 | import static org.apache.commons.codec.digest.DigestUtils.md5Hex;
4 |
5 | import java.util.ArrayList;
6 | import java.util.Collections;
7 | import java.util.Comparator;
8 | import java.util.List;
9 | import java.util.Map;
10 | import java.util.Map.Entry;
11 |
12 | import javax.ws.rs.FormParam;
13 |
14 | import si.mazi.rescu.Params;
15 | import si.mazi.rescu.ParamsDigest;
16 | import si.mazi.rescu.RestInvocation;
17 |
18 | public class HuobiDigest implements ParamsDigest {
19 |
20 | private final String secretKey;
21 |
22 | public HuobiDigest(final String secretKey) {
23 | this.secretKey = secretKey;
24 | }
25 |
26 | /**
27 | * {@inheritDoc}
28 | */
29 | @Override
30 | public String digestParams(RestInvocation restInvocation) {
31 | final Params params = restInvocation.getParamsMap().get(FormParam.class);
32 |
33 | final Map nameValueMap = params.asHttpHeaders();
34 | nameValueMap.remove("sign");
35 | nameValueMap.remove("trade_password");
36 | nameValueMap.put("secret_key", secretKey);
37 |
38 | final List> nameValueList = new ArrayList<>(
39 | nameValueMap.entrySet());
40 | Collections.sort(nameValueList, new Comparator>() {
41 | @Override
42 | public int compare(
43 | Entry o1,
44 | Entry o2) {
45 | return o1.getKey().compareTo(o2.getKey());
46 | }
47 | });
48 |
49 | final Params newParams = Params.of();
50 | for (Map.Entry param : nameValueList) {
51 | newParams.add(param.getKey(), param.getValue());
52 | }
53 |
54 | final String message = newParams.asQueryString();
55 |
56 | return md5Hex(message);
57 | }
58 |
59 | }
60 |
--------------------------------------------------------------------------------
/huobi-client-rest/src/main/java/org/oxerr/huobi/rest/service/polling/HuobiAccountService.java:
--------------------------------------------------------------------------------
1 | package org.oxerr.huobi.rest.service.polling;
2 |
3 | import java.io.IOException;
4 | import java.math.BigDecimal;
5 |
6 | import org.oxerr.huobi.rest.HuobiAdapters;
7 |
8 | import com.xeiam.xchange.Exchange;
9 | import com.xeiam.xchange.dto.account.AccountInfo;
10 | import com.xeiam.xchange.exceptions.NotAvailableFromExchangeException;
11 | import com.xeiam.xchange.service.polling.account.PollingAccountService;
12 |
13 | public class HuobiAccountService extends HuobiAccountServiceRaw implements
14 | PollingAccountService {
15 |
16 | public HuobiAccountService(Exchange exchange) {
17 | super(exchange);
18 | }
19 |
20 | /**
21 | * {@inheritDoc}
22 | */
23 | @Override
24 | public AccountInfo getAccountInfo() throws IOException {
25 | return HuobiAdapters.adaptAccountInfo(getHUOBIAccountInfo());
26 | }
27 |
28 | /**
29 | * {@inheritDoc}
30 | */
31 | @Override
32 | public String withdrawFunds(String currency, BigDecimal amount,
33 | String address) {
34 | throw new NotAvailableFromExchangeException();
35 | }
36 |
37 | /**
38 | * {@inheritDoc}
39 | */
40 | @Override
41 | public String requestDepositAddress(String currency, String... args) {
42 | throw new NotAvailableFromExchangeException();
43 | }
44 |
45 | }
46 |
--------------------------------------------------------------------------------
/huobi-client-rest/src/main/java/org/oxerr/huobi/rest/service/polling/HuobiAccountServiceRaw.java:
--------------------------------------------------------------------------------
1 | package org.oxerr.huobi.rest.service.polling;
2 |
3 | import java.io.IOException;
4 |
5 | import org.oxerr.huobi.rest.dto.account.AccountInfo;
6 |
7 | import com.xeiam.xchange.Exchange;
8 |
9 | public class HuobiAccountServiceRaw extends HuobiBaseTradeService {
10 |
11 | protected HuobiAccountServiceRaw(Exchange exchange) {
12 | super(exchange);
13 | }
14 |
15 | public AccountInfo getHUOBIAccountInfo() throws IOException {
16 | return huobi.getAccountInfo("get_account_info",
17 | accessKey, nextCreated(), digest);
18 | }
19 |
20 | }
21 |
--------------------------------------------------------------------------------
/huobi-client-rest/src/main/java/org/oxerr/huobi/rest/service/polling/HuobiBasePollingService.java:
--------------------------------------------------------------------------------
1 | package org.oxerr.huobi.rest.service.polling;
2 |
3 | import static org.oxerr.huobi.rest.HuobiExchange.SYMBOLS_PARAMETER;
4 |
5 | import java.util.List;
6 |
7 | import com.xeiam.xchange.Exchange;
8 | import com.xeiam.xchange.ExchangeSpecification;
9 | import com.xeiam.xchange.currency.CurrencyPair;
10 | import com.xeiam.xchange.service.BaseExchangeService;
11 | import com.xeiam.xchange.service.polling.BasePollingService;
12 |
13 | public class HuobiBasePollingService extends BaseExchangeService implements
14 | BasePollingService {
15 |
16 | private final List symbols;
17 |
18 | @SuppressWarnings("unchecked")
19 | protected HuobiBasePollingService(Exchange exchange) {
20 | super(exchange);
21 | ExchangeSpecification spec = exchange.getExchangeSpecification();
22 | symbols = (List) spec
23 | .getExchangeSpecificParametersItem(SYMBOLS_PARAMETER);
24 | }
25 |
26 | /**
27 | * {@inheritDoc}
28 | */
29 | @Override
30 | public List getExchangeSymbols() {
31 | return symbols;
32 | }
33 |
34 | }
35 |
--------------------------------------------------------------------------------
/huobi-client-rest/src/main/java/org/oxerr/huobi/rest/service/polling/HuobiBaseTradeService.java:
--------------------------------------------------------------------------------
1 | package org.oxerr.huobi.rest.service.polling;
2 |
3 | import org.oxerr.huobi.rest.Huobi;
4 | import org.oxerr.huobi.rest.service.HuobiDigest;
5 |
6 | import si.mazi.rescu.RestProxyFactory;
7 |
8 | import com.xeiam.xchange.Exchange;
9 | import com.xeiam.xchange.ExchangeSpecification;
10 |
11 | public class HuobiBaseTradeService extends HuobiBasePollingService {
12 |
13 | protected final Huobi huobi;
14 | protected final String accessKey;
15 | protected final HuobiDigest digest;
16 |
17 | protected HuobiBaseTradeService(Exchange exchange) {
18 | super(exchange);
19 | ExchangeSpecification spec = exchange.getExchangeSpecification();
20 | final String baseUrl = spec.getSslUri();
21 | huobi = RestProxyFactory.createProxy(Huobi.class, baseUrl);
22 | accessKey = spec.getApiKey();
23 | digest = new HuobiDigest(spec.getSecretKey());
24 | }
25 |
26 | protected long nextCreated() {
27 | return System.currentTimeMillis() / 1000;
28 | }
29 |
30 | }
31 |
--------------------------------------------------------------------------------
/huobi-client-rest/src/main/java/org/oxerr/huobi/rest/service/polling/HuobiMarketDataService.java:
--------------------------------------------------------------------------------
1 | package org.oxerr.huobi.rest.service.polling;
2 |
3 | import java.io.IOException;
4 |
5 | import org.oxerr.huobi.rest.HuobiAdapters;
6 |
7 | import com.xeiam.xchange.Exchange;
8 | import com.xeiam.xchange.currency.CurrencyPair;
9 | import com.xeiam.xchange.dto.marketdata.OrderBook;
10 | import com.xeiam.xchange.dto.marketdata.Ticker;
11 | import com.xeiam.xchange.dto.marketdata.Trades;
12 | import com.xeiam.xchange.service.polling.marketdata.PollingMarketDataService;
13 |
14 | public class HuobiMarketDataService extends HuobiMarketDataServiceRaw implements
15 | PollingMarketDataService {
16 |
17 | public HuobiMarketDataService(Exchange exchange) {
18 | super(exchange);
19 | }
20 |
21 | /**
22 | * {@inheritDoc}
23 | */
24 | @Override
25 | public Ticker getTicker(CurrencyPair currencyPair, Object... args)
26 | throws IOException {
27 | return HuobiAdapters.adaptTicker(
28 | getHUOBITicker(currencyPair.baseSymbol.toLowerCase()),
29 | currencyPair);
30 | }
31 |
32 | /**
33 | * {@inheritDoc}
34 | */
35 | @Override
36 | public OrderBook getOrderBook(CurrencyPair currencyPair, Object... args)
37 | throws IOException {
38 | return HuobiAdapters.adaptOrderBook(
39 | getHUOBIDepth(currencyPair.baseSymbol.toLowerCase()),
40 | currencyPair);
41 | }
42 |
43 | /**
44 | * {@inheritDoc}
45 | */
46 | @Override
47 | public Trades getTrades(CurrencyPair currencyPair, Object... args)
48 | throws IOException {
49 | return HuobiAdapters.adaptTrades(
50 | getHUOBIDetail(currencyPair.baseSymbol.toLowerCase()),
51 | currencyPair);
52 | }
53 |
54 | }
55 |
--------------------------------------------------------------------------------
/huobi-client-rest/src/main/java/org/oxerr/huobi/rest/service/polling/HuobiMarketDataServiceRaw.java:
--------------------------------------------------------------------------------
1 | package org.oxerr.huobi.rest.service.polling;
2 |
3 | import java.io.IOException;
4 |
5 | import org.oxerr.huobi.rest.Huobi;
6 | import org.oxerr.huobi.rest.dto.marketdata.Depth;
7 | import org.oxerr.huobi.rest.dto.marketdata.OrderBookTAS;
8 | import org.oxerr.huobi.rest.dto.marketdata.Ticker;
9 |
10 | import si.mazi.rescu.RestProxyFactory;
11 |
12 | import com.xeiam.xchange.Exchange;
13 | import com.xeiam.xchange.ExchangeSpecification;
14 |
15 | public class HuobiMarketDataServiceRaw extends HuobiBasePollingService {
16 |
17 | private final Huobi huobi;
18 |
19 | protected HuobiMarketDataServiceRaw(Exchange exchange) {
20 | super(exchange);
21 | ExchangeSpecification spec = exchange.getExchangeSpecification();
22 | final String baseUrl = spec.getPlainTextUri();
23 | huobi = RestProxyFactory.createProxy(Huobi.class, baseUrl);
24 | }
25 |
26 | public Ticker getHUOBITicker(String symbol) throws IOException {
27 | return huobi.getTicker(symbol);
28 | }
29 |
30 | public Depth getHUOBIDepth(String symbol) throws IOException {
31 | return huobi.getDepth(symbol);
32 | }
33 |
34 | public String[][] getHUOBIKline(String symbol, String period)
35 | throws IOException {
36 | return huobi.getKline(symbol, period);
37 | }
38 |
39 | public OrderBookTAS getHUOBIDetail(String symbol)
40 | throws IOException {
41 | return huobi.getDetail(symbol);
42 | }
43 |
44 | }
45 |
--------------------------------------------------------------------------------
/huobi-client-rest/src/main/java/org/oxerr/huobi/rest/service/polling/package-info.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Polling services.
3 | */
4 | package org.oxerr.huobi.rest.service.polling;
5 |
--------------------------------------------------------------------------------
/huobi-client-rest/src/main/java/org/oxerr/huobi/rest/valuereader/HTMLReader.java:
--------------------------------------------------------------------------------
1 | package org.oxerr.huobi.rest.valuereader;
2 |
3 | import static org.oxerr.huobi.rest.HuobiClient.ENCODING;
4 |
5 | import java.io.IOException;
6 | import java.io.InputStream;
7 | import java.io.InputStreamReader;
8 | import java.io.UnsupportedEncodingException;
9 |
10 | import org.apache.commons.io.IOUtils;
11 | import org.cyberneko.html.parsers.DOMParser;
12 | import org.oxerr.huobi.rest.HuobiClientException;
13 | import org.slf4j.Logger;
14 | import org.slf4j.LoggerFactory;
15 | import org.w3c.dom.html.HTMLDocument;
16 | import org.xml.sax.InputSource;
17 | import org.xml.sax.SAXException;
18 |
19 | public abstract class HTMLReader implements ValueReader{
20 |
21 | private final Logger log = LoggerFactory.getLogger(HTMLReader.class);
22 |
23 | @Override
24 | public T read(InputStream inputStream) throws IOException {
25 | final String content = IOUtils.toString(inputStream, ENCODING);
26 | log.debug("Parsing HTML: {}", content);
27 | try {
28 | return parse(content);
29 | } catch (HuobiClientException e) {
30 | throw e;
31 | } catch (IOException e) {
32 | log.error("Parse from \"{}\" failed.", content);
33 | throw e;
34 | } catch (SAXException e) {
35 | String msg = String.format("Parse from \"%1$s\" failed.", content);
36 | throw new IOException(msg, e);
37 | }
38 | }
39 |
40 | protected abstract T parse(HTMLDocument document)
41 | throws HuobiClientException;
42 |
43 | private T parse(String content) throws UnsupportedEncodingException,
44 | IOException, SAXException {
45 | HTMLDocument document = toDocument(content);
46 | return parse(document);
47 | }
48 |
49 | private HTMLDocument toDocument(String content)
50 | throws UnsupportedEncodingException, IOException, SAXException {
51 | final InputSource inputSource;
52 | inputSource = new InputSource(new InputStreamReader(
53 | IOUtils.toInputStream(content, ENCODING), ENCODING));
54 |
55 | DOMParser parser = new DOMParser();
56 | parser.parse(inputSource);
57 | HTMLDocument document = (HTMLDocument) parser.getDocument();
58 | return document;
59 | }
60 |
61 | }
62 |
--------------------------------------------------------------------------------
/huobi-client-rest/src/main/java/org/oxerr/huobi/rest/valuereader/JsonValueReader.java:
--------------------------------------------------------------------------------
1 | package org.oxerr.huobi.rest.valuereader;
2 |
3 | import static org.oxerr.huobi.rest.HuobiClient.ENCODING;
4 |
5 | import java.io.IOException;
6 | import java.io.InputStream;
7 |
8 | import org.apache.commons.io.IOUtils;
9 | import org.slf4j.Logger;
10 | import org.slf4j.LoggerFactory;
11 |
12 | import com.fasterxml.jackson.core.JsonParseException;
13 | import com.fasterxml.jackson.databind.ObjectMapper;
14 |
15 | public class JsonValueReader implements ValueReader {
16 |
17 | private final Logger log = LoggerFactory.getLogger(JsonValueReader.class);
18 |
19 | private final ObjectMapper objectMapper;
20 |
21 | private final Class valueType;
22 |
23 | public JsonValueReader(ObjectMapper objectMapper, Class valueType) {
24 | this.objectMapper = objectMapper;
25 | this.valueType = valueType;
26 | }
27 |
28 | /**
29 | * {@inheritDoc}
30 | */
31 | @Override
32 | public T read(InputStream inputStream) throws IOException {
33 | final String content = IOUtils.toString(inputStream, ENCODING);
34 | return read(content);
35 | }
36 |
37 | protected T read(String content) throws IOException {
38 | log.debug("Reading {} from \"{}\".", valueType, content);
39 |
40 | try (InputStream in = IOUtils.toInputStream(content, ENCODING)) {
41 | return objectMapper.readValue(in, valueType);
42 | } catch (JsonParseException e) {
43 | String msg = String.format("Parse from \"%1$s\" failed: %2$s",
44 | content,
45 | e.getMessage());
46 | throw new JsonParseException(msg, e.getLocation(), e);
47 | }
48 | }
49 |
50 | }
--------------------------------------------------------------------------------
/huobi-client-rest/src/main/java/org/oxerr/huobi/rest/valuereader/JsonValueTypeRefReader.java:
--------------------------------------------------------------------------------
1 | package org.oxerr.huobi.rest.valuereader;
2 |
3 | import java.io.IOException;
4 | import java.io.InputStream;
5 |
6 | import com.fasterxml.jackson.core.type.TypeReference;
7 | import com.fasterxml.jackson.databind.ObjectMapper;
8 |
9 | public class JsonValueTypeRefReader implements ValueReader {
10 |
11 | private final ObjectMapper objectMapper;
12 |
13 | private final TypeReference valueTypeRef;
14 |
15 | public JsonValueTypeRefReader(ObjectMapper objectMapper, TypeReference valueTypeRef) {
16 | this.objectMapper = objectMapper;
17 | this.valueTypeRef = valueTypeRef;
18 | }
19 |
20 | /**
21 | * {@inheritDoc}
22 | */
23 | @Override
24 | public T read(InputStream content) throws IOException {
25 | return objectMapper.readValue(content, valueTypeRef);
26 | }
27 |
28 | }
--------------------------------------------------------------------------------
/huobi-client-rest/src/main/java/org/oxerr/huobi/rest/valuereader/ValueReader.java:
--------------------------------------------------------------------------------
1 | package org.oxerr.huobi.rest.valuereader;
2 |
3 | import java.io.IOException;
4 | import java.io.InputStream;
5 |
6 | public interface ValueReader {
7 |
8 | T read(InputStream inputStream) throws IOException;
9 |
10 | }
--------------------------------------------------------------------------------
/huobi-client-rest/src/main/java/org/oxerr/huobi/rest/valuereader/VoidValueReader.java:
--------------------------------------------------------------------------------
1 | package org.oxerr.huobi.rest.valuereader;
2 |
3 | import static org.oxerr.huobi.rest.HuobiClient.ENCODING;
4 |
5 | import java.io.IOException;
6 | import java.io.InputStream;
7 |
8 | import org.apache.commons.io.IOUtils;
9 | import org.slf4j.Logger;
10 | import org.slf4j.LoggerFactory;
11 |
12 | public class VoidValueReader implements ValueReader{
13 |
14 | private static final VoidValueReader INSTANCE = new VoidValueReader();
15 |
16 | private final Logger log = LoggerFactory.getLogger(VoidValueReader.class);
17 |
18 | public static final VoidValueReader getInstance() {
19 | return INSTANCE;
20 | }
21 |
22 | /**
23 | * {@inheritDoc}
24 | */
25 | @Override
26 | public Void read(InputStream inputStream) throws IOException {
27 | final String content = IOUtils.toString(inputStream, ENCODING);
28 | log.debug("Parsing: {}", content);
29 |
30 | return null;
31 | }
32 |
33 | }
34 |
--------------------------------------------------------------------------------
/huobi-client-rest/src/main/java/org/oxerr/huobi/rest/valuereader/package-info.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Value Readers.
3 | */
4 | package org.oxerr.huobi.rest.valuereader;
5 |
--------------------------------------------------------------------------------
/huobi-client-rest/src/main/resources/huobi.json:
--------------------------------------------------------------------------------
1 | {
2 | "currency_pairs":[
3 | "BTC/CNY",
4 | "LTC/CNY"
5 | ]
6 | }
7 |
--------------------------------------------------------------------------------
/huobi-client-rest/src/test/java/org/oxerr/huobi/rest/HuobiAdaptersTest.java:
--------------------------------------------------------------------------------
1 | package org.oxerr.huobi.rest;
2 |
3 | import static org.junit.Assert.assertEquals;
4 |
5 | import java.io.IOException;
6 | import java.math.BigDecimal;
7 | import java.util.List;
8 |
9 | import org.junit.Test;
10 | import org.oxerr.huobi.rest.HuobiAdapters;
11 | import org.oxerr.huobi.rest.dto.marketdata.Depth;
12 | import org.oxerr.huobi.rest.dto.marketdata.DepthTest;
13 | import org.oxerr.huobi.rest.dto.marketdata.UnmarshalTest;
14 |
15 | import com.xeiam.xchange.currency.CurrencyPair;
16 | import com.xeiam.xchange.dto.marketdata.OrderBook;
17 | import com.xeiam.xchange.dto.trade.LimitOrder;
18 |
19 | public class HuobiAdaptersTest extends UnmarshalTest {
20 |
21 | @Test
22 | public void testAdaptOrderBook() throws IOException {
23 | Depth huobiDepth = readValue(DepthTest.class, "depth.json", Depth.class);
24 | OrderBook orderBook = HuobiAdapters.adaptOrderBook(huobiDepth, CurrencyPair.BTC_CNY);
25 |
26 | List asks = orderBook.getAsks();
27 | List bids = orderBook.getBids();
28 |
29 | // asks should be sorted ascending
30 | // ask 0.01@90.7
31 | assertEquals(new BigDecimal("90.7"), asks.get(0).getLimitPrice());
32 | assertEquals(new BigDecimal("0.01"), asks.get(0).getTradableAmount());
33 |
34 | // ask 0.5@90.8
35 | assertEquals(new BigDecimal("90.8"), asks.get(1).getLimitPrice());
36 | assertEquals(new BigDecimal("0.5"), asks.get(1).getTradableAmount());
37 |
38 | // bids should be sorted deascending
39 | // bid 79.243@86.06
40 | assertEquals(new BigDecimal("86.06"), bids.get(0).getLimitPrice());
41 | assertEquals(new BigDecimal("79.243"), bids.get(0).getTradableAmount());
42 |
43 | // bid 0.02@86.05
44 | assertEquals(new BigDecimal("86.05"), bids.get(1).getLimitPrice());
45 | assertEquals(new BigDecimal("0.02"), bids.get(1).getTradableAmount());
46 | }
47 |
48 | }
49 |
--------------------------------------------------------------------------------
/huobi-client-rest/src/test/java/org/oxerr/huobi/rest/domain/TradeResultTest.java:
--------------------------------------------------------------------------------
1 | package org.oxerr.huobi.rest.domain;
2 |
3 | import static org.junit.Assert.*;
4 |
5 | import java.io.IOException;
6 | import java.io.InputStream;
7 |
8 | import org.junit.Test;
9 | import org.oxerr.huobi.rest.domain.TradeResult;
10 | import org.oxerr.huobi.rest.valuereader.JsonValueReader;
11 |
12 | import com.fasterxml.jackson.databind.ObjectMapper;
13 |
14 | public class TradeResultTest {
15 |
16 | private JsonValueReader jvr = new JsonValueReader<>(
17 | new ObjectMapper(), TradeResult.class);
18 |
19 | @Test
20 | public void test0() throws IOException {
21 | try (InputStream inputStream = getClass().getResourceAsStream(
22 | "tradeResult0.json")) {
23 | TradeResult tr = jvr.read(inputStream);
24 | assertEquals(0, tr.getCode());
25 | assertEquals("卖单已委托,查看结果",
26 | tr.getMsg());
27 | }
28 | }
29 |
30 | @Test
31 | public void test2() throws IOException {
32 | try (InputStream inputStream = getClass().getResourceAsStream(
33 | "tradeResult2.json")) {
34 | TradeResult tr = jvr.read(inputStream);
35 | assertEquals(2, tr.getCode());
36 | assertEquals("没有足够的人民币", tr.getMsg());
37 | }
38 | }
39 |
40 | @Test
41 | public void testCancel() throws IOException {
42 | try (InputStream inputStream = getClass().getResourceAsStream("cancel.json")) {
43 | TradeResult tr = jvr.read(inputStream);
44 | assertEquals(0, tr.getCode());
45 | assertEquals("取消委托成功", tr.getMsg());
46 | }
47 | }
48 |
49 | }
50 |
--------------------------------------------------------------------------------
/huobi-client-rest/src/test/java/org/oxerr/huobi/rest/domain/TypeTest.java:
--------------------------------------------------------------------------------
1 | package org.oxerr.huobi.rest.domain;
2 |
3 | import static org.junit.Assert.assertEquals;
4 | import static org.junit.Assert.assertTrue;
5 |
6 | import org.junit.Test;
7 | import org.oxerr.huobi.rest.domain.Type;
8 |
9 | public class TypeTest {
10 |
11 | @Test
12 | public void testToType() {
13 | assertTrue(Type.toType("do_sell") == Type.SELL);
14 | assertTrue(Type.delegationToType("卖出") == Type.SELL);
15 | }
16 |
17 | @Test
18 | public void testType() {
19 | assertEquals("do_sell", Type.SELL.toString());
20 | assertEquals("卖出", Type.SELL.getDelegationType());
21 | }
22 |
23 | }
24 |
--------------------------------------------------------------------------------
/huobi-client-rest/src/test/java/org/oxerr/huobi/rest/dto/account/AccountInfoTest.java:
--------------------------------------------------------------------------------
1 | package org.oxerr.huobi.rest.dto.account;
2 |
3 | import static org.junit.Assert.assertEquals;
4 |
5 | import java.io.IOException;
6 | import java.math.BigDecimal;
7 |
8 | import org.junit.Test;
9 | import org.oxerr.huobi.rest.dto.account.AccountInfo;
10 | import org.oxerr.huobi.rest.dto.marketdata.UnmarshalTest;
11 |
12 | public class AccountInfoTest extends UnmarshalTest {
13 |
14 | @Test
15 | public void test() throws IOException {
16 | AccountInfo accountInfo = readValue(getClass(), "account-info.json", AccountInfo.class);
17 | assertEquals(new BigDecimal("4459.38"), accountInfo.getTotal());
18 | assertEquals(new BigDecimal("4459.38"), accountInfo.getNetAsset());
19 | assertEquals(new BigDecimal("2985.40"), accountInfo.getAvailableCnyDisplay());
20 | assertEquals(new BigDecimal("0.3244"), accountInfo.getAvailableBtcDisplay());
21 | assertEquals(new BigDecimal("0.1000"), accountInfo.getAvailableLtcDisplay());
22 | assertEquals(new BigDecimal("0.20"), accountInfo.getFrozenCnyDisplay());
23 | assertEquals(new BigDecimal("0.0530"), accountInfo.getFrozenBtcDisplay());
24 | assertEquals(new BigDecimal("0.3000"), accountInfo.getFrozenLtcDisplay());
25 | assertEquals(new BigDecimal("0.40"), accountInfo.getLoanCnyDisplay());
26 | assertEquals(new BigDecimal("0.5000"), accountInfo.getLoanBtcDisplay());
27 | assertEquals(new BigDecimal("0.6000"), accountInfo.getLoanLtcDisplay());
28 | }
29 |
30 | }
31 |
--------------------------------------------------------------------------------
/huobi-client-rest/src/test/java/org/oxerr/huobi/rest/dto/marketdata/DepthTest.java:
--------------------------------------------------------------------------------
1 | package org.oxerr.huobi.rest.dto.marketdata;
2 |
3 | import static org.junit.Assert.assertEquals;
4 |
5 | import java.io.IOException;
6 | import java.math.BigDecimal;
7 |
8 | import org.junit.Test;
9 |
10 | public class DepthTest extends UnmarshalTest {
11 |
12 | @Test
13 | public void test() throws IOException {
14 | Depth depth = readValue(getClass(), "depth.json", Depth.class);
15 | assertEquals(new BigDecimal("90.7"), depth.getAsks()[0][0]);
16 | assertEquals(new BigDecimal("0.01"), depth.getAsks()[0][1]);
17 | assertEquals(new BigDecimal("86.06"), depth.getBids()[0][0]);
18 | assertEquals(new BigDecimal("79.243"), depth.getBids()[0][1]);
19 | }
20 |
21 | }
22 |
--------------------------------------------------------------------------------
/huobi-client-rest/src/test/java/org/oxerr/huobi/rest/dto/marketdata/OHLCVTest.java:
--------------------------------------------------------------------------------
1 | package org.oxerr.huobi.rest.dto.marketdata;
2 |
3 | import static org.junit.Assert.assertEquals;
4 |
5 | import java.io.IOException;
6 |
7 | import org.junit.Test;
8 |
9 | public class OHLCVTest extends UnmarshalTest {
10 |
11 | @Test
12 | public void test() throws IOException {
13 | String[][] ohlcv = readValue(getClass(), "ohlcv.json", String[][].class);
14 |
15 | // time
16 | assertEquals("20130101000000000", ohlcv[0][0]);
17 |
18 | // open
19 | assertEquals("770.0000", ohlcv[0][1]);
20 |
21 | // high
22 | assertEquals("8000", ohlcv[0][2]);
23 |
24 | // low
25 | assertEquals("679.107", ohlcv[0][3]);
26 |
27 | // close
28 | assertEquals("4373", ohlcv[0][4]);
29 |
30 | // volume
31 | assertEquals("2948602.5158", ohlcv[0][5]);
32 |
33 | // time
34 | assertEquals("20140101000000000", ohlcv[1][0]);
35 |
36 | // open
37 | assertEquals("4373.1", ohlcv[1][1]);
38 |
39 | // high
40 | assertEquals("5999", ohlcv[1][2]);
41 |
42 | // low
43 | assertEquals("2223.22", ohlcv[1][3]);
44 |
45 | // close
46 | assertEquals("3898.01", ohlcv[1][4]);
47 |
48 | // volume
49 | assertEquals("14126124.983874", ohlcv[1][5]);
50 | }
51 |
52 | }
53 |
--------------------------------------------------------------------------------
/huobi-client-rest/src/test/java/org/oxerr/huobi/rest/dto/marketdata/OrderBookTASTest.java:
--------------------------------------------------------------------------------
1 | package org.oxerr.huobi.rest.dto.marketdata;
2 |
3 | import static org.junit.Assert.assertEquals;
4 |
5 | import java.io.IOException;
6 | import java.math.BigDecimal;
7 |
8 | import org.junit.Test;
9 | import org.oxerr.huobi.rest.dto.marketdata.OrderBookTAS;
10 |
11 | public class OrderBookTASTest extends UnmarshalTest {
12 |
13 | @Test
14 | public void testHUOBIOrderBookTAS() throws IOException {
15 | OrderBookTAS obtas = readValue(getClass(), "detail.json", OrderBookTAS.class);
16 |
17 | assertEquals(new BigDecimal("3904.7"), obtas.getSells()[0].getPrice());
18 | assertEquals(new BigDecimal("0"), obtas.getSells()[0].getLevel());
19 | assertEquals(new BigDecimal("0.3995"), obtas.getSells()[0].getAmount());
20 |
21 | assertEquals(new BigDecimal("3904.04"), obtas.getBuys()[0].getPrice());
22 | assertEquals(new BigDecimal("0"), obtas.getBuys()[0].getLevel());
23 | assertEquals(new BigDecimal("0.0624"), obtas.getBuys()[0].getAmount());
24 |
25 | assertEquals("13:19:57", obtas.getTrades()[0].getTime());
26 | assertEquals(new BigDecimal("3904.7"), obtas.getTrades()[0].getPrice());
27 | assertEquals(new BigDecimal("0.14"), obtas.getTrades()[0].getAmount());
28 | assertEquals("买入", obtas.getTrades()[0].getType());
29 |
30 | assertEquals(new BigDecimal("3904.7"), obtas.getPNew());
31 | assertEquals(new BigDecimal("-9.28"), obtas.getLevel());
32 | assertEquals(new BigDecimal("23886"), obtas.getAmount());
33 | assertEquals(new BigDecimal("93246158.340222"), obtas.getTotal());
34 | assertEquals(new BigDecimal("-0"), obtas.getAmp());
35 | assertEquals(new BigDecimal("3914"), obtas.getPOpen());
36 | assertEquals(new BigDecimal("3936"), obtas.getPHigh());
37 | assertEquals(new BigDecimal("3875.12"), obtas.getPLow());
38 | assertEquals(new BigDecimal("3914"), obtas.getPLast());
39 |
40 | assertEquals(new BigDecimal("3904.7"), obtas.getTopSell()[0].getPrice());
41 | assertEquals(new BigDecimal("0"), obtas.getTopSell()[0].getLevel());
42 | assertEquals(new BigDecimal("0.3995"), obtas.getTopSell()[0].getAmount());
43 | assertEquals(new BigDecimal("0.3995"), obtas.getTopSell()[0].getAccu());
44 |
45 | assertEquals(new BigDecimal("3904.04"), obtas.getTopBuy()[0].getPrice());
46 | assertEquals(new BigDecimal("0"), obtas.getTopBuy()[0].getLevel());
47 | assertEquals(new BigDecimal("0.0624"), obtas.getTopBuy()[0].getAmount());
48 | assertEquals(new BigDecimal("0.0624"), obtas.getTopBuy()[0].getAccu());
49 | }
50 |
51 | }
52 |
--------------------------------------------------------------------------------
/huobi-client-rest/src/test/java/org/oxerr/huobi/rest/dto/marketdata/TickerTest.java:
--------------------------------------------------------------------------------
1 | package org.oxerr.huobi.rest.dto.marketdata;
2 |
3 | import static org.junit.Assert.assertEquals;
4 |
5 | import java.io.IOException;
6 | import java.math.BigDecimal;
7 |
8 | import org.junit.Test;
9 | import org.oxerr.huobi.rest.dto.marketdata.Ticker;
10 | import org.oxerr.huobi.rest.dto.marketdata.TickerObject;
11 |
12 | public class TickerTest extends UnmarshalTest {
13 |
14 | @Test
15 | public void test() throws IOException {
16 | TickerObject ticker = readValue(getClass(), "ticker.json", Ticker.class).getTicker();
17 | assertEquals(new BigDecimal("86.48"), ticker.getHigh());
18 | assertEquals(new BigDecimal("79.75"), ticker.getLow());
19 | assertEquals(new BigDecimal("83.9"), ticker.getLast());
20 | assertEquals(new BigDecimal("2239560.1752883"), ticker.getVol());
21 | assertEquals(new BigDecimal("83.88"), ticker.getBuy());
22 | assertEquals(new BigDecimal("83.9"), ticker.getSell());
23 | }
24 |
25 | }
26 |
--------------------------------------------------------------------------------
/huobi-client-rest/src/test/java/org/oxerr/huobi/rest/dto/marketdata/UnmarshalTest.java:
--------------------------------------------------------------------------------
1 | package org.oxerr.huobi.rest.dto.marketdata;
2 |
3 | import java.io.IOException;
4 | import java.net.URL;
5 |
6 | import com.fasterxml.jackson.core.type.TypeReference;
7 | import com.fasterxml.jackson.databind.ObjectMapper;
8 |
9 | public class UnmarshalTest {
10 |
11 | private final ObjectMapper objectMapper = new ObjectMapper();
12 |
13 | protected T readValue(Class> clazz, String resource, Class valueType)
14 | throws IOException {
15 | URL url = clazz.getResource(resource);
16 | return objectMapper.readValue(url, valueType);
17 | }
18 |
19 | protected T readValue(Class> clazz, String resource, TypeReference valueTypeRef)
20 | throws IOException {
21 | URL url = clazz.getResource(resource);
22 | return objectMapper.readValue(url, valueTypeRef);
23 | }
24 |
25 | }
26 |
--------------------------------------------------------------------------------
/huobi-client-rest/src/test/java/org/oxerr/huobi/rest/dto/trade/HuobiErrorTest.java:
--------------------------------------------------------------------------------
1 | package org.oxerr.huobi.rest.dto.trade;
2 |
3 | import static org.junit.Assert.assertEquals;
4 |
5 | import java.io.IOException;
6 |
7 | import org.junit.Test;
8 | import org.oxerr.huobi.rest.dto.marketdata.UnmarshalTest;
9 | import org.oxerr.huobi.rest.dto.trade.HuobiError;
10 |
11 | public class HuobiErrorTest extends UnmarshalTest {
12 |
13 | @Test
14 | public void test() throws IOException {
15 | HuobiError error = readValue(getClass(), "error.json", HuobiError.class);
16 | assertEquals(65, error.getCode());
17 | assertEquals("无效的方法", error.getMsg());
18 | assertEquals(1404651007, error.getTime());
19 | }
20 |
21 | }
22 |
--------------------------------------------------------------------------------
/huobi-client-rest/src/test/java/org/oxerr/huobi/rest/dto/trade/HuobiOrderTest.java:
--------------------------------------------------------------------------------
1 | package org.oxerr.huobi.rest.dto.trade;
2 |
3 | import static org.junit.Assert.assertEquals;
4 |
5 | import java.io.IOException;
6 | import java.math.BigDecimal;
7 |
8 | import org.junit.Test;
9 | import org.oxerr.huobi.rest.dto.marketdata.UnmarshalTest;
10 | import org.oxerr.huobi.rest.dto.trade.Order;
11 |
12 | public class HuobiOrderTest extends UnmarshalTest {
13 |
14 | @Test
15 | public void testOrders() throws IOException {
16 | Order[] orders = readValue(getClass(), "orders.json", Order[].class);
17 | assertEquals(8, orders.length);
18 | assertEquals(25502826L, orders[0].getId());
19 | assertEquals(2, orders[0].getType());
20 | assertEquals(new BigDecimal("3964.00"), orders[0].getOrderPrice());
21 | assertEquals(new BigDecimal("0.0100"), orders[0].getOrderAmount());
22 | assertEquals(new BigDecimal("0.0000"), orders[0].getProcessedAmount());
23 | assertEquals(1404469218L, orders[0].getOrderTime());
24 | }
25 |
26 | @Test
27 | public void testOrder() throws IOException {
28 | Order order = readValue(getClass(), "order.json", Order.class);
29 | assertEquals(25502826L, order.getId());
30 | assertEquals(2, order.getType());
31 | assertEquals(new BigDecimal("3964.00"), order.getOrderPrice());
32 | assertEquals(new BigDecimal("0.0100"), order.getOrderAmount());
33 | assertEquals(new BigDecimal("0.0000"), order.getProcessedAmount());
34 | assertEquals(new BigDecimal("0.00"), order.getProcessedPrice());
35 | assertEquals(new BigDecimal("0.00"), order.getTotal());
36 | assertEquals(new BigDecimal("0.00"), order.getFee());
37 | assertEquals(new BigDecimal("0.00"), order.getVot());
38 | }
39 |
40 | }
41 |
--------------------------------------------------------------------------------
/huobi-client-rest/src/test/java/org/oxerr/huobi/rest/dto/trade/HuobiPlaceOrderResultTest.java:
--------------------------------------------------------------------------------
1 | package org.oxerr.huobi.rest.dto.trade;
2 |
3 | import static org.junit.Assert.assertEquals;
4 |
5 | import java.io.IOException;
6 |
7 | import org.junit.Test;
8 | import org.oxerr.huobi.rest.dto.marketdata.UnmarshalTest;
9 | import org.oxerr.huobi.rest.dto.trade.PlaceOrderResult;
10 |
11 | public class HuobiPlaceOrderResultTest extends UnmarshalTest {
12 |
13 | @Test
14 | public void test() throws IOException {
15 | PlaceOrderResult result = readValue(getClass(), "place-order-result.json",
16 | PlaceOrderResult.class);
17 | assertEquals("success", result.getResult());
18 | assertEquals(25841172L, result.getId());
19 | }
20 |
21 | }
22 |
--------------------------------------------------------------------------------
/huobi-client-rest/src/test/java/org/oxerr/huobi/rest/valuereader/DelegationReaderTest.java:
--------------------------------------------------------------------------------
1 | package org.oxerr.huobi.rest.valuereader;
2 |
3 | import static org.junit.Assert.*;
4 |
5 | import java.io.IOException;
6 | import java.io.InputStream;
7 | import java.math.BigDecimal;
8 | import java.text.SimpleDateFormat;
9 | import java.util.List;
10 |
11 | import org.junit.Test;
12 | import org.oxerr.huobi.rest.domain.Delegation;
13 | import org.oxerr.huobi.rest.domain.Type;
14 | import org.oxerr.huobi.rest.valuereader.DelegationReader;
15 |
16 | public class DelegationReaderTest {
17 |
18 | private DelegationReader delegationReader = new DelegationReader();
19 |
20 | @Test
21 | public void testRead() throws IOException {
22 | try (InputStream inputStream = getClass().getResourceAsStream(
23 | "delegation.html")) {
24 | List delegations = delegationReader.read(inputStream);
25 |
26 | assertEquals(3, delegations.size());
27 |
28 | Delegation delegation = delegations.get(0);
29 | assertEquals(12787624, delegation.getId());
30 | assertEquals("2014.04.12 01:42", new SimpleDateFormat(
31 | "yyyy.MM.dd HH:mm").format(delegation.getDate()));
32 | assertEquals(Type.BUY, delegation.getType());
33 | assertEquals(new BigDecimal("0.10"), delegation.getPrice());
34 | assertEquals(new BigDecimal("0.0010"), delegation.getAmount());
35 | assertEquals(new BigDecimal("0.00"), delegation.getTrading());
36 | assertEquals(null, delegation.getFee());
37 | assertEquals(null, delegation.getTotal());
38 | }
39 | }
40 |
41 | }
42 |
--------------------------------------------------------------------------------
/huobi-client-rest/src/test/resources/org/oxerr/huobi/rest/domain/cancel.json:
--------------------------------------------------------------------------------
1 | {"code":0,"msg":"\u53d6\u6d88\u59d4\u6258\u6210\u529f"}
--------------------------------------------------------------------------------
/huobi-client-rest/src/test/resources/org/oxerr/huobi/rest/domain/my_trade_info.json:
--------------------------------------------------------------------------------
1 | {"code":0,"msg":"","extra":{"sell":{"price":"4837.000","amount":"0.999","available_btc":"0.9999"},"buy":{"price":"0.000","amount":"0.000","available_cny":"0.00"},"balance":{"id":1,"initialized_cny":0,"initialized_btc":0,"user_id":1,"available_cny":0,"available_btc":9999000000,"available_usd":0,"frozen_cny":0,"frozen_btc":0,"frozen_usd":0,"debt_bitcoin":0,"debt_rmb":0,"total":"4836.51","loan_total":"0.00","net_asset":"4836.51","loan_cny_display":"0.00","loan_btc_display":"0.0000","available_btc_display":"0.9999","available_cny_display":"0.00","frozen_btc_display":"0.0000","frozen_cny_display":"0.00"}}}
--------------------------------------------------------------------------------
/huobi-client-rest/src/test/resources/org/oxerr/huobi/rest/domain/tradeResult0.json:
--------------------------------------------------------------------------------
1 | {"code":0,"msg":"\u5356\u5355\u5df2\u59d4\u6258\uff0c\u67e5\u770b\u7ed3\u679c<\/a>"}
--------------------------------------------------------------------------------
/huobi-client-rest/src/test/resources/org/oxerr/huobi/rest/domain/tradeResult2.json:
--------------------------------------------------------------------------------
1 | {"code":2,"msg":"\u6ca1\u6709\u8db3\u591f\u7684\u4eba\u6c11\u5e01"}
--------------------------------------------------------------------------------
/huobi-client-rest/src/test/resources/org/oxerr/huobi/rest/dto/account/account-info.json:
--------------------------------------------------------------------------------
1 | {
2 | "total": "4459.38",
3 | "net_asset": "4459.38",
4 | "available_cny_display": "2985.40",
5 | "available_btc_display": "0.3244",
6 | "available_ltc_display": "0.1000",
7 | "frozen_cny_display": "0.20",
8 | "frozen_btc_display": "0.0530",
9 | "frozen_ltc_display": "0.3000",
10 | "loan_cny_display": "0.40",
11 | "loan_btc_display": "0.5000",
12 | "loan_ltc_display": "0.6000"
13 | }
14 |
--------------------------------------------------------------------------------
/huobi-client-rest/src/test/resources/org/oxerr/huobi/rest/dto/marketdata/depth.json:
--------------------------------------------------------------------------------
1 | {
2 | "asks": [
3 | ["90.7", 0.01],
4 | ["90.8", 0.5]
5 | ],
6 | "bids": [
7 | ["86.06", 79.243],
8 | ["86.05", 0.02]
9 | ]
10 | }
11 |
--------------------------------------------------------------------------------
/huobi-client-rest/src/test/resources/org/oxerr/huobi/rest/dto/marketdata/ohlcv.json:
--------------------------------------------------------------------------------
1 | [
2 | ["20130101000000000", "770.0000", "8000", "679.107", "4373", "2948602.5158"],
3 | ["20140101000000000", "4373.1", "5999", "2223.22", "3898.01", "14126124.983874"]
4 | ]
5 |
--------------------------------------------------------------------------------
/huobi-client-rest/src/test/resources/org/oxerr/huobi/rest/dto/marketdata/ticker.json:
--------------------------------------------------------------------------------
1 | {
2 | "ticker": {
3 | "high": "86.48",
4 | "low": "79.75",
5 | "last": "83.9",
6 | "vol": 2239560.1752883,
7 | "buy": "83.88",
8 | "sell": "83.9"
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/huobi-client-rest/src/test/resources/org/oxerr/huobi/rest/dto/trade/error.json:
--------------------------------------------------------------------------------
1 | {
2 | "code": 65,
3 | "msg": "\u65e0\u6548\u7684\u65b9\u6cd5",
4 | "time": 1404651007
5 | }
6 |
--------------------------------------------------------------------------------
/huobi-client-rest/src/test/resources/org/oxerr/huobi/rest/dto/trade/order.json:
--------------------------------------------------------------------------------
1 | {
2 | "id": 25502826,
3 | "type": 2,
4 | "order_price": "3964.00",
5 | "order_amount": "0.0100",
6 | "processed_amount": "0.0000",
7 | "processed_price": "0.00",
8 | "total": "0.00",
9 | "fee": "0.00",
10 | "vot": "0.00",
11 | "status": 0
12 | }
13 |
--------------------------------------------------------------------------------
/huobi-client-rest/src/test/resources/org/oxerr/huobi/rest/dto/trade/orders.json:
--------------------------------------------------------------------------------
1 | [{
2 | "id": 25502826,
3 | "type": 2,
4 | "order_price": "3964.00",
5 | "order_amount": "0.0100",
6 | "processed_amount": "0.0000",
7 | "order_time": 1404469218
8 | }, {
9 | "id": 25336707,
10 | "type": 2,
11 | "order_price": "4050.10",
12 | "order_amount": "0.0100",
13 | "processed_amount": "0.0000",
14 | "order_time": 1404373653
15 | }, {
16 | "id": 23101954,
17 | "type": 2,
18 | "order_price": "9999.00",
19 | "order_amount": "0.0100",
20 | "processed_amount": "0.0000",
21 | "order_time": 1403187207
22 | }, {
23 | "id": 23101903,
24 | "type": 2,
25 | "order_price": "9999.00",
26 | "order_amount": "0.0100",
27 | "processed_amount": "0.0000",
28 | "order_time": 1403187176
29 | }, {
30 | "id": 23099139,
31 | "type": 2,
32 | "order_price": "99999.00",
33 | "order_amount": "0.0010",
34 | "processed_amount": "0.0000",
35 | "order_time": 1403185589
36 | }, {
37 | "id": 23097842,
38 | "type": 2,
39 | "order_price": "99999.00",
40 | "order_amount": "0.0010",
41 | "processed_amount": "0.0000",
42 | "order_time": 1403184727
43 | }, {
44 | "id": 23096425,
45 | "type": 2,
46 | "order_price": "9999.00",
47 | "order_amount": "0.0100",
48 | "processed_amount": "0.0000",
49 | "order_time": 1403183959
50 | }, {
51 | "id": 23095767,
52 | "type": 2,
53 | "order_price": "99999.00",
54 | "order_amount": "0.0010",
55 | "processed_amount": "0.0000",
56 | "order_time": 1403183655
57 | }]
58 |
--------------------------------------------------------------------------------
/huobi-client-rest/src/test/resources/org/oxerr/huobi/rest/dto/trade/place-order-result.json:
--------------------------------------------------------------------------------
1 | {"result":"success","id":25841172}
2 |
--------------------------------------------------------------------------------
/huobi-client-websocket/pom.xml:
--------------------------------------------------------------------------------
1 |
5 | 4.0.0
6 |
7 |
8 | org.oxerr
9 | huobi-client
10 | 2.1.0-SNAPSHOT
11 |
12 |
13 | huobi-client-websocket
14 |
15 | Huobi Client - WebSocket
16 |
17 | Huobi WebSocket API.
19 | ]]>
20 |
21 |
22 |
23 | org.apache.commons
24 | commons-lang3
25 |
26 |
27 | org.slf4j
28 | slf4j-api
29 |
30 |
31 | io.socket
32 | socket.io-client
33 | 0.2.1
34 |
35 |
36 |
37 |
38 | keytwo.net
39 | Keytwo.net Repository
40 | http://audiobox.keytwo.net
41 |
42 |
43 |
44 |
--------------------------------------------------------------------------------
/huobi-client-websocket/src/main/java/org/oxerr/huobi/websocket/dto/Depth.java:
--------------------------------------------------------------------------------
1 | package org.oxerr.huobi.websocket.dto;
2 |
3 | import java.math.BigDecimal;
4 |
5 | public interface Depth {
6 |
7 | String getSymbolId();
8 | long getTime();
9 | long getVersion();
10 |
11 | BigDecimal[] getBidPrice();
12 | BigDecimal[] getBidAmount();
13 |
14 | BigDecimal[] getAskPrice();
15 | BigDecimal[] getAskAmount();
16 |
17 | void merge(DepthDiff diff);
18 |
19 | }
20 |
--------------------------------------------------------------------------------
/huobi-client-websocket/src/main/java/org/oxerr/huobi/websocket/dto/DepthDiff.java:
--------------------------------------------------------------------------------
1 | package org.oxerr.huobi.websocket.dto;
2 |
3 | import org.oxerr.huobi.websocket.dto.response.marketdata.payload.Update;
4 |
5 | public interface DepthDiff {
6 |
7 | long getVersion();
8 | long getVersionOld();
9 |
10 | Update getBidInsert();
11 | int[] getBidDelete();
12 | Update getBidUpdate();
13 |
14 | Update getAskInsert();
15 | int[] getAskDelete();
16 | Update getAskUpdate();
17 |
18 | }
19 |
--------------------------------------------------------------------------------
/huobi-client-websocket/src/main/java/org/oxerr/huobi/websocket/dto/GsonFactory.java:
--------------------------------------------------------------------------------
1 | package org.oxerr.huobi.websocket.dto;
2 |
3 | import java.time.Instant;
4 |
5 | import com.google.gson.Gson;
6 | import com.google.gson.GsonBuilder;
7 |
8 | /**
9 | * Provides Gson object for Huobi WebSocket API implementation.
10 | */
11 | public class GsonFactory {
12 |
13 | private static final Gson gson = buildGson();
14 |
15 | private static Gson buildGson() {
16 | GsonBuilder gsonBuilder = new GsonBuilder();
17 | gsonBuilder.registerTypeAdapter(Instant.class, new InstantAdapter());
18 | Gson gson = gsonBuilder.create();
19 | return gson;
20 | }
21 |
22 | public static Gson getGson() {
23 | return gson;
24 | }
25 |
26 | }
27 |
--------------------------------------------------------------------------------
/huobi-client-websocket/src/main/java/org/oxerr/huobi/websocket/dto/InstantAdapter.java:
--------------------------------------------------------------------------------
1 | package org.oxerr.huobi.websocket.dto;
2 |
3 | import java.lang.reflect.Type;
4 | import java.time.Instant;
5 |
6 | import com.google.gson.JsonDeserializationContext;
7 | import com.google.gson.JsonDeserializer;
8 | import com.google.gson.JsonElement;
9 | import com.google.gson.JsonParseException;
10 | import com.google.gson.JsonPrimitive;
11 | import com.google.gson.JsonSerializationContext;
12 | import com.google.gson.JsonSerializer;
13 |
14 | /**
15 | * {@link JsonSerializer} and {@link JsonDeserializer} for {@link Instant}.
16 | */
17 | public class InstantAdapter implements JsonSerializer,
18 | JsonDeserializer {
19 |
20 | /**
21 | * {@inheritDoc}
22 | */
23 | @Override
24 | public JsonElement serialize(Instant src, Type typeOfSrc,
25 | JsonSerializationContext context) {
26 | return new JsonPrimitive(src.toEpochMilli());
27 | }
28 |
29 | /**
30 | * {@inheritDoc}
31 | */
32 | @Override
33 | public Instant deserialize(JsonElement json, Type typeOfT,
34 | JsonDeserializationContext context) throws JsonParseException {
35 | return Instant.ofEpochMilli(json.getAsLong());
36 | }
37 |
38 | }
39 |
--------------------------------------------------------------------------------
/huobi-client-websocket/src/main/java/org/oxerr/huobi/websocket/dto/Percent.java:
--------------------------------------------------------------------------------
1 | package org.oxerr.huobi.websocket.dto;
2 |
3 | import com.google.gson.annotations.SerializedName;
4 |
5 | /**
6 | * Market data depth percents.
7 | */
8 | public enum Percent {
9 |
10 | @SerializedName("10")
11 | PERCENT10,
12 |
13 | @SerializedName("20")
14 | PERCENT20,
15 |
16 | @SerializedName("50")
17 | PERCENT50,
18 |
19 | @SerializedName("80")
20 | PERCENT80,
21 |
22 | @SerializedName("100")
23 | PERCENT100,
24 |
25 | @SerializedName("top")
26 | PERCENT_TOP;
27 |
28 | }
29 |
--------------------------------------------------------------------------------
/huobi-client-websocket/src/main/java/org/oxerr/huobi/websocket/dto/Period.java:
--------------------------------------------------------------------------------
1 | package org.oxerr.huobi.websocket.dto;
2 |
3 | import com.google.gson.annotations.SerializedName;
4 |
5 | /**
6 | * K Line periods.
7 | */
8 | public enum Period {
9 |
10 | @SerializedName("1min")
11 | KLINE_1MIN,
12 |
13 | @SerializedName("5min")
14 | KLINE_5MIN,
15 |
16 | @SerializedName("15min")
17 | KLINE_15MIN,
18 |
19 | @SerializedName("30min")
20 | KLINE_30MIN,
21 |
22 | @SerializedName("60min")
23 | KLINE_60MIN,
24 |
25 | @SerializedName("1day")
26 | KLINE_1DAY,
27 |
28 | @SerializedName("1week")
29 | KLINE_1WEEK,
30 |
31 | @SerializedName("1mon")
32 | KLINE_1MON,
33 |
34 | @SerializedName("1year")
35 | KLINE_1YEAR,
36 |
37 | @SerializedName("tl")
38 | KLINE_TIMELINE;
39 |
40 | }
41 |
--------------------------------------------------------------------------------
/huobi-client-websocket/src/main/java/org/oxerr/huobi/websocket/dto/TradeDetail.java:
--------------------------------------------------------------------------------
1 | package org.oxerr.huobi.websocket.dto;
2 |
3 | import java.math.BigDecimal;
4 |
5 | import org.oxerr.huobi.websocket.dto.response.payload.Orders;
6 |
7 | public interface TradeDetail {
8 |
9 | String getSymbolId();
10 | long[] getTradeId();
11 | BigDecimal[] getPrice();
12 | long[] getTime();
13 | BigDecimal[] getAmount();
14 | int[] getDirection();
15 | Orders[] getTopAsks();
16 | Orders[] getTopBids();
17 |
18 | }
19 |
--------------------------------------------------------------------------------
/huobi-client-websocket/src/main/java/org/oxerr/huobi/websocket/dto/package-info.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Huobi WebSocket API DTOs.
3 | */
4 | package org.oxerr.huobi.websocket.dto;
5 |
--------------------------------------------------------------------------------
/huobi-client-websocket/src/main/java/org/oxerr/huobi/websocket/dto/request/AbstractSymbolIdListRequest.java:
--------------------------------------------------------------------------------
1 | package org.oxerr.huobi.websocket.dto.request;
2 |
3 | /**
4 | * Request that contains {@link #symbolIdList}.
5 | */
6 | public abstract class AbstractSymbolIdListRequest extends Request {
7 |
8 | private String[] symbolIdList;
9 |
10 | public AbstractSymbolIdListRequest(int version, String msgType) {
11 | super(version, msgType);
12 | }
13 |
14 | public String[] getSymbolIdList() {
15 | return symbolIdList;
16 | }
17 |
18 | public void setSymbolIdList(String[] symbolIdList) {
19 | this.symbolIdList = symbolIdList;
20 | }
21 |
22 | }
23 |
--------------------------------------------------------------------------------
/huobi-client-websocket/src/main/java/org/oxerr/huobi/websocket/dto/request/AbstractSymbolIdRequest.java:
--------------------------------------------------------------------------------
1 | package org.oxerr.huobi.websocket.dto.request;
2 |
3 | /**
4 | * Request that contain {@link #symbolId}.
5 | */
6 | public abstract class AbstractSymbolIdRequest extends Request {
7 |
8 | private final String symbolId;
9 |
10 | public AbstractSymbolIdRequest(int version, String msgType, String symbolId) {
11 | super(version, msgType);
12 | this.symbolId = symbolId;
13 | }
14 |
15 | public String getSymbolId() {
16 | return symbolId;
17 | }
18 |
19 | }
20 |
--------------------------------------------------------------------------------
/huobi-client-websocket/src/main/java/org/oxerr/huobi/websocket/dto/request/Request.java:
--------------------------------------------------------------------------------
1 | package org.oxerr.huobi.websocket.dto.request;
2 |
3 | import org.apache.commons.lang3.builder.ToStringBuilder;
4 | import org.oxerr.huobi.websocket.HuobiSocket;
5 |
6 | /**
7 | * The request for {@link HuobiSocket}.
8 | */
9 | public class Request {
10 |
11 | private final int version;
12 | private final String msgType;
13 | private long requestIndex;
14 |
15 | /**
16 | * Constructs a request.
17 | *
18 | * @param version
19 | * Client version.
20 | * @param msgType
21 | * Message type.
22 | */
23 | public Request(int version, String msgType) {
24 | this.version = version;
25 | this.msgType = msgType;
26 | }
27 |
28 | /**
29 | * Returns the serial number to sort multiple requests, the server side will
30 | * echo back the consistent data that client posted.
31 | *
32 | * @return serial number.
33 | */
34 | public long getRequestIndex() {
35 | return requestIndex;
36 | }
37 |
38 | public void setRequestIndex(long requestIndex) {
39 | this.requestIndex = requestIndex;
40 | }
41 |
42 | public int getVersion() {
43 | return version;
44 | }
45 |
46 | public String getMsgType() {
47 | return msgType;
48 | }
49 |
50 | @Override
51 | public String toString() {
52 | return ToStringBuilder.reflectionToString(this);
53 | }
54 |
55 | }
56 |
--------------------------------------------------------------------------------
/huobi-client-websocket/src/main/java/org/oxerr/huobi/websocket/dto/request/historydata/ReqKLineRequest.java:
--------------------------------------------------------------------------------
1 | package org.oxerr.huobi.websocket.dto.request.historydata;
2 |
3 | import java.time.Instant;
4 |
5 | import org.oxerr.huobi.websocket.dto.Period;
6 | import org.oxerr.huobi.websocket.dto.request.AbstractSymbolIdRequest;
7 |
8 | /**
9 | * Request of history candlestick data.
10 | */
11 | public class ReqKLineRequest extends AbstractSymbolIdRequest {
12 |
13 | private final Period period;
14 |
15 | private Instant from, to;
16 |
17 | /**
18 | * @param version 终端版本
19 | * @param symbolId 交易代码
20 | * @param period k线类型
21 | */
22 | public ReqKLineRequest(int version, String symbolId, Period period) {
23 | super(version, "reqKLine", symbolId);
24 | this.period = period;
25 | }
26 |
27 | /**
28 | * @return 开始时间,默认最近300条的时间区间。
29 | */
30 | public Instant getFrom() {
31 | return from;
32 | }
33 |
34 | public void setFrom(Instant from) {
35 | this.from = from;
36 | }
37 |
38 | /**
39 | * @return 结束时间,默认到最新。
40 | */
41 | public Instant getTo() {
42 | return to;
43 | }
44 |
45 | public void setTo(Instant to) {
46 | this.to = to;
47 | }
48 |
49 | public Period getPeriod() {
50 | return period;
51 | }
52 |
53 | }
54 |
--------------------------------------------------------------------------------
/huobi-client-websocket/src/main/java/org/oxerr/huobi/websocket/dto/request/historydata/ReqMarketDepthRequest.java:
--------------------------------------------------------------------------------
1 | package org.oxerr.huobi.websocket.dto.request.historydata;
2 |
3 | import org.oxerr.huobi.websocket.dto.Percent;
4 | import org.oxerr.huobi.websocket.dto.request.AbstractSymbolIdRequest;
5 |
6 | /**
7 | * Request of market-depth.
8 | */
9 | public class ReqMarketDepthRequest extends AbstractSymbolIdRequest {
10 |
11 | private final Percent percent;
12 |
13 | /**
14 | * @param version 终端版本
15 | * @param symbolId 交易代码
16 | * @param percent 行情深度的百分比,缺省10%
17 | */
18 | public ReqMarketDepthRequest(int version, String symbolId, Percent percent) {
19 | super(version, "reqMarketDepth", symbolId);
20 | this.percent = percent;
21 | }
22 |
23 | public Percent getPercent() {
24 | return percent;
25 | }
26 |
27 | }
28 |
--------------------------------------------------------------------------------
/huobi-client-websocket/src/main/java/org/oxerr/huobi/websocket/dto/request/historydata/ReqMarketDepthTopRequest.java:
--------------------------------------------------------------------------------
1 | package org.oxerr.huobi.websocket.dto.request.historydata;
2 |
3 | import org.oxerr.huobi.websocket.dto.request.AbstractSymbolIdRequest;
4 |
5 | /**
6 | * Request of top market-depth.
7 | */
8 | public class ReqMarketDepthTopRequest extends AbstractSymbolIdRequest {
9 |
10 | public ReqMarketDepthTopRequest(int version, String symbolId) {
11 | super(version, "reqMarketDepthTop", symbolId);
12 | }
13 |
14 | }
15 |
--------------------------------------------------------------------------------
/huobi-client-websocket/src/main/java/org/oxerr/huobi/websocket/dto/request/historydata/ReqMarketDetailRequest.java:
--------------------------------------------------------------------------------
1 | package org.oxerr.huobi.websocket.dto.request.historydata;
2 |
3 | import org.oxerr.huobi.websocket.dto.request.AbstractSymbolIdRequest;
4 |
5 | /**
6 | * Request of market details.
7 | */
8 | public class ReqMarketDetailRequest extends AbstractSymbolIdRequest {
9 |
10 | public ReqMarketDetailRequest(int version, String symbolId) {
11 | super(version, "reqMarketDetail", symbolId);
12 | }
13 |
14 | }
15 |
--------------------------------------------------------------------------------
/huobi-client-websocket/src/main/java/org/oxerr/huobi/websocket/dto/request/historydata/ReqTimeLineRequest.java:
--------------------------------------------------------------------------------
1 | package org.oxerr.huobi.websocket.dto.request.historydata;
2 |
3 | import java.time.Instant;
4 |
5 | import org.oxerr.huobi.websocket.dto.request.AbstractSymbolIdRequest;
6 |
7 | /**
8 | * Request of history time-interval.
9 | */
10 | public class ReqTimeLineRequest extends AbstractSymbolIdRequest {
11 |
12 | private Instant from, to;
13 |
14 | public ReqTimeLineRequest(int version, String symbolId) {
15 | super(version, "reqTimeLine", symbolId);
16 | }
17 |
18 | /**
19 | * @return 开始时间,默认最近300条的时间区间。
20 | */
21 | public Instant getFrom() {
22 | return from;
23 | }
24 |
25 | public void setFrom(Instant from) {
26 | this.from = from;
27 | }
28 |
29 | /**
30 | * @return 结束时间,默认到最新。
31 | */
32 | public Instant getTo() {
33 | return to;
34 | }
35 |
36 | public void setTo(Instant to) {
37 | this.to = to;
38 | }
39 |
40 | }
41 |
--------------------------------------------------------------------------------
/huobi-client-websocket/src/main/java/org/oxerr/huobi/websocket/dto/request/historydata/ReqTradeDetailTopRequest.java:
--------------------------------------------------------------------------------
1 | package org.oxerr.huobi.websocket.dto.request.historydata;
2 |
3 | import org.oxerr.huobi.websocket.dto.request.AbstractSymbolIdRequest;
4 |
5 | /**
6 | * Request of top trade details.
7 | */
8 | public class ReqTradeDetailTopRequest extends AbstractSymbolIdRequest {
9 |
10 | private int count;
11 |
12 | public ReqTradeDetailTopRequest(int version, String symbolId) {
13 | super(version, "reqTradeDetailTop", symbolId);
14 | }
15 |
16 | /**
17 | * @return 获取明细条数,缺省50条
18 | */
19 | public int getCount() {
20 | return count;
21 | }
22 |
23 | public void setCount(int count) {
24 | this.count = count;
25 | }
26 |
27 | }
28 |
--------------------------------------------------------------------------------
/huobi-client-websocket/src/main/java/org/oxerr/huobi/websocket/dto/request/historydata/package-info.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Requests for history data API.
3 | */
4 | package org.oxerr.huobi.websocket.dto.request.historydata;
5 |
--------------------------------------------------------------------------------
/huobi-client-websocket/src/main/java/org/oxerr/huobi/websocket/dto/request/marketdata/AbstractPush.java:
--------------------------------------------------------------------------------
1 | package org.oxerr.huobi.websocket.dto.request.marketdata;
2 |
3 | import org.apache.commons.lang3.builder.ToStringBuilder;
4 |
5 | /**
6 | * The push subscription.
7 | */
8 | public abstract class AbstractPush {
9 |
10 | private final String symbolId;
11 | private final PushType pushType;
12 |
13 | public AbstractPush(String symbolId, PushType pushType) {
14 | this.symbolId = symbolId;
15 | this.pushType = pushType;
16 | }
17 |
18 | public String getSymbolId() {
19 | return symbolId;
20 | }
21 |
22 | public PushType getPushType() {
23 | return pushType;
24 | }
25 |
26 | /**
27 | * {@inheritDoc}
28 | */
29 | @Override
30 | public String toString() {
31 | return ToStringBuilder.reflectionToString(this);
32 | }
33 |
34 | }
35 |
--------------------------------------------------------------------------------
/huobi-client-websocket/src/main/java/org/oxerr/huobi/websocket/dto/request/marketdata/LastKLine.java:
--------------------------------------------------------------------------------
1 | package org.oxerr.huobi.websocket.dto.request.marketdata;
2 |
3 | import org.oxerr.huobi.websocket.dto.Period;
4 |
5 | /**
6 | * Message for subscribing to push the last data details from candlestick chart.
7 | */
8 | public class LastKLine extends AbstractPush {
9 |
10 | private final Period period;
11 |
12 | public LastKLine(String symbolId, PushType pushType, Period period) {
13 | super(symbolId, pushType);
14 | this.period = period;
15 | }
16 |
17 | public Period getPeriod() {
18 | return period;
19 | }
20 |
21 | }
22 |
--------------------------------------------------------------------------------
/huobi-client-websocket/src/main/java/org/oxerr/huobi/websocket/dto/request/marketdata/LastTimeLine.java:
--------------------------------------------------------------------------------
1 | package org.oxerr.huobi.websocket.dto.request.marketdata;
2 |
3 | /**
4 | * Message for subscribing to push the last time-interval data.
5 | */
6 | public class LastTimeLine extends AbstractPush {
7 |
8 | public LastTimeLine(String symbolId, PushType pushType) {
9 | super(symbolId, pushType);
10 | }
11 |
12 | }
13 |
--------------------------------------------------------------------------------
/huobi-client-websocket/src/main/java/org/oxerr/huobi/websocket/dto/request/marketdata/MarketDepthDiff.java:
--------------------------------------------------------------------------------
1 | package org.oxerr.huobi.websocket.dto.request.marketdata;
2 |
3 | import org.oxerr.huobi.websocket.dto.Percent;
4 |
5 | /**
6 | * Message for subscribing to push market-depth difference.
7 | */
8 | public class MarketDepthDiff extends AbstractPush {
9 |
10 | private final Percent percent;
11 |
12 | public MarketDepthDiff(String symbolId, PushType pushType, Percent percent) {
13 | super(symbolId, pushType);
14 | this.percent = percent;
15 | }
16 |
17 | public Percent getPercent() {
18 | return percent;
19 | }
20 |
21 | }
22 |
--------------------------------------------------------------------------------
/huobi-client-websocket/src/main/java/org/oxerr/huobi/websocket/dto/request/marketdata/MarketDepthTopDiff.java:
--------------------------------------------------------------------------------
1 | package org.oxerr.huobi.websocket.dto.request.marketdata;
2 |
3 | /**
4 | * Message for subscribing to push top market-depth difference.
5 | */
6 | public class MarketDepthTopDiff extends AbstractPush {
7 |
8 | public MarketDepthTopDiff(String symbolId, PushType pushType) {
9 | super(symbolId, pushType);
10 | }
11 |
12 | }
13 |
--------------------------------------------------------------------------------
/huobi-client-websocket/src/main/java/org/oxerr/huobi/websocket/dto/request/marketdata/MarketDetail.java:
--------------------------------------------------------------------------------
1 | package org.oxerr.huobi.websocket.dto.request.marketdata;
2 |
3 | /**
4 | * Message for subscribing to push market detail.
5 | */
6 | public class MarketDetail extends AbstractPush {
7 |
8 | public MarketDetail(String symbolId, PushType pushType) {
9 | super(symbolId, pushType);
10 | }
11 |
12 | }
13 |
--------------------------------------------------------------------------------
/huobi-client-websocket/src/main/java/org/oxerr/huobi/websocket/dto/request/marketdata/MarketOverview.java:
--------------------------------------------------------------------------------
1 | package org.oxerr.huobi.websocket.dto.request.marketdata;
2 |
3 | /**
4 | * Message for subscribing to push the market overview data.
5 | */
6 | public class MarketOverview extends AbstractPush {
7 |
8 | public MarketOverview(String symbolId, PushType pushType) {
9 | super(symbolId, pushType);
10 | }
11 |
12 | }
13 |
--------------------------------------------------------------------------------
/huobi-client-websocket/src/main/java/org/oxerr/huobi/websocket/dto/request/marketdata/PushType.java:
--------------------------------------------------------------------------------
1 | package org.oxerr.huobi.websocket.dto.request.marketdata;
2 |
3 | import com.google.gson.annotations.SerializedName;
4 |
5 | /**
6 | * Push type.
7 | */
8 | public enum PushType {
9 |
10 | @SerializedName("pushLong")
11 | PUSH_LONG,
12 |
13 | @SerializedName("pushShort")
14 | PUSH_SHORT;
15 |
16 | }
17 |
--------------------------------------------------------------------------------
/huobi-client-websocket/src/main/java/org/oxerr/huobi/websocket/dto/request/marketdata/TradeDetail.java:
--------------------------------------------------------------------------------
1 | package org.oxerr.huobi.websocket.dto.request.marketdata;
2 |
3 | /**
4 | * Message for subscribing to push trade details.
5 | */
6 | public class TradeDetail extends AbstractPush {
7 |
8 | public TradeDetail(String symbolId, PushType pushType) {
9 | super(symbolId, pushType);
10 | }
11 |
12 | }
13 |
--------------------------------------------------------------------------------
/huobi-client-websocket/src/main/java/org/oxerr/huobi/websocket/dto/request/marketdata/package-info.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Message for {@link org.oxerr.huobi.websocket.dto.request.service.ReqMsgSubscribeRequest}.
3 | */
4 | package org.oxerr.huobi.websocket.dto.request.marketdata;
5 |
--------------------------------------------------------------------------------
/huobi-client-websocket/src/main/java/org/oxerr/huobi/websocket/dto/request/package-info.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Request DTOs.
3 | */
4 | package org.oxerr.huobi.websocket.dto.request;
5 |
--------------------------------------------------------------------------------
/huobi-client-websocket/src/main/java/org/oxerr/huobi/websocket/dto/request/service/ReqMsgSubscribeRequest.java:
--------------------------------------------------------------------------------
1 | package org.oxerr.huobi.websocket.dto.request.service;
2 |
3 | import org.oxerr.huobi.websocket.dto.request.Request;
4 | import org.oxerr.huobi.websocket.dto.request.marketdata.Message;
5 |
6 | /**
7 | * Request of subscribing push message.
8 | */
9 | public class ReqMsgSubscribeRequest extends Request {
10 |
11 | private final Message symbolList;
12 |
13 | public ReqMsgSubscribeRequest(int version, Message symbolList) {
14 | super(version, "reqMsgSubscribe");
15 | this.symbolList = symbolList;
16 | }
17 |
18 | public Message getSymbolList() {
19 | return symbolList;
20 | }
21 |
22 | }
23 |
--------------------------------------------------------------------------------
/huobi-client-websocket/src/main/java/org/oxerr/huobi/websocket/dto/request/service/ReqMsgUnsubscribeRequest.java:
--------------------------------------------------------------------------------
1 | package org.oxerr.huobi.websocket.dto.request.service;
2 |
3 | import org.oxerr.huobi.websocket.dto.request.AbstractSymbolIdListRequest;
4 | import org.oxerr.huobi.websocket.dto.request.marketdata.Message;
5 |
6 | /**
7 | * Request of canceling push message subscription.
8 | */
9 | public class ReqMsgUnsubscribeRequest extends AbstractSymbolIdListRequest {
10 |
11 | private final Message symbolList;
12 |
13 | public ReqMsgUnsubscribeRequest(int version, Message symbolList) {
14 | super(version, "reqMsgUnsubscribe");
15 | this.symbolList = symbolList;
16 | }
17 |
18 | public Message getSymbolList() {
19 | return symbolList;
20 | }
21 |
22 | }
23 |
--------------------------------------------------------------------------------
/huobi-client-websocket/src/main/java/org/oxerr/huobi/websocket/dto/request/service/ReqSymbolDetailRequest.java:
--------------------------------------------------------------------------------
1 | package org.oxerr.huobi.websocket.dto.request.service;
2 |
3 | import org.oxerr.huobi.websocket.dto.request.AbstractSymbolIdListRequest;
4 |
5 | /**
6 | * Request of symbol details.
7 | */
8 | public class ReqSymbolDetailRequest extends AbstractSymbolIdListRequest {
9 |
10 | public ReqSymbolDetailRequest(int version, String... symbolIdList) {
11 | super(version, "reqSymbolDetail");
12 | setSymbolIdList(symbolIdList);
13 | }
14 |
15 | }
16 |
--------------------------------------------------------------------------------
/huobi-client-websocket/src/main/java/org/oxerr/huobi/websocket/dto/request/service/ReqSymbolListRequest.java:
--------------------------------------------------------------------------------
1 | package org.oxerr.huobi.websocket.dto.request.service;
2 |
3 | import org.oxerr.huobi.websocket.dto.request.AbstractSymbolIdListRequest;
4 |
5 | /**
6 | * Request of symbol list.
7 | */
8 | public class ReqSymbolListRequest extends AbstractSymbolIdListRequest {
9 |
10 | public ReqSymbolListRequest(int version) {
11 | super(version, "reqSymbolList");
12 | }
13 |
14 | }
15 |
--------------------------------------------------------------------------------
/huobi-client-websocket/src/main/java/org/oxerr/huobi/websocket/dto/request/service/package-info.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Requests for Service API.
3 | */
4 | package org.oxerr.huobi.websocket.dto.request.service;
5 |
--------------------------------------------------------------------------------
/huobi-client-websocket/src/main/java/org/oxerr/huobi/websocket/dto/response/ErrorResponse.java:
--------------------------------------------------------------------------------
1 | package org.oxerr.huobi.websocket.dto.response;
2 |
3 | import org.oxerr.huobi.websocket.dto.response.payload.VoidPayload;
4 |
5 | /**
6 | * Error response.
7 | */
8 | public class ErrorResponse extends ReqResponse {
9 |
10 | public static final int CODE_OK = 200;
11 | public static final int CODE_PARAM_ERROR = 601;
12 | public static final int CODE_SERVER_ERROR = 701;
13 |
14 | public ErrorResponse(int version, String msgType, int retCode, String retMsg) {
15 | super(version, msgType, retCode, retMsg);
16 | }
17 |
18 | }
19 |
--------------------------------------------------------------------------------
/huobi-client-websocket/src/main/java/org/oxerr/huobi/websocket/dto/response/ReqResponse.java:
--------------------------------------------------------------------------------
1 | package org.oxerr.huobi.websocket.dto.response;
2 |
3 | import org.oxerr.huobi.websocket.HuobiSocket;
4 | import org.oxerr.huobi.websocket.dto.response.payload.Payload;
5 |
6 | /**
7 | * Response of {@link HuobiSocket}.
8 | */
9 | public class ReqResponse extends Response {
10 |
11 | private long requestIndex;
12 | private final int retCode;
13 | private final String retMsg;
14 |
15 | /**
16 | * Constructs the response.
17 | *
18 | * @param version
19 | * For client version.
20 | * @param msgType
21 | * Message type.
22 | * @param retCode
23 | * Echo back the error data. 200 for Success, for other results
24 | * please check HTTP return code for reference.
25 | * @param retMsg
26 | * Return tips.
27 | */
28 | public ReqResponse(int version, String msgType, int retCode, String retMsg) {
29 | super(version, msgType);
30 | this.retCode = retCode;
31 | this.retMsg = retMsg;
32 | }
33 |
34 | public long getRequestIndex() {
35 | return requestIndex;
36 | }
37 |
38 | public void setRequestIndex(long requestIndex) {
39 | this.requestIndex = requestIndex;
40 | }
41 |
42 | public int getRetCode() {
43 | return retCode;
44 | }
45 |
46 | public String getRetMsg() {
47 | return retMsg;
48 | }
49 |
50 | }
51 |
--------------------------------------------------------------------------------
/huobi-client-websocket/src/main/java/org/oxerr/huobi/websocket/dto/response/Response.java:
--------------------------------------------------------------------------------
1 | package org.oxerr.huobi.websocket.dto.response;
2 |
3 | import org.apache.commons.lang3.builder.ToStringBuilder;
4 | import org.oxerr.huobi.websocket.dto.response.payload.Payload;
5 |
6 | /**
7 | * Response of Huobi WebSocket API.
8 | */
9 | public class Response {
10 |
11 | private final int version;
12 | private final String msgType;
13 | private T payload;
14 |
15 | public Response(int version, String msgType) {
16 | this.version = version;
17 | this.msgType = msgType;
18 | }
19 |
20 | public int getVersion() {
21 | return version;
22 | }
23 |
24 | public String getMsgType() {
25 | return msgType;
26 | }
27 |
28 | public T getPayload() {
29 | return payload;
30 | }
31 |
32 | public void setPayload(T payload) {
33 | this.payload = payload;
34 | }
35 |
36 | @Override
37 | public String toString() {
38 | return ToStringBuilder.reflectionToString(this);
39 | }
40 |
41 | }
42 |
--------------------------------------------------------------------------------
/huobi-client-websocket/src/main/java/org/oxerr/huobi/websocket/dto/response/historydata/ReqKLineResponse.java:
--------------------------------------------------------------------------------
1 | package org.oxerr.huobi.websocket.dto.response.historydata;
2 |
3 | import org.oxerr.huobi.websocket.dto.response.ReqResponse;
4 | import org.oxerr.huobi.websocket.dto.response.payload.ReqKLinePayload;
5 |
6 | /**
7 | * Response of history candlestick data.
8 | */
9 | public class ReqKLineResponse extends ReqResponse {
10 |
11 | public ReqKLineResponse(int version, String msgType, int retCode,
12 | String retMsg) {
13 | super(version, msgType, retCode, retMsg);
14 | }
15 |
16 | }
17 |
--------------------------------------------------------------------------------
/huobi-client-websocket/src/main/java/org/oxerr/huobi/websocket/dto/response/historydata/ReqMarketDepthResponse.java:
--------------------------------------------------------------------------------
1 | package org.oxerr.huobi.websocket.dto.response.historydata;
2 |
3 | import org.oxerr.huobi.websocket.dto.response.ReqResponse;
4 | import org.oxerr.huobi.websocket.dto.response.payload.ReqMarketDepthPayload;
5 |
6 | /**
7 | * Response of market-depth.
8 | */
9 | public class ReqMarketDepthResponse extends ReqResponse {
10 |
11 | public ReqMarketDepthResponse(int version, String msgType, int retCode,
12 | String retMsg) {
13 | super(version, msgType, retCode, retMsg);
14 | }
15 |
16 | }
17 |
--------------------------------------------------------------------------------
/huobi-client-websocket/src/main/java/org/oxerr/huobi/websocket/dto/response/historydata/ReqMarketDepthTopResponse.java:
--------------------------------------------------------------------------------
1 | package org.oxerr.huobi.websocket.dto.response.historydata;
2 |
3 | import org.oxerr.huobi.websocket.dto.response.ReqResponse;
4 | import org.oxerr.huobi.websocket.dto.response.payload.ReqMarketDepthTopPayload;
5 |
6 | /**
7 | * Response of top market-depth.
8 | */
9 | public class ReqMarketDepthTopResponse extends
10 | ReqResponse {
11 |
12 | public ReqMarketDepthTopResponse(int version, String msgType, int retCode,
13 | String retMsg) {
14 | super(version, msgType, retCode, retMsg);
15 | }
16 |
17 | }
18 |
--------------------------------------------------------------------------------
/huobi-client-websocket/src/main/java/org/oxerr/huobi/websocket/dto/response/historydata/ReqMarketDetailResponse.java:
--------------------------------------------------------------------------------
1 | package org.oxerr.huobi.websocket.dto.response.historydata;
2 |
3 | import org.oxerr.huobi.websocket.dto.response.ReqResponse;
4 | import org.oxerr.huobi.websocket.dto.response.payload.ReqMarketDetailPayload;
5 |
6 | /**
7 | * Response of market details.
8 | */
9 | public class ReqMarketDetailResponse extends ReqResponse {
10 |
11 | public ReqMarketDetailResponse(int version, String msgType, int retCode,
12 | String retMsg) {
13 | super(version, msgType, retCode, retMsg);
14 | }
15 |
16 | }
17 |
--------------------------------------------------------------------------------
/huobi-client-websocket/src/main/java/org/oxerr/huobi/websocket/dto/response/historydata/ReqTimeLineResponse.java:
--------------------------------------------------------------------------------
1 | package org.oxerr.huobi.websocket.dto.response.historydata;
2 |
3 | import org.oxerr.huobi.websocket.dto.response.ReqResponse;
4 | import org.oxerr.huobi.websocket.dto.response.payload.ReqTimeLinePayload;
5 |
6 | /**
7 | * Response of history time-interval.
8 | */
9 | public class ReqTimeLineResponse extends ReqResponse {
10 |
11 | public ReqTimeLineResponse(int version, String msgType, int retCode,
12 | String retMsg) {
13 | super(version, msgType, retCode, retMsg);
14 | }
15 |
16 | }
17 |
--------------------------------------------------------------------------------
/huobi-client-websocket/src/main/java/org/oxerr/huobi/websocket/dto/response/historydata/ReqTradeDetailTopResponse.java:
--------------------------------------------------------------------------------
1 | package org.oxerr.huobi.websocket.dto.response.historydata;
2 |
3 | import org.oxerr.huobi.websocket.dto.response.ReqResponse;
4 | import org.oxerr.huobi.websocket.dto.response.payload.ReqTradeDetailTopPayload;
5 |
6 | /**
7 | * Response of top trade details.
8 | */
9 | public class ReqTradeDetailTopResponse extends
10 | ReqResponse {
11 |
12 | public ReqTradeDetailTopResponse(int version, String msgType, int retCode,
13 | String retMsg) {
14 | super(version, msgType, retCode, retMsg);
15 | }
16 |
17 | }
18 |
--------------------------------------------------------------------------------
/huobi-client-websocket/src/main/java/org/oxerr/huobi/websocket/dto/response/historydata/package-info.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Responses for history data API.
3 | */
4 | package org.oxerr.huobi.websocket.dto.response.historydata;
5 |
--------------------------------------------------------------------------------
/huobi-client-websocket/src/main/java/org/oxerr/huobi/websocket/dto/response/marketdata/LastKLine.java:
--------------------------------------------------------------------------------
1 | package org.oxerr.huobi.websocket.dto.response.marketdata;
2 |
3 | import org.oxerr.huobi.websocket.dto.response.marketdata.payload.LastKLinePayload;
4 |
5 | /**
6 | * Push of the last data details from candlestick chart.
7 | */
8 | public class LastKLine extends Message {
9 |
10 | public LastKLine(int version, String msgType, String symbolId,
11 | LastKLinePayload payload) {
12 | super(version, msgType, symbolId, payload);
13 | }
14 |
15 | }
16 |
--------------------------------------------------------------------------------
/huobi-client-websocket/src/main/java/org/oxerr/huobi/websocket/dto/response/marketdata/LastTimeLine.java:
--------------------------------------------------------------------------------
1 | package org.oxerr.huobi.websocket.dto.response.marketdata;
2 |
3 | import org.oxerr.huobi.websocket.dto.response.marketdata.payload.LastTimeLinePayload;
4 |
5 | /**
6 | * Push of the last time-interval data.
7 | */
8 | public class LastTimeLine extends Message {
9 |
10 | public LastTimeLine(int version, String msgType, String symbolId,
11 | LastTimeLinePayload payload) {
12 | super(version, msgType, symbolId, payload);
13 | }
14 |
15 | }
16 |
--------------------------------------------------------------------------------
/huobi-client-websocket/src/main/java/org/oxerr/huobi/websocket/dto/response/marketdata/MarketDepthDiff.java:
--------------------------------------------------------------------------------
1 | package org.oxerr.huobi.websocket.dto.response.marketdata;
2 |
3 | import org.oxerr.huobi.websocket.dto.response.marketdata.payload.MarketDepthDiffPayload;
4 |
5 | /**
6 | * Push of market-depth difference.
7 | */
8 | public class MarketDepthDiff extends Message {
9 |
10 | public MarketDepthDiff(int version, String msgType, String symbolId,
11 | MarketDepthDiffPayload payload) {
12 | super(version, msgType, symbolId, payload);
13 | }
14 |
15 | }
16 |
--------------------------------------------------------------------------------
/huobi-client-websocket/src/main/java/org/oxerr/huobi/websocket/dto/response/marketdata/MarketDepthTopDiff.java:
--------------------------------------------------------------------------------
1 | package org.oxerr.huobi.websocket.dto.response.marketdata;
2 |
3 | import org.oxerr.huobi.websocket.dto.response.marketdata.payload.MarketDepthTopDiffPayload;
4 |
5 | /**
6 | * Push of top market-depth difference.
7 | */
8 | public class MarketDepthTopDiff extends Message {
9 |
10 | public MarketDepthTopDiff(int version, String msgType, String symbolId,
11 | MarketDepthTopDiffPayload payload) {
12 | super(version, msgType, symbolId, payload);
13 | }
14 |
15 | }
16 |
--------------------------------------------------------------------------------
/huobi-client-websocket/src/main/java/org/oxerr/huobi/websocket/dto/response/marketdata/MarketDetail.java:
--------------------------------------------------------------------------------
1 | package org.oxerr.huobi.websocket.dto.response.marketdata;
2 |
3 | import org.oxerr.huobi.websocket.dto.response.marketdata.payload.MarketDetailPayload;
4 |
5 | /**
6 | * Push of market detail.
7 | */
8 | public class MarketDetail extends Message {
9 |
10 | private final long _id;
11 | private final long idCur;
12 | private final long idPrev;
13 |
14 | public MarketDetail(int version, long _id, String msgType, String symbolId,
15 | long idCur, long idPrev, MarketDetailPayload payload) {
16 | super(version, msgType, symbolId, payload);
17 | this._id = _id;
18 | this.idCur = idCur;
19 | this.idPrev = idPrev;
20 | }
21 |
22 | public long get_id() {
23 | return _id;
24 | }
25 |
26 | public long getIdCur() {
27 | return idCur;
28 | }
29 |
30 | public long getIdPrev() {
31 | return idPrev;
32 | }
33 |
34 | }
35 |
--------------------------------------------------------------------------------
/huobi-client-websocket/src/main/java/org/oxerr/huobi/websocket/dto/response/marketdata/MarketOverview.java:
--------------------------------------------------------------------------------
1 | package org.oxerr.huobi.websocket.dto.response.marketdata;
2 |
3 | import org.oxerr.huobi.websocket.dto.response.marketdata.payload.MarketOverviewPayload;
4 |
5 | /**
6 | * Push of the market overview data.
7 | */
8 | public class MarketOverview extends Message {
9 |
10 | public MarketOverview(int version, String msgType, String symbolId,
11 | MarketOverviewPayload payload) {
12 | super(version, msgType, symbolId, payload);
13 | }
14 |
15 | }
16 |
--------------------------------------------------------------------------------
/huobi-client-websocket/src/main/java/org/oxerr/huobi/websocket/dto/response/marketdata/Message.java:
--------------------------------------------------------------------------------
1 | package org.oxerr.huobi.websocket.dto.response.marketdata;
2 |
3 | import org.oxerr.huobi.websocket.dto.response.Response;
4 | import org.oxerr.huobi.websocket.dto.response.payload.Payload;
5 |
6 | /**
7 | * Push message.
8 | */
9 | public abstract class Message extends Response {
10 |
11 | private final String symbolId;
12 |
13 | public Message(int version, String msgType, String symbolId, T payload) {
14 | super(version, msgType);
15 | this.symbolId = symbolId;
16 | setPayload(payload);
17 | }
18 |
19 | public String getSymbolId() {
20 | return symbolId;
21 | }
22 |
23 | }
24 |
--------------------------------------------------------------------------------
/huobi-client-websocket/src/main/java/org/oxerr/huobi/websocket/dto/response/marketdata/TradeDetail.java:
--------------------------------------------------------------------------------
1 | package org.oxerr.huobi.websocket.dto.response.marketdata;
2 |
3 | import org.oxerr.huobi.websocket.dto.response.marketdata.payload.TradeDetailPayload;
4 |
5 | /**
6 | * Push of trade details.
7 | */
8 | public class TradeDetail extends Message {
9 |
10 | private final long _id;
11 | private final long idCur;
12 | private final long idPrev;
13 | private final long timeMax;
14 | private final long timeMin;
15 |
16 | public TradeDetail(int version, long _id, String msgType, String symbolId,
17 | long idCur, long idPrev, long timeMax, long timeMin,
18 | TradeDetailPayload payload) {
19 | super(version, msgType, symbolId, payload);
20 | this._id = _id;
21 | this.idCur = idCur;
22 | this.idPrev = idPrev;
23 | this.timeMax = timeMax;
24 | this.timeMin = timeMin;
25 | }
26 |
27 | public long get_id() {
28 | return _id;
29 | }
30 |
31 | public long getIdCur() {
32 | return idCur;
33 | }
34 |
35 | public long getIdPrev() {
36 | return idPrev;
37 | }
38 |
39 | public long getTimeMax() {
40 | return timeMax;
41 | }
42 |
43 | public long getTimeMin() {
44 | return timeMin;
45 | }
46 |
47 | }
48 |
--------------------------------------------------------------------------------
/huobi-client-websocket/src/main/java/org/oxerr/huobi/websocket/dto/response/marketdata/package-info.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Messages pushed from Huobi exchange for the request of {@link org.oxerr.huobi.websocket.dto.request.service.ReqMsgSubscribeRequest}.
3 | */
4 | package org.oxerr.huobi.websocket.dto.response.marketdata;
5 |
6 |
--------------------------------------------------------------------------------
/huobi-client-websocket/src/main/java/org/oxerr/huobi/websocket/dto/response/marketdata/payload/LastKLinePayload.java:
--------------------------------------------------------------------------------
1 | package org.oxerr.huobi.websocket.dto.response.marketdata.payload;
2 |
3 | import java.math.BigDecimal;
4 |
5 | import org.oxerr.huobi.websocket.dto.Period;
6 | import org.oxerr.huobi.websocket.dto.response.marketdata.LastKLine;
7 | import org.oxerr.huobi.websocket.dto.response.payload.AbstractPayload;
8 |
9 | /**
10 | * Payload of {@link LastKLine}.
11 | */
12 | public class LastKLinePayload extends AbstractPayload {
13 |
14 | private final long _id;
15 | private final String symbolId;
16 | private final long time;
17 | private final Period period;
18 | private final BigDecimal priceOpen;
19 | private final BigDecimal priceHigh;
20 | private final BigDecimal priceLow;
21 | private final BigDecimal priceLast;
22 | private final BigDecimal amount;
23 | private final BigDecimal volume;
24 | private final int count;
25 |
26 | /**
27 | * 最后k线
28 | *
29 | * @param _id 唯一id
30 | * @param symbolId 交易代码
31 | * @param time 时间
32 | * @param period k线周期
33 | * @param priceOpen 开盘
34 | * @param priceHigh 最高
35 | * @param priceLow 最低
36 | * @param priceLast 收盘
37 | * @param amount 成交量
38 | * @param volume 成交额
39 | * @param count 成交笔数
40 | */
41 | public LastKLinePayload(long _id, String symbolId, long time,
42 | Period period, BigDecimal priceOpen, BigDecimal priceHigh,
43 | BigDecimal priceLow, BigDecimal priceLast, BigDecimal amount,
44 | BigDecimal volume, int count) {
45 | super();
46 | this._id = _id;
47 | this.symbolId = symbolId;
48 | this.time = time;
49 | this.period = period;
50 | this.priceOpen = priceOpen;
51 | this.priceHigh = priceHigh;
52 | this.priceLow = priceLow;
53 | this.priceLast = priceLast;
54 | this.amount = amount;
55 | this.volume = volume;
56 | this.count = count;
57 | }
58 |
59 | public long get_id() {
60 | return _id;
61 | }
62 |
63 | public String getSymbolId() {
64 | return symbolId;
65 | }
66 |
67 | public long getTime() {
68 | return time;
69 | }
70 |
71 | public Period getPeriod() {
72 | return period;
73 | }
74 |
75 | public BigDecimal getPriceOpen() {
76 | return priceOpen;
77 | }
78 |
79 | public BigDecimal getPriceHigh() {
80 | return priceHigh;
81 | }
82 |
83 | public BigDecimal getPriceLow() {
84 | return priceLow;
85 | }
86 |
87 | public BigDecimal getPriceLast() {
88 | return priceLast;
89 | }
90 |
91 | public BigDecimal getAmount() {
92 | return amount;
93 | }
94 |
95 | public BigDecimal getVolume() {
96 | return volume;
97 | }
98 |
99 | public int getCount() {
100 | return count;
101 | }
102 |
103 | }
104 |
--------------------------------------------------------------------------------
/huobi-client-websocket/src/main/java/org/oxerr/huobi/websocket/dto/response/marketdata/payload/LastTimeLinePayload.java:
--------------------------------------------------------------------------------
1 | package org.oxerr.huobi.websocket.dto.response.marketdata.payload;
2 |
3 | import java.math.BigDecimal;
4 |
5 | import org.oxerr.huobi.websocket.dto.response.marketdata.LastTimeLine;
6 | import org.oxerr.huobi.websocket.dto.response.payload.AbstractPayload;
7 |
8 | /**
9 | * Payload of {@link LastTimeLine}.
10 | */
11 | public class LastTimeLinePayload extends AbstractPayload {
12 |
13 | private final long _id;
14 | private final String symbolId;
15 | private final long time;
16 | private final BigDecimal priceLast;
17 | private final BigDecimal amount;
18 | private final BigDecimal volume;
19 | private final int count;
20 |
21 | /**
22 | * 最后分时
23 | *
24 | * @param _id 唯一id
25 | * @param symbolId 交易代码
26 | * @param time 时间,秒数
27 | * @param priceLast 收盘
28 | * @param amount 成交量
29 | * @param volume 成交额
30 | * @param count 成交笔数
31 | */
32 | public LastTimeLinePayload(long _id, String symbolId, long time,
33 | BigDecimal priceLast, BigDecimal amount, BigDecimal volume,
34 | int count) {
35 | super();
36 | this._id = _id;
37 | this.symbolId = symbolId;
38 | this.time = time;
39 | this.priceLast = priceLast;
40 | this.amount = amount;
41 | this.volume = volume;
42 | this.count = count;
43 | }
44 |
45 | public long get_id() {
46 | return _id;
47 | }
48 |
49 | public String getSymbolId() {
50 | return symbolId;
51 | }
52 |
53 | public long getTime() {
54 | return time;
55 | }
56 |
57 | public BigDecimal getPriceLast() {
58 | return priceLast;
59 | }
60 |
61 | public BigDecimal getAmount() {
62 | return amount;
63 | }
64 |
65 | public BigDecimal getVolume() {
66 | return volume;
67 | }
68 |
69 | public int getCount() {
70 | return count;
71 | }
72 |
73 | }
74 |
--------------------------------------------------------------------------------
/huobi-client-websocket/src/main/java/org/oxerr/huobi/websocket/dto/response/marketdata/payload/MarketDepthDiffPayload.java:
--------------------------------------------------------------------------------
1 | package org.oxerr.huobi.websocket.dto.response.marketdata.payload;
2 |
3 | import org.oxerr.huobi.websocket.dto.DepthDiff;
4 | import org.oxerr.huobi.websocket.dto.Percent;
5 | import org.oxerr.huobi.websocket.dto.response.marketdata.MarketDepthDiff;
6 |
7 | /**
8 | * Payload of {@link MarketDepthDiff}
9 | */
10 | public class MarketDepthDiffPayload extends MarketDepthTopDiffPayload implements
11 | DepthDiff {
12 |
13 | private final Percent percent;
14 |
15 | /**
16 | * 差量行情深度
17 | *
18 | * @param symbolId 交易代码
19 | * @param percent 行情深度百分比
20 | * @param version 快照版本,方便进行差量更新,如果终端的最后快照版本不一致,则需要重新获取最新完整行情深度。
21 | * @param versionOld 产生该差量的旧快照版本,方便进行差量更新,如果终端的最后快照版本不一致,则需要重新获取最新完整行情深度。
22 | * @param bidInsert 委托买单需要添加的行
23 | * @param bidDelete 委托买单需要删除的行
24 | * @param bidUpdate 委托买单需要修改的行,以及该行新的委单量。
25 | * @param askInsert 委托卖单需要添加的行
26 | * @param askDelete 委托卖单需要删除的行
27 | * @param askUpdate 委托卖单需要修改的行,以及该行新的委单量。
28 | */
29 | public MarketDepthDiffPayload(String symbolId, Percent percent,
30 | long version, long versionOld, Update bidInsert, int[] bidDelete,
31 | Update bidUpdate, Update askInsert, int[] askDelete,
32 | Update askUpdate) {
33 | super(symbolId, version, versionOld, bidInsert, bidDelete, bidUpdate,
34 | askInsert, askDelete, askUpdate);
35 | this.percent = percent;
36 | }
37 |
38 | public Percent getPercent() {
39 | return percent;
40 | }
41 |
42 | }
43 |
--------------------------------------------------------------------------------
/huobi-client-websocket/src/main/java/org/oxerr/huobi/websocket/dto/response/marketdata/payload/MarketDepthTopDiffPayload.java:
--------------------------------------------------------------------------------
1 | package org.oxerr.huobi.websocket.dto.response.marketdata.payload;
2 |
3 | import org.oxerr.huobi.websocket.dto.DepthDiff;
4 | import org.oxerr.huobi.websocket.dto.response.marketdata.MarketDepthTopDiff;
5 | import org.oxerr.huobi.websocket.dto.response.payload.AbstractPayload;
6 |
7 | /**
8 | * Payload of {@link MarketDepthTopDiff}.
9 | */
10 | public class MarketDepthTopDiffPayload extends AbstractPayload implements
11 | DepthDiff {
12 |
13 | private final String symbolId;
14 |
15 | private final long version;
16 | private final long versionOld;
17 |
18 | private final Update bidInsert;
19 | private final int[] bidDelete;
20 | private final Update bidUpdate;
21 |
22 | private final Update askInsert;
23 | private final int[] askDelete;
24 | private final Update askUpdate;
25 |
26 | /**
27 | * 差量行情深度
28 | *
29 | * @param symbolId 交易代码
30 | * @param version 快照版本,方便进行差量更新,如果终端的最后快照版本不一致,则需要重新获取最新完整行情深度。
31 | * @param versionOld 产生该差量的旧快照版本,方便进行差量更新,如果终端的最后快照版本不一致,则需要重新获取最新完整行情深度。
32 | * @param bidInsert 委托买单需要添加的行
33 | * @param bidDelete 委托买单需要删除的行
34 | * @param bidUpdate 委托买单需要修改的行,以及该行新的委单量。
35 | * @param askInsert 委托卖单需要添加的行
36 | * @param askDelete 委托卖单需要删除的行
37 | * @param askUpdate 委托卖单需要修改的行,以及该行新的委单量。
38 | */
39 | public MarketDepthTopDiffPayload(String symbolId, long version,
40 | long versionOld, Update bidInsert, int[] bidDelete,
41 | Update bidUpdate, Update askInsert, int[] askDelete,
42 | Update askUpdate) {
43 | this.symbolId = symbolId;
44 | this.version = version;
45 | this.versionOld = versionOld;
46 | this.bidInsert = bidInsert;
47 | this.bidDelete = bidDelete;
48 | this.bidUpdate = bidUpdate;
49 | this.askInsert = askInsert;
50 | this.askDelete = askDelete;
51 | this.askUpdate = askUpdate;
52 | }
53 |
54 | public String getSymbolId() {
55 | return symbolId;
56 | }
57 |
58 | public long getVersion() {
59 | return version;
60 | }
61 |
62 | public long getVersionOld() {
63 | return versionOld;
64 | }
65 |
66 | public Update getBidInsert() {
67 | return bidInsert;
68 | }
69 |
70 | public int[] getBidDelete() {
71 | return bidDelete;
72 | }
73 |
74 | public Update getBidUpdate() {
75 | return bidUpdate;
76 | }
77 |
78 | public Update getAskInsert() {
79 | return askInsert;
80 | }
81 |
82 | public int[] getAskDelete() {
83 | return askDelete;
84 | }
85 |
86 | public Update getAskUpdate() {
87 | return askUpdate;
88 | }
89 |
90 | }
91 |
--------------------------------------------------------------------------------
/huobi-client-websocket/src/main/java/org/oxerr/huobi/websocket/dto/response/marketdata/payload/MarketDetailPayload.java:
--------------------------------------------------------------------------------
1 | package org.oxerr.huobi.websocket.dto.response.marketdata.payload;
2 |
3 | import java.math.BigDecimal;
4 |
5 | import org.oxerr.huobi.websocket.dto.response.marketdata.MarketDetail;
6 | import org.oxerr.huobi.websocket.dto.response.payload.Orders;
7 | import org.oxerr.huobi.websocket.dto.response.payload.ReqMarketDetailPayload;
8 | import org.oxerr.huobi.websocket.dto.response.payload.Trades;
9 |
10 | /**
11 | * Payload of {@link MarketDetail}.
12 | */
13 | public class MarketDetailPayload extends ReqMarketDetailPayload {
14 |
15 | public MarketDetailPayload(String symbolId, BigDecimal priceNew,
16 | BigDecimal priceOpen, BigDecimal priceHigh, BigDecimal priceLow,
17 | BigDecimal priceLast, int level, BigDecimal amount,
18 | BigDecimal totalAmount, String amp, Trades trades, Orders bids,
19 | Orders asks, BigDecimal commissionRatio, BigDecimal poor,
20 | BigDecimal updownVolume, BigDecimal updownRatio,
21 | BigDecimal priceAverage, BigDecimal volumeRatio,
22 | BigDecimal turnVolume, BigDecimal turnoverRate,
23 | BigDecimal outerDisc, BigDecimal innerDisc, BigDecimal totalVolume) {
24 | super(symbolId, priceNew, priceOpen, priceHigh, priceLow, priceLast,
25 | level, amount, totalAmount, amp, trades, bids, asks,
26 | commissionRatio, poor, updownVolume, updownRatio, priceAverage,
27 | volumeRatio, turnVolume, turnoverRate, outerDisc, innerDisc,
28 | totalVolume);
29 | }
30 |
31 | }
32 |
--------------------------------------------------------------------------------
/huobi-client-websocket/src/main/java/org/oxerr/huobi/websocket/dto/response/marketdata/payload/MarketOverviewPayload.java:
--------------------------------------------------------------------------------
1 | package org.oxerr.huobi.websocket.dto.response.marketdata.payload;
2 |
3 | import java.math.BigDecimal;
4 |
5 | import org.oxerr.huobi.websocket.dto.response.marketdata.MarketOverview;
6 | import org.oxerr.huobi.websocket.dto.response.payload.AbstractPayload;
7 |
8 | /**
9 | * Payload of {@link MarketOverview}.
10 | */
11 | public class MarketOverviewPayload extends AbstractPayload {
12 |
13 | private final String symbolId;
14 | private final BigDecimal priceNew;
15 | private final BigDecimal priceOpen;
16 | private final BigDecimal priceHigh;
17 | private final BigDecimal priceLow;
18 | private final BigDecimal priceAsk;
19 | private final BigDecimal priceBid;
20 | private final BigDecimal totalVolume;
21 | private final BigDecimal totalAmount;
22 |
23 | /**
24 | * 市场概况
25 | *
26 | * @param symbolId 交易代码
27 | * @param priceNew 当前价格
28 | * @param priceOpen 开盘
29 | * @param priceHigh 最高
30 | * @param priceLow 最低
31 | * @param priceAsk 卖一
32 | * @param priceBid 买一
33 | * @param totalVolume 今日累计成交量
34 | * @param totalAmount 今日累计成交额
35 | */
36 | public MarketOverviewPayload(String symbolId, BigDecimal priceNew,
37 | BigDecimal priceOpen, BigDecimal priceHigh, BigDecimal priceLow,
38 | BigDecimal priceAsk, BigDecimal priceBid, BigDecimal totalVolume,
39 | BigDecimal totalAmount) {
40 | super();
41 | this.symbolId = symbolId;
42 | this.priceNew = priceNew;
43 | this.priceOpen = priceOpen;
44 | this.priceHigh = priceHigh;
45 | this.priceLow = priceLow;
46 | this.priceAsk = priceAsk;
47 | this.priceBid = priceBid;
48 | this.totalVolume = totalVolume;
49 | this.totalAmount = totalAmount;
50 | }
51 |
52 | public String getSymbolId() {
53 | return symbolId;
54 | }
55 |
56 | public BigDecimal getPriceNew() {
57 | return priceNew;
58 | }
59 |
60 | public BigDecimal getPriceOpen() {
61 | return priceOpen;
62 | }
63 |
64 | public BigDecimal getPriceHigh() {
65 | return priceHigh;
66 | }
67 |
68 | public BigDecimal getPriceLow() {
69 | return priceLow;
70 | }
71 |
72 | public BigDecimal getPriceAsk() {
73 | return priceAsk;
74 | }
75 |
76 | public BigDecimal getPriceBid() {
77 | return priceBid;
78 | }
79 |
80 | public BigDecimal getTotalVolume() {
81 | return totalVolume;
82 | }
83 |
84 | public BigDecimal getTotalAmount() {
85 | return totalAmount;
86 | }
87 |
88 | }
89 |
--------------------------------------------------------------------------------
/huobi-client-websocket/src/main/java/org/oxerr/huobi/websocket/dto/response/marketdata/payload/TradeDetailPayload.java:
--------------------------------------------------------------------------------
1 | package org.oxerr.huobi.websocket.dto.response.marketdata.payload;
2 |
3 | import java.math.BigDecimal;
4 |
5 | import org.oxerr.huobi.websocket.dto.response.marketdata.TradeDetail;
6 | import org.oxerr.huobi.websocket.dto.response.payload.Orders;
7 | import org.oxerr.huobi.websocket.dto.response.payload.ReqTradeDetailTopPayload;
8 |
9 | /**
10 | * Payload of {@link TradeDetail}.
11 | */
12 | public class TradeDetailPayload extends ReqTradeDetailTopPayload implements
13 | org.oxerr.huobi.websocket.dto.TradeDetail {
14 |
15 | public TradeDetailPayload(String symbolId, long[] tradeId,
16 | BigDecimal[] price, long[] time, BigDecimal[] amount,
17 | int[] direction, Orders[] topAsks, Orders[] topBids) {
18 | super(symbolId, tradeId, price, time, amount, direction, topAsks,
19 | topBids);
20 | }
21 |
22 | }
23 |
--------------------------------------------------------------------------------
/huobi-client-websocket/src/main/java/org/oxerr/huobi/websocket/dto/response/marketdata/payload/Update.java:
--------------------------------------------------------------------------------
1 | package org.oxerr.huobi.websocket.dto.response.marketdata.payload;
2 |
3 | import java.math.BigDecimal;
4 |
5 | /**
6 | * Update of {@link MarketDepthDiffPayload} and {@link MarketDepthTopDiffPayload}.
7 | */
8 | public class Update {
9 |
10 | private final BigDecimal[] price;
11 | private final BigDecimal[] amount;
12 | private final int[] row;
13 |
14 | public Update(BigDecimal[] price, BigDecimal[] amount, int[] row) {
15 | this.price = price;
16 | this.amount = amount;
17 | this.row = row;
18 | }
19 |
20 | public BigDecimal[] getPrice() {
21 | return price;
22 | }
23 |
24 | public BigDecimal[] getAmount() {
25 | return amount;
26 | }
27 |
28 | public int[] getRow() {
29 | return row;
30 | }
31 |
32 | }
33 |
--------------------------------------------------------------------------------
/huobi-client-websocket/src/main/java/org/oxerr/huobi/websocket/dto/response/marketdata/payload/package-info.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Payloads of {@link org.oxerr.huobi.websocket.dto.response.marketdata.Message}.
3 | */
4 | package org.oxerr.huobi.websocket.dto.response.marketdata.payload;
5 |
--------------------------------------------------------------------------------
/huobi-client-websocket/src/main/java/org/oxerr/huobi/websocket/dto/response/package-info.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Response DTOs.
3 | */
4 | package org.oxerr.huobi.websocket.dto.response;
5 |
--------------------------------------------------------------------------------
/huobi-client-websocket/src/main/java/org/oxerr/huobi/websocket/dto/response/payload/AbstractPayload.java:
--------------------------------------------------------------------------------
1 | package org.oxerr.huobi.websocket.dto.response.payload;
2 |
3 | import org.apache.commons.lang3.builder.ToStringBuilder;
4 |
5 | public abstract class AbstractPayload implements Payload {
6 |
7 | /**
8 | * {@inheritDoc}
9 | */
10 | @Override
11 | public String toString() {
12 | return ToStringBuilder.reflectionToString(this);
13 | }
14 |
15 | }
16 |
--------------------------------------------------------------------------------
/huobi-client-websocket/src/main/java/org/oxerr/huobi/websocket/dto/response/payload/Orders.java:
--------------------------------------------------------------------------------
1 | package org.oxerr.huobi.websocket.dto.response.payload;
2 |
3 | import java.math.BigDecimal;
4 |
5 | public class Orders {
6 |
7 | private final BigDecimal[] price;
8 | private final int[] level;
9 | private final BigDecimal[] amount;
10 | private final BigDecimal[] accuAmount;
11 |
12 | public Orders(BigDecimal[] price, int[] level, BigDecimal[] amount,
13 | BigDecimal[] accuAmount) {
14 | super();
15 | this.price = price;
16 | this.level = level;
17 | this.amount = amount;
18 | this.accuAmount = accuAmount;
19 | }
20 |
21 | public BigDecimal[] getPrice() {
22 | return price;
23 | }
24 |
25 | public int[] getLevel() {
26 | return level;
27 | }
28 |
29 | public BigDecimal[] getAmount() {
30 | return amount;
31 | }
32 |
33 | public BigDecimal[] getAccuAmount() {
34 | return accuAmount;
35 | }
36 |
37 | }
38 |
--------------------------------------------------------------------------------
/huobi-client-websocket/src/main/java/org/oxerr/huobi/websocket/dto/response/payload/Payload.java:
--------------------------------------------------------------------------------
1 | package org.oxerr.huobi.websocket.dto.response.payload;
2 |
3 | import org.oxerr.huobi.websocket.dto.response.Response;
4 |
5 | /**
6 | * The payload of {@link Response}.
7 | */
8 | public interface Payload {
9 |
10 | }
11 |
--------------------------------------------------------------------------------
/huobi-client-websocket/src/main/java/org/oxerr/huobi/websocket/dto/response/payload/ReqKLinePayload.java:
--------------------------------------------------------------------------------
1 | package org.oxerr.huobi.websocket.dto.response.payload;
2 |
3 | import java.math.BigDecimal;
4 |
5 | import org.oxerr.huobi.websocket.dto.Period;
6 | import org.oxerr.huobi.websocket.dto.response.historydata.ReqKLineResponse;
7 |
8 | /**
9 | * Payload of {@link ReqKLineResponse}.
10 | */
11 | public class ReqKLinePayload extends AbstractPayload {
12 |
13 | private final String symbolId;
14 | private final Period period;
15 | private final long[] time;
16 | private final BigDecimal[] priceOpen;
17 | private final BigDecimal[] priceHigh;
18 | private final BigDecimal[] priceLow;
19 | private final BigDecimal[] priceLast;
20 | private final BigDecimal[] amount;
21 | private final BigDecimal[] volume;
22 | private final int[] count;
23 |
24 | /**
25 | * 历史k线
26 | *
27 | * @param symbolId 交易代码
28 | * @param period k线周期
29 | * @param time 时间
30 | * @param priceOpen 开盘
31 | * @param priceHigh 最高
32 | * @param priceLow 最低
33 | * @param priceLast 收盘
34 | * @param amount 成交量
35 | * @param volume 成交额
36 | * @param count 成交笔数
37 | */
38 | public ReqKLinePayload(String symbolId, Period period, long[] time,
39 | BigDecimal[] priceOpen, BigDecimal[] priceHigh,
40 | BigDecimal[] priceLow, BigDecimal[] priceLast, BigDecimal[] amount,
41 | BigDecimal[] volume, int[] count) {
42 | this.symbolId = symbolId;
43 | this.period = period;
44 | this.time = time;
45 | this.priceOpen = priceOpen;
46 | this.priceHigh = priceHigh;
47 | this.priceLow = priceLow;
48 | this.priceLast = priceLast;
49 | this.amount = amount;
50 | this.volume = volume;
51 | this.count = count;
52 | }
53 |
54 | public String getSymbolId() {
55 | return symbolId;
56 | }
57 |
58 | public Period getPeriod() {
59 | return period;
60 | }
61 |
62 | public long[] getTime() {
63 | return time;
64 | }
65 |
66 | public BigDecimal[] getPriceOpen() {
67 | return priceOpen;
68 | }
69 |
70 | public BigDecimal[] getPriceHigh() {
71 | return priceHigh;
72 | }
73 |
74 | public BigDecimal[] getPriceLow() {
75 | return priceLow;
76 | }
77 |
78 | public BigDecimal[] getPriceLast() {
79 | return priceLast;
80 | }
81 |
82 | public BigDecimal[] getAmount() {
83 | return amount;
84 | }
85 |
86 | public BigDecimal[] getVolume() {
87 | return volume;
88 | }
89 |
90 | public int[] getCount() {
91 | return count;
92 | }
93 |
94 | }
95 |
--------------------------------------------------------------------------------
/huobi-client-websocket/src/main/java/org/oxerr/huobi/websocket/dto/response/payload/ReqMarketDepthPayload.java:
--------------------------------------------------------------------------------
1 | package org.oxerr.huobi.websocket.dto.response.payload;
2 |
3 | import java.math.BigDecimal;
4 |
5 | import org.oxerr.huobi.websocket.dto.Depth;
6 | import org.oxerr.huobi.websocket.dto.Percent;
7 | import org.oxerr.huobi.websocket.dto.response.historydata.ReqMarketDepthResponse;
8 |
9 | /**
10 | * Payload of {@link ReqMarketDepthResponse}.
11 | */
12 | public class ReqMarketDepthPayload extends ReqMarketDepthTopPayload implements
13 | Depth {
14 |
15 | private final Percent percent;
16 |
17 | /**
18 | * 行情深度
19 | *
20 | * @param symbolId 交易代码
21 | * @param percent 行情深度百分比
22 | * @param time 时间
23 | * @param version 快照版本,方便进行差量更新,如果终端的最后快照版本不一致,则需要重新获取最新完整行情深度。
24 | * @param bidName 买单文字描述
25 | * @param bidPrice 买单价格
26 | * @param bidTotal 累计买单量
27 | * @param bidAmount 买单量
28 | * @param askName 卖单文字描述
29 | * @param askPrice 卖单价格
30 | * @param askTotal 累计卖单量
31 | * @param askAmount 卖单量
32 | */
33 | public ReqMarketDepthPayload(String symbolId, Percent percent, long time,
34 | long version,
35 |
36 | String bidName, BigDecimal[] bidPrice, BigDecimal[] bidTotal,
37 | BigDecimal[] bidAmount,
38 |
39 | String askName, BigDecimal[] askPrice, BigDecimal[] askTotal,
40 | BigDecimal[] askAmount) {
41 | super(symbolId, time, version, bidName, bidPrice, bidTotal, bidAmount,
42 | askName, askPrice, askTotal, askAmount);
43 | this.percent = percent;
44 | }
45 |
46 | public Percent getPercent() {
47 | return percent;
48 | }
49 |
50 | }
51 |
--------------------------------------------------------------------------------
/huobi-client-websocket/src/main/java/org/oxerr/huobi/websocket/dto/response/payload/ReqSymbolDetailPayload.java:
--------------------------------------------------------------------------------
1 | package org.oxerr.huobi.websocket.dto.response.payload;
2 |
3 | import java.math.BigDecimal;
4 |
5 | import org.oxerr.huobi.websocket.dto.response.service.ReqSymbolDetailResponse;
6 |
7 | /**
8 | * Payload of {@link ReqSymbolDetailResponse}.
9 | */
10 | public class ReqSymbolDetailPayload extends ReqSymbolListPayload {
11 |
12 | private final BigDecimal[] total;
13 | private final BigDecimal[] suply;
14 | private final String[] introduction;
15 |
16 | /**
17 | * 获取交易代码详细信息
18 | *
19 | * @param symbolId 交易代码
20 | * @param symbolName 虚拟货币名称
21 | * @param cryptoId 数字货币id
22 | * @param cryptoName 数字货币名称
23 | * @param exchangeId 交易所Id
24 | * @param exchangeName 交易所名称
25 | * @param currencyId 现金Id
26 | * @param currencyName 现金名称
27 | * @param total 总量
28 | * @param suply 流通量
29 | * @param introduction 中文名
30 | */
31 | public ReqSymbolDetailPayload(String[] symbolId, String[] symbolName,
32 | String[] cryptoId, String[] cryptoName, String[] exchangeId,
33 | String[] exchangeName, String[] currencyId, String[] currencyName,
34 | BigDecimal[] total, BigDecimal[] suply, String[] introduction) {
35 | super(symbolId, symbolName, cryptoId, cryptoName, exchangeId,
36 | exchangeName, currencyId, currencyName);
37 | this.total = total;
38 | this.suply = suply;
39 | this.introduction = introduction;
40 | }
41 |
42 | public BigDecimal[] getTotal() {
43 | return total;
44 | }
45 |
46 | public BigDecimal[] getSuply() {
47 | return suply;
48 | }
49 |
50 | public String[] getIntroduction() {
51 | return introduction;
52 | }
53 |
54 | }
55 |
--------------------------------------------------------------------------------
/huobi-client-websocket/src/main/java/org/oxerr/huobi/websocket/dto/response/payload/ReqSymbolListPayload.java:
--------------------------------------------------------------------------------
1 | package org.oxerr.huobi.websocket.dto.response.payload;
2 |
3 | import org.oxerr.huobi.websocket.dto.response.service.ReqSymbolListResponse;
4 |
5 | /**
6 | * Payload of {@link ReqSymbolListResponse}.
7 | */
8 | public class ReqSymbolListPayload extends AbstractPayload {
9 |
10 | private final String[] symbolId;
11 | private final String[] symbolName;
12 | private final String[] cryptoId;
13 | private final String[] cryptoName;
14 | private final String[] exchangeId;
15 | private final String[] exchangeName;
16 | private final String[] currencyId;
17 | private final String[] currencyName;
18 |
19 | /**
20 | * 获取交易代码列表
21 | *
22 | * @param symbolId 交易代码
23 | * @param symbolName 虚拟货币名称
24 | * @param cryptoId 数字货币id
25 | * @param cryptoName 数字货币名称
26 | * @param exchangeId 交易所Id
27 | * @param exchangeName 交易所名称
28 | * @param currencyId 现金Id
29 | * @param currencyName 现金名称
30 | */
31 | public ReqSymbolListPayload(String[] symbolId, String[] symbolName,
32 | String[] cryptoId, String[] cryptoName, String[] exchangeId,
33 | String[] exchangeName, String[] currencyId, String[] currencyName) {
34 | this.symbolId = symbolId;
35 | this.symbolName = symbolName;
36 | this.cryptoId = cryptoId;
37 | this.cryptoName = cryptoName;
38 | this.exchangeId = exchangeId;
39 | this.exchangeName = exchangeName;
40 | this.currencyId = currencyId;
41 | this.currencyName = currencyName;
42 | }
43 |
44 | public String[] getSymbolId() {
45 | return symbolId;
46 | }
47 |
48 | public String[] getSymbolName() {
49 | return symbolName;
50 | }
51 |
52 | public String[] getCryptoId() {
53 | return cryptoId;
54 | }
55 |
56 | public String[] getCryptoName() {
57 | return cryptoName;
58 | }
59 |
60 | public String[] getExchangeId() {
61 | return exchangeId;
62 | }
63 |
64 | public String[] getExchangeName() {
65 | return exchangeName;
66 | }
67 |
68 | public String[] getCurrencyId() {
69 | return currencyId;
70 | }
71 |
72 | public String[] getCurrencyName() {
73 | return currencyName;
74 | }
75 |
76 | }
77 |
--------------------------------------------------------------------------------
/huobi-client-websocket/src/main/java/org/oxerr/huobi/websocket/dto/response/payload/ReqTimeLinePayload.java:
--------------------------------------------------------------------------------
1 | package org.oxerr.huobi.websocket.dto.response.payload;
2 |
3 | import java.math.BigDecimal;
4 |
5 | import org.oxerr.huobi.websocket.dto.response.historydata.ReqTimeLineResponse;
6 |
7 | /**
8 | * Payload of {@link ReqTimeLineResponse}.
9 | */
10 | public class ReqTimeLinePayload extends AbstractPayload {
11 |
12 | private final String symbolId;
13 | private final long[] time;
14 | private final BigDecimal[] priceLast;
15 | private final BigDecimal[] amount;
16 | private final BigDecimal[] volume;
17 | private final int[] count;
18 |
19 | /**
20 | * 历史分时
21 | *
22 | * @param symbolId 交易代码
23 | * @param time 时间,秒数
24 | * @param priceLast 收盘
25 | * @param amount 成交量
26 | * @param volume 成交额
27 | * @param count 成交笔数
28 | */
29 | public ReqTimeLinePayload(String symbolId, long[] time,
30 | BigDecimal[] priceLast, BigDecimal[] amount, BigDecimal[] volume,
31 | int[] count) {
32 | super();
33 | this.symbolId = symbolId;
34 | this.time = time;
35 | this.priceLast = priceLast;
36 | this.amount = amount;
37 | this.volume = volume;
38 | this.count = count;
39 | }
40 |
41 | public String getSymbolId() {
42 | return symbolId;
43 | }
44 |
45 | public long[] getTime() {
46 | return time;
47 | }
48 |
49 | public BigDecimal[] getPriceLast() {
50 | return priceLast;
51 | }
52 |
53 | public BigDecimal[] getAmount() {
54 | return amount;
55 | }
56 |
57 | public BigDecimal[] getVolume() {
58 | return volume;
59 | }
60 |
61 | public int[] getCount() {
62 | return count;
63 | }
64 |
65 | }
66 |
--------------------------------------------------------------------------------
/huobi-client-websocket/src/main/java/org/oxerr/huobi/websocket/dto/response/payload/ReqTradeDetailTopPayload.java:
--------------------------------------------------------------------------------
1 | package org.oxerr.huobi.websocket.dto.response.payload;
2 |
3 | import java.math.BigDecimal;
4 |
5 | import org.oxerr.huobi.websocket.dto.TradeDetail;
6 | import org.oxerr.huobi.websocket.dto.response.historydata.ReqTradeDetailTopResponse;
7 |
8 | /**
9 | * Payload of {@link ReqTradeDetailTopResponse}.
10 | */
11 | public class ReqTradeDetailTopPayload extends AbstractPayload implements
12 | TradeDetail {
13 |
14 | private final String symbolId;
15 | private final long[] tradeId;
16 | private final BigDecimal[] price;
17 | private final long[] time;
18 | private final BigDecimal[] amount;
19 | private final int[] direction;
20 | private final Orders[] topAsks;
21 | private final Orders[] topBids;
22 |
23 | /**
24 | * 交易明细
25 | *
26 | * @param symbolId 交易代码
27 | * @param tradeId 交易id
28 | * @param price 成交价格
29 | * @param time 成交时间
30 | * @param amount 成交量
31 | * @param direction 成交类型:买入或者卖出
32 | * @param topAsks top5卖单
33 | * @param topBids top5买单
34 | */
35 | public ReqTradeDetailTopPayload(String symbolId, long[] tradeId,
36 | BigDecimal[] price, long[] time, BigDecimal[] amount,
37 | int[] direction, Orders[] topAsks, Orders[] topBids) {
38 | super();
39 | this.symbolId = symbolId;
40 | this.tradeId = tradeId;
41 | this.price = price;
42 | this.time = time;
43 | this.amount = amount;
44 | this.direction = direction;
45 | this.topAsks = topAsks;
46 | this.topBids = topBids;
47 | }
48 |
49 | @Override
50 | public String getSymbolId() {
51 | return symbolId;
52 | }
53 |
54 | @Override
55 | public long[] getTradeId() {
56 | return tradeId;
57 | }
58 |
59 | @Override
60 | public BigDecimal[] getPrice() {
61 | return price;
62 | }
63 |
64 | @Override
65 | public long[] getTime() {
66 | return time;
67 | }
68 |
69 | @Override
70 | public BigDecimal[] getAmount() {
71 | return amount;
72 | }
73 |
74 | @Override
75 | public int[] getDirection() {
76 | return direction;
77 | }
78 |
79 | @Override
80 | public Orders[] getTopAsks() {
81 | return topAsks;
82 | }
83 |
84 | @Override
85 | public Orders[] getTopBids() {
86 | return topBids;
87 | }
88 |
89 | }
90 |
--------------------------------------------------------------------------------
/huobi-client-websocket/src/main/java/org/oxerr/huobi/websocket/dto/response/payload/Trades.java:
--------------------------------------------------------------------------------
1 | package org.oxerr.huobi.websocket.dto.response.payload;
2 |
3 | import java.math.BigDecimal;
4 |
5 | import org.oxerr.huobi.websocket.dto.response.marketdata.payload.MarketDetailPayload;
6 |
7 | /**
8 | * Trades for {@link MarketDetailPayload} and {@link ReqMarketDetailPayload}.
9 | */
10 | public class Trades {
11 | private final BigDecimal[] price;
12 | private final long[] time;
13 | private final BigDecimal[] amount;
14 | private final int[] direction;
15 |
16 | public Trades(BigDecimal[] price, long[] time, BigDecimal[] amount,
17 | int[] direction) {
18 | super();
19 | this.price = price;
20 | this.time = time;
21 | this.amount = amount;
22 | this.direction = direction;
23 | }
24 |
25 | public BigDecimal[] getPrice() {
26 | return price;
27 | }
28 |
29 | public long[] getTime() {
30 | return time;
31 | }
32 |
33 | public BigDecimal[] getAmount() {
34 | return amount;
35 | }
36 |
37 | public int[] getDirection() {
38 | return direction;
39 | }
40 |
41 | }
42 |
--------------------------------------------------------------------------------
/huobi-client-websocket/src/main/java/org/oxerr/huobi/websocket/dto/response/payload/VoidPayload.java:
--------------------------------------------------------------------------------
1 | package org.oxerr.huobi.websocket.dto.response.payload;
2 |
3 | /**
4 | * Void payload.
5 | */
6 | public class VoidPayload extends AbstractPayload {
7 |
8 | }
9 |
--------------------------------------------------------------------------------
/huobi-client-websocket/src/main/java/org/oxerr/huobi/websocket/dto/response/payload/package-info.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Payload of {@link org.oxerr.huobi.websocket.dto.response.Response}.
3 | */
4 | package org.oxerr.huobi.websocket.dto.response.payload;
5 |
--------------------------------------------------------------------------------
/huobi-client-websocket/src/main/java/org/oxerr/huobi/websocket/dto/response/service/ReqMsgSubscribeResponse.java:
--------------------------------------------------------------------------------
1 | package org.oxerr.huobi.websocket.dto.response.service;
2 |
3 | import org.oxerr.huobi.websocket.dto.response.ReqResponse;
4 | import org.oxerr.huobi.websocket.dto.response.payload.VoidPayload;
5 |
6 | /**
7 | * Response of subscribing push message.
8 | */
9 | public class ReqMsgSubscribeResponse extends ReqResponse {
10 |
11 | public ReqMsgSubscribeResponse(int version, String msgType, int retCode,
12 | String retMsg) {
13 | super(version, msgType, retCode, retMsg);
14 | }
15 |
16 | }
17 |
--------------------------------------------------------------------------------
/huobi-client-websocket/src/main/java/org/oxerr/huobi/websocket/dto/response/service/ReqMsgUnsubscribeResponse.java:
--------------------------------------------------------------------------------
1 | package org.oxerr.huobi.websocket.dto.response.service;
2 |
3 | import org.oxerr.huobi.websocket.dto.response.ReqResponse;
4 | import org.oxerr.huobi.websocket.dto.response.payload.VoidPayload;
5 |
6 | /**
7 | * Response of canceling push message subscription.
8 | */
9 | public class ReqMsgUnsubscribeResponse extends ReqResponse {
10 |
11 | public ReqMsgUnsubscribeResponse(int version, String msgType, int retCode,
12 | String retMsg) {
13 | super(version, msgType, retCode, retMsg);
14 | }
15 |
16 | }
17 |
--------------------------------------------------------------------------------
/huobi-client-websocket/src/main/java/org/oxerr/huobi/websocket/dto/response/service/ReqSymbolDetailResponse.java:
--------------------------------------------------------------------------------
1 | package org.oxerr.huobi.websocket.dto.response.service;
2 |
3 | import org.oxerr.huobi.websocket.dto.response.ReqResponse;
4 | import org.oxerr.huobi.websocket.dto.response.payload.ReqSymbolDetailPayload;
5 |
6 | /**
7 | * Response of symbol details.
8 | */
9 | public class ReqSymbolDetailResponse extends ReqResponse {
10 |
11 | public ReqSymbolDetailResponse(int version, String msgType, int retCode,
12 | String retMsg, ReqSymbolDetailPayload payload) {
13 | super(version, msgType, retCode, retMsg);
14 | setPayload(payload);
15 | }
16 |
17 | }
18 |
--------------------------------------------------------------------------------
/huobi-client-websocket/src/main/java/org/oxerr/huobi/websocket/dto/response/service/ReqSymbolListResponse.java:
--------------------------------------------------------------------------------
1 | package org.oxerr.huobi.websocket.dto.response.service;
2 |
3 | import org.oxerr.huobi.websocket.dto.response.ReqResponse;
4 | import org.oxerr.huobi.websocket.dto.response.payload.ReqSymbolListPayload;
5 |
6 | /**
7 | * Response of symbol list.
8 | */
9 | public class ReqSymbolListResponse extends ReqResponse {
10 |
11 | public ReqSymbolListResponse(int version, String msgType, int retCode,
12 | String retMsg) {
13 | super(version, msgType, retCode, retMsg);
14 | }
15 |
16 | }
17 |
--------------------------------------------------------------------------------
/huobi-client-websocket/src/main/java/org/oxerr/huobi/websocket/dto/response/service/package-info.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Responses for Service API.
3 | */
4 | package org.oxerr.huobi.websocket.dto.response.service;
5 |
--------------------------------------------------------------------------------
/huobi-client-websocket/src/main/java/org/oxerr/huobi/websocket/event/HuobiSocketAdapter.java:
--------------------------------------------------------------------------------
1 | package org.oxerr.huobi.websocket.event;
2 |
3 | import io.socket.IOAcknowledge;
4 | import io.socket.SocketIOException;
5 |
6 | import com.google.gson.JsonElement;
7 |
8 | /**
9 | * An abstract adapter class for receiving Huobi socket events. The methods in
10 | * this class are empty. This class exists as convenience for creating listener
11 | * objects.
12 | */
13 | public abstract class HuobiSocketAdapter implements HuobiSocketListener {
14 |
15 | /**
16 | * {@inheritDoc}
17 | */
18 | @Override
19 | public void onConnect() {
20 | }
21 |
22 | /**
23 | * {@inheritDoc}
24 | */
25 | @Override
26 | public void onDisconnect() {
27 | }
28 |
29 | /**
30 | * {@inheritDoc}
31 | */
32 | @Override
33 | public void onError(SocketIOException socketIOException) {
34 | }
35 |
36 | /**
37 | * {@inheritDoc}
38 | */
39 | @Override
40 | public void onMessage(String data, IOAcknowledge ack) {
41 | }
42 |
43 | /**
44 | * {@inheritDoc}
45 | */
46 | @Override
47 | public void onMessage(JsonElement json, IOAcknowledge ack) {
48 | }
49 |
50 | /**
51 | * {@inheritDoc}
52 | */
53 | @Override
54 | public void on(String event, IOAcknowledge ack, JsonElement... args) {
55 | }
56 |
57 | }
58 |
--------------------------------------------------------------------------------
/huobi-client-websocket/src/main/java/org/oxerr/huobi/websocket/event/HuobiSocketListener.java:
--------------------------------------------------------------------------------
1 | package org.oxerr.huobi.websocket.event;
2 |
3 | import io.socket.IOCallback;
4 |
5 | import org.oxerr.huobi.websocket.HuobiSocket;
6 |
7 | /**
8 | * The listener interface for receiving {@link HuobiSocket} events.
9 | */
10 | public interface HuobiSocketListener extends IOCallback {
11 |
12 | }
13 |
--------------------------------------------------------------------------------
/huobi-client-websocket/src/main/java/org/oxerr/huobi/websocket/event/ResponseAdapter.java:
--------------------------------------------------------------------------------
1 | package org.oxerr.huobi.websocket.event;
2 |
3 | import org.oxerr.huobi.websocket.dto.response.Response;
4 | import org.oxerr.huobi.websocket.dto.response.payload.Payload;
5 |
6 | /**
7 | * An abstract adapter class for receiving Huobi exchange events. The methods in
8 | * this class are empty. This class exists as convenience for creating listener
9 | * objects.
10 | */
11 | public abstract class ResponseAdapter implements ResponseListener {
12 |
13 | @Override
14 | public void onResponse(Response extends Payload> response) {
15 | }
16 |
17 | }
18 |
--------------------------------------------------------------------------------
/huobi-client-websocket/src/main/java/org/oxerr/huobi/websocket/event/ResponseListener.java:
--------------------------------------------------------------------------------
1 | package org.oxerr.huobi.websocket.event;
2 |
3 | import org.oxerr.huobi.websocket.dto.response.Response;
4 | import org.oxerr.huobi.websocket.dto.response.payload.Payload;
5 |
6 | /**
7 | * The listener interface for receiving Huobi exchange response.
8 | */
9 | public interface ResponseListener {
10 |
11 | void onResponse(Response extends Payload> response);
12 |
13 | }
14 |
--------------------------------------------------------------------------------
/huobi-client-websocket/src/main/java/org/oxerr/huobi/websocket/event/package-info.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Provides interfaces and classes for dealing with Huobi exchange events.
3 | */
4 | package org.oxerr.huobi.websocket.event;
5 |
--------------------------------------------------------------------------------
/huobi-client-websocket/src/main/java/org/oxerr/huobi/websocket/package-info.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Implementation for Huobi WebSocket API v1.0.
3 | */
4 | package org.oxerr.huobi.websocket;
5 |
--------------------------------------------------------------------------------
/huobi-client-websocket/src/test/java/org/oxerr/huobi/websocket/dto/request/historydata/ReqTimeLineRequestTest.java:
--------------------------------------------------------------------------------
1 | package org.oxerr.huobi.websocket.dto.request.historydata;
2 |
3 | import static org.junit.Assert.assertEquals;
4 |
5 | import java.time.Instant;
6 |
7 | import org.junit.Test;
8 | import org.oxerr.huobi.websocket.dto.GsonFactory;
9 |
10 | import com.google.gson.Gson;
11 |
12 | public class ReqTimeLineRequestTest {
13 |
14 | private static Gson gson = GsonFactory.getGson();
15 |
16 | @Test
17 | public void test() {
18 | ReqTimeLineRequest req = new ReqTimeLineRequest(1, "btccny");
19 | req.setFrom(Instant.ofEpochMilli(1));
20 | req.setTo(Instant.ofEpochMilli(2));
21 | String json = gson.toJson(req);
22 | assertEquals("{\"from\":1,\"to\":2,\"symbolId\":\"btccny\",\"version\":1,\"msgType\":\"reqTimeLine\",\"requestIndex\":0}", json);
23 | }
24 |
25 | }
26 |
--------------------------------------------------------------------------------
/huobi-client-websocket/src/test/java/org/oxerr/huobi/websocket/dto/response/AbstractResponseTest.java:
--------------------------------------------------------------------------------
1 | package org.oxerr.huobi.websocket.dto.response;
2 |
3 | import java.io.IOException;
4 | import java.io.InputStreamReader;
5 | import java.io.Reader;
6 | import java.lang.reflect.Type;
7 | import java.nio.charset.StandardCharsets;
8 |
9 | import com.google.gson.Gson;
10 |
11 | public abstract class AbstractResponseTest {
12 |
13 | private Gson gson = new Gson();
14 |
15 | protected T fromJson(String resource, Type type) throws IOException {
16 | try (Reader reader = new InputStreamReader(getClass()
17 | .getResourceAsStream(resource), StandardCharsets.UTF_8)) {
18 | return gson.fromJson(reader, type);
19 | }
20 | }
21 |
22 | }
23 |
--------------------------------------------------------------------------------
/huobi-client-websocket/src/test/java/org/oxerr/huobi/websocket/dto/response/ErrorResponseTest.java:
--------------------------------------------------------------------------------
1 | package org.oxerr.huobi.websocket.dto.response;
2 |
3 | import static org.junit.Assert.assertEquals;
4 | import static org.junit.Assert.assertNotNull;
5 |
6 | import java.io.IOException;
7 |
8 | import org.junit.Test;
9 | import org.oxerr.huobi.websocket.dto.response.payload.VoidPayload;
10 |
11 | public class ErrorResponseTest extends AbstractResponseTest {
12 |
13 | @Test
14 | public void test() throws IOException {
15 | ErrorResponse r = fromJson("error-601.json", ErrorResponse.class);
16 | assertEquals(1, r.getVersion());
17 | assertEquals("test", r.getMsgType());
18 | assertEquals(0, r.getRequestIndex());
19 | assertEquals(601, r.getRetCode());
20 | assertEquals("", r.getRetMsg());
21 | VoidPayload p = r.getPayload();
22 | assertNotNull(p);
23 | }
24 |
25 | }
26 |
--------------------------------------------------------------------------------
/huobi-client-websocket/src/test/java/org/oxerr/huobi/websocket/dto/response/ReqKLineResponseTest.java:
--------------------------------------------------------------------------------
1 | package org.oxerr.huobi.websocket.dto.response;
2 |
3 | import static org.junit.Assert.assertEquals;
4 |
5 | import java.io.IOException;
6 | import java.math.BigDecimal;
7 |
8 | import org.junit.Test;
9 | import org.oxerr.huobi.websocket.dto.Period;
10 | import org.oxerr.huobi.websocket.dto.response.historydata.ReqKLineResponse;
11 | import org.oxerr.huobi.websocket.dto.response.payload.ReqKLinePayload;
12 |
13 | public class ReqKLineResponseTest extends AbstractResponseTest {
14 |
15 | @Test
16 | public void test() throws IOException {
17 | ReqKLineResponse r = fromJson("reqKLine.json", ReqKLineResponse.class);
18 | assertEquals(1, r.getVersion());
19 | assertEquals("reqKLine", r.getMsgType());
20 | assertEquals(0, r.getRequestIndex());
21 | assertEquals(200, r.getRetCode());
22 | assertEquals("", r.getRetMsg());
23 |
24 | ReqKLinePayload p = r.getPayload();
25 | assertEquals("btccny", p.getSymbolId());
26 | assertEquals(Period.KLINE_1MIN, p.getPeriod());
27 | assertEquals(1378035000L, p.getTime()[0]);
28 | assertEquals(1378035060L, p.getTime()[1]);
29 | assertEquals(new BigDecimal("806.37"), p.getPriceOpen()[0]);
30 | assertEquals(new BigDecimal("805"), p.getPriceOpen()[1]);
31 | assertEquals(new BigDecimal("810"), p.getPriceHigh()[0]);
32 | assertEquals(new BigDecimal("805"), p.getPriceHigh()[1]);
33 | assertEquals(new BigDecimal("803.2"), p.getPriceLow()[0]);
34 | assertEquals(new BigDecimal("805"), p.getPriceLow()[1]);
35 | assertEquals(new BigDecimal("805"), p.getPriceLast()[0]);
36 | assertEquals(new BigDecimal("805"), p.getPriceLast()[1]);
37 | assertEquals(new BigDecimal("8.748000000000001"), p.getAmount()[0]);
38 | assertEquals(new BigDecimal("0"), p.getAmount()[1]);
39 | assertEquals(new BigDecimal("7049.681800000001"), p.getVolume()[0]);
40 | assertEquals(new BigDecimal("0"), p.getVolume()[1]);
41 | assertEquals(6, p.getCount()[0]);
42 | assertEquals(0, p.getCount()[1]);
43 | }
44 |
45 | }
46 |
--------------------------------------------------------------------------------
/huobi-client-websocket/src/test/java/org/oxerr/huobi/websocket/dto/response/ReqMarketDepthResponseTest.java:
--------------------------------------------------------------------------------
1 | package org.oxerr.huobi.websocket.dto.response;
2 |
3 | import static org.junit.Assert.assertEquals;
4 |
5 | import java.io.IOException;
6 | import java.math.BigDecimal;
7 |
8 | import org.junit.Test;
9 | import org.oxerr.huobi.websocket.dto.Percent;
10 | import org.oxerr.huobi.websocket.dto.response.historydata.ReqMarketDepthResponse;
11 | import org.oxerr.huobi.websocket.dto.response.payload.ReqMarketDepthPayload;
12 |
13 | public class ReqMarketDepthResponseTest extends AbstractResponseTest {
14 |
15 | @Test
16 | public void test() throws IOException {
17 | ReqMarketDepthResponse r = fromJson("reqMarketDepth.json",
18 | ReqMarketDepthResponse.class);
19 | assertEquals(1, r.getVersion());
20 | assertEquals("reqMarketDepth", r.getMsgType());
21 | assertEquals(0, r.getRequestIndex());
22 | assertEquals(200, r.getRetCode());
23 | assertEquals("", r.getRetMsg());
24 |
25 | ReqMarketDepthPayload p = r.getPayload();
26 | assertEquals("btccny", p.getSymbolId());
27 | assertEquals(Percent.PERCENT10, p.getPercent());
28 | assertEquals(1414083454000L, p.getTime());
29 | assertEquals(1414083454000L, p.getVersion());
30 |
31 | assertEquals("累计买单", p.getBidName());
32 | assertEquals(new BigDecimal("2207.92"), p.getBidPrice()[0]);
33 | assertEquals(new BigDecimal("2206.438174496644"), p.getBidPrice()[1]);
34 | assertEquals(new BigDecimal("2.47"), p.getBidTotal()[0]);
35 | assertEquals(new BigDecimal("27.9097"), p.getBidTotal()[1]);
36 | assertEquals(new BigDecimal("2.47"), p.getBidAmount()[0]);
37 | assertEquals(new BigDecimal("25.4397"), p.getBidAmount()[1]);
38 |
39 | assertEquals("累计卖单", p.getAskName());
40 | assertEquals(new BigDecimal("2208.1"), p.getAskPrice()[0]);
41 | assertEquals(new BigDecimal("2209.581946308725"), p.getAskPrice()[1]);
42 | assertEquals(new BigDecimal("0.4909"), p.getAskTotal()[0]);
43 | assertEquals(new BigDecimal("1.3719"), p.getAskTotal()[1]);
44 | assertEquals(new BigDecimal("0.4909"), p.getAskAmount()[0]);
45 | assertEquals(new BigDecimal("0.881"), p.getAskAmount()[1]);
46 | }
47 |
48 | }
49 |
--------------------------------------------------------------------------------
/huobi-client-websocket/src/test/java/org/oxerr/huobi/websocket/dto/response/ReqMarketDepthTopResponseTest.java:
--------------------------------------------------------------------------------
1 | package org.oxerr.huobi.websocket.dto.response;
2 |
3 | import static org.junit.Assert.assertEquals;
4 |
5 | import java.io.IOException;
6 | import java.math.BigDecimal;
7 |
8 | import org.junit.Test;
9 | import org.oxerr.huobi.websocket.dto.response.historydata.ReqMarketDepthTopResponse;
10 | import org.oxerr.huobi.websocket.dto.response.payload.ReqMarketDepthTopPayload;
11 |
12 | public class ReqMarketDepthTopResponseTest extends AbstractResponseTest {
13 |
14 | @Test
15 | public void test() throws IOException {
16 | ReqMarketDepthTopResponse r = fromJson("reqMarketDepthTop.json",
17 | ReqMarketDepthTopResponse.class);
18 | assertEquals(1, r.getVersion());
19 | assertEquals("reqMarketDepthTop", r.getMsgType());
20 | assertEquals(0, r.getRequestIndex());
21 | assertEquals(200, r.getRetCode());
22 | assertEquals("", r.getRetMsg());
23 |
24 | ReqMarketDepthTopPayload p = r.getPayload();
25 | assertEquals("btccny", p.getSymbolId());
26 | assertEquals(1414083399339L, p.getTime());
27 | assertEquals(1414083399339L, p.getVersion());
28 |
29 | assertEquals("累计买单", p.getBidName());
30 | assertEquals(new BigDecimal("2207.13"), p.getBidPrice()[0]);
31 | assertEquals(new BigDecimal("2207.01"), p.getBidPrice()[1]);
32 | assertEquals(new BigDecimal("0.9"), p.getBidTotal()[0]);
33 | assertEquals(new BigDecimal("1.644"), p.getBidTotal()[1]);
34 | assertEquals(new BigDecimal("0.9"), p.getBidAmount()[0]);
35 | assertEquals(new BigDecimal("0.744"), p.getBidAmount()[1]);
36 |
37 | assertEquals("累计卖单", p.getAskName());
38 | assertEquals(new BigDecimal("2207.9"), p.getAskPrice()[0]);
39 | assertEquals(new BigDecimal("2208.02"), p.getAskPrice()[1]);
40 | assertEquals(new BigDecimal("0.0167"), p.getAskTotal()[0]);
41 | assertEquals(new BigDecimal("0.7167"), p.getAskTotal()[1]);
42 | assertEquals(new BigDecimal("0.0167"), p.getAskAmount()[0]);
43 | assertEquals(new BigDecimal("0.7"), p.getAskAmount()[1]);
44 | }
45 |
46 | }
47 |
--------------------------------------------------------------------------------
/huobi-client-websocket/src/test/java/org/oxerr/huobi/websocket/dto/response/ReqMsgSubscribeResponseTest.java:
--------------------------------------------------------------------------------
1 | package org.oxerr.huobi.websocket.dto.response;
2 |
3 | import static org.junit.Assert.assertEquals;
4 | import static org.junit.Assert.assertNotNull;
5 |
6 | import java.io.IOException;
7 |
8 | import org.junit.Test;
9 | import org.oxerr.huobi.websocket.dto.response.payload.VoidPayload;
10 | import org.oxerr.huobi.websocket.dto.response.service.ReqMsgSubscribeResponse;
11 |
12 | public class ReqMsgSubscribeResponseTest extends AbstractResponseTest {
13 |
14 | @Test
15 | public void testReqMsgSubscribeResponse() throws IOException {
16 | ReqMsgSubscribeResponse r = fromJson("reqMsgSubscribe.json",
17 | ReqMsgSubscribeResponse.class);
18 | assertEquals(1, r.getVersion());
19 | assertEquals("reqMsgSubscribe", r.getMsgType());
20 | assertEquals(0, r.getRequestIndex());
21 | assertEquals(200, r.getRetCode());
22 | assertEquals("", r.getRetMsg());
23 | VoidPayload p = r.getPayload();
24 | assertNotNull(p);
25 | }
26 |
27 | }
28 |
--------------------------------------------------------------------------------
/huobi-client-websocket/src/test/java/org/oxerr/huobi/websocket/dto/response/ReqMsgUnsubscribeResponseTest.java:
--------------------------------------------------------------------------------
1 | package org.oxerr.huobi.websocket.dto.response;
2 |
3 | import static org.junit.Assert.assertEquals;
4 | import static org.junit.Assert.assertNotNull;
5 |
6 | import java.io.IOException;
7 |
8 | import org.junit.Test;
9 | import org.oxerr.huobi.websocket.dto.response.payload.VoidPayload;
10 | import org.oxerr.huobi.websocket.dto.response.service.ReqMsgSubscribeResponse;
11 |
12 | public class ReqMsgUnsubscribeResponseTest extends AbstractResponseTest{
13 |
14 | @Test
15 | public void test() throws IOException {
16 | ReqMsgSubscribeResponse r = fromJson("reqMsgUnsubscribe.json",
17 | ReqMsgSubscribeResponse.class);
18 | assertEquals(1, r.getVersion());
19 | assertEquals("reqMsgUnsubscribe", r.getMsgType());
20 | assertEquals(0, r.getRequestIndex());
21 | assertEquals(200, r.getRetCode());
22 | assertEquals("", r.getRetMsg());
23 | VoidPayload p = r.getPayload();
24 | assertNotNull(p);
25 | }
26 |
27 | }
28 |
--------------------------------------------------------------------------------
/huobi-client-websocket/src/test/java/org/oxerr/huobi/websocket/dto/response/ReqSymbolListResponseTest.java:
--------------------------------------------------------------------------------
1 | package org.oxerr.huobi.websocket.dto.response;
2 |
3 | import static org.junit.Assert.assertArrayEquals;
4 | import static org.junit.Assert.assertEquals;
5 |
6 | import java.io.IOException;
7 |
8 | import org.junit.Test;
9 | import org.oxerr.huobi.websocket.dto.response.payload.ReqSymbolListPayload;
10 | import org.oxerr.huobi.websocket.dto.response.service.ReqSymbolListResponse;
11 |
12 | public class ReqSymbolListResponseTest extends AbstractResponseTest {
13 |
14 | @Test
15 | public void testReqSymbolListResponse() throws IOException {
16 | ReqSymbolListResponse r = fromJson("reqSymbolList.json",
17 | ReqSymbolListResponse.class);
18 | assertEquals(1, r.getVersion());
19 | assertEquals("reqSymbolList", r.getMsgType());
20 | assertEquals(0, r.getRequestIndex());
21 | assertEquals(200, r.getRetCode());
22 | assertEquals("", r.getRetMsg());
23 |
24 | ReqSymbolListPayload p = r.getPayload();
25 | assertArrayEquals(new String[] { "btccny", "ltccny", }, p.getSymbolId());
26 | assertArrayEquals(new String[] { "比特币人民币", "莱特币人民币", },
27 | p.getSymbolName());
28 | assertArrayEquals(new String[] { "btc", "ltc", }, p.getCryptoId());
29 | assertArrayEquals(new String[] { "bitcoin", "litecoin", },
30 | p.getCryptoName());
31 | assertArrayEquals(new String[] { "huobi", "huobi", }, p.getExchangeId());
32 | assertArrayEquals(new String[] { "火币", "火币", }, p.getExchangeName());
33 | assertArrayEquals(new String[] { "cny", "cny", }, p.getCurrencyId());
34 | assertArrayEquals(new String[] { "人民币", "人民币", }, p.getCurrencyName());
35 | }
36 |
37 | }
38 |
--------------------------------------------------------------------------------
/huobi-client-websocket/src/test/java/org/oxerr/huobi/websocket/dto/response/ReqTimeLineResponseTest.java:
--------------------------------------------------------------------------------
1 | package org.oxerr.huobi.websocket.dto.response;
2 |
3 | import static org.junit.Assert.assertEquals;
4 |
5 | import java.io.IOException;
6 | import java.math.BigDecimal;
7 |
8 | import org.junit.Test;
9 | import org.oxerr.huobi.websocket.dto.response.historydata.ReqTimeLineResponse;
10 | import org.oxerr.huobi.websocket.dto.response.payload.ReqTimeLinePayload;
11 |
12 | public class ReqTimeLineResponseTest extends AbstractResponseTest {
13 |
14 | @Test
15 | public void test() throws IOException {
16 | ReqTimeLineResponse r = fromJson("reqTimeLine.json", ReqTimeLineResponse.class);
17 | assertEquals(1, r.getVersion());
18 | assertEquals("reqTimeLine", r.getMsgType());
19 | assertEquals(0, r.getRequestIndex());
20 | assertEquals(200, r.getRetCode());
21 | assertEquals("", r.getRetMsg());
22 |
23 | ReqTimeLinePayload p = r.getPayload();
24 | assertEquals("btccny", p.getSymbolId());
25 | assertEquals(1378035000L, p.getTime()[0]);
26 | assertEquals(1378035060L, p.getTime()[1]);
27 | assertEquals(new BigDecimal("805"), p.getPriceLast()[0]);
28 | assertEquals(new BigDecimal("805"), p.getPriceLast()[1]);
29 | assertEquals(new BigDecimal("8.748000000000001"), p.getAmount()[0]);
30 | assertEquals(new BigDecimal("0"), p.getAmount()[1]);
31 | assertEquals(new BigDecimal("7049.681800000001"), p.getVolume()[0]);
32 | assertEquals(6, p.getCount()[0]);
33 | }
34 |
35 | }
36 |
--------------------------------------------------------------------------------
/huobi-client-websocket/src/test/java/org/oxerr/huobi/websocket/dto/response/message/LastKLineTest.java:
--------------------------------------------------------------------------------
1 | package org.oxerr.huobi.websocket.dto.response.message;
2 |
3 | import static org.junit.Assert.assertEquals;
4 |
5 | import java.io.IOException;
6 | import java.math.BigDecimal;
7 |
8 | import org.junit.Test;
9 | import org.oxerr.huobi.websocket.dto.Period;
10 | import org.oxerr.huobi.websocket.dto.response.AbstractResponseTest;
11 | import org.oxerr.huobi.websocket.dto.response.marketdata.LastKLine;
12 | import org.oxerr.huobi.websocket.dto.response.marketdata.payload.LastKLinePayload;
13 |
14 | public class LastKLineTest extends AbstractResponseTest {
15 |
16 | @Test
17 | public void test() throws IOException {
18 | LastKLine r = fromJson("lastKLine.json", LastKLine.class);
19 | assertEquals(1, r.getVersion());
20 | assertEquals("lastKLine", r.getMsgType());
21 | assertEquals("btccny", r.getSymbolId());
22 |
23 | LastKLinePayload p = r.getPayload();
24 | assertEquals(1414079040L, p.get_id());
25 | assertEquals("btccny", p.getSymbolId());
26 | assertEquals(1414079040L, p.getTime());
27 | assertEquals(Period.KLINE_1MIN, p.getPeriod());
28 | assertEquals(new BigDecimal("2214.98"), p.getPriceOpen());
29 | assertEquals(new BigDecimal("2215"), p.getPriceHigh());
30 | assertEquals(new BigDecimal("2213.95"), p.getPriceLow());
31 | assertEquals(new BigDecimal("2213.95"), p.getPriceLast());
32 | assertEquals(new BigDecimal("4.6168"), p.getAmount());
33 | assertEquals(new BigDecimal("10223.067363000002"), p.getVolume());
34 | assertEquals(13, p.getCount());
35 | }
36 |
37 | }
38 |
--------------------------------------------------------------------------------
/huobi-client-websocket/src/test/java/org/oxerr/huobi/websocket/dto/response/message/LastTimeLineTest.java:
--------------------------------------------------------------------------------
1 | package org.oxerr.huobi.websocket.dto.response.message;
2 |
3 | import static org.junit.Assert.assertEquals;
4 |
5 | import java.io.IOException;
6 | import java.math.BigDecimal;
7 |
8 | import org.junit.Test;
9 | import org.oxerr.huobi.websocket.dto.response.AbstractResponseTest;
10 | import org.oxerr.huobi.websocket.dto.response.marketdata.LastTimeLine;
11 | import org.oxerr.huobi.websocket.dto.response.marketdata.payload.LastTimeLinePayload;
12 |
13 | public class LastTimeLineTest extends AbstractResponseTest {
14 |
15 | @Test
16 | public void test() throws IOException {
17 | LastTimeLine r = fromJson("lastTimeLine.json", LastTimeLine.class);
18 | assertEquals(1, r.getVersion());
19 | assertEquals("lastTimeLine", r.getMsgType());
20 | assertEquals("btccny", r.getSymbolId());
21 |
22 | LastTimeLinePayload p = r.getPayload();
23 | assertEquals(1414078140L, p.get_id());
24 | assertEquals("btccny", p.getSymbolId());
25 | assertEquals(1414078140, p.getTime());
26 | assertEquals(new BigDecimal("2219.28"), p.getPriceLast());
27 | assertEquals(new BigDecimal("8.3297"), p.getAmount());
28 | assertEquals(new BigDecimal("18488.978877"), p.getVolume());
29 | assertEquals(7, p.getCount());
30 | }
31 |
32 | }
33 |
--------------------------------------------------------------------------------
/huobi-client-websocket/src/test/java/org/oxerr/huobi/websocket/dto/response/message/MarketDepthDiffTest.java:
--------------------------------------------------------------------------------
1 | package org.oxerr.huobi.websocket.dto.response.message;
2 |
3 | import static org.junit.Assert.assertEquals;
4 |
5 | import java.io.IOException;
6 | import java.math.BigDecimal;
7 |
8 | import org.junit.Test;
9 | import org.oxerr.huobi.websocket.dto.Percent;
10 | import org.oxerr.huobi.websocket.dto.response.AbstractResponseTest;
11 | import org.oxerr.huobi.websocket.dto.response.marketdata.MarketDepthDiff;
12 | import org.oxerr.huobi.websocket.dto.response.marketdata.payload.MarketDepthDiffPayload;
13 |
14 | public class MarketDepthDiffTest extends AbstractResponseTest {
15 |
16 | @Test
17 | public void test() throws IOException {
18 | MarketDepthDiff r = fromJson("marketDepthDiff.json",
19 | MarketDepthDiff.class);
20 | assertEquals(1, r.getVersion());
21 | assertEquals("marketDepthDiff", r.getMsgType());
22 | assertEquals("btccny", r.getSymbolId());
23 |
24 | MarketDepthDiffPayload p = r.getPayload();
25 |
26 | assertEquals("btccny", p.getSymbolId());
27 | assertEquals(Percent.PERCENT10, p.getPercent());
28 | assertEquals(1414079070000L, p.getVersion());
29 | assertEquals(1414079069000L, p.getVersionOld());
30 |
31 | assertEquals(0, p.getBidInsert().getPrice().length);
32 | assertEquals(0, p.getBidInsert().getAmount().length);
33 | assertEquals(0, p.getBidInsert().getRow().length);
34 |
35 | assertEquals(0, p.getBidDelete().length);
36 |
37 | assertEquals(new BigDecimal("2212.514093959732"), p.getBidUpdate()
38 | .getPrice()[0]);
39 | assertEquals(new BigDecimal("2.771"), p.getBidUpdate().getAmount()[0]);
40 | assertEquals(1, p.getBidUpdate().getRow()[0]);
41 |
42 | assertEquals(new BigDecimal("2436.368"), p.getAskInsert().getPrice()[0]);
43 | assertEquals(new BigDecimal("2434.881503355705"), p.getAskInsert()
44 | .getPrice()[1]);
45 | assertEquals(new BigDecimal("1.2024"), p.getAskInsert().getAmount()[0]);
46 | assertEquals(new BigDecimal("0"), p.getAskInsert().getAmount()[1]);
47 | assertEquals(149, p.getAskInsert().getRow()[0]);
48 | assertEquals(148, p.getAskInsert().getRow()[1]);
49 |
50 | assertEquals(149, p.getAskDelete()[0]);
51 | assertEquals(148, p.getAskDelete()[1]);
52 |
53 | assertEquals(0, p.getAskUpdate().getPrice().length);
54 | assertEquals(0, p.getAskUpdate().getAmount().length);
55 | assertEquals(0, p.getAskUpdate().getRow().length);
56 | }
57 |
58 | }
59 |
--------------------------------------------------------------------------------
/huobi-client-websocket/src/test/java/org/oxerr/huobi/websocket/dto/response/message/MarketDepthTopDiffTest.java:
--------------------------------------------------------------------------------
1 | package org.oxerr.huobi.websocket.dto.response.message;
2 |
3 | import static org.junit.Assert.assertEquals;
4 |
5 | import java.io.IOException;
6 | import java.math.BigDecimal;
7 |
8 | import org.junit.Test;
9 | import org.oxerr.huobi.websocket.dto.response.AbstractResponseTest;
10 | import org.oxerr.huobi.websocket.dto.response.marketdata.MarketDepthTopDiff;
11 | import org.oxerr.huobi.websocket.dto.response.marketdata.payload.MarketDepthTopDiffPayload;
12 |
13 | public class MarketDepthTopDiffTest extends AbstractResponseTest {
14 |
15 | @Test
16 | public void test() throws IOException {
17 | MarketDepthTopDiff r = fromJson("marketDepthTopDiff.json",
18 | MarketDepthTopDiff.class);
19 | assertEquals(1, r.getVersion());
20 | assertEquals("marketDepthTopDiff", r.getMsgType());
21 | assertEquals("btccny", r.getSymbolId());
22 |
23 | MarketDepthTopDiffPayload p = r.getPayload();
24 |
25 | assertEquals(new BigDecimal("2213.01"), p.getBidInsert().getPrice()[0]);
26 | assertEquals(new BigDecimal("5.6636"), p.getBidInsert().getAmount()[0]);
27 | assertEquals(1, p.getBidInsert().getRow()[0]);
28 |
29 | assertEquals(149, p.getBidDelete()[0]);
30 |
31 | assertEquals(0, p.getBidUpdate().getPrice().length);
32 | assertEquals(0, p.getBidUpdate().getAmount().length);
33 | assertEquals(0, p.getBidUpdate().getRow().length);
34 |
35 | assertEquals(new BigDecimal("2215.98"), p.getAskInsert().getPrice()[0]);
36 | assertEquals(new BigDecimal("1.5296"), p.getAskInsert().getAmount()[0]);
37 | assertEquals(9, p.getAskInsert().getRow()[0]);
38 |
39 | assertEquals(149, p.getAskDelete()[0]);
40 |
41 | assertEquals(new BigDecimal("2213.95"), p.getAskUpdate().getPrice()[0]);
42 | assertEquals(new BigDecimal("0.7708"), p.getAskUpdate().getAmount()[0]);
43 | assertEquals(0, p.getAskUpdate().getRow()[0]);
44 | }
45 |
46 | }
47 |
--------------------------------------------------------------------------------
/huobi-client-websocket/src/test/java/org/oxerr/huobi/websocket/dto/response/message/MarketOverviewTest.java:
--------------------------------------------------------------------------------
1 | package org.oxerr.huobi.websocket.dto.response.message;
2 |
3 | import static org.junit.Assert.assertEquals;
4 |
5 | import java.io.IOException;
6 | import java.math.BigDecimal;
7 |
8 | import org.junit.Test;
9 | import org.oxerr.huobi.websocket.dto.response.AbstractResponseTest;
10 | import org.oxerr.huobi.websocket.dto.response.marketdata.MarketOverview;
11 | import org.oxerr.huobi.websocket.dto.response.marketdata.payload.MarketOverviewPayload;
12 |
13 | public class MarketOverviewTest extends AbstractResponseTest {
14 |
15 | @Test
16 | public void test() throws IOException {
17 | MarketOverview r = fromJson("marketOverview.json", MarketOverview.class);
18 | assertEquals(1, r.getVersion());
19 | assertEquals("marketOverview", r.getMsgType());
20 | assertEquals("btccny", r.getSymbolId());
21 |
22 | MarketOverviewPayload p = r.getPayload();
23 | assertEquals("btccny", p.getSymbolId());
24 | assertEquals(new BigDecimal("2214"), p.getPriceNew());
25 | assertEquals(new BigDecimal("2338.44"), p.getPriceOpen());
26 | assertEquals(new BigDecimal("2341.97"), p.getPriceHigh());
27 | assertEquals(new BigDecimal("2191.24"), p.getPriceLow());
28 | assertEquals(new BigDecimal("2213.95"), p.getPriceAsk());
29 | assertEquals(new BigDecimal("2213.64"), p.getPriceBid());
30 | assertEquals(new BigDecimal("212459736.82506347"), p.getTotalVolume());
31 | assertEquals(new BigDecimal("93652.9105000004"), p.getTotalAmount());
32 | }
33 |
34 | }
35 |
--------------------------------------------------------------------------------
/huobi-client-websocket/src/test/java/org/oxerr/huobi/websocket/dto/response/message/TradeDetailTest.java:
--------------------------------------------------------------------------------
1 | package org.oxerr.huobi.websocket.dto.response.message;
2 |
3 | import static org.junit.Assert.assertEquals;
4 |
5 | import java.io.IOException;
6 | import java.math.BigDecimal;
7 |
8 | import org.junit.Test;
9 | import org.oxerr.huobi.websocket.dto.response.AbstractResponseTest;
10 | import org.oxerr.huobi.websocket.dto.response.marketdata.TradeDetail;
11 | import org.oxerr.huobi.websocket.dto.response.marketdata.payload.TradeDetailPayload;
12 |
13 | public class TradeDetailTest extends AbstractResponseTest {
14 |
15 | @Test
16 | public void test() throws IOException {
17 | TradeDetail r = fromJson("tradeDetail.json", TradeDetail.class);
18 | assertEquals(1, r.getVersion());
19 | assertEquals(23932618L, r.get_id());
20 | assertEquals("tradeDetail", r.getMsgType());
21 | assertEquals("btccny", r.getSymbolId());
22 | assertEquals(23932618L, r.getIdCur());
23 | assertEquals(23932617L, r.getIdPrev());
24 | assertEquals(1414178400L, r.getTimeMax());
25 | assertEquals(1414178400L, r.getTimeMin());
26 |
27 | TradeDetailPayload p = r.getPayload();
28 |
29 | assertEquals("btccny", p.getSymbolId());
30 | assertEquals(23932618L, p.getTradeId()[0]);
31 | assertEquals(new BigDecimal("2186.21"), p.getPrice()[0]);
32 | assertEquals(1414178400L, p.getTime()[0]);
33 | assertEquals(new BigDecimal("0.009"), p.getAmount()[0]);
34 | assertEquals(2, p.getDirection()[0]);
35 |
36 | assertEquals(new BigDecimal("2186.21"), p.getTopBids()[0].getPrice()[0]);
37 | assertEquals(new BigDecimal("2186.19"), p.getTopBids()[0].getPrice()[1]);
38 | assertEquals(0, p.getTopBids()[0].getLevel()[0]);
39 | assertEquals(0, p.getTopBids()[0].getLevel()[1]);
40 | assertEquals(new BigDecimal("0.7122"), p.getTopBids()[0].getAmount()[0]);
41 | assertEquals(new BigDecimal("0.916"), p.getTopBids()[0].getAmount()[1]);
42 | assertEquals(new BigDecimal("0.7122"),
43 | p.getTopBids()[0].getAccuAmount()[0]);
44 | assertEquals(new BigDecimal("1.6282"),
45 | p.getTopBids()[0].getAccuAmount()[1]);
46 |
47 | assertEquals(new BigDecimal("2187.49"), p.getTopAsks()[0].getPrice()[0]);
48 | assertEquals(new BigDecimal("2187.53"), p.getTopAsks()[0].getPrice()[1]);
49 | assertEquals(0, p.getTopAsks()[0].getLevel()[0]);
50 | assertEquals(0, p.getTopAsks()[0].getLevel()[1]);
51 | assertEquals(new BigDecimal("0.303"), p.getTopAsks()[0].getAmount()[0]);
52 | assertEquals(new BigDecimal("0.046"), p.getTopAsks()[0].getAmount()[1]);
53 | assertEquals(new BigDecimal("0.303"),
54 | p.getTopAsks()[0].getAccuAmount()[0]);
55 | assertEquals(new BigDecimal("0.349"),
56 | p.getTopAsks()[0].getAccuAmount()[1]);
57 | }
58 |
59 | }
60 |
--------------------------------------------------------------------------------
/huobi-client-websocket/src/test/resources/org/oxerr/huobi/websocket/dto/response/error-601.json:
--------------------------------------------------------------------------------
1 | {
2 | "version":1,
3 | "msgType":"test",
4 | "requestIndex":0,
5 | "retCode":601,
6 | "retMsg":"",
7 | "payload":{
8 | }
9 | }
--------------------------------------------------------------------------------
/huobi-client-websocket/src/test/resources/org/oxerr/huobi/websocket/dto/response/message/lastKLine.json:
--------------------------------------------------------------------------------
1 | {
2 | "version":1,
3 | "msgType":"lastKLine",
4 | "symbolId":"btccny",
5 | "payload":{
6 | "_id":1414079040,
7 | "symbolId":"btccny",
8 | "time":1414079040,
9 | "period":"1min",
10 | "priceOpen":2214.98,
11 | "priceHigh":2215,
12 | "priceLow":2213.95,
13 | "priceLast":2213.95,
14 | "amount":4.6168,
15 | "volume":10223.067363000002,
16 | "count":13
17 | }
18 | }
--------------------------------------------------------------------------------
/huobi-client-websocket/src/test/resources/org/oxerr/huobi/websocket/dto/response/message/lastTimeLine.json:
--------------------------------------------------------------------------------
1 | {
2 | "version":1,
3 | "msgType":"lastTimeLine",
4 | "symbolId":"btccny",
5 | "payload":{
6 | "_id":1414078140,
7 | "symbolId":"btccny",
8 | "time":1414078140,
9 | "priceLast":2219.28,
10 | "amount":8.3297,
11 | "volume":18488.978877,
12 | "count":7
13 | }
14 | }
--------------------------------------------------------------------------------
/huobi-client-websocket/src/test/resources/org/oxerr/huobi/websocket/dto/response/message/marketDepthTopDiff.json:
--------------------------------------------------------------------------------
1 | {
2 | "version":1,
3 | "msgType":"marketDepthTopDiff",
4 | "symbolId":"btccny",
5 | "payload":{
6 | "symbolId":"btccny",
7 | "version":1414079071044,
8 | "versionOld":1414079069374,
9 | "bidInsert":{
10 | "price":[
11 | 2213.01
12 | ],
13 | "amount":[
14 | 5.6636
15 | ],
16 | "row":[
17 | 1
18 | ]
19 | },
20 | "bidDelete":[
21 | 149
22 | ],
23 | "bidUpdate":{
24 | "price":[
25 |
26 | ],
27 | "amount":[
28 |
29 | ],
30 | "row":[
31 |
32 | ]
33 | },
34 | "askInsert":{
35 | "price":[
36 | 2215.98
37 | ],
38 | "amount":[
39 | 1.5296
40 | ],
41 | "row":[
42 | 9
43 | ]
44 | },
45 | "askDelete":[
46 | 149
47 | ],
48 | "askUpdate":{
49 | "price":[
50 | 2213.95
51 | ],
52 | "amount":[
53 | 0.7708
54 | ],
55 | "row":[
56 | 0
57 | ]
58 | }
59 | }
60 | }
--------------------------------------------------------------------------------
/huobi-client-websocket/src/test/resources/org/oxerr/huobi/websocket/dto/response/message/marketOverview.json:
--------------------------------------------------------------------------------
1 | {
2 | "version":1,
3 | "msgType":"marketOverview",
4 | "symbolId":"btccny",
5 | "payload":{
6 | "symbolId":"btccny",
7 | "priceNew":2214,
8 | "priceOpen":2338.44,
9 | "priceHigh":2341.97,
10 | "priceLow":2191.24,
11 | "priceAsk":2213.95,
12 | "priceBid":2213.64,
13 | "totalVolume":212459736.82506347,
14 | "totalAmount":93652.9105000004
15 | }
16 | }
--------------------------------------------------------------------------------
/huobi-client-websocket/src/test/resources/org/oxerr/huobi/websocket/dto/response/message/tradeDetail.json:
--------------------------------------------------------------------------------
1 | {
2 | "version":1,
3 | "_id":23932618,
4 | "msgType":"tradeDetail",
5 | "symbolId":"btccny",
6 | "idCur":23932618,
7 | "idPrev":23932617,
8 | "timeMax":1414178400,
9 | "timeMin":1414178400,
10 | "payload":{
11 | "symbolId":"btccny",
12 | "tradeId":[
13 | 23932618
14 | ],
15 | "price":[
16 | 2186.21
17 | ],
18 | "time":[
19 | 1414178400
20 | ],
21 | "amount":[
22 | 0.009
23 | ],
24 | "direction":[
25 | 2
26 | ],
27 | "topBids":[
28 | {
29 | "price":[
30 | 2186.21,
31 | 2186.19,
32 | 2185.05,
33 | 2185.04,
34 | 2185
35 | ],
36 | "level":[
37 | 0,
38 | 0,
39 | 0,
40 | 0,
41 | 0
42 | ],
43 | "amount":[
44 | 0.7122,
45 | 0.916,
46 | 1.1844,
47 | 0.4,
48 | 5
49 | ],
50 | "accuAmount":[
51 | 0.7122,
52 | 1.6282,
53 | 2.8125999999999998,
54 | 3.2125999999999997,
55 | 8.2126
56 | ]
57 | }
58 | ],
59 | "topAsks":[
60 | {
61 | "price":[
62 | 2187.49,
63 | 2187.53,
64 | 2187.54,
65 | 2187.93,
66 | 2187.96
67 | ],
68 | "level":[
69 | 0,
70 | 0,
71 | 0,
72 | 0,
73 | 0
74 | ],
75 | "amount":[
76 | 0.303,
77 | 0.046,
78 | 0.2119,
79 | 0.6368,
80 | 5.6268
81 | ],
82 | "accuAmount":[
83 | 0.303,
84 | 0.349,
85 | 0.5609,
86 | 1.1977,
87 | 6.8245000000000005
88 | ]
89 | }
90 | ]
91 | }
92 | }
--------------------------------------------------------------------------------
/huobi-client-websocket/src/test/resources/org/oxerr/huobi/websocket/dto/response/payload/1416498909000/marketDepthDiff1.json:
--------------------------------------------------------------------------------
1 | {
2 | "version": 1,
3 | "msgType": "marketDepthDiff",
4 | "symbolId": "btccny",
5 | "payload": {
6 | "symbolId": "btccny",
7 | "percent": "10",
8 | "version": 1416498910000,
9 | "versionOld": 1416498909000,
10 | "bidInsert": {
11 | "price": [],
12 | "amount": [],
13 | "row": []
14 | },
15 | "bidDelete": [],
16 | "bidUpdate": {
17 | "price": [2206.638140939597, 2209.606046979866],
18 | "amount": [3.6432, 5.1242],
19 | "row": [3, 1]
20 | },
21 | "askInsert": {
22 | "price": [],
23 | "amount": [],
24 | "row": []
25 | },
26 | "askDelete": [],
27 | "askUpdate": {
28 | "price": [2226.8456375838928],
29 | "amount": [42],
30 | "row": [10]
31 | }
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/huobi-client-websocket/src/test/resources/org/oxerr/huobi/websocket/dto/response/payload/1416498909000/marketDepthDiff2.json:
--------------------------------------------------------------------------------
1 | {
2 | "version": 1,
3 | "msgType": "marketDepthDiff",
4 | "symbolId": "btccny",
5 | "payload": {
6 | "symbolId": "btccny",
7 | "percent": "10",
8 | "version": 1416498911000,
9 | "versionOld": 1416498910000,
10 | "bidInsert": {
11 | "price": [],
12 | "amount": [],
13 | "row": []
14 | },
15 | "bidDelete": [],
16 | "bidUpdate": {
17 | "price": [2209.606046979866],
18 | "amount": [6.3877],
19 | "row": [1]
20 | },
21 | "askInsert": {
22 | "price": [],
23 | "amount": [],
24 | "row": []
25 | },
26 | "askDelete": [],
27 | "askUpdate": {
28 | "price": [2214.9691275167784],
29 | "amount": [24.4304],
30 | "row": [2]
31 | }
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/huobi-client-websocket/src/test/resources/org/oxerr/huobi/websocket/dto/response/reqMsgSubscribe.json:
--------------------------------------------------------------------------------
1 | {
2 | "version":1,
3 | "msgType":"reqMsgSubscribe",
4 | "requestIndex":0,
5 | "retCode":200,
6 | "retMsg":"",
7 | "payload":{
8 | }
9 | }
--------------------------------------------------------------------------------
/huobi-client-websocket/src/test/resources/org/oxerr/huobi/websocket/dto/response/reqMsgUnsubscribe.json:
--------------------------------------------------------------------------------
1 | {
2 | "version":1,
3 | "msgType":"reqMsgUnsubscribe",
4 | "requestIndex":0,
5 | "retCode":200,
6 | "retMsg":"",
7 | "payload":{
8 | }
9 | }
--------------------------------------------------------------------------------
/huobi-client-websocket/src/test/resources/org/oxerr/huobi/websocket/dto/response/reqSymbolDetail-btccny,ltccny.json:
--------------------------------------------------------------------------------
1 | {
2 | "version":1,
3 | "msgType":"reqSymbolDetail",
4 | "requestIndex":0,
5 | "retCode":200,
6 | "retMsg":"",
7 | "payload":{
8 | "symbolId":[
9 | "btccny",
10 | "ltccny"
11 | ],
12 | "symbolName":[
13 | "比特币人民币",
14 | "莱特币人民币"
15 | ],
16 | "cryptoId":[
17 | "btc",
18 | "ltc"
19 | ],
20 | "cryptoName":[
21 | "bitcoin",
22 | "litecoin"
23 | ],
24 | "exchangeId":[
25 | "huobi",
26 | "huobi"
27 | ],
28 | "exchangeName":[
29 | "火币",
30 | "火币"
31 | ],
32 | "currencyId":[
33 | "cny",
34 | "cny"
35 | ],
36 | "currencyName":[
37 | "人民币",
38 | "人民币"
39 | ],
40 | "total":[
41 | 21000000,
42 | 84000000
43 | ],
44 | "suply":[
45 | 12000000,
46 | 40000000
47 | ],
48 | "introduction":[
49 | "火币上的比特币人民币交易",
50 | "火币上的莱特币人民币交易"
51 | ]
52 | }
53 | }
--------------------------------------------------------------------------------
/huobi-client-websocket/src/test/resources/org/oxerr/huobi/websocket/dto/response/reqSymbolDetail-btccny.json:
--------------------------------------------------------------------------------
1 | {
2 | "version":1,
3 | "msgType":"reqSymbolDetail",
4 | "requestIndex":0,
5 | "retCode":200,
6 | "retMsg":"",
7 | "payload":{
8 | "symbolId":[
9 | "btccny"
10 | ],
11 | "symbolName":[
12 | "比特币人民币"
13 | ],
14 | "cryptoId":[
15 | "btc"
16 | ],
17 | "cryptoName":[
18 | "bitcoin"
19 | ],
20 | "exchangeId":[
21 | "huobi"
22 | ],
23 | "exchangeName":[
24 | "火币"
25 | ],
26 | "currencyId":[
27 | "cny"
28 | ],
29 | "currencyName":[
30 | "人民币"
31 | ],
32 | "total":[
33 | 21000000
34 | ],
35 | "suply":[
36 | 12000000
37 | ],
38 | "introduction":[
39 | "火币上的比特币人民币交易"
40 | ]
41 | }
42 | }
--------------------------------------------------------------------------------
/huobi-client-websocket/src/test/resources/org/oxerr/huobi/websocket/dto/response/reqSymbolList.json:
--------------------------------------------------------------------------------
1 | {
2 | "version":1,
3 | "msgType":"reqSymbolList",
4 | "requestIndex":0,
5 | "retCode":200,
6 | "retMsg":"",
7 | "payload":{
8 | "symbolId":[
9 | "btccny",
10 | "ltccny"
11 | ],
12 | "symbolName":[
13 | "比特币人民币",
14 | "莱特币人民币"
15 | ],
16 | "cryptoId":[
17 | "btc",
18 | "ltc"
19 | ],
20 | "cryptoName":[
21 | "bitcoin",
22 | "litecoin"
23 | ],
24 | "exchangeId":[
25 | "huobi",
26 | "huobi"
27 | ],
28 | "exchangeName":[
29 | "火币",
30 | "火币"
31 | ],
32 | "currencyId":[
33 | "cny",
34 | "cny"
35 | ],
36 | "currencyName":[
37 | "人民币",
38 | "人民币"
39 | ]
40 | }
41 | }
--------------------------------------------------------------------------------
/huobi-client-xchange/pom.xml:
--------------------------------------------------------------------------------
1 |
5 | 4.0.0
6 |
7 |
8 | org.oxerr
9 | huobi-client
10 | 2.1.0-SNAPSHOT
11 |
12 |
13 | huobi-client-xchange
14 |
15 | Huobi Client - XChange
16 |
17 | XChange compatibility.
19 | ]]>
20 |
21 |
22 |
23 | ${project.groupId}
24 | huobi-client-rest
25 | ${project.version}
26 |
27 |
28 | ${project.groupId}
29 | huobi-client-websocket
30 | ${project.version}
31 |
32 |
33 |
34 |
--------------------------------------------------------------------------------
/huobi-client-xchange/src/main/java/org/oxerr/huobi/xchange/HuobiExchange.java:
--------------------------------------------------------------------------------
1 | package org.oxerr.huobi.xchange;
2 |
3 | import java.util.List;
4 |
5 | import org.oxerr.huobi.xchange.service.streaming.HuobiSocketIOService;
6 | import org.oxerr.huobi.xchange.service.streaming.HuobiStreamingConfiguration;
7 |
8 | import com.xeiam.xchange.Exchange;
9 | import com.xeiam.xchange.ExchangeSpecification;
10 | import com.xeiam.xchange.currency.CurrencyPair;
11 | import com.xeiam.xchange.service.streaming.ExchangeStreamingConfiguration;
12 | import com.xeiam.xchange.service.streaming.StreamingExchangeService;
13 |
14 | /**
15 | * Entry point to the XChange APIs.
16 | */
17 | public class HuobiExchange extends org.oxerr.huobi.rest.HuobiExchange implements
18 | Exchange {
19 |
20 | public static final String WEBSOCKET_URI_KEY = "websocket.uri";
21 |
22 | @Override
23 | public void applySpecification(ExchangeSpecification exchangeSpecification) {
24 | super.applySpecification(exchangeSpecification);
25 | }
26 |
27 | /**
28 | * {@inheritDoc}
29 | */
30 | @Override
31 | public ExchangeSpecification getDefaultExchangeSpecification() {
32 | ExchangeSpecification spec = super.getDefaultExchangeSpecification();
33 | spec.setExchangeSpecificParametersItem(WEBSOCKET_URI_KEY,
34 | "http://hq.huobi.com:80");
35 | return spec;
36 | }
37 |
38 | @Override
39 | public StreamingExchangeService getStreamingExchangeService(
40 | ExchangeStreamingConfiguration configuration) {
41 | final HuobiStreamingConfiguration huobiStreamingConfiguration;
42 |
43 | if (configuration == null) {
44 | @SuppressWarnings("unchecked")
45 | List currencyPairs = (List) getExchangeSpecification()
46 | .getExchangeSpecificParametersItem(SYMBOLS_PARAMETER);
47 | huobiStreamingConfiguration = new HuobiStreamingConfiguration(
48 | currencyPairs);
49 | } else if (configuration instanceof HuobiStreamingConfiguration) {
50 | huobiStreamingConfiguration = (HuobiStreamingConfiguration) configuration;
51 | } else {
52 | throw new IllegalArgumentException(
53 | "Huobi only supports HuobiStreamingConfiguration");
54 | }
55 |
56 | return new HuobiSocketIOService(getExchangeSpecification(),
57 | huobiStreamingConfiguration);
58 | }
59 |
60 | }
61 |
--------------------------------------------------------------------------------
/huobi-client-xchange/src/main/java/org/oxerr/huobi/xchange/package-info.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Implementation for XChange.
3 | */
4 | package org.oxerr.huobi.xchange;
5 |
--------------------------------------------------------------------------------
/huobi-client-xchange/src/main/java/org/oxerr/huobi/xchange/service/package-info.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Service implementations of XChange APIs.
3 | */
4 | package org.oxerr.huobi.xchange.service;
5 |
--------------------------------------------------------------------------------
/huobi-client-xchange/src/main/java/org/oxerr/huobi/xchange/service/streaming/HuobiExchangeEvent.java:
--------------------------------------------------------------------------------
1 | package org.oxerr.huobi.xchange.service.streaming;
2 |
3 | import org.oxerr.huobi.websocket.dto.response.Response;
4 | import org.oxerr.huobi.websocket.dto.response.payload.Payload;
5 |
6 | import com.xeiam.xchange.service.streaming.DefaultExchangeEvent;
7 | import com.xeiam.xchange.service.streaming.ExchangeEventType;
8 |
9 | public class HuobiExchangeEvent extends DefaultExchangeEvent {
10 |
11 | private final Response extends Payload> response;
12 |
13 | public HuobiExchangeEvent(ExchangeEventType exchangeEventType,
14 | Response extends Payload> response, Object payload) {
15 | super(exchangeEventType, null, payload);
16 | this.response = response;
17 | }
18 |
19 | public Response extends Payload> getResponse() {
20 | return response;
21 | }
22 |
23 | }
24 |
--------------------------------------------------------------------------------
/huobi-client-xchange/src/main/java/org/oxerr/huobi/xchange/service/streaming/HuobiStreamingConfiguration.java:
--------------------------------------------------------------------------------
1 | package org.oxerr.huobi.xchange.service.streaming;
2 |
3 | import java.util.Arrays;
4 | import java.util.HashSet;
5 | import java.util.Set;
6 |
7 | import com.xeiam.xchange.currency.CurrencyPair;
8 | import com.xeiam.xchange.service.streaming.ExchangeStreamingConfiguration;
9 |
10 | public class HuobiStreamingConfiguration implements
11 | ExchangeStreamingConfiguration {
12 |
13 | private final int maxReconnectAttempts;
14 | private final int reconnectWaitTimeInMs;
15 | private final Set currencyPairs = new HashSet<>();
16 |
17 | public HuobiStreamingConfiguration(CurrencyPair... currencyPairs) {
18 | this(Arrays.asList(currencyPairs));
19 | }
20 |
21 | public HuobiStreamingConfiguration(Iterable currencyPairs) {
22 | this(currencyPairs, 0, 0);
23 | }
24 |
25 | public HuobiStreamingConfiguration(Iterable currencyPairs,
26 | int maxReconnectAttempts, int reconnectWaitTimeInMs) {
27 | for (CurrencyPair currencyPair : currencyPairs) {
28 | this.currencyPairs.add(currencyPair);
29 | }
30 |
31 | this.maxReconnectAttempts = maxReconnectAttempts;
32 | this.reconnectWaitTimeInMs = reconnectWaitTimeInMs;
33 | }
34 |
35 | /**
36 | * {@inheritDoc}
37 | */
38 | @Override
39 | public int getMaxReconnectAttempts() {
40 | return maxReconnectAttempts;
41 | }
42 |
43 | /**
44 | * {@inheritDoc}
45 | */
46 | @Override
47 | public int getReconnectWaitTimeInMs() {
48 | return reconnectWaitTimeInMs;
49 | }
50 |
51 | /**
52 | * {@inheritDoc}
53 | */
54 | @Override
55 | public int getTimeoutInMs() {
56 | return 0;
57 | }
58 |
59 | /**
60 | * {@inheritDoc}
61 | */
62 | @Override
63 | public boolean isEncryptedChannel() {
64 | return false;
65 | }
66 |
67 | /**
68 | * {@inheritDoc}
69 | */
70 | @Override
71 | public boolean keepAlive() {
72 | return false;
73 | }
74 |
75 | public Set getCurrencyPairs() {
76 | return currencyPairs;
77 | }
78 |
79 | }
80 |
--------------------------------------------------------------------------------
/huobi-client-xchange/src/main/java/org/oxerr/huobi/xchange/service/streaming/package-info.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Streaming service implementation.
3 | */
4 | package org.oxerr.huobi.xchange.service.streaming;
5 |
--------------------------------------------------------------------------------
/huobi-client-xchange/src/test/java/org/oxerr/huobi/xchange/service/streaming/HuobiAdaptersTest.java:
--------------------------------------------------------------------------------
1 | package org.oxerr.huobi.xchange.service.streaming;
2 |
3 | import static org.junit.Assert.assertEquals;
4 |
5 | import org.junit.Test;
6 |
7 | import com.xeiam.xchange.currency.CurrencyPair;
8 |
9 | public class HuobiAdaptersTest {
10 |
11 | @Test
12 | public void testAdaptCurrencyPair() {
13 | assertEquals(CurrencyPair.BTC_CNY, HuobiSocketIOAdapters.adaptCurrencyPair("btccny"));
14 | }
15 |
16 | }
17 |
--------------------------------------------------------------------------------
/src/site/site.xml:
--------------------------------------------------------------------------------
1 |
5 |
6 | org.apache.maven.skins
7 | maven-fluido-skin
8 | 1.3.1
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 | true
18 | true
19 | true
20 | pull-right
21 |
22 |
23 |
24 |
--------------------------------------------------------------------------------