
org.oxerr.huobi.rest.service.HuobiDigest Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of huobi-client-rest Show documentation
Show all versions of huobi-client-rest Show documentation
Client for <a href="https://www.huobi.com">Huobi</a> RESTful API.
The newest version!
package org.oxerr.huobi.rest.service;
import static org.apache.commons.codec.digest.DigestUtils.md5Hex;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import javax.ws.rs.FormParam;
import si.mazi.rescu.Params;
import si.mazi.rescu.ParamsDigest;
import si.mazi.rescu.RestInvocation;
public class HuobiDigest implements ParamsDigest {
private final String secretKey;
public HuobiDigest(final String secretKey) {
this.secretKey = secretKey;
}
/**
* {@inheritDoc}
*/
@Override
public String digestParams(RestInvocation restInvocation) {
final Params params = restInvocation.getParamsMap().get(FormParam.class);
final Map nameValueMap = params.asHttpHeaders();
nameValueMap.remove("sign");
nameValueMap.remove("trade_password");
nameValueMap.put("secret_key", secretKey);
final List> nameValueList = new ArrayList<>(
nameValueMap.entrySet());
Collections.sort(nameValueList, new Comparator>() {
@Override
public int compare(
Entry o1,
Entry o2) {
return o1.getKey().compareTo(o2.getKey());
}
});
final Params newParams = Params.of();
for (Map.Entry param : nameValueList) {
newParams.add(param.getKey(), param.getValue());
}
final String message = newParams.asQueryString();
return md5Hex(message);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy