Skip to content

Commit

Permalink
添加 /v1/trust/user/active/credit、 /v1/account/switch/user/info、 /v1/ac…
Browse files Browse the repository at this point in the history
…count/overview/info、	/v1/account/fee/switch等新增接口
  • Loading branch information
“VincentCai” committed May 21, 2024
1 parent ef5324d commit 19d675c
Show file tree
Hide file tree
Showing 12 changed files with 179 additions and 1 deletion.
6 changes: 6 additions & 0 deletions src/main/java/com/huobi/client/AccountClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,12 @@ public interface AccountClient {

AccountTransferV2Result accountTransferV2(AccountTransferV2Request request);

UserInfo getAccountUserInfo();

OverviewInfo getOverviewInfo();

void feeSwitch(FeeSwitchRequest request);

void subAccountsUpdate(SubAccountUpdateRequest request, ResponseCallback<AccountUpdateEvent> callback);

void subOrderUpdateV2(SubOrderUpdateV2Request request, ResponseCallback<OrderUpdateV2Event> callback);
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/com/huobi/client/SubUserClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ public interface SubUserClient {

List<DeductModeResult> setDeductMode(DeductModeRequest request);

public boolean setCredit(CreditRequest request);

static SubUserClient create(Options options) {

if (options.getExchange().equals(ExchangeEnum.HUOBI)) {
Expand Down
13 changes: 13 additions & 0 deletions src/main/java/com/huobi/client/req/account/FeeSwitchRequest.java
Original file line number Diff line number Diff line change
@@ -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;
}
18 changes: 18 additions & 0 deletions src/main/java/com/huobi/client/req/subuser/CreditRequest.java
Original file line number Diff line number Diff line change
@@ -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;
}
12 changes: 12 additions & 0 deletions src/main/java/com/huobi/model/account/OverviewInfo.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.huobi.model.account;

import lombok.*;

@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
@ToString
public class OverviewInfo {
private String currency;
}
14 changes: 14 additions & 0 deletions src/main/java/com/huobi/model/account/UserInfo.java
Original file line number Diff line number Diff line change
@@ -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;
}
32 changes: 31 additions & 1 deletion src/main/java/com/huobi/service/huobi/HuobiAccountService.java
Original file line number Diff line number Diff line change
Expand Up @@ -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";// 设置现货/杠杆抵扣手续费方式



Expand Down Expand Up @@ -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<AccountUpdateEvent> callback) {
InputChecker.checker()
.shouldNotNull(request.getAccountUpdateMode(), "account update model");
Expand Down Expand Up @@ -312,7 +343,6 @@ public void subTradeClearing(SubTradeClearingRequest request, ResponseCallback<T
commandList.add(command.toJSONString());
}
HuobiWebSocketConnection.createAssetV2Connection(options, commandList, new TradeClearingEventParser(), callback, false);

}

}
20 changes: 20 additions & 0 deletions src/main/java/com/huobi/service/huobi/HuobiSubUserService.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ public class HuobiSubUserService implements SubUserClient {
public static final String GET_SUBUSER_DEPOSIT_PATH = "/v2/sub-user/query-deposit";//子用户充币记录查询
public static final String GET_UID_PATH = "/v2/user/uid";//母子用户获取用户UID
public static final String SET_DDEDUCT_MODE_PATH = "/v2/sub-user/deduct-mode";//设置子用户手续费抵扣模式
public static final String SET_CREDIT_PATH = "/v1/trust/user/active/credit";//用户主动授信


private Options options;
Expand Down Expand Up @@ -312,4 +313,23 @@ public long getUid() {
return data;
}

@Override
public boolean setCredit(CreditRequest request) {
InputChecker.checker()
.shouldNotNull(request.getTransactionId(), "transactionId")
.shouldNotNull(request.getCurrency(), "currency")
.shouldNotNull(request.getAmount(), "amount")
.shouldNotNull(request.getAccountId(), "accountId")
.shouldNotNull(request.getUserId(), "userId");
UrlParamsBuilder builder = UrlParamsBuilder.build()
.putToPost("transactionId", request.getTransactionId())
.putToPost("currency", request.getCurrency())
.putToPost("amount", request.getAmount())
.putToPost("accountId", request.getAccountId())
.putToPost("userId", request.getUserId())
;
JSONObject jsonObject = restConnection.executePostWithSignature(SET_CREDIT_PATH, builder);
return jsonObject.getBoolean("data");
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.huobi.service.huobi.parser.account;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.huobi.model.account.OverviewInfo;
import com.huobi.model.account.UserInfo;
import com.huobi.service.huobi.parser.HuobiModelParser;

import java.util.List;

public class OverviewInfoParser implements HuobiModelParser<OverviewInfo> {
@Override
public OverviewInfo parse(JSONObject json) {
return json.toJavaObject(OverviewInfo.class);
}

@Override
public OverviewInfo parse(JSONArray json) {
return null;
}

@Override
public List<OverviewInfo> parseArray(JSONArray jsonArray) {
return null;
}
}
Original file line number Diff line number Diff line change
@@ -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<UserInfo> {

@Override
public UserInfo parse(JSONObject json) {
return json.toJavaObject(UserInfo.class);
}

@Override
public UserInfo parse(JSONArray json) {
return null;
}

@Override
public List<UserInfo> parseArray(JSONArray jsonArray) {
return null;
}
}
7 changes: 7 additions & 0 deletions src/test/java/com/huobi/examples/AccountClientExample.java
Original file line number Diff line number Diff line change
Expand Up @@ -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());

}

Expand Down
3 changes: 3 additions & 0 deletions src/test/java/com/huobi/examples/SubUserClientExample.java
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,9 @@ public static void main(String[] args) {
List<DeductModeResult> 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 + "===============");

Expand Down

0 comments on commit 19d675c

Please sign in to comment.