Coder Social home page Coder Social logo

huobirdcenter / huobi_java Goto Github PK

View Code? Open in Web Editor NEW
269.0 269.0 201.0 721 KB

Java SDK for Huobi Spot API

Home Page: https://www.htx.com/zh-cn/opend/newApiPages/

License: Apache License 2.0

Java 100.00%
api cryptocurrency exchange huobi java rest sdk spot websocket

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

huobi_java's Issues

连不上啊

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 少一位

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

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

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

有没有web端的集成demo?

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

提现报错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,为什么会提币失败?

BalanceType error

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

少了一个balance type : bank
.

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

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

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

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...

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),没有字段可以区分。

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 [校验失败]

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

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;
}

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)?

获取账户资产估值—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);
}

关于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错误]

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,只有对现货的SDK,有没有关系永续合约和交割合约的SDK呢 ,如果有,请提供地址。

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)```

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");

内存泄露

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

关于订阅订单的疑问

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.