Git Product home page Git Product logo

coinbase's Introduction

Coinbase

Coinbase is a wrapper around the Coinbase.com bitcoin wallet and exchange API.

How to use it:

Require coinbase

var Coinbase = require('coinbase');
var coinbase = new Coinbase({
  APIKey: process.env.COINBASE_API_KEY,
  APISecret: process.env.COINBASE_API_SECRET
});

Make a call to the API using a chosen method.

coinbase.account.balance(function (err, data) {
  if (err) throw err;
  log('data: ' + util.inspect(data));
  data.should.have.property('amount');
  data.should.have.property('currency', 'BTC');
  done();
});

The following methods have been implemented and work against the Coinbase api.

TOC

coinbase.account.balance

should return account balance.

coinbase.account.balance(function (err, data) {
  if (err) throw err;
  log('data: ' + util.inspect(data));
  data.should.have.property('amount');
  data.should.have.property('currency', 'BTC');
  done();
});

coinbase.account.receiveAddress

should return the user's current bitcoin receive address.

coinbase.account.receiveAddress(function (err, data) {
  if (err) throw err;
  log('data: ' + util.inspect(data));
  data.should.have.property('success', true);
  data.should.have.property('address');
  data.should.have.property('callback_url');
  done();
});

coinbase.account.generateReceiveAddress

should generate a new receive address.

coinbase.account.generateReceiveAddress(function (err, data) {
  if (err) throw err;
  log('data: ' + util.inspect(data));
  data.should.have.property('success', true);
  data.should.have.property('address');
  data.should.have.property('callback_url');
  done();
});

should generate a new receive address with callback.

coinbase.account.generateReceiveAddress('https://www.example.com/callback', function (err, data) {
  if (err) throw err;
  log('data: ' + util.inspect(data));
  data.should.have.property('success', true);
  data.should.have.property('address');
  data.should.have.property('callback_url'); // TODO: enforce callback value ***api is currently not passing this back. may be a bug in the api
  done();
});

coinbase.button

should generate a new button.

var param = {
              "button": {
                "name": 'test',
                "price_string": '1.23',
                "price_currency_iso": 'USD',
                "custom": 'Order123',
                "description": 'Sample description',
                "type": 'buy_now',
                "style": 'custom_large'
              }
            };
coinbase.buttons.create(param, function (err, data) {
  if (err) throw err;
  log('data: ' + util.inspect(data));
  data.should.have.property('success', true);
  data.should.have.property('button');
  data.button.should.have.property('code');
  data.button.should.have.property('type');
  data.button.should.have.property('style');
  data.button.should.have.property('text');
  data.button.should.have.property('name');
  data.button.should.have.property('description');
  data.button.should.have.property('custom');
  data.button.should.have.property('price');
  done();
});

coinbase.buy

coinbase.contacts

should return the user's previously emailed contacts.

coinbase.contacts(function (err, data) {
  if (err) throw err;
  log('data: ' + util.inspect(data));
  data.should.have.property('contacts');
  data.should.have.property('total_count');
  data.should.have.property('num_pages');
  data.should.have.property('current_page');
  done();
});

coinbase.currencies.list

should return list of supported currencies.

coinbase.currencies.list(function (err, data) {
  if (err) throw err;
  log('data: ' + util.inspect(data));
  data.length.should.be.above(0);
  done();
});

coinbase.currencies.exchangeRates

should return current currency exchange rates.

coinbase.currencies.exchangeRates(function (err, data) {
  if (err) throw err;
  log('data: ' + util.inspect(data));
  data.should.have.property('btc_to_usd');
  data.should.have.property('usd_to_btc');
  done();
});

coinbase.orders.list

should return list of supported orders.

coinbase.orders.list(function (err, data) {
  if (err) throw err;
  log('data: ' + util.inspect(data));
  data.should.have.property('orders');
  data.should.have.property('total_count');
  data.should.have.property('num_pages');
  data.should.have.property('current_page');
  done();
});

coinbase.orders.get

coinbase.orders.create

should create a new order.

var param = {
              "button": {
                "name": "test",
                "type": "buy_now",
                "price_string": "1.23",
                "price_currency_iso": "USD"
              }
            };
coinbase.orders.create(param, function (err, data) {
  if (err) throw err;
  log('data: ' + util.inspect(data));
  data.should.have.property('id');
  data.should.have.property('order');
  done();
});

coinbase.prices.buy

should return the total buy price for some bitcoin amount.

coinbase.prices.buy(function (err, data) {
  if (err) throw err;
  log('data: ' + util.inspect(data));
  data.should.have.property('amount');
  data.should.have.property('currency');
  done();
});

coinbase.prices.sell

should return the total sell price for some bitcoin amount.

coinbase.prices.sell(function (err, data) {
  if (err) throw err;
  log('data: ' + util.inspect(data));
  data.should.have.property('amount');
  data.should.have.property('currency');
  done();
});

coinbase.transactions.list

should return the user's most recent transactions.

coinbase.transactions.list(function (err, data) {
  if (err) throw err;
  log('data: ' + util.inspect(data));
  data.should.have.property('current_user');
  data.should.have.property('balance');
  data.should.have.property('total_count');
  data.should.have.property('transactions');
  done();
});

coinbase.transactions.get

coinbase.transfers.list

should return the user's most recent transfers.

coinbase.transfers.list(function (err, data) {
  if (err) throw err;
  log('data: ' + util.inspect(data));
  data.should.have.property('transfers');
  data.should.have.property('total_count');
  data.should.have.property('num_pages');
  data.should.have.property('current_page');
  done();
});

TODO:

The api currently only supports access via the API Key method. Oauth is next.

The following methods are implemented, but not yet tested:

  • GET /api/v1/orders/:id
  • GET /api/v1/transactions/:id

The following methods are implemented, but don't seem to match the actual api (parameters or constraints cause failure):

  • POST /api/v1/buys *

The following methods are not yet implemented:

  • POST /api/v1/sells
  • POST /api/v1/transactions/send_money
  • POST /api/v1/transactions/request_money
  • PUT /api/v1/transactions/:id/resend_request
  • DELETE /api/v1/transactions/:id/cancel_request
  • PUT /api/v1/transactions/:id/complete_request
  • POST /api/v1/users
  • PUT /api/v1/users/:id

* The following error is returned from the cb api when calling /buys:

  1. coinbase #buys should buy one btc:
  CoinbaseError: Price can't be blank
      at Request._callback (/Users/matt/development/coinbase/lib/index.js:67:22)
      at Request.self.callback (/Users/matt/development/coinbase/node_modules/request/index.js:142:22)
      at Request.EventEmitter.emit (events.js:98:17)
      at Request.<anonymous> (/Users/matt/development/coinbase/node_modules/request/index.js:856:14)
      at Request.EventEmitter.emit (events.js:117:20)
      at IncomingMessage.<anonymous> (/Users/matt/development/coinbase/node_modules/request/index.js:808:12)
      at IncomingMessage.EventEmitter.emit (events.js:117:20)
      at _stream_readable.js:895:16
      at process._tickCallback (node.js:415:13)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.