Created
February 9, 2019 16:05
-
-
Save bennycode/317ad971a04266c10cdf0ebb1972a2ff to your computer and use it in GitHub Desktop.
Log Coinbase buy transactions
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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