Raja covered most here I guess but I'd advise to avoid eval unless very very necessary. So yeah, just for reference you could use the following "bracket notation property accessor":
ticker[tickerName]
const path = require("path");
const Max = require("max-api");
const nodeBinanceApi = require("node-binance-api");
let tickerName; // Holds the ticker pair name (eg BTCUSDT)
const binance = require("node-binance-api")().options({
APIKEY: "<key>",
APISECRET: "<secret>",
// If you get timestamp errors, synchronize to server time at startup
useServerTime: true,
// If you want to use sandbox mode where orders are simulated
test: true
});
// This will be printed directly to the Max console
Max.post(`loaded the ${path.basename(__filename)} script`);
// Use the 'addHandler' function to register a function for a particular message
Max.addHandler("tickerNameSelector", (tickerName) => {
binance.prices(tickerName, (error, ticker) => {
Max.post("Price of BTCUSDT: ", ticker.BTCUSDT);
Max.post("Price of BTCUSDT: ", ticker[tickerName]);
});
});