0

I'm trying to scrape the binance price

I play arround with.

price1=$(echo -s https://api.binance.com/api/v3/ticker/price?symbol=ETHBTC | grep -o 'price":"[^"]*' | cut -d\" -f3)
echo $price1

I got the price but also an error like:

line 15: https://api.binance.com/api/v3/ticker/price?symbol=ETHBTC:

No such file or directory

someone can explain me how to use it correctly maybe

finally I like to have it in dollar

cyber4nt
  • 1
  • 1
  • See [https://stackoverflow.com/questions/3742983/how-to-get-the-contents-of-a-webpage-in-a-shell-variable](https://stackoverflow.com/questions/3742983/how-to-get-the-contents-of-a-webpage-in-a-shell-variable) – Irfan434 Mar 07 '19 at 10:42
  • cool thank you iam not far away from the solution :-) – cyber4nt Mar 07 '19 at 11:02
  • curl https://api.binance.com/api/v3/ticker/price?symbol=ETHBTC > tmp_file cat tmp_file | grep 'price":"[^"]*' | cut -d'>' -f4 | cut -d'<' -f3 – cyber4nt Mar 07 '19 at 11:03

1 Answers1

0

echo -s doesn't do anything special on my Linux. It just prints -s.

Use curl to download the data and jq to process it.
It is as simple as:

curl -s 'https://api.binance.com/api/v3/ticker/price?symbol=ETHBTC' | jq -r .price

The arguments of jq:

  • .price is the price property of the current object (.).
  • -r tells it to return raw data; the value of .price is a string in the JSON downloaded from the URL.
axiac
  • 68,258
  • 9
  • 99
  • 134