我正在使用带有 socket.io-client 的 nodejs 连接到此处描述的 MtGox Streaming API:https ://en.bitcoin.it/wiki/MtGox/API/Streaming#Authenticated_commands
这些示例是用 php 编写的,我尽力将它们转换为 JS,但我不断收到来自服务器“无效调用”的响应
var sec_key_buffer = Buffer(secret_key, 'base64');
var hmac = crypto.createHmac('sha512', sec_key_buffer);
var nonce = Date.now() + "";
var id = crypto.createHash('md5').update(nonce).digest('hex');
var query = {
"call": 'private/info',
"id": id,
"nonce": nonce
};
var body = JSON.stringify(query);
var sign = hmac.update(body).digest('binary');
// The 'api_key' field has already stripped of the '-' character
var callBody = new Buffer(api_key + sign + body).toString('base64');
// 'connection' is the socket.io connection to 'https://socketio.mtgox.com/mtgox'
connection.json.send({
"op": "call",
"id": id,
"call": callBody,
"context": 'mtgox.com'
});
任何帮助,将不胜感激。