Need Help with command - Nightbot URLFETCH

I was able to search for this command which works

$(eval try{a=$(urlfetch json https://api.binance.com/api/v1/ticker/price?symbol=BTCUSDT);Binance BTC $ ${parseFloat(a.price)};}catch(e){Error!;})

But when I tried with the command below, I get a NaN

$(eval try{a=$(urlfetch json https://api.upbit.com/v1/candles/minutes/1?market=KRW-BTC&count=1);Upbit BTC ${parseFloat(a.trade_price)};}catch(e){Error!;})

I’m assuming that the second command is giving me a NaN because of the [ ] brackets.
After some hours of trying I’ve come to the point I must request for some help how to resolve this.

Hey @cdtank!

The [] brackets means that the data is stored in an array, you get a NaN error because you’re trying to exploit data of an array without accessing one of its item first, the fix simply consists of specifying which item of the array you want to read the content from: a[0].trade_price

1 Like

I came up with a different answer, to slice the brackets.

$(eval a= $(urlfetch json https://api.upbit.com/v1/candles/minutes/1?market=KRW-BTC&count=1).slice(1,-1); JSON.parse(a).trade_price;)

but I didn’t get any luck with

$(eval try{a=$(urlfetch json https://api.upbit.com/v1/candles/minutes/1?market=KRW-BTC&count=1 );Upbit BTC ${parseFloat(a[0].trade_price)};}catch(e){Error!;})

Uh? I’m sorry but this command works:

$(eval try{a=$(urlfetch json https://api.upbit.com/v1/candles/minutes/1?market=KRW-BTC&count=1);`Upbit BTC ${parseFloat(a[0].trade_price)}`;}catch(e){`Error!`;})

You have to be careful about the backticks ⁣` that the forum uses to format the text when you post your code outside of a code area.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.