Bitcoin Stack Exchange is a question and answer site for Bitcoin crypto-currency enthusiasts. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have been looking for some help building a platform using node that works with the MtGox api. It seems easy to make request, but I am confused about how to pass a parameter.

Right now my code starts off like below. I can hit the server and get basic market data but I don't know how to do anything else....

request = require('request');

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

exports.market_data = function(req, res, next){
  request('', function (err, response, body) {
    APIResponder.respond(res, response);
share|improve this question
up vote 2 down vote accepted

The Bitcoin wiki has a nice example program:

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'));

        // this is our query
        var options = {
                host: '',
                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) {
                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

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

Here's documentation for the v1 API

share|improve this answer

Wanted to add to this, for the streaming/ws API the wiki links to a git repo from ralphtheninja, who has provided a library for a node.js readable stream for mtgox.

Basically it converts the stream to a node.js stream.Readable object.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.