¿Hay alguna documentación útil sobre el uso de la API de MtGox con node.js?

He estado buscando ayuda para construir una plataforma usando un nodo que funcione con la API de MtGox. Parece fácil hacer una solicitud, pero estoy confundido acerca de cómo pasar un parámetro.

En este momento, mi código comienza como a continuación. Puedo acceder al servidor y obtener datos básicos del mercado, pero no sé cómo hacer nada más...

request = require('request');

APIResponder = require('../libraries/apiresponder');

exports.market_data = function(req, res, next){
  request('https://mtgox.com/api/1/BTCUSD/ticker', function (err, response, body) {
    console.log(response);
    console.log(body);
    APIResponder.respond(res, response);
  });
};

Respuestas (2)

El wiki de Bitcoin tiene un buen programa de ejemplo :

var querystring = require('querystring'),
        https = require('https'),
        crypto = require('crypto');

function MtGoxClient(key, secret) {
        this.key = key;
        this.secret = secret;
}

MtGoxClient.prototype.query = function(path, args, callback) {
        var client = this;

        // if no args or invalid args provided, just reset the arg object
        if (typeof args != "object") args = {};

        // generate a nonce
        args['nonce'] = (new Date()).getTime() * 1000;
        // compute the post data
        var post = querystring.stringify(args);
        // compute the sha512 signature of the post data
        var hmac = crypto.createHmac('sha512', new Buffer(client.secret, 'base64'));
        hmac.update(post);

        // this is our query
        var options = {
                host: 'mtgox.com',
                port: 443,
                path: '/api/' + path,
                method: 'POST',
                agent: false,
                headers: {
                        'Rest-Key': client.key,
                        'Rest-Sign': hmac.digest('base64'),
                        'User-Agent': 'Mozilla/4.0 (compatible; MtGox node.js client)',
                        'Content-type': 'application/x-www-form-urlencoded',
                        'Content-Length': post.length
                }
        };

        // run the query, buffer the data and call the callback
        var req = https.request(options, function(res) {
                res.setEncoding('utf8');
                var buffer = '';
                res.on('data', function(data) { buffer += data; });
                res.on('end', function() { if (typeof callback == "function") { callback(JSON.parse(buffer)); } });
        });

        // basic error management
        req.on('error', function(e) {
                console.log('warning: problem with request: ' + e.message);
        });

        // post the data
        req.write(post);
        req.end();
};

var client = new MtGoxClient('mykey', 'mysecret');
client.query('1/BTCUSD/public/ticker', {}, function(json) {
        // do something
        console.log(json);
});

Aquí está la documentación para la API v1

Quería agregar a esto, para la API de streaming/ws, la wiki se vincula a un repositorio de git de ralphtheninja, quien proporcionó una biblioteca para una transmisión legible de node.js para mtgox.

Básicamente, convierte la transmisión en una transmisión node.js. Objeto legible.