There is a more effective way to retrieve prices using the npm package, node-binance-api, rather than relying on the "coin" variable that I am currently struggling with. If anyone could assist me in finding a better solution or the optimal method for fetching prices using this package within Discord, it would be greatly appreciated. I have been stuck on this problem for quite some time now.
Here's what I'm looking for:
I need to replace "ticker.XRPBTC" (see code below).
For instance, if I input ETH, the goal is to change from ticker.XRPBTC to ticker.ETHBTC
var coin = (message.content.toUpperCase()).slice(2) + "BTC";
binance.prices((error, ticker) => {
console.log("Price of " + coin + ":", ticker.XRPBTC);
});
In an attempt to achieve this, I created the variable "coin," thinking that I could simply write ticker.coin but unfortunately, it does not work...
I have experimented with the following:
As an example:
ticker.XRPBTC - This code works, output: the actual price of the currency.
What I am trying:
var coin = XRPBTC
console.log(ticker.coin) - output: undefined
Moreover, when testing in the console by writing the following, I encounter an error:
if (msg.startsWith ("eth")) {
message.reply ("Price of " + coin + ":", ticker.TRXBTC);
}
An explanation of the functionality of "ticker":
The ticker serves the purpose of obtaining the most recent price for each currency, such as ETHBTC, XRPBTC, TRXBTC, etc. The currency pairs are represented here by eth, xrp, and trx. Therefore, in order to fetch the price for a specific pair, I must format it accordingly within the ticker function.
As demonstrated in the provided code snippet, I am structuring the text precisely as required by the ticker for accurate retrieval.
Hence, when I input eth, the variable "coin" automatically transforms it into ETHBTC
Thank you!