Skip to content

Instantly share code, notes, and snippets.

@bennycode
Created February 9, 2019 16:05
Show Gist options
  • Select an option

  • Save bennycode/317ad971a04266c10cdf0ebb1972a2ff to your computer and use it in GitHub Desktop.

Select an option

Save bennycode/317ad971a04266c10cdf0ebb1972a2ff to your computer and use it in GitHub Desktop.
Log Coinbase buy transactions
require('dotenv').config();
const Client = require('coinbase').Client;
const {promisify} = require('util');
const {COINBASE_API_KEY, COINBASE_API_SECRET} = process.env;
const client = new Client({
apiKey: COINBASE_API_KEY,
apiSecret: COINBASE_API_SECRET
});
(async () => {
const currency = 'ETH';
const accounts = await promisify(client.getAccounts.bind(client))({});
const account = accounts.find(account => (account.currency === currency));
const transactions = await promisify(account.getBuys.bind(account))(null);
transactions.forEach(transaction => {
console.log(`[${transaction.created_at}] Bought "${transaction.amount.amount} ${transaction.amount.currency}" for "${transaction.total.amount} ${transaction.total.currency}".`);
});
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment