Code Monkey home page Code Monkey logo

huobi_java's Introduction

Build Status

Huobi Java SDK For Spot v3

This is Huobi Java SDK v3, you can import to your project and use this SDK to query all market data, trading and manage your account. The SDK supports RESTful API invoking, and subscribing the market, account and order update from the WebSocket connection.

If you already use SDK v1 or v2, it is strongly suggested migrate to v3 as we refactor the implementation to make it simpler and easy to maintain. The SDK v3 is completely consistent with the API documentation of the new HTX open platform. Compared to SDK versions v1 and v2, due to changes in parameters of many interfaces, in order to match the latest interface parameter situation, v3 version has made adjustments to parameters of more than 80 interfaces to ensure that requests can be correctly initiated and accurate response data can be obtained. Meanwhile, the v3 version has added over 130 new interfaces available for use, greatly expanding the number of available interfaces. We will stop the maintenance of v2 in the near future. Please refer to the instruction on how to migrate v1 or v2 to v3 in section Migrate from v1 or v2

Table of Contents

Quick start

The SDK is compiled by Java8, you can import the source code in java IDE (idea or eclipse)

The example code are in folder /java/src/test/java/com/huobi/examples that you can run directly

If you want to create your own application, you can follow below steps:

  • Create the client instance.
  • Call the interfaces provided by client.
// Create GenericClient instance and get the timestamp
GenericClient genericService = GenericClient.create(HuobiOptions.builder().build());

Long serverTime = genericService.getTimestamp();
System.out.println("server time:" + serverTime);

// Create MarketClient instance and get btcusdt latest 1-min candlestick
MarketClient marketClient = MarketClient.create(new HuobiOptions());

List<Candlestick> list = marketClient.getCandlestick(CandlestickRequest.builder()
    .symbol("btcusdt")
    .interval(CandlestickIntervalEnum.MIN1)
    .size(10)
    .build());

list.forEach(candlestick -> {
  System.out.println(candlestick.toString());
});

Usage

Folder Structure

This is the folder and package structure of SDK source code and the description

  • src/main/java/com/huobi: The core of the SDK
    • client: The client that are responsible to access data, this is the external interface layer
    • constant: The enum and constant definition
    • exception: The exception definition
    • model: The data model for response
    • service: The internal implementation for each client
    • utils: The utilities that include signature, websocket management etc
  • src/test/java/com/huobi: The test of the SDK
    • examples: The examples how to use client instance to access API and read response
    • service: The unit test for service package
    • test: The additional test such as performance test
    • utils: The unit test for utils package

Run Examples

This SDK provides examples that under src/test/java/com/huobi/example folder, if you want to run the examples to access private data, you need below additional steps:

  1. Create an API Key first from Huobi official website
  2. Assign your API access key and secret key to "Constant.java" as below:
public static final String API_KEY = "hrf5gdfghe-e74bebd8-2f4a33bc-e7963"
public static final String SECRET_KEY = "fecbaab2-35befe7e-2ea695e8-67e56"

If you don't need to access private data, you can ignore the API key.

Regarding the difference between public data and private data you can find details in Client section below.

Client

In this SDK, the client is the class to access the Huobi API. In order to isolate the private data with public data, and isolated different kind of data, the client category is designated to match the API category.

All the client is listed in below table. Each client is very small and simple, it is only responsible to operate its related data, you can pick up multiple clients to create your own application based on your business.

Data Category Client Privacy API Protocol
Generic GenericClient Public Rest
Market MarketClient Public Rest, WebSocket
Account AccountClient Private Rest, WebSocket v2
Wallet WalletClient Private Rest
Sub user SubUserClient Private Rest
Trade TradeClient Private Rest
Algo AlgoClient Private Rest
Isolated margin IsolatedMarginClient Private Rest
Cross margin CrossMarginClient Private Rest

Public and Private

There are two types of privacy that is correspondent with privacy of API:

Public client: It invokes public API to get public data (Generic data and Market data), therefore you can create a new instance without applying an API Key.

// Create a GenericClient instance
GenericClient genericService = GenericClient.create(new HuobiOptions());

// Create a MarketClient instance
MarketClient marketClient = MarketClient.create(new HuobiOptions());

Private client: It invokes private API to access private data, you need to follow the API document to apply an API Key first, and pass the API Key to the init function

// Create an AccountClient instance with APIKey
AccountClient accountService = AccountClient.create(HuobiOptions.builder()
        .apiKey(Constants.API_KEY)
        .secretKey(Constants.SECRET_KEY)
        .build());

// Create a TradeClient instance with API Key
TradeClient tradeService = TradeClient.create(HuobiOptions.builder()
        .apiKey(Constants.API_KEY)
        .secretKey(Constants.SECRET_KEY)
        .build());

The API key is used for authentication. If the authentication cannot pass, the invoking of private interface will fail.

Rest and WebSocket

There are two protocols of API, Rest and WebSocket

Rest: It invokes Rest API and get once-off response, it has two basic types of method: GET and POST

WebSocket: It establishes WebSocket connection with server and data will be pushed from server actively. There are two types of method for WebSocket client:

  • Request method: The method name starts with "req-", it will receive the once-off data after sending the request.
  • Subscription: The method name starts with "sub-", it will receive update after sending the subscription.

Migrate from v1 or v2

Why v3

The major difference between v1 and v2 is that the client category.

In SDK v1, the client is categorized as two protocol, request client and subscription client. For example, for Rest API, you can operate everything in request client. It is simple to choose which client you use, however, when you have a client instance, you will have dozens of method, and it is not easy to choose the proper method.

The thing is different in SDK v2, the client class is categorized as seven data categories, so that the responsibility for each client is clear. For example, if you only need to access market data, you can use MarketClient without applying API Key, and all the market data can be retrieved from MarketClient. If you want to operate your order, then you know you should use TradeClient and all the order related methods are there. Since the category is exactly same as the API document, so it is easy to find the relationship between API and SDK. In SDK v2, each client is smaller and simpler, which means it is easier to maintain and less bugs.

Compared to SDK versions v1 and v2, due to changes and updates in the out and in parameters of many interfaces, in order to match the latest interface in and out parameter situation, v3 version has made adjustments and updates to the out and in parameters of more than 80 interfaces to ensure that requests can be correctly initiated and accurate response data can be obtained. Meanwhile, the v3 version has added over 130 new interfaces available for use, greatly expanding the number of available interfaces.

How to migrate

You don't need to change your business logic, what you need is to find the v1 or v2 request client and subscription client, and replace with the proper v3 client. The additional cost is that you need to have additional initialization for each v3 client.

Request example

Reference data

Exchange timestamp

GenericClient genericService = GenericClient.create(new HuobiOptions());
Long serverTime = genericService.getTimestamp();

Symbol and currencies

GenericClient genericService = GenericClient.create(new HuobiOptions());
List<SymbolV2> symbolList = genericService.getSymbolsV2();
List<CurrencyV2> currencyList = genericService.getCurrencyV2();

Market data

Candlestick

MarketClient marketClient = MarketClient.create(new HuobiOptions());
List<Candlestick> list = marketClient.getCandlestick(CandlestickRequest.builder()
    .symbol(symbol)
    .interval(CandlestickIntervalEnum.MIN15)
    .size(10)
    .build());

Depth

MarketClient marketClient = MarketClient.create(new HuobiOptions());
MarketDepth marketDepth = marketClient.getMarketDepth(MarketDepthRequest.builder()
    .symbol(symbol)
    .depth(DepthSizeEnum.SIZE_5)
    .step(DepthStepEnum.STEP0)
    .build());

Latest trade

MarketClient marketClient = MarketClient.create(new HuobiOptions());
List<MarketTrade> marketTradeList = marketClient.getMarketTrade(MarketTradeRequest.builder().symbol(symbol).build());

Historical

MarketClient marketClient = MarketClient.create(new HuobiOptions());
List<MarketTrade> marketHistoryTradeList = marketClient.getMarketHistoryTrade(MarketHistoryTradeRequest.builder().symbol(symbol).build());

Account

Authentication is required.

Get account balance

AccountClient accountService = AccountClient.create(HuobiOptions.builder()
    .apiKey(Constants.API_KEY)
    .secretKey(Constants.SECRET_KEY)
    .build());
AccountBalance accountBalance = accountService.getAccountBalance(AccountBalanceRequest.builder()
    .accountId(accountId)
    .build());

Wallet

Authentication is required.

Withdraw

HuobiWalletService walletService = new HuobiWalletService(HuobiOptions.builder()
    .apiKey(Constants.API_KEY)
    .secretKey(Constants.SECRET_KEY)
    .build());
long withdrawId = walletService.createWithdraw(CreateWithdrawRequest.builder()
    .address(withdrawAddress)
    .addrTag(withdrawAddressTag)
    .currency("eos")
    .amount(new BigDecimal("1"))
    .fee(new BigDecimal("0.1"))
    .build());

Cancel withdraw

HuobiWalletService walletService = new HuobiWalletService(HuobiOptions.builder()
    .apiKey(Constants.API_KEY)
    .secretKey(Constants.SECRET_KEY)
    .build());
long res = walletService.cancelWithdraw(withdrawId);

Withdraw and deposit history

List<DepositWithdraw> depositWithdrawList = walletService.getDepositWithdraw(DepositWithdrawRequest.builder()
    .type(DepositWithdrawTypeEnum.WITHDRAW)
    .build());

Trading

Authentication is required.

Create order

TradeClient tradeService = TradeClient.create(HuobiOptions.builder()
    .apiKey(Constants.API_KEY)
    .secretKey(Constants.SECRET_KEY)
    .build());
CreateOrderRequest buyLimitRequest = CreateOrderRequest.spotBuyLimit(spotAccountId, clientOrderId, symbol, bidPrice, new BigDecimal("2"));
Long buyLimitId = tradeService.createOrder(buyLimitRequest);

Cancel order

TradeClient tradeService = TradeClient.create(HuobiOptions.builder()
    .apiKey(Constants.API_KEY)
    .secretKey(Constants.SECRET_KEY)
    .build());
int cancelResult = tradeService.cancelOrder(clientOrderId);

Cancel open orders

TradeClient tradeService = TradeClient.create(HuobiOptions.builder()
    .apiKey(Constants.API_KEY)
    .secretKey(Constants.SECRET_KEY)
    .build());
BatchCancelOpenOrdersResult result = tradeService.batchCancelOpenOrders(BatchCancelOpenOrdersRequest.builder()
    .accountId(spotAccountId)
    .symbol(symbol)
    .build());

Get order info

TradeClient tradeService = TradeClient.create(HuobiOptions.builder()
    .apiKey(Constants.API_KEY)
    .secretKey(Constants.SECRET_KEY)
    .build());
Order getOrder = tradeService.getOrder(51210074624L);

Historical orders

TradeClient tradeService = TradeClient.create(HuobiOptions.builder()
    .apiKey(Constants.API_KEY)
    .secretKey(Constants.SECRET_KEY)
    .build());
List<Order> historyOrderList = tradeService.getOrdersHistory(OrderHistoryRequest.builder()
    .symbol(symbol)
    .startTime(1565107200000L)
    .direction(QueryDirectionEnum.PREV)
    .build());

Margin Loan

Authentication is required.

These are examples for cross margin

Apply loan

CrossMarginClient marginService = CrossMarginClient.create(HuobiOptions.builder()
    .apiKey(Constants.API_KEY)
    .secretKey(Constants.SECRET_KEY)
    .build());
Long applyId = marginService.applyLoan(CrossMarginApplyLoanRequest.builder()
    .currency("usdt")
    .amount(new BigDecimal("100"))
    .build());

Repay loan

CrossMarginClient marginService = CrossMarginClient.create(HuobiOptions.builder()
    .apiKey(Constants.API_KEY)
    .secretKey(Constants.SECRET_KEY)
    .build());
marginService.repayLoan(CrossMarginRepayLoanRequest.builder()
    .orderId(applyId)
    .amount(loanAmount)
    .build());

Loan history

CrossMarginClient marginService = CrossMarginClient.create(HuobiOptions.builder()
    .apiKey(Constants.API_KEY)
    .secretKey(Constants.SECRET_KEY)
    .build());
List<Balance> balanceList = crossMarginAccount1.getBalanceList()

Subscription example

Subscribe trade update

MarketClient marketClient = MarketClient.create(new HuobiOptions());
marketClient.subMarketTrade(SubMarketTradeRequest.builder().symbol(symbol).build(), (marketTradeEvent) -> {
    System.out.println("ch:" + marketTradeEvent.getCh());
    System.out.println("ts:" + marketTradeEvent.getTs());

    marketTradeEvent.getList().forEach(marketTrade -> {
      System.out.println(marketTrade.toString());
    });
});

###Subscribe candlestick update

MarketClient marketClient = MarketClient.create(new HuobiOptions());
marketClient.subCandlestick(SubCandlestickRequest.builder()
    .symbol(symbol)
    .interval(CandlestickIntervalEnum.MIN15)
    .build(), (candlestick) -> {

  System.out.println(candlestick.toString());
});

Subscribe order update

Authentication is required.

TradeClient tradeService = TradeClient.create(HuobiOptions.builder()
    .apiKey(Constants.API_KEY)
    .secretKey(Constants.SECRET_KEY)
    .build());
tradeService.subOrderUpdateV2(SubOrderUpdateV2Request.builder().symbols("*").build(), orderUpdateV2Event -> {
    System.out.println(orderUpdateV2Event.toString());
});

Subscribe account change

Authentication is required.

AccountBalance accountBalance = accountService.getAccountBalance(AccountBalanceRequest.builder()
    .accountId(accountId)
    .build());
accountService.subAccountsUpdate(SubAccountUpdateRequest.builder()
    .accountUpdateMode(AccountUpdateModeEnum.ACCOUNT_CHANGE).build(), event -> {
  System.out.println(event.toString());
});

huobi_java's People

Contributors

cray-cmd avatar dependabot[bot] avatar devin-y avatar eynzhang avatar huobiapi avatar huobidqx avatar liuxiaoyi avatar macomfan avatar yxq212526 avatar zhangshaonan043 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

huobi_java's Issues

Exception in syncClient.getPriceDepth if parameter size greater than market depth

If parameter size for syncClient.getPriceDepth call is greater than market depth client throws exception.

Code sample:

SyncRequestClient syncClient = SyncRequestClient.create();

PriceDepth priceDepth = syncClient.getPriceDepth("wavesusdt", 150);

Stake Trace:

com.huobi.client.exception.HuobiApiException: [Json] Index is out of bound or array is null
	at com.huobi.client.impl.utils.JsonWrapperArray.getArrayAt(JsonWrapperArray.java:39)
	at com.huobi.client.impl.RestApiRequestImpl.lambda$getPriceDepth$24(RestApiRequestImpl.java:710)
	at com.huobi.client.impl.RestApiInvoker.callSync(RestApiInvoker.java:131)
	at com.huobi.client.impl.RestApiInvoker.callSync(RestApiInvoker.java:106)
	at com.huobi.client.impl.SyncRequestImpl.getPriceDepth(SyncRequestImpl.java:122)
	at com.tradisys.commons.exchange.huobi.HuobiApiTest.investigateHuobiApi(HuobiApiTest.java:18)```

BalanceType error

[Enum] Cannot found bank in Enum com.huobi.client.model.enums.BalanceType

少了一个balance type : bank
.

IndexOutOfBoundsException

After updating to the latest release, I've started to see such errors in logs:

Exception in thread "OkHttp Dispatcher" java.lang.IndexOutOfBoundsException: Index: 0
	at java.base/java.util.Collections$EmptyList.get(Collections.java:4481)
	at okhttp3.internal.connection.RealConnection.connectTls(RealConnection.java:326)
	at okhttp3.internal.connection.RealConnection.establishProtocol(RealConnection.java:283)
	at okhttp3.internal.connection.RealConnection.connect(RealConnection.java:168)
	at okhttp3.internal.connection.StreamAllocation.findConnection(StreamAllocation.java:257)
	at okhttp3.internal.connection.StreamAllocation.findHealthyConnection(StreamAllocation.java:135)
	at okhttp3.internal.connection.StreamAllocation.newStream(StreamAllocation.java:114)
	at okhttp3.internal.connection.ConnectInterceptor.intercept(ConnectInterceptor.java:42)
	at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147)
	at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:121)
	at okhttp3.internal.cache.CacheInterceptor.intercept(CacheInterceptor.java:93)
	at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147)
	at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:121)
	at okhttp3.internal.http.BridgeInterceptor.intercept(BridgeInterceptor.java:93)
	at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147)
	at okhttp3.internal.http.RetryAndFollowUpInterceptor.intercept(RetryAndFollowUpInterceptor.java:126)
	at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147)
	at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:121)
	at com.huobi.client.impl.RestApiInvoker$1.intercept(RestApiInvoker.java:47)
	at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147)
	at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:121)
	at okhttp3.RealCall.getResponseWithInterceptorChain(RealCall.java:254)
	at okhttp3.RealCall$AsyncCall.execute(RealCall.java:200)
	at okhttp3.internal.NamedRunnable.run(NamedRunnable.java:32)
	at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
	at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
	at java.base/java.lang.Thread.run(Thread.java:834)

Unfortunately the stacktrace is not very informative...

提现报错invalid amount

Exception in thread "main" com.huobi.client.exception.HuobiApiException: [Executing] invalid-amount: Parameter amount is invalid.
at com.huobi.client.impl.RestApiInvoker.checkResponse(RestApiInvoker.java:35)
at com.huobi.client.impl.RestApiInvoker.callSync(RestApiInvoker.java:90)
at com.huobi.client.impl.SyncRequestImpl.withdraw(SyncRequestImpl.java:342)

WithdrawRequest withdrawRequest = new WithdrawRequest("xxx",
new BigDecimal(0.01), "btc");
long withdrawId = syncRequestClient.withdraw(withdrawRequest);

用的1.0.8-SNAPSHOT版本,我看账户里显示的最小提币数据应该是0.01,为什么会提币失败?

I can't find api about user-center/orders/

你好,找不到user-center/orders/相关的api,我想查询法币交易订单,比如btc和CNY交易的订单,请问只能自己发送http请求吗?
浏览器上的请求需要fingerprint,trace_id,token等参数,每次需要登陆后,才能在cookies中看到。。。能给我一个用私钥参考吗?感谢了

OrderSource和API文档描述不一致,建议修改

com.huobi.client.model.enums.OrderSource里面和API文档描述不一致,建议修改
SPOTWEB("spot-web"), // 现货 Web 交易单
SPOTAPI("spot-api"), // 现货 Api 交易单
SPOTAPP("spot-app"), // 现货 App 交易单
MARGINAPI("margin-api"), // 借贷 Api 交易单
MARGINWEB("margin-web"), // 借贷 Web 交易单
MARGINAPP("margin-app"), // 借贷 App 交易单
FLSYS("fl-sys"), // 借贷强制平仓单(爆仓单)
INVALID("invalid");

com.huobi.client.impl.utils.TimeService#convertCSTInMillisecondToUTC 服务端返回的 long 已经是UTC

com.huobi.client.impl.utils.TimeService#convertCSTInMillisecondToUTC

服务端返回的 long timeInMs 已经是 GMT 的,建议在转 Date 或 Instant 时处理时区;此处强减只保证东八区的程序 new Date(convert...()) 是正确的 UTC 时间;

public static long convertCSTInMillisecondToUTC(long timeInMs) {
if (timeInMs > 946656000000L) {
// bigger than 2000-01-01 00:00:00
return timeInMs - 8 * 60 * 60 * 1000; // 此处减8小时,只对东八区的 new Date(convert...()) 才表达出转 UTC 的含义;
}
return 0;
}

有没有web端的集成demo?

拉下代码,以为是springboot的微服务项目,但是没找到application.properties;有没有web端的集成项目,方便第一次接触的人快速上手。

关于使用sdk订阅出现的问题

image
image
当把深度放在第一位订阅时候。深度推送正常、最新成交推送不正常。
image
image
更换顺序以后最新成交推送正常。深度推送不正常。、
不知道是有什么sdk订阅的规则限制吗。

Publish to maven

Can you publish this lib to a publish repository, to make it possible to use it from maven (and other build tools)?

Verification Failure when create futures contract

I follow the authentication request guide to create request and place order via "POST api/v1/contract_order"
The request url is request_url: "https://api.hbdm.com/api/v1/contract_order?AccessKeyId=3c8dd81a-d8b5e97e-qv2d5ctgbn-9bd14&SignatureMethod=HmacSHA256&SignatureVersion=2&Timestamp=2020-03-09T10%3A46%3A21&Signature=/4tZI8AHjF8tdpyB+j5RMOA7/E91bOItkq17wqoOgtI=",
The body is body: "{\"contract_type\":\"this_week\",\"direction\":\"Buy\",\"lever_rate\":5,\"offset\":\"open\",\"order_price_type\":\"limit\",\"price\":5000,\"symbol\":\"BTC\",\"volume\":1}",

But I intermittently run into %{ "err_code" => 403, "err_msg" => "Verification failure [校验失败]", "status" => "error", "ts" => 1583750781573 }
It fails for about 3,4 request, and then the next request succeeded.
Why is it so unstable ? How can I improve it ?

关于sdk取消订阅某一交易对的问题

如题,是不是sdk不提供取消订阅单个交易对的接口,在sdk中只找到了
image取消区别的方法,如果我只取消订阅一个交易对,那我需要取消全部,然后再重新订阅吗。

Incorrect Access key

修改 api key /secret key 后运行出现这个错误, 有哪位同学帮吗解答下吗

run AccountClientExample.main

[Executing] api-signature-not-valid: Signature not valid: Incorrect Access key [Access key错误]

有没有永续合约和交割合约SDK呢

我在使用SDK时,发现并没有关于永续合约和交割合约这两个相关的SDK,只有对现货的SDK,有没有关系永续合约和交割合约的SDK呢 ,如果有,请提供地址。

ws订阅accounts,同时订阅 可用和total,返回的数据没有字段可以区分

model string 选填;订阅账户balance类型。0 代表可用,即type=trade的balance; 1 代表 total,即该账户的总余额,包括type=trade 和type=frozen的余额的和。当mode缺省时,默认值为0.

发起两个订阅,0 和 1的,当币币交易成功,账户发生变化时,每个订阅各收到一条消息,格式如下:{"changeType":"TRADE","data":[{"accountType":"SPOT","balance":,"balanceType":"TRADE","currency":"usdt"}],"timestamp":}

除了 balance 字段值不同以外(对应可用和total),没有字段可以区分。

连不上啊

java.net.SocketTimeoutException: connect timed out
at java.net.DualStackPlainSocketImpl.waitForConnect(Native Method)
at java.net.DualStackPlainSocketImpl.socketConnect(DualStackPlainSocketImpl.java:85)
at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:350)
at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206)
at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188)
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:172)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
at java.net.Socket.connect(Socket.java:606)
at okhttp3.internal.platform.Platform.connectSocket(Platform.kt:117)
at okhttp3.internal.connection.RealConnection.connectSocket(RealConnection.kt:283)
at okhttp3.internal.connection.RealConnection.connect(RealConnection.kt:195)
at okhttp3.internal.connection.ExchangeFinder.findConnection(ExchangeFinder.kt:249)
at okhttp3.internal.connection.ExchangeFinder.findHealthyConnection(ExchangeFinder.kt:108)
at okhttp3.internal.connection.ExchangeFinder.find(ExchangeFinder.kt:76)
at okhttp3.internal.connection.RealCall.initExchange$okhttp(RealCall.kt:245)
at okhttp3.internal.connection.ConnectInterceptor.intercept(ConnectInterceptor.kt:32)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:100)
at okhttp3.internal.cache.CacheInterceptor.intercept(CacheInterceptor.kt:82)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:100)
at okhttp3.internal.http.BridgeInterceptor.intercept(BridgeInterceptor.kt:83)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:100)
at okhttp3.internal.http.RetryAndFollowUpInterceptor.intercept(RetryAndFollowUpInterceptor.kt:76)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:100)
at okhttp3.internal.connection.RealCall.getResponseWithInterceptorChain$okhttp(RealCall.kt:197)
at okhttp3.internal.connection.RealCall.execute(RealCall.kt:148)
at com.huobi.utils.ConnectionFactory.execute(ConnectionFactory.java:70)
at com.huobi.service.huobi.connection.HuobiRestConnection.executeGet(HuobiRestConnection.java:47)
at com.huobi.service.huobi.HuobiGenericService.getTimestamp(HuobiGenericService.java:84)
at client.demo.HuobiDemo.main(HuobiDemo.java:9)
Suppressed: java.net.SocketTimeoutException: connect timed out

AccountClientExample 为啥显示的错误信息,user id 少一位

AccountClientExample 为啥显示的错误信息,user id 少一位
比如user id yyy ,真实的user id yyy5 ,那个5为啥没有?
Exception in thread "main" com.huobi.exception.SDKException: [Executing] account-get-balance-account-inexistent-error: account for id xxx and user id yyy does not exist

获取账户资产估值—JSON返回解析有问题

/v2/account/asset-valuation接口

package: com.huobi.service.huobi.parser.account;

方法转换失败:
@OverRide
public AccountAssetValuationResult parse(JSONObject json) {
return json.toJavaObject(AccountAssetValuationResult.class);
}
修改后返回正常:
@OverRide
public AccountAssetValuationResult parse(JSONObject json) {
return json.getJSONObject("data").toJavaObject(AccountAssetValuationResult.class);
}

内存泄露

okkhttp使用有问题,会导致内存泄露

Verification failure [校验失败]

修改 API_KEYSECRET_KEY 以后,使用 https://api.huobi.de.com 的地址,调用:

   AccountClient accountService = AccountClient.create(HuobiOptions.builder()
        .apiKey(Constants.API_KEY)
        .secretKey(Constants.SECRET_KEY)
        .build());

    List<Account> accountList = accountService.getAccounts();

提示:

Exception in thread "main" com.huobi.exception.SDKException: [Executing] api-signature-not-valid: Signature not valid: Verification failure [校验失败]

请问有哪位同学知道哪里有问题吗?谢谢。

Cannot found investment and borrow accounts

After accepting C2C Lending terms on the website, I'vs started to get errors on initialization:

2020-06-16 11:46:01 ERROR [main] c.h.c.i.utils.EnumLookup - [Enum] Cannot found investment in Enum com.huobi.client.model.enums.AccountType
2020-06-16 11:46:01 ERROR [main] c.h.c.i.utils.EnumLookup - [Enum] Cannot found borrow in Enum com.huobi.client.model.enums.AccountType

你好,请问如何获取指定时间范围的行情数据

在API文档https://huobiapi.github.io/docs/spot/v1/cn/#k-2中提到,通过一次性请求可以获取时间范围内的行情数据。

{
"req": "market.$symbol.kline.$period",
"id": "id generated by client",
"from": "from time in epoch seconds",
"to": "to time in epoch seconds"
}

我在SDK中,修改了一个方法,将订阅改为直接请求


public static String klineChannel2(String symbol, CandlestickInterval interval) {
           JSONObject json = new JSONObject();
           json.put("req", "market." + symbol + ".kline." + interval.toString());
           json.put("id", TimeService.getCurrentTimeStamp() + "");
           //    json.put("from", 1325347200);
           //    json.put("to",   1325348200);
           return json.toJSONString();
}

接口可以调通,有提示from、to范围不正确啥的,但调整from to后,没有错误提示了,但也一直不返回数据。

关于订阅订单的疑问

AX2TI267Y96%D18R2_DFS07
按照sdk中描述,订阅订单不是依靠订单号、而是依靠交易对来订阅,是否意味着同一交易对、只能存在一个订单?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.