Authentication and Authorization
Regarding token and secret-key application and modification, please carry out the relevant operations on the "Personal Center - Open API" page.
Interface Permission Verification
Client requests the transaction interface, the headers must include the Nonce, token, Signature parameters. For example:
Python
$header[] = 'Nonce: 1534927978_ab43c';
$header[] = 'Token: 57ba172a6be125cca2f449826f9980ca';
$header[] = 'Signature: v490hupi0s0bckcp6ivb69p921';
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
token:
User Token, please check in "Personal Center - Open API".
Nonce:
Random Number, the client generates a random character with each request. Generation rule, timestamp_5 alphanumeric characters. For example: 1534927978_ab43c Note: The time deviation must not exceed 60 seconds, and the same random number can only be used once.
Signature:
Signature, calculated using $token, $secret_key, $nonce, $_POST, $_GET, verified by the server to ensure the request originates from the user.
Python Sample Code for Generating Signature:
Python
def sign(Nonce,data=dict()):
tmp = list()
tmp.append(TOKEN)
tmp.append(SECRET)
tmp.append(Nonce)
for d,x in data.items():
tmp.append(str(d) + "=" + str(x))
return hashlib.sha1(''.join(sorted(tmp))).hexdigest()
PHP Example Code for Generating Signature:
PHP
private function signature($nonce)
{
$token = TOKEN;
$secret_key = SECRET-KEY;
$tmpArr = array($api_key,$secret_key,$nonce);
foreach($_GET as $k=>$v){
$tmpArr[] = $k."=".$v;
}
foreach($_POST as $k=>$v){
$tmpArr[] = $k."=".$v;
}
sort($tmpArr, SORT_STRING);
$tmpStr = implode( $tmpArr );
$signature = sha1( $tmpStr );
return $signature;
}
Generating Signature Java Sample Code:
Java
List<String> paramArr = new ArrayList<>();
String token = "57ba172a6be125c";
String nonce = "1534927978_ab43c";
String secretKey = "ca2f449826f9980ca";
paramArr.add(token);
paramArr.add(secretKey);
paramArr.add(nonce);
//Get all request parameters
Enumeration enu=request.getParameterNames();
while(enu.hasMoreElements()){
String paramKv = "";
String paramName=(String)enu.nextElement();
String paramVal=request.getParameter(paramName);
paramKv += paramName;
paramKv += "=";
paramKv += paramVal;
paramArr.add(paramKv);
}
Collections.sort(paramArr, new Comparator<String>() {
@Override
public int compare(String o1, String o2) {
String str1=(String) o1;
String str2=(String) o2;
if (str1.compareToIgnoreCase(str2)<0){
return -1;
}
return 1;
}
});
//Convert Connection String
String paramStr = String.join("", paramArr);
String signature =DigestUtils.sha1Hex(paramStr);
Example:
Text Only
#Assumption:
$token = "57ba172a6be125c";
$secret_key = "ca2f449826f9980ca";
$nonce = "1534927978_ab43c";
#Request Interface URL
/openApi/entrust/currentList
# Submission Parameters
symbol = "BTC-USDT";
type = "1"
#Sorted String
1534927978_ab43c57ba172a6be125cca2f449826f9980casymbol=BTC-USDTtype=1
# After SHA1 calculation:
$signature is 731faa3d170bb746a767cea58ae563830594e1fe