How to use cryptocomapre api to display price of BTC?
I'm working on an electron app and im using cryptocompare api to display BTC price but it dosen't displays. I've tried every solution i could think of, some help would be appreciated!!
const electron = require('electron');
const path = require('path');
const BrowserWindow = electron.remote.BrowserWindow;
const axios = require('axios');
const notifyBtn = document.querySelector('.notify-btn');
const price = document.querySelector('.price');
const targetPrice = document.querySelector('.target-price');
function getBTC(){
const cryptos = axios.get('https://min-api.cryptocompare.com/data/price?fsym=BTC&tsyms=USD&api_key={api_key}')
price.innerHTML = '$'+cryptos
}
getBTC();
setInterval(getBTC, 20000);
It gives me an output of '$[object Promise]'
api electron bitcoin
add a comment |
I'm working on an electron app and im using cryptocompare api to display BTC price but it dosen't displays. I've tried every solution i could think of, some help would be appreciated!!
const electron = require('electron');
const path = require('path');
const BrowserWindow = electron.remote.BrowserWindow;
const axios = require('axios');
const notifyBtn = document.querySelector('.notify-btn');
const price = document.querySelector('.price');
const targetPrice = document.querySelector('.target-price');
function getBTC(){
const cryptos = axios.get('https://min-api.cryptocompare.com/data/price?fsym=BTC&tsyms=USD&api_key={api_key}')
price.innerHTML = '$'+cryptos
}
getBTC();
setInterval(getBTC, 20000);
It gives me an output of '$[object Promise]'
api electron bitcoin
add a comment |
I'm working on an electron app and im using cryptocompare api to display BTC price but it dosen't displays. I've tried every solution i could think of, some help would be appreciated!!
const electron = require('electron');
const path = require('path');
const BrowserWindow = electron.remote.BrowserWindow;
const axios = require('axios');
const notifyBtn = document.querySelector('.notify-btn');
const price = document.querySelector('.price');
const targetPrice = document.querySelector('.target-price');
function getBTC(){
const cryptos = axios.get('https://min-api.cryptocompare.com/data/price?fsym=BTC&tsyms=USD&api_key={api_key}')
price.innerHTML = '$'+cryptos
}
getBTC();
setInterval(getBTC, 20000);
It gives me an output of '$[object Promise]'
api electron bitcoin
I'm working on an electron app and im using cryptocompare api to display BTC price but it dosen't displays. I've tried every solution i could think of, some help would be appreciated!!
const electron = require('electron');
const path = require('path');
const BrowserWindow = electron.remote.BrowserWindow;
const axios = require('axios');
const notifyBtn = document.querySelector('.notify-btn');
const price = document.querySelector('.price');
const targetPrice = document.querySelector('.target-price');
function getBTC(){
const cryptos = axios.get('https://min-api.cryptocompare.com/data/price?fsym=BTC&tsyms=USD&api_key={api_key}')
price.innerHTML = '$'+cryptos
}
getBTC();
setInterval(getBTC, 20000);
It gives me an output of '$[object Promise]'
api electron bitcoin
api electron bitcoin
asked Jan 1 at 11:42
CybilCybil
134
134
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
In the documentation for axios, it says you need to do this instead:
axios.get(url)
.then(function (response) {
// do something with response
});
This is because the value returned by axios.get
isn't a response, it's a promise that will resolve to a response. (So it gets coerced to the string [object Promise]
.) If you don't know what this means, read this link. Basically promises are a way of dealing with tasks that take a long time to run (such as api calls) without blocking other javascript code from runnning. But anyway, what you want is this:
function getBTC(){
axios.get('https://min-api.cryptocompare.com/data/price?fsym=BTC&tsyms=USD&api_key={api_key}')
.then(function(response) {
var data = response.data;
var cryptos = // get cryptos from data somehow
price.innerHTML = '$'+cryptos;
});
}
I haven't read the axios documentation in detail. I believe what you are looking for is in response.data
, but I couldn't tell you any more than that. Try console.log('Response:', response);
to find out how the response is structured.
Now Im getting $undefined.
– Cybil
Jan 1 at 13:52
That wasn't a complete answer, because I couldn't figure out all the details from the documentation. I meant that you need to find out howresponse
is structured by logging it (or possibly by reading the docs more thoroughly than I did). Then you can replace thevar cryptos
line with something more sensible. Currently it's joining that line onto the next line because it doesn't end with a semicolon; so it's equivalent tovar cryptos; price.innerHTML = '$'+cryptos; cryptos = price.innerHTML;
. That's why it's setting the price to$undefined
.
– David Knipe
Jan 1 at 16:47
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53995137%2fhow-to-use-cryptocomapre-api-to-display-price-of-btc%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
In the documentation for axios, it says you need to do this instead:
axios.get(url)
.then(function (response) {
// do something with response
});
This is because the value returned by axios.get
isn't a response, it's a promise that will resolve to a response. (So it gets coerced to the string [object Promise]
.) If you don't know what this means, read this link. Basically promises are a way of dealing with tasks that take a long time to run (such as api calls) without blocking other javascript code from runnning. But anyway, what you want is this:
function getBTC(){
axios.get('https://min-api.cryptocompare.com/data/price?fsym=BTC&tsyms=USD&api_key={api_key}')
.then(function(response) {
var data = response.data;
var cryptos = // get cryptos from data somehow
price.innerHTML = '$'+cryptos;
});
}
I haven't read the axios documentation in detail. I believe what you are looking for is in response.data
, but I couldn't tell you any more than that. Try console.log('Response:', response);
to find out how the response is structured.
Now Im getting $undefined.
– Cybil
Jan 1 at 13:52
That wasn't a complete answer, because I couldn't figure out all the details from the documentation. I meant that you need to find out howresponse
is structured by logging it (or possibly by reading the docs more thoroughly than I did). Then you can replace thevar cryptos
line with something more sensible. Currently it's joining that line onto the next line because it doesn't end with a semicolon; so it's equivalent tovar cryptos; price.innerHTML = '$'+cryptos; cryptos = price.innerHTML;
. That's why it's setting the price to$undefined
.
– David Knipe
Jan 1 at 16:47
add a comment |
In the documentation for axios, it says you need to do this instead:
axios.get(url)
.then(function (response) {
// do something with response
});
This is because the value returned by axios.get
isn't a response, it's a promise that will resolve to a response. (So it gets coerced to the string [object Promise]
.) If you don't know what this means, read this link. Basically promises are a way of dealing with tasks that take a long time to run (such as api calls) without blocking other javascript code from runnning. But anyway, what you want is this:
function getBTC(){
axios.get('https://min-api.cryptocompare.com/data/price?fsym=BTC&tsyms=USD&api_key={api_key}')
.then(function(response) {
var data = response.data;
var cryptos = // get cryptos from data somehow
price.innerHTML = '$'+cryptos;
});
}
I haven't read the axios documentation in detail. I believe what you are looking for is in response.data
, but I couldn't tell you any more than that. Try console.log('Response:', response);
to find out how the response is structured.
Now Im getting $undefined.
– Cybil
Jan 1 at 13:52
That wasn't a complete answer, because I couldn't figure out all the details from the documentation. I meant that you need to find out howresponse
is structured by logging it (or possibly by reading the docs more thoroughly than I did). Then you can replace thevar cryptos
line with something more sensible. Currently it's joining that line onto the next line because it doesn't end with a semicolon; so it's equivalent tovar cryptos; price.innerHTML = '$'+cryptos; cryptos = price.innerHTML;
. That's why it's setting the price to$undefined
.
– David Knipe
Jan 1 at 16:47
add a comment |
In the documentation for axios, it says you need to do this instead:
axios.get(url)
.then(function (response) {
// do something with response
});
This is because the value returned by axios.get
isn't a response, it's a promise that will resolve to a response. (So it gets coerced to the string [object Promise]
.) If you don't know what this means, read this link. Basically promises are a way of dealing with tasks that take a long time to run (such as api calls) without blocking other javascript code from runnning. But anyway, what you want is this:
function getBTC(){
axios.get('https://min-api.cryptocompare.com/data/price?fsym=BTC&tsyms=USD&api_key={api_key}')
.then(function(response) {
var data = response.data;
var cryptos = // get cryptos from data somehow
price.innerHTML = '$'+cryptos;
});
}
I haven't read the axios documentation in detail. I believe what you are looking for is in response.data
, but I couldn't tell you any more than that. Try console.log('Response:', response);
to find out how the response is structured.
In the documentation for axios, it says you need to do this instead:
axios.get(url)
.then(function (response) {
// do something with response
});
This is because the value returned by axios.get
isn't a response, it's a promise that will resolve to a response. (So it gets coerced to the string [object Promise]
.) If you don't know what this means, read this link. Basically promises are a way of dealing with tasks that take a long time to run (such as api calls) without blocking other javascript code from runnning. But anyway, what you want is this:
function getBTC(){
axios.get('https://min-api.cryptocompare.com/data/price?fsym=BTC&tsyms=USD&api_key={api_key}')
.then(function(response) {
var data = response.data;
var cryptos = // get cryptos from data somehow
price.innerHTML = '$'+cryptos;
});
}
I haven't read the axios documentation in detail. I believe what you are looking for is in response.data
, but I couldn't tell you any more than that. Try console.log('Response:', response);
to find out how the response is structured.
answered Jan 1 at 12:32
David KnipeDavid Knipe
2,59611216
2,59611216
Now Im getting $undefined.
– Cybil
Jan 1 at 13:52
That wasn't a complete answer, because I couldn't figure out all the details from the documentation. I meant that you need to find out howresponse
is structured by logging it (or possibly by reading the docs more thoroughly than I did). Then you can replace thevar cryptos
line with something more sensible. Currently it's joining that line onto the next line because it doesn't end with a semicolon; so it's equivalent tovar cryptos; price.innerHTML = '$'+cryptos; cryptos = price.innerHTML;
. That's why it's setting the price to$undefined
.
– David Knipe
Jan 1 at 16:47
add a comment |
Now Im getting $undefined.
– Cybil
Jan 1 at 13:52
That wasn't a complete answer, because I couldn't figure out all the details from the documentation. I meant that you need to find out howresponse
is structured by logging it (or possibly by reading the docs more thoroughly than I did). Then you can replace thevar cryptos
line with something more sensible. Currently it's joining that line onto the next line because it doesn't end with a semicolon; so it's equivalent tovar cryptos; price.innerHTML = '$'+cryptos; cryptos = price.innerHTML;
. That's why it's setting the price to$undefined
.
– David Knipe
Jan 1 at 16:47
Now Im getting $undefined.
– Cybil
Jan 1 at 13:52
Now Im getting $undefined.
– Cybil
Jan 1 at 13:52
That wasn't a complete answer, because I couldn't figure out all the details from the documentation. I meant that you need to find out how
response
is structured by logging it (or possibly by reading the docs more thoroughly than I did). Then you can replace the var cryptos
line with something more sensible. Currently it's joining that line onto the next line because it doesn't end with a semicolon; so it's equivalent to var cryptos; price.innerHTML = '$'+cryptos; cryptos = price.innerHTML;
. That's why it's setting the price to $undefined
.– David Knipe
Jan 1 at 16:47
That wasn't a complete answer, because I couldn't figure out all the details from the documentation. I meant that you need to find out how
response
is structured by logging it (or possibly by reading the docs more thoroughly than I did). Then you can replace the var cryptos
line with something more sensible. Currently it's joining that line onto the next line because it doesn't end with a semicolon; so it's equivalent to var cryptos; price.innerHTML = '$'+cryptos; cryptos = price.innerHTML;
. That's why it's setting the price to $undefined
.– David Knipe
Jan 1 at 16:47
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53995137%2fhow-to-use-cryptocomapre-api-to-display-price-of-btc%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown