Closed elbojoloco closed 5 years ago
If you provide a callback function then the first argument is error
. You can see the example here. The following code will show you the ticker (if there is no error)
Client.getProductTicker('BTC-USD', (error, response, data) => {
console.log(data);
});
Thanks @vansergen!
I tried the following but still got a null value.
publicClient.getProductTrades(instrument, (e, res, data) => {
console.log("this is snapshot_data");
console.log(e)
})
Also, are we required to add a header (with the API secret) to get public data? I've followed the API GET request format on https://docs.pro.coinbase.com/#get-trades but I get a "CB-ACCESS-KEY header is required" error.
Thanks in advance! :)
@shimeilee, there is no need to add headers (the library does it for you). You got null
value because there was no error in your request (as I wrote in the previous answer). It simply means that you made a successful request. I suggest you read REAMDE. It contains some examples. So, if you want to get the trades you can do something like this (using callbacks)
publicClient.getProductTrades('ETH-BTC', (error, response, data) => {
if (error) {
// handle errors here
console.error(error);
} else {
// work with data here
console.log(data);
}
});
or with async/await
let myFunc = async function() {
try {
console.log(await publicClient.getProductTrades('ETH-BTC'));
} catch (error) {
console.error(error);
}
};
myFunc();
Thank you! My bad on my carelessness.
Thanks for the info everyone :)
I follow the simple instructions from the documentation on this package and the api, but my basic script just returns null and exits:
Even when keeping the script alive it does not show anything else than
null
once, what am I doing wrong?