From 19d675cda83f52a20d0ea5b83f9cea1b6b6ffd1e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9CVincentCai=E2=80=9D?= <“vincent.cai@htx-inc.com”> Date: Tue, 21 May 2024 16:25:45 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=09/v1/trust/user/active/cred?= =?UTF-8?q?it=E3=80=81=09/v1/account/switch/user/info=E3=80=81=09/v1/accou?= =?UTF-8?q?nt/overview/info=E3=80=81=09/v1/account/fee/switch=E7=AD=89?= =?UTF-8?q?=E6=96=B0=E5=A2=9E=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/huobi/client/AccountClient.java | 6 ++++ .../java/com/huobi/client/SubUserClient.java | 2 ++ .../client/req/account/FeeSwitchRequest.java | 13 ++++++++ .../client/req/subuser/CreditRequest.java | 18 +++++++++++ .../com/huobi/model/account/OverviewInfo.java | 12 +++++++ .../com/huobi/model/account/UserInfo.java | 14 ++++++++ .../service/huobi/HuobiAccountService.java | 32 ++++++++++++++++++- .../service/huobi/HuobiSubUserService.java | 20 ++++++++++++ .../parser/account/OverviewInfoParser.java | 26 +++++++++++++++ .../huobi/parser/account/UserInfoParser.java | 27 ++++++++++++++++ .../huobi/examples/AccountClientExample.java | 7 ++++ .../huobi/examples/SubUserClientExample.java | 3 ++ 12 files changed, 179 insertions(+), 1 deletion(-) create mode 100644 src/main/java/com/huobi/client/req/account/FeeSwitchRequest.java create mode 100644 src/main/java/com/huobi/client/req/subuser/CreditRequest.java create mode 100644 src/main/java/com/huobi/model/account/OverviewInfo.java create mode 100644 src/main/java/com/huobi/model/account/UserInfo.java create mode 100644 src/main/java/com/huobi/service/huobi/parser/account/OverviewInfoParser.java create mode 100644 src/main/java/com/huobi/service/huobi/parser/account/UserInfoParser.java diff --git a/src/main/java/com/huobi/client/AccountClient.java b/src/main/java/com/huobi/client/AccountClient.java index 95204ca..08add7a 100644 --- a/src/main/java/com/huobi/client/AccountClient.java +++ b/src/main/java/com/huobi/client/AccountClient.java @@ -48,6 +48,12 @@ public interface AccountClient { AccountTransferV2Result accountTransferV2(AccountTransferV2Request request); + UserInfo getAccountUserInfo(); + + OverviewInfo getOverviewInfo(); + + void feeSwitch(FeeSwitchRequest request); + void subAccountsUpdate(SubAccountUpdateRequest request, ResponseCallback callback); void subOrderUpdateV2(SubOrderUpdateV2Request request, ResponseCallback callback); diff --git a/src/main/java/com/huobi/client/SubUserClient.java b/src/main/java/com/huobi/client/SubUserClient.java index 4cbe205..0ab890f 100644 --- a/src/main/java/com/huobi/client/SubUserClient.java +++ b/src/main/java/com/huobi/client/SubUserClient.java @@ -75,6 +75,8 @@ public interface SubUserClient { List setDeductMode(DeductModeRequest request); + public boolean setCredit(CreditRequest request); + static SubUserClient create(Options options) { if (options.getExchange().equals(ExchangeEnum.HUOBI)) { diff --git a/src/main/java/com/huobi/client/req/account/FeeSwitchRequest.java b/src/main/java/com/huobi/client/req/account/FeeSwitchRequest.java new file mode 100644 index 0000000..298084a --- /dev/null +++ b/src/main/java/com/huobi/client/req/account/FeeSwitchRequest.java @@ -0,0 +1,13 @@ +package com.huobi.client.req.account; + +import lombok.*; + +@Data +@Builder +@AllArgsConstructor +@NoArgsConstructor +@ToString +public class FeeSwitchRequest { + private Integer switchType; + private String deductionCurrency; +} diff --git a/src/main/java/com/huobi/client/req/subuser/CreditRequest.java b/src/main/java/com/huobi/client/req/subuser/CreditRequest.java new file mode 100644 index 0000000..a0c5eae --- /dev/null +++ b/src/main/java/com/huobi/client/req/subuser/CreditRequest.java @@ -0,0 +1,18 @@ +package com.huobi.client.req.subuser; + +import lombok.*; + +import java.math.BigDecimal; + +@Data +@Builder +@AllArgsConstructor +@NoArgsConstructor +@ToString +public class CreditRequest { + private Long transactionId; + private String currency; + private BigDecimal amount; + private Long accountId; + private Long userId; +} diff --git a/src/main/java/com/huobi/model/account/OverviewInfo.java b/src/main/java/com/huobi/model/account/OverviewInfo.java new file mode 100644 index 0000000..8301096 --- /dev/null +++ b/src/main/java/com/huobi/model/account/OverviewInfo.java @@ -0,0 +1,12 @@ +package com.huobi.model.account; + +import lombok.*; + +@Data +@Builder +@AllArgsConstructor +@NoArgsConstructor +@ToString +public class OverviewInfo { + private String currency; +} diff --git a/src/main/java/com/huobi/model/account/UserInfo.java b/src/main/java/com/huobi/model/account/UserInfo.java new file mode 100644 index 0000000..673d5d3 --- /dev/null +++ b/src/main/java/com/huobi/model/account/UserInfo.java @@ -0,0 +1,14 @@ +package com.huobi.model.account; + +import lombok.*; + +@Data +@Builder +@AllArgsConstructor +@NoArgsConstructor +@ToString +public class UserInfo { + private Integer pointSwitch; + private Integer currencySwitch; + private String deductionCurrency; +} diff --git a/src/main/java/com/huobi/service/huobi/HuobiAccountService.java b/src/main/java/com/huobi/service/huobi/HuobiAccountService.java index 1254696..b668b63 100644 --- a/src/main/java/com/huobi/service/huobi/HuobiAccountService.java +++ b/src/main/java/com/huobi/service/huobi/HuobiAccountService.java @@ -42,6 +42,9 @@ public class HuobiAccountService implements AccountClient { public static final String ACCOUNT_ASSET_VALUATION_PATH = "/v2/account/asset-valuation";//获取指定账户资产估值(现货、杠杆、OTC) public static final String ACCOUNT_VALUATION_PATH = "/v2/account/valuation";//获取平台资产总估值 public static final String ACCOUNT_TRANSFER_PATH_V2 = "/v2/account/transfer";//【通用】现货-合约账户和OTC账户间进行资金的划转 + public static final String ACCOUNT_USER_INFO_PATH = "/v1/account/switch/user/info";// 用户抵扣信息查询 + public static final String ACCOUNT_OVERVIEW_INFO_PATH = "/v1/account/overview/info";// 可抵扣币种查询信息 + public static final String ACCOUNT_FEE_SWITCH_PATH = "/v1/account/fee/switch";// 设置现货/杠杆抵扣手续费方式 @@ -242,6 +245,34 @@ public AccountTransferV2Result accountTransferV2(AccountTransferV2Request reques return new AccountTransferV2ResultParser().parse(jsonObject); } + @Override + public UserInfo getAccountUserInfo() { + JSONObject jsonObject = restConnection.executeGetWithSignature(ACCOUNT_USER_INFO_PATH, UrlParamsBuilder.build()); + JSONObject data = jsonObject.getJSONObject("data"); + return new UserInfoParser().parse(data); + } + + @Override + public OverviewInfo getOverviewInfo() { + JSONObject jsonObject = restConnection.executeGetWithSignature(ACCOUNT_OVERVIEW_INFO_PATH, UrlParamsBuilder.build()); + JSONObject data = jsonObject.getJSONObject("data"); + return new OverviewInfoParser().parse(data); + } + + @Override + public void feeSwitch(FeeSwitchRequest request) { + InputChecker.checker() + .shouldNotNull(request.getSwitchType(), "switchType") + .shouldNotNull(request.getDeductionCurrency(), "deductionCurrency"); + + UrlParamsBuilder builder = UrlParamsBuilder.build() + .putToPost("switchType", request.getSwitchType()) + .putToPost("deductionCurrency", request.getDeductionCurrency()); + + restConnection.executePostWithSignature(ACCOUNT_FEE_SWITCH_PATH, builder); + } + + public void subAccountsUpdate(SubAccountUpdateRequest request, ResponseCallback callback) { InputChecker.checker() .shouldNotNull(request.getAccountUpdateMode(), "account update model"); @@ -312,7 +343,6 @@ public void subTradeClearing(SubTradeClearingRequest request, ResponseCallback { + @Override + public OverviewInfo parse(JSONObject json) { + return json.toJavaObject(OverviewInfo.class); + } + + @Override + public OverviewInfo parse(JSONArray json) { + return null; + } + + @Override + public List parseArray(JSONArray jsonArray) { + return null; + } +} diff --git a/src/main/java/com/huobi/service/huobi/parser/account/UserInfoParser.java b/src/main/java/com/huobi/service/huobi/parser/account/UserInfoParser.java new file mode 100644 index 0000000..a3167aa --- /dev/null +++ b/src/main/java/com/huobi/service/huobi/parser/account/UserInfoParser.java @@ -0,0 +1,27 @@ +package com.huobi.service.huobi.parser.account; + +import com.alibaba.fastjson.JSONArray; +import com.alibaba.fastjson.JSONObject; +import com.huobi.model.account.AccountBalance; +import com.huobi.model.account.UserInfo; +import com.huobi.service.huobi.parser.HuobiModelParser; + +import java.util.List; + +public class UserInfoParser implements HuobiModelParser { + + @Override + public UserInfo parse(JSONObject json) { + return json.toJavaObject(UserInfo.class); + } + + @Override + public UserInfo parse(JSONArray json) { + return null; + } + + @Override + public List parseArray(JSONArray jsonArray) { + return null; + } +} diff --git a/src/test/java/com/huobi/examples/AccountClientExample.java b/src/test/java/com/huobi/examples/AccountClientExample.java index e45adf3..2ce6396 100644 --- a/src/test/java/com/huobi/examples/AccountClientExample.java +++ b/src/test/java/com/huobi/examples/AccountClientExample.java @@ -114,6 +114,13 @@ public static void main(String[] args) { AccountTransferV2Result accountTransferV2Result = accountService.accountTransferV2(accountTransferV2Request); System.out.println(accountTransferV2Result); + UserInfo accountUserInfo = accountService.getAccountUserInfo(); + System.out.println(accountUserInfo); + + OverviewInfo overviewInfo = accountService.getOverviewInfo(); + System.out.println(overviewInfo); + + accountService.feeSwitch(FeeSwitchRequest.builder().switchType(1).deductionCurrency("TRX").build()); } diff --git a/src/test/java/com/huobi/examples/SubUserClientExample.java b/src/test/java/com/huobi/examples/SubUserClientExample.java index c10c23b..4450d2d 100644 --- a/src/test/java/com/huobi/examples/SubUserClientExample.java +++ b/src/test/java/com/huobi/examples/SubUserClientExample.java @@ -214,6 +214,9 @@ public static void main(String[] args) { List deductModeResults = subUserClient.setDeductMode(DeductModeRequest.builder().subUids(178211L).deductMode("master").build()); System.out.println(deductModeResults); + boolean setCreditResults = subUserClient.setCredit(CreditRequest.builder().userId(41262769L).accountId(31260495L).currency("usdt").amount(new BigDecimal(10)).transactionId(17L).build()); + System.out.println(setCreditResults); + long uid = subUserClient.getUid(); System.out.println("===========uid:" + uid + "===============");