hbdmapi / huobi_usdt_swap_java Goto Github PK
View Code? Open in Web Editor NEWJava demo of huobi usdt swap api.
Java demo of huobi usdt swap api.
FangdeMacBook-Pro:huobi_usdt_swap_Java-master fangzheng$ mvn install
[INFO] Scanning for projects...
[INFO]
[INFO] ----------< com.huobi.linear.swap.api:huobi-linear-swap-api >-----------
[INFO] Building huobi-linear-swap-api 1.0.1
[INFO] --------------------------------[ jar ]---------------------------------
[INFO]
[INFO] --- maven-resources-plugin:3.1.0:resources (default-resources) @ huobi-linear-swap-api ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 0 resource
[INFO] Copying 1 resource
[INFO]
[INFO] --- maven-compiler-plugin:3.8.1:compile (default-compile) @ huobi-linear-swap-api ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 207 source files to /Users/fangzheng/OneDrive/WorkSpace/Develop/MacWorkspace/huobi_usdt_swap_Java-master/target/classes
[WARNING] /Users/fangzheng/OneDrive/WorkSpace/Develop/MacWorkspace/huobi_usdt_swap_Java-master/src/main/java/com/huobi/api/response/market/LinearSwapPremiumIndexKlineResponse.java:[6,23] sun.rmi.runtime.Log是内部专用 API, 可能会在未来发行版中删除
[WARNING] /Users/fangzheng/OneDrive/WorkSpace/Develop/MacWorkspace/huobi_usdt_swap_Java-master/src/main/java/com/huobi/api/response/account/SwapMasterSubTransferRecordResponse.java:[7,23] sun.rmi.runtime.Log是内部专用 API, 可能会在未来发行版中删除
[WARNING] /Users/fangzheng/OneDrive/WorkSpace/Develop/MacWorkspace/huobi_usdt_swap_Java-master/src/main/java/com/huobi/api/response/account/SwapApiTradingStatusResponse.java:[7,23] sun.rmi.runtime.Log是内部专用 API, 可能会在未来发行版中删除
[WARNING] /Users/fangzheng/OneDrive/WorkSpace/Develop/MacWorkspace/huobi_usdt_swap_Java-master/src/main/java/com/huobi/api/response/account/SwapAccountPositionInfoResponse.java:[4,38] com.sun.imageio.plugins.common.BogusColorSpace是内部专用 API, 可能会在未来发行版中删除
[WARNING] /Users/fangzheng/OneDrive/WorkSpace/Develop/MacWorkspace/huobi_usdt_swap_Java-master/src/main/java/com/huobi/api/response/market/LinearSwapPremiumIndexKlineResponse.java:[6,23] sun.rmi.runtime.Log是内部专用 API, 可能会在未来发行版中删除
[WARNING] /Users/fangzheng/OneDrive/WorkSpace/Develop/MacWorkspace/huobi_usdt_swap_Java-master/src/main/java/com/huobi/api/response/account/SwapMasterSubTransferRecordResponse.java:[7,23] sun.rmi.runtime.Log是内部专用 API, 可能会在未来发行版中删除
[WARNING] /Users/fangzheng/OneDrive/WorkSpace/Develop/MacWorkspace/huobi_usdt_swap_Java-master/src/main/java/com/huobi/api/response/account/SwapApiTradingStatusResponse.java:[7,23] sun.rmi.runtime.Log是内部专用 API, 可能会在未来发行版中删除
[WARNING] /Users/fangzheng/OneDrive/WorkSpace/Develop/MacWorkspace/huobi_usdt_swap_Java-master/src/main/java/com/huobi/api/response/account/SwapAccountPositionInfoResponse.java:[4,38] com.sun.imageio.plugins.common.BogusColorSpace是内部专用 API, 可能会在未来发行版中删除
[WARNING] /Users/fangzheng/OneDrive/WorkSpace/Develop/MacWorkspace/huobi_usdt_swap_Java-master/src/main/java/com/huobi/api/response/market/LinearSwapPremiumIndexKlineResponse.java:[6,23] sun.rmi.runtime.Log是内部专用 API, 可能会在未来发行版中删除
[WARNING] /Users/fangzheng/OneDrive/WorkSpace/Develop/MacWorkspace/huobi_usdt_swap_Java-master/src/main/java/com/huobi/api/response/account/SwapMasterSubTransferRecordResponse.java:[7,23] sun.rmi.runtime.Log是内部专用 API, 可能会在未来发行版中删除
[WARNING] /Users/fangzheng/OneDrive/WorkSpace/Develop/MacWorkspace/huobi_usdt_swap_Java-master/src/main/java/com/huobi/api/response/account/SwapApiTradingStatusResponse.java:[7,23] sun.rmi.runtime.Log是内部专用 API, 可能会在未来发行版中删除
[WARNING] /Users/fangzheng/OneDrive/WorkSpace/Develop/MacWorkspace/huobi_usdt_swap_Java-master/src/main/java/com/huobi/api/response/account/SwapAccountPositionInfoResponse.java:[4,38] com.sun.imageio.plugins.common.BogusColorSpace是内部专用 API, 可能会在未来发行版中删除
[WARNING] /Users/fangzheng/OneDrive/WorkSpace/Develop/MacWorkspace/huobi_usdt_swap_Java-master/src/main/java/com/huobi/api/response/market/LinearSwapPremiumIndexKlineResponse.java:[6,23] sun.rmi.runtime.Log是内部专用 API, 可能会在未来发行版中删除
[WARNING] /Users/fangzheng/OneDrive/WorkSpace/Develop/MacWorkspace/huobi_usdt_swap_Java-master/src/main/java/com/huobi/api/response/account/SwapMasterSubTransferRecordResponse.java:[7,23] sun.rmi.runtime.Log是内部专用 API, 可能会在未来发行版中删除
[WARNING] /Users/fangzheng/OneDrive/WorkSpace/Develop/MacWorkspace/huobi_usdt_swap_Java-master/src/main/java/com/huobi/api/response/account/SwapApiTradingStatusResponse.java:[7,23] sun.rmi.runtime.Log是内部专用 API, 可能会在未来发行版中删除
[WARNING] /Users/fangzheng/OneDrive/WorkSpace/Develop/MacWorkspace/huobi_usdt_swap_Java-master/src/main/java/com/huobi/api/response/account/SwapAccountPositionInfoResponse.java:[4,38] com.sun.imageio.plugins.common.BogusColorSpace是内部专用 API, 可能会在未来发行版中删除
[WARNING] /Users/fangzheng/OneDrive/WorkSpace/Develop/MacWorkspace/huobi_usdt_swap_Java-master/src/main/java/com/huobi/api/response/market/LinearSwapPremiumIndexKlineResponse.java:[6,23] sun.rmi.runtime.Log是内部专用 API, 可能会在未来发行版中删除
[WARNING] /Users/fangzheng/OneDrive/WorkSpace/Develop/MacWorkspace/huobi_usdt_swap_Java-master/src/main/java/com/huobi/api/response/account/SwapMasterSubTransferRecordResponse.java:[7,23] sun.rmi.runtime.Log是内部专用 API, 可能会在未来发行版中删除
[WARNING] /Users/fangzheng/OneDrive/WorkSpace/Develop/MacWorkspace/huobi_usdt_swap_Java-master/src/main/java/com/huobi/api/response/account/SwapApiTradingStatusResponse.java:[7,23] sun.rmi.runtime.Log是内部专用 API, 可能会在未来发行版中删除
[WARNING] /Users/fangzheng/OneDrive/WorkSpace/Develop/MacWorkspace/huobi_usdt_swap_Java-master/src/main/java/com/huobi/api/response/account/SwapAccountPositionInfoResponse.java:[4,38] com.sun.imageio.plugins.common.BogusColorSpace是内部专用 API, 可能会在未来发行版中删除
[INFO]
[INFO] --- maven-resources-plugin:3.1.0:testResources (default-testResources) @ huobi-linear-swap-api ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory /Users/fangzheng/OneDrive/WorkSpace/Develop/MacWorkspace/huobi_usdt_swap_Java-master/src/test/resources
[INFO]
[INFO] --- maven-compiler-plugin:3.8.1:testCompile (default-testCompile) @ huobi-linear-swap-api ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 11 source files to /Users/fangzheng/OneDrive/WorkSpace/Develop/MacWorkspace/huobi_usdt_swap_Java-master/target/test-classes
[INFO]
[INFO] --- maven-surefire-plugin:2.22.2:test (default-test) @ huobi-linear-swap-api ---
[INFO]
[INFO] -------------------------------------------------------
[INFO] T E S T S
[INFO] -------------------------------------------------------
[INFO] Running com.huobi.linear.swap.wss.WssMarketSubTest
2021-08-25 17:19:00.756 [ERROR] [WebSocketConnectReadThread-13] [com.huobi.wss.handle.WssMarketHandle.onError:98] - onError:
java.net.ConnectException: Operation timed out (Connection timed out)
at java.net.PlainSocketImpl.socketConnect(Native Method)
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.Socket.connect(Socket.java:589)
at org.java_websocket.client.WebSocketClient.run(WebSocketClient.java:395)
at java.lang.Thread.run(Thread.java:748)
2021-08-25 17:19:00.763 [ERROR] [WebSocketConnectReadThread-13] [com.huobi.wss.handle.WssMarketHandle.onClose:93] - onClose i:-1,s:Operation timed out (Connection timed out),b:false
{"status":"error","err_code":1030,"err_msg":"Abnormal service. Please try again later.","ts":1621378117939}
2021-05-21 11:17:24.126 [ERROR] [WebSocketConnectReadThread-15] [com.huobi.wss.handle.WssMarketHandle.onError:98] - onError:
java.net.ConnectException: Operation timed out (Connection timed out)
at java.base/java.net.PlainSocketImpl.socketConnect(Native Method)
at java.base/java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:399)
at java.base/java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:242)
at java.base/java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:224)
at java.base/java.net.Socket.connect(Socket.java:591)
at org.java_websocket.client.WebSocketClient.run(WebSocketClient.java:395)
at java.base/java.lang.Thread.run(Thread.java:835)
2021-05-21 11:17:24.129 [ERROR] [WebSocketConnectReadThread-15] [com.huobi.wss.handle.WssMarketHandle.onClose:93] - onClose i:-1,s:Operation timed out (Connection timed out),b:false
TASK:
新增查询用户可用杠杆倍数和切换杠杆倍数的接口。
Shecdule:
2020-10-20 到 2020-10-21
单元测试:
查询用户可用杠杆倍数(/linear-swap-api/v1/swap_available_level_rate ) 通过
切换杠杆(/linear-swap-api/v1/swap_switch_lever_rate ) 通过
集成测试:
通过
I use huobiCrossAPIService.swapCrossOrderRequest
to place the order. It produces the Request:
Request{
method=POST,
url=https://api.hbdm.com/linear-swap-api/v1/swap_cross_order?
volume=1&
lever_rate=10&
SignatureVersion=2&
offset=open&
contract_code=BTC-USDT&
AccessKeyId=h6n2***&
Signature=yHZS***&
SignatureMethod=HmacSHA256&
order_price_type=opponent&
Timestamp=2021-10-18T11%3A38%3A06&
direction=buy,
tag=null}
in response I get:
SwapCrossOrderResponse(status=ok, data=SwapCrossOrderResponse.DataBean(orderId=89***76, orderIdStr=89***76, clientOrderId=null), ts=1634557188608)
Then I need to place TPSL order. I naively tried to fill request parameters as follows:
val request = SwapTpslOrderRequest.builder()
.contractCode(contractCode) // BTC-USDT
.volume(volume.bigDecimal) // 1
.slTriggerPrice(sellPrice) // currentPrice - 5.0
.direction(DirectionEnum.SELL.getValue)
.build()
which produces the Request:
Request{
method=POST,
url=https://api.hbdm.com/linear-swap-api/v1/swap_cross_tpsl_order?
volume=1&
SignatureVersion=2&
contract_code=BTC-USDT&
AccessKeyId=h6n2***&
sl_trigger_price=61251.2&
Signature=rd7f***&
SignatureMethod=HmacSHA256&
Timestamp=2021-10-18T11%3A44%3A00&
direction=sell,
tag=null}
and get the response:
{"status":"error","err_code":1069,"err_msg":"The price is not reasonable.","ts":1634557478538}
I use ceiling to tenths:
val sellPrice = (currentPrice - 5).setScale(1, RoundingMode.CEILING).bigDecimal
// currentPrice is the price of the contract from /linear-swap-notification
which fits the price_tick
of BTC_USDT. I don't know the reason of “price is not reasonable”.
Please, explain how to connect TPSL order with an existing opened long position?
测试类是com.huobi.linear.swap.api.TradeAPITest类的swapOrderRequest()方法
//填写申请的API-KEY 和 SECRET
HuobiAPIServiceImpl huobiAPIService = new HuobiAPIServiceImpl("API-KEY", "SECRET");
@test
public void swapOrderRequest() {
SwapOrderRequest request = SwapOrderRequest.builder()
.contractCode("BTC-USDT")
.volume(100l)
.price(BigDecimal.valueOf(10121))
.direction(DirectionEnum.SELL)
.offset(OffsetEnum.OPEN)
.leverRate(5)
.orderPriceType("opponent")
.build();
SwapOrderResponse response =
huobiAPIService.swapOrderRequest(request);
logger.debug("1合约下单:{}", JSON.toJSONString(response));
}
用这个方法 提示 {"status":"error","err_code":1047,"err_msg":"Insufficient margin available.","ts":1622033531177}
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.