我正在尝试使用JS和PHP向Bitmex API发出发布请求。
这就是我所做的:
Javascript:
var post_data = {"symbol" : symbol, "side": side, "simpleOrderQty" : qty, "ordType" : ordType};
var path = '/api/v1/order';
var expire = Math.round((new Date()).getTime() / 1000) + 10;
var message = "POST" + path+ expire.toString() + data;
var secret = CryptoJS.HmacSHA256(message, secret).toString(CryptoJS.enc.Hex); // this is the secret that I will use in my php code
//hash from this string: POST/api/v1/order1541770067{"symbol":"XBTUSD","side":"Buy","simpleOrderQty":5,"ordType":"Market"} which looks like their example
但是,当我使用curl PHP时,如果将post字段设置为此:
{"symbol":"XBTUSD","side":"Buy","simpleOrderQty":5,"ordType":"Market"} // as a string
它给我一个“符号”是必需的参数,我认为如果正确,因为该字符串无论如何都不会起作用。
但是如果我使用
http_build_query(json_decode($that_string, true));
它将给出签名错误。
那么我应该如何处理它呢?