huobirdcenter / huobi_java Goto Github PK
View Code? Open in Web Editor NEWJava SDK for Huobi Spot API
Home Page: https://www.htx.com/zh-cn/opend/newApiPages/
License: Apache License 2.0
Java SDK for Huobi Spot API
Home Page: https://www.htx.com/zh-cn/opend/newApiPages/
License: Apache License 2.0
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
在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后,没有错误提示了,但也一直不返回数据。
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
你好,找不到user-center/orders/相关的api,我想查询法币交易订单,比如btc和CNY交易的订单,请问只能自己发送http请求吗?
浏览器上的请求需要fingerprint,trace_id,token等参数,每次需要登陆后,才能在cookies中看到。。。能给我一个用私钥参考吗?感谢了
拉下代码,以为是springboot的微服务项目,但是没找到application.properties;有没有web端的集成项目,方便第一次接触的人快速上手。
这个JAVA版本的,不兼容最新的Android Studio,因为现在的AS不支持lombok啦,里面都是lombok的注解,能不能进入AS啊?
void reConnect() {
if (delayInSecond != 0) {
delayInSecond--;
} else {
connect();
}
}
修改为
void reConnect() {
if (delayInSecond != 0) {
delayInSecond--;
} else {
delayInSecond = 15;
connect();
}
}
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,为什么会提币失败?
[Enum] Cannot found bank in Enum com.huobi.client.model.enums.BalanceType
少了一个balance type : bank
.
ERROR: API withdrawal does not support temporary addresses
currency:ada
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
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...
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),没有字段可以区分。
修改 API_KEY
和 SECRET_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 [校验失败]
请问有哪位同学知道哪里有问题吗?谢谢。
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;
}
Can you publish this lib to a publish repository, to make it possible to use it from maven (and other build tools)?
how to set proxy in client;
/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);
}
修改 api key /secret key 后运行出现这个错误, 有哪位同学帮吗解答下吗
run AccountClientExample.main
[Executing] api-signature-not-valid: Signature not valid: Incorrect Access key [Access key错误]
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 ?
Error:Maven Resources Compiler: Maven project configuration required for module 'huobi-client' isn't available. Compilation of Maven projects is supported only if external build is started from an IDE.
你好,请问如何实时监听某个交易对的当前最新价格?非常感谢
就比如我想实时监听BTC/USDT的当前最新价格,该怎么做?
我在使用SDK时,发现并没有关于永续合约和交割合约这两个相关的SDK,只有对现货的SDK,有没有关系永续合约和交割合约的SDK呢 ,如果有,请提供地址。
In some cases, the VPN connection can make outgoing connection deaf (no messages from web socket). Thus watchdog constantly tries to create WebSockets more and more without closing existing ones.
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)```
SDK中查询借贷订单接口
缺少direct字段,查询借贷订单默认截取更旧的数据。sdk可以完善,业务更灵活
demo里并不能使用
hello,
文档上定义了借贷账户详情的接口
,但SDK并没有提供。麻烦核实,希望后续在sdk中补充该接口
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");
取消订阅 unsuded topic
下单,一直报这个错
请问 如果 DNS解析返回了 IPV6地址, WebSocket 出现无法连接问题, 有什么好的解决办法么?
com.huobi.client.model.request.HistoricalOrdersRequest#startId 该字段目前是 Integer,应该是 Long 或者 String 的订单号。
okkhttp使用有问题,会导致内存泄露
你好,文档中描述的HuobiClientFactory这个类找不到,请问是不是更名了,文档没有更新?
java.net.SocketTimeoutException: connect timed out
Why not access the interface
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.