0

I am trying to use jq to get certain information from this endpoint

curl -s https://bittrex.com/api/v1.1/public/getmarketsummaries/ | jq '[.]'

and the output below

[
  {
    "success": true,
    "message": "",
    "result": [
      {
        "MarketName": "BTC-1ST",
        "High": 0.00010322,
        "Low": 9.32e-05,
        "Volume": 1475820.53114847,
        "Last": 9.414e-05,
        "BaseVolume": 145.89904728,
        "TimeStamp": "2017-10-05T00:32:45.283",
        "Bid": 9.415e-05,
        "Ask": 9.521e-05,
        "OpenBuyOrders": 614,
        "OpenSellOrders": 5887,
        "PrevDay": 0.00010169,
        "Created": "2017-06-06T01:22:35.727"
      },
      {
        "MarketName": "BTC-2GIVE",
        "High": 1.31e-06,
        "Low": 1.24e-06,
        "Volume": 4356547.69360079,
        "Last": 1.29e-06,
        "BaseVolume": 5.59000303,
        "TimeStamp": "2017-10-05T00:21:46.333",
        "Bid": 1.29e-06,
        "Ask": 1.31e-06,
        "OpenBuyOrders": 298,
        "OpenSellOrders": 2290,
        "PrevDay": 1.29e-06,
        "Created": "2016-05-16T06:44:15.287"
      },
      {
        "MarketName": "BTC-ABY",
        "High": 1.89e-06,
        "Low": 1.62e-06,
        "Volume": 31422008.3611497,
        "Last": 1.68e-06,
        "BaseVolume": 53.99330434,
        "TimeStamp": "2017-10-05T00:25:21.307",
        "Bid": 1.68e-06,
        "Ask": 1.7e-06,
        "OpenBuyOrders": 437,
        "OpenSellOrders": 4761,
        "PrevDay": 1.63e-06,
        "Created": "2014-10-31T01:43:25.743"
      }

When i try to get only MarketName

curl -s https://bittrex.com/api/v1.1/public/getmarketsummaries/ | jq '.[] | select(.MarketName=="BTC-1ST")'

i get the following error

jq: error (at <stdin>:0): Cannot index boolean with string "MarketName"

Other errors

curl -s https://bittrex.com/api/v1.1/public/getmarketsummaries/ | jq '.[1]'

and i get this

jq: error (at <stdin>:0): Cannot index object with number

Anyone know the right command to get those?

uberrebu
  • 503
  • 6
  • 17
  • 36

2 Answers2

1

If you want everything in the {} that matches that marketName you can do

$ curl -s https://bittrex.com/api/v1.1/public/getmarketsummaries/ | jq '.result[] | select(.MarketName=="BTC-1ST")'
{
  "MarketName": "BTC-1ST",
  "High": 0.00010322,
  "Low": 8.402e-05,
  "Volume": 1820113.98502106,
  "Last": 8.799e-05,
  "BaseVolume": 175.00575508,
  "TimeStamp": "2017-10-05T03:40:26.463",
  "Bid": 8.799e-05,
  "Ask": 8.817e-05,
  "OpenBuyOrders": 329,
  "OpenSellOrders": 6316,
  "PrevDay": 0.00010101,
  "Created": "2017-06-06T01:22:35.727"
}

If you want to list all the MarketNames you can do

$ curl -s https://bittrex.com/api/v1.1/public/getmarketsummaries/ | jq '.result[].MarketName'
"BTC-1ST"
"BTC-2GIVE"
"BTC-ABY"
....

Also must programming landuages the lists start at 0.. so if I want to get the first item in the list in jq I can do

jq '.[0]'

There's only 1 list item so that's why you get an error if you use [1]

Mike
  • 22,310
  • 7
  • 56
  • 79
  • did you try to test the commands with the url i gave? the url is public anyways your commands not working still – uberrebu Oct 05 '17 at 03:38
  • `curl -s https://bittrex.com/api/v1.1/public/getmarketsummaries/ | jq '.[].result[] | select(.MarketName=="BTC-1ST")'` error `jq: error (at :0): Cannot index boolean with string "result"` AND `curl -s https://bittrex.com/api/v1.1/public/getmarketsummaries/ | jq '.[].result[].MarketName'` error `jq: error (at :0): Cannot index boolean with string "result"` – uberrebu Oct 05 '17 at 03:39
  • updated the answer to work with the site.. you example has the wrong json from what is returned from the curl call – Mike Oct 05 '17 at 03:42
0

Know this is awhile ago, but I was able to do it by having

| jq '.[0.].result'
Gerald Schneider
  • 23,274
  • 8
  • 57
  • 89