Search code examples
javascriptnode.jsexpressrequestcoinbase-api

External API not being called within express route


I am trying to make a call to an external library from within an express route, but I'm not getting a response from the library, not even an error. I am supplying the library with the necessary credentials, but it never seems to invoke the function.

var express = require("express");
var router = express.Router();
var { CoinbasePro } = require('coinbase-pro-node');

router.get("/", function (req, res, next) {
    let query = req.query

    var auth = {
        apiKey: query.api_key,
        apiSecret: query.secret_key,
        passphrase: query.passphrase,
    };
    
    var client = new CoinbasePro(auth);

    client.rest.account.listAccounts().then(accounts => {
        const message = `You can trade "${accounts.length}" different pairs.`;
        res.send(message)

    }).catch((error) => {
        res.send(error)
    })
});

module.exports = router;

This is what I have so far, any help would be greatly appreciated!


Solution

  • Turns out that the auth for the coinbase-pro-node library requires a "useSandbox" property. I solved it with this.

    var auth = {
        apiKey: query.api_key,
        apiSecret: query.secret_key,
        passphrase: query.passphrase,
        useSandbox: false
    };