Bitcoin Forum
May 29, 2024, 09:55:49 PM *
News: Latest Bitcoin Core release: 27.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: accessing coinbase API using node.js  (Read 417 times)
btc junkie (OP)
Sr. Member
****
Offline Offline

Activity: 265
Merit: 250


View Profile
May 06, 2017, 05:27:13 AM
 #1

I'm having problems doing the simplest tasks such as displaying balance. I'm no pro at node.js but I think I should know enough to do this. Is anyoine familiar with the coinbase node.js API?

 Their website contains some basic code for listing accounts but this always returns NULL when I run it:

        var Client = require('coinbase').Client;
        var client = new Client({'apiKey': 'myApiKeyHere',
                         'apiSecret': 'myApiSecretHere'});

        client.getAccounts({}, function(err, accounts) {
          console.log(accounts);
        });

Does anyone have any experience with using this API? I'm willing to offer a $15 tip or more in btc if someone can help me with this API and some of the other node.js APIs. If you are willing to teach me this stuff for a higher fee then feel free to PM me about it. But I'm running on a low budget so I'm not in a position to pay the price of hiring a professional node.js developer.
Joel_Jantsen
Legendary
*
Offline Offline

Activity: 1890
Merit: 1310

Get your game girl


View Profile
May 06, 2017, 07:31:15 AM
 #2

I'm having problems doing the simplest tasks such as displaying balance. I'm no pro at node.js but I think I should know enough to do this. Is anyoine familiar with the coinbase node.js API?

 Their website contains some basic code for listing accounts but this always returns NULL when I run it:

        var Client = require('coinbase').Client;
        var client = new Client({'apiKey': 'myApiKeyHere',
                         'apiSecret': 'myApiSecretHere'});

        client.getAccounts({}, function(err, accounts) {
          console.log(accounts);
        });
->Make an account at coinbase,did you ?
-> Open the following link once logged in : https://www.coinbase.com/settings/api
->Click + New Api Key ->Enter your password ->Select all API wallets for which you suppose to write the code.
->Under Permissions : Tick whatever that applies for your application:
Code:
wallet:accounts:create wallet:accounts:delete
wallet:accounts:read wallet:accounts:update
wallet:addresses:create wallet:addresses:read
wallet:buys:create wallet:buys:read
wallet:checkouts:create wallet:checkouts:read
wallet:contacts:read wallet:deposits:create
wallet:deposits:read wallet:notifications:read
wallet:orders:create wallet:orders:read
wallet:orders:refund wallet:payment-methods:delete

Depending on your selection the API would get the details.After clicking create,you will be have a pop-up which displays your API key and API secret.Something like,
Quote
API Key details
NOTE: Please store these credentials in a safe place. For your protection, we will not show them again. If you misplace your API key, you should delete this API key and generate a new one.


API Key: DqpXhGBhLAbXdW40y

API Secret: YWPcmKSbKtqgS7do49t5kBiSyA0D397C

In your code,replace the values with the keys like
Code:
var Client = require('coinbase').Client;
var client = new Client({'apiKey': DqpXhGBhLAbXdW40y, 'apiSecret': YWPcmKSbKtqgS7do49t5kBiSyA0D397C});
You need an account Id for displaying balance and passing that id as a parameter.You need to write code for that,
Code:
//Should return accounts along with the ID
var coinbase = require('coinbase');
var client   = new coinbase.Client({'apiKey': DqpXhGBhLAbXdW40y, 'apiSecret': YWPcmKSbKtqgS7do49t5kBiSyA0D397C});

client.getAccounts({}, function(err, accounts) {
  accounts.forEach(function(acct) {
    console.log('my bal: ' + acct.balance.amount + ' for ' + acct.name);
  });
});

Displaying Balance from an account :
Code:
//Use the ID returned from above function and pass in that <Account ID> parameter
var coinbase = require('coinbase');
var client   = new coinbase.Client({'apiKey': DqpXhGBhLAbXdW40y, 'apiSecret': YWPcmKSbKtqgS7do49t5kBiSyA0D397C});

client.getAccount('<ACCOUNT ID>', function(err, account) {
  console.log('bal: ' + account.balance.amount + ' currency: ' + account.balance.currency);
});
That should be enough to display an account balance.

My Bitcoin address : 17HyAaFmjECaAsQJjWvevqtxb8GA44nxmd

Does anyone have any experience with using this API? I'm willing to offer a $15 tip or more in btc if someone can help me with this API and some of the other node.js APIs. If you are willing to teach me this stuff for a higher fee then feel free to PM me about it. But I'm running on a low budget so I'm not in a position to pay the price of hiring a professional node.js developer.

Send me a message .I'll be more than happy to teach you things.
btc junkie (OP)
Sr. Member
****
Offline Offline

Activity: 265
Merit: 250


View Profile
May 06, 2017, 05:21:52 PM
 #3

Yea I already created the API keys and set the relevant permissions already.

In your code,replace the values with the keys like
Code:
var Client = require('coinbase').Client;
var client = new Client({'apiKey': DqpXhGBhLAbXdW40y, 'apiSecret': YWPcmKSbKtqgS7do49t5kBiSyA0D397C});

Shouldn't I be passing these API keys as string 'DqpXhGBhLAbXdW40y'? Otherwise it tells me DqpXhGBhLAbXdW40y is undefined.


Code:
//Should return accounts along with the ID
var coinbase = require('coinbase');
var client   = new coinbase.Client({'apiKey': DqpXhGBhLAbXdW40y, 'apiSecret': YWPcmKSbKtqgS7do49t5kBiSyA0D397C});

client.getAccounts({}, function(err, accounts) {
  accounts.forEach(function(acct) {
    console.log('my bal: ' + acct.balance.amount + ' for ' + acct.name);
  });
});

^ The above code is what I initially used but I get an error at this line since the value is still null.
Code:
  accounts.forEach(function(acct) {



*Please note that I have followed the instructions obtained from github https://github.com/coinbase/coinbase-node but I'm not sure what specific files I'm supposed to copy and where I need to place them. I'm assuming this might be the cause of the error.*

 
Here is a screenshot of my code:



and this is a screenshot of the error I got:





Joel_Jantsen
Legendary
*
Offline Offline

Activity: 1890
Merit: 1310

Get your game girl


View Profile
May 07, 2017, 10:56:07 AM
 #4

Try the following code and let me know if that works.I don't really want to run the app locally so it will be better if you add on skype or something,much better to solve in real time.
Code:
client.getAccounts({}, function(err, accounts) {
  accounts.forEach(function(acct) {
    console.log(acct.name + ': ' + acct.balance.amount + ' ' + acct.balance.currency);
    acct.getTransactions(null, function(err, txns) {
      txns.forEach(function(txn) {
        console.log('txn: ' + txn.id);
      });
    });
  });
});

Yes that API keys should be passed a string only.
btc junkie (OP)
Sr. Member
****
Offline Offline

Activity: 265
Merit: 250


View Profile
May 07, 2017, 06:36:59 PM
 #5

Try the following code and let me know if that works.I don't really want to run the app locally so it will be better if you add on skype or something,much better to solve in real time.
Code:
client.getAccounts({}, function(err, accounts) {
  accounts.forEach(function(acct) {
    console.log(acct.name + ': ' + acct.balance.amount + ' ' + acct.balance.currency);
    acct.getTransactions(null, function(err, txns) {
      txns.forEach(function(txn) {
        console.log('txn: ' + txn.id);
      });
    });
  });
});

Yes that API keys should be passed a string only.

The error occurs at this line
Code:
accounts.forEach(function(acct) {
the extra code added comes after the error occurs and the app has already crashed.
Joel_Jantsen
Legendary
*
Offline Offline

Activity: 1890
Merit: 1310

Get your game girl


View Profile
May 07, 2017, 06:40:11 PM
 #6

Try the following code and let me know if that works.I don't really want to run the app locally so it will be better if you add on skype or something,much better to solve in real time.
Code:
client.getAccounts({}, function(err, accounts) {
  accounts.forEach(function(acct) {
    console.log(acct.name + ': ' + acct.balance.amount + ' ' + acct.balance.currency);
    acct.getTransactions(null, function(err, txns) {
      txns.forEach(function(txn) {
        console.log('txn: ' + txn.id);
      });
    });
  });
});

Yes that API keys should be passed a string only.

The error occurs at this line
Code:
accounts.forEach(function(acct) {
the extra code added comes after the error occurs and the app has already crashed.
Pretty sure you're doing something wrong.Have tested the network part in the console ? Is it receiving any data back ? Want me to take a look through teamviewer ? Otherwise I'll implement it locally tomorrow and check where you're going wrong..
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!