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