zj
2025-10-17 bbc4713b23778aebc1eb3d46cb04d539179d883d
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
package com.yami.trading.huobi.websocket.service.huobi;
 
import java.util.List;
 
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
 
import com.yami.trading.huobi.websocket.client.WalletClient;
import com.yami.trading.huobi.websocket.client.req.wallet.CreateWithdrawRequest;
import com.yami.trading.huobi.websocket.client.req.wallet.DepositAddressRequest;
import com.yami.trading.huobi.websocket.client.req.wallet.DepositWithdrawRequest;
import com.yami.trading.huobi.websocket.client.req.wallet.WithdrawAddressRequest;
import com.yami.trading.huobi.websocket.client.req.wallet.WithdrawQuotaRequest;
 
import com.yami.trading.huobi.websocket.constant.Options;
import com.yami.trading.huobi.websocket.constant.enums.DepositWithdrawTypeEnum;
import com.yami.trading.huobi.websocket.model.wallet.*;
import com.yami.trading.huobi.websocket.service.huobi.connection.HuobiRestConnection;
import com.yami.trading.huobi.websocket.service.huobi.connection.HuobiRestConnection25519;
import com.yami.trading.huobi.websocket.service.huobi.parser.wallet.*;
import com.yami.trading.huobi.websocket.service.huobi.signature.UrlParamsBuilder;
import com.yami.trading.huobi.websocket.utils.InputChecker;
 
public class HuobiWalletService implements WalletClient {
 
 
  public static final String GET_DEPOSIT_ADDRESS_PATH = "/v2/account/deposit/address";//充币地址查询
  public static final String GET_WITHDRAW_ADDRESS_PATH = "/v2/account/withdraw/address";//提币地址查询
  public static final String GET_WITHDRAW_QUOTA_PATH = "/v2/account/withdraw/quota";//提币额度查询
  public static final String CREATE_WITHDRAW_PATH = "/v1/dw/withdraw/api/create";//虚拟币提币
  public static final String CANCEL_WITHDRAW_PATH = "/v1/dw/withdraw-virtual/{withdraw-id}/cancel";//取消提币
  public static final String DEPOSIT_WITHDRAW_PATH = "/v1/query/deposit-withdraw";//充提记录
  public static final String GET_WITHDRAW_ORDER_PATH = "/v1/query/withdraw/client-order-id";//通过clientOrderId查询提币订单
 
  private Options options;
 
  private HuobiRestConnection restConnection;
 
  public HuobiWalletService(Options options) {
    this.options = options;
    if(options.getSign().equals("256")){
      this.restConnection = new HuobiRestConnection(options);
    }else if(options.getSign().equals("25519")){
      this.restConnection = new HuobiRestConnection25519(options);
    }
  }
 
  @Override
  public List<DepositAddress> getDepositAddress(DepositAddressRequest request) {
 
    // 验证参数
    InputChecker.checker()
        .shouldNotNull(request.getCurrency(), "currency");
 
    UrlParamsBuilder builder = UrlParamsBuilder.build()
        .putToUrl("currency", request.getCurrency());
 
    JSONObject jsonObject = restConnection.executeGetWithSignature(GET_DEPOSIT_ADDRESS_PATH, builder);
    JSONArray array = jsonObject.getJSONArray("data");
    return new DepositAddressParser().parseArray(array);
  }
 
  @Override
  public WithdrawQuota getWithdrawQuota(WithdrawQuotaRequest request) {
    // 验证参数
    InputChecker.checker()
        .shouldNotNull(request.getCurrency(), "currency");
 
    UrlParamsBuilder builder = UrlParamsBuilder.build()
        .putToUrl("currency", request.getCurrency());
 
    JSONObject jsonObject = restConnection.executeGetWithSignature(GET_WITHDRAW_QUOTA_PATH, builder);
    JSONObject data = jsonObject.getJSONObject("data");
    return new WithdrawQuotaParser().parse(data);
  }
 
  public WithdrawAddressResult getWithdrawAddress(WithdrawAddressRequest request) {
 
    // 验证参数
    InputChecker.checker()
        .shouldNotNull(request.getCurrency(), "currency");
 
    UrlParamsBuilder builder = UrlParamsBuilder.build()
        .putToUrl("currency", request.getCurrency())
        .putToUrl("chain", request.getChain())
        .putToUrl("note", request.getNote())
        .putToUrl("limit", request.getLimit())
        .putToUrl("fromId", request.getFromId());
 
    JSONObject jsonObject = restConnection.executeGetWithSignature(GET_WITHDRAW_ADDRESS_PATH, builder);
    JSONArray array = jsonObject.getJSONArray("data");
 
    return WithdrawAddressResult.builder()
        .nextId(jsonObject.getLong("next-id"))
        .withdrawAddressList(new WithdrawAddressParser().parseArray(array))
        .build();
  }
 
  @Override
  public Long createWithdraw(CreateWithdrawRequest request) {
 
    InputChecker.checker()
        .shouldNotNull(request.getAddress(), "address")
        .shouldNotNull(request.getAmount(), "amount")
        .shouldNotNull(request.getCurrency(), "currency")
        .shouldNotNull(request.getFee(), "fee");
 
    UrlParamsBuilder builder = UrlParamsBuilder.build()
        .putToPost("address", request.getAddress())
        .putToPost("amount", request.getAmount())
        .putToPost("currency", request.getCurrency())
        .putToPost("fee", request.getFee())
        .putToPost("addr-tag", request.getAddrTag())
        .putToPost("chain", request.getChain())
        .putToPost("client-order-id", request.getClientOrderId());
 
    JSONObject jsonObject = restConnection.executePostWithSignature(CREATE_WITHDRAW_PATH, builder);
    return jsonObject.getLong("data");
  }
 
  @Override
  public Long cancelWithdraw(Long withdrawId) {
 
    InputChecker.checker()
        .shouldNotNull(withdrawId, "withdraw-id");
 
    String path = CANCEL_WITHDRAW_PATH.replace("{withdraw-id}", withdrawId + "");
 
    JSONObject jsonObject = restConnection.executePostWithSignature(path, UrlParamsBuilder.build());
    return jsonObject.getLong("data");
  }
 
  @Override
  public List<DepositWithdraw> getDepositWithdraw(DepositWithdrawRequest request) {
 
    InputChecker.checker()
        .shouldNotNull(request.getType(), "type");
    UrlParamsBuilder builder = UrlParamsBuilder.build()
        .putToUrl("type", request.getType().getType())
        .putToUrl("currency", request.getCurrency())
        .putToUrl("from", request.getFrom())
        .putToUrl("size", request.getSize())
        .putToUrl("direct", request.getDirection() == null ? null : request.getDirection().getCode());
 
    JSONObject jsonObject = restConnection.executeGetWithSignature(DEPOSIT_WITHDRAW_PATH, builder);
    JSONArray data = jsonObject.getJSONArray("data");
    return new DepositWithdrawParser().parseArray(data);
  }
 
  @Override
  public WithdrawOrderResult getWithdrawOrder(String clientOrderId) {
    InputChecker.checker()
            .shouldNotNull(clientOrderId, "clientOrderId");
    UrlParamsBuilder builder = UrlParamsBuilder.build()
            .putToUrl("clientOrderId", clientOrderId);
 
    JSONObject jsonObject = restConnection.executeGetWithSignature(GET_WITHDRAW_ORDER_PATH, builder);
    JSONObject data = jsonObject.getJSONObject("data");
    return new WithdrawOrderResultParser().parse(data);
  }
 
 
}