Maxximiliann

Maxximiliann

Parsing nested JSON

(Please Note: Elixir Experience Level: Beginner)

From mix.exs-

defp deps do
    [
      	{:httpoison, "~> 1.6"},
	{:poison, "~> 4.0"}
    ]
  end


In IEX - 

iex(2)> res = HTTPoison.get! ("https://api.wavesplatform.com/v0/pairs")

%HTTPoison.Response{
 body: "{\"__type\":\"list\",\"data\":[{\"__type\":\"pair\",\"data\":{\"firstPrice\":0.22605,\"lastPrice\":0.183,\"low\":0.182,\"high\":0.22605,\"weightedAveragePrice\":0.199292871612085,\"volume\":732311.857444342,\"quoteVolume\":145944.532985663,\"volumeWaves\":145944.532985663,\"txsCount\":2974},\"amountAsset\":\"4LHHvYGNKJUg5hj65aGD5vgScvCBmLpdRFtjokvCjSL8\",\"priceAsset\":\"WAVES\"},{\"__type\":\"pair\",\"data\":{\"firstPrice\":0.00010967,\"lastPrice\":0.00011121,\"low\":0.0001078,\"high\":0.000113,\"weightedAveragePrice\":0.000111679201769491,\"volume\":138114.26699538,\"quoteVolume\":15.4244910910224,\"volumeWaves\":138114.26699538,\"txsCount\":2192},\"amountAsset\":\"WAVES\",\"priceAsset\":\"8LQW8f7P5d5PZM7GtZEBgaqRPGSzS3DfPuiXrURJ4AJS\"},{\"__type\":\"pair\",\"data\":{\"firstPrice\":8360,\"lastPrice\":8630.71,\"low\":8183,\"high\":8666,\"weightedAveragePrice\":8322.46563502579,\"volume\":8.95597220000001,\"quoteVolume\":74535.7708627464,\"volumeWaves\":78239.1291224059,\"txsCount\":267},\"amountAsset\":\"8LQW8f7P5d5PZM7GtZEBgaqRPGSzS3DfPuiXrURJ4AJS\",\"priceAsset\":\"Ft8X1v1LTa1ABafufpaCWyVj8KkaxUWE6xBhW6sNFJck\"},{\"__type\":\"pair\",\"data\":{\"firstPrice\":196.16698506,\"lastPrice\":197.61817326,\"low\":191.9827021,\"high\":198.35016891,\"weightedAveragePrice\":194.200358923929,\"volume\":306.50228458,\"quoteVolume\":59522.8536764403,\"volumeWaves\":59522.8536764403,\"txsCount\":1083},\"amountAsset\":\"474jTeYx2r2Va35794tCScAXWJG9hU2HcgxzMowaZUnu\",\"priceAsset\":\"WAVES\"},{\"__type\":\"pair\",\"data\":{\"firstPrice\":0.00001699,\"lastPrice\":0.00002001,\"low\":0.000012,\"high\":0.000037,\"weightedAveragePrice\":0.0000182454824214892,\"volume\":2569761604.661,\"quoteVolume\":46886.54018526,\"volumeWaves\":46886.54018526,\"txsCount\":60},\"amountAsset\":\"7x5Efh41w4k2Q2ikxHQtAa9uR91qnmGQMVkqcb2SPfde\",\"priceAsset\":\"WAVES\"},{\"__type\":\"pair\",\"data\":{\"firstPrice\":0.02134005,\"lastPrice\":0.02198548,\"low\":0.02134005,\"high\":0.0220278,\"weightedAveragePrice\":0.0217290690497021,\"volume\":185.14934025,\"quoteVolume\":4.02312279879904,\"volumeWaves\":36023.9215096012,\"txsCount\":549},\"amountAsset\":\"474jTeYx2r2Va35794tCScAXWJG9hU2HcgxzMowaZUnu\",\"priceAsset\":\"8LQW8f7P5d5PZM7GtZEBgaqRPGSzS3DfPuiXrURJ4AJS\"},{\"__type\":\"pair\",\"data\":{\"firstPrice\":0.99,\"lastPrice\":0.99999999,\"low\":0.99,\"high\":1,\"weightedAveragePrice\":0.998652039818104,\"volume\":52032.18850477,\"quoteVolume\":51962.0511864887,\"volumeWaves\":31260.1893633205,\"txsCount\":30},\"amountAsset\":\"725Yv9oceWsB4GsYwyy4A52kEwyVrL5avubkeChSnL46\",\"priceAsset\":\"5dJj4Hn9t2Ve3tRpNGirUHy4yBK6qdJRAJYV21yPPuGz\"},{\"__type\":\"pair\",\"data\":{\"firstPrice\":0.91,\"lastPrice\":0.96,\"low\":0.91,\"high\":0.97,\"weightedAveragePrice\":0.952666162044499,\"volume\":20147.36196732,\"quoteVolume\":19193.7100007281,\"volumeWaves\":20147.36196732,\"txsCount\":272},\"amountAsset\":\"WAVES\",\"priceAsset\":\"Ft8X1v1LTa1ABafufpaCWyVj8KkaxUWE6xBhW6sNFJck\"},{\"__type\":\"pair\",\"data\":{\"firstPrice\":1.00999999,\"lastPrice\":0.11999999,\"low\":0.11999999,\"high\":1.11,\"weightedAveragePrice\":1.03881808932202,\"volume\":15639.51718921,\"quoteVolume\":16246.613364414,\"volumeWaves\":16246.613364414,\"txsCount\":34},\"amountAsset\":\"3k6vM987VAEVKJdD1J9eaXB2qi48Q7iYTEct7g9DMmtv\",\"priceAsset\":\"WAVES\"},{\"__type\":\"pair\",\"data\":{\"firstPrice\":1500,\"lastPrice\":1500,\"low\":1500,\"high\":1501,\"weightedAveragePrice\":1500.01449275362,\"volume\":69,\"quoteVolume\":103501,\"volumeWaves\":14951.0923323936,\"txsCount\":69},\"amountAsset\":\"DHgwrRvVyqJsepd32YbBqUeDH4GJ1N984X8QoekjgH8J\",\"priceAsset\":\"7zoGYmqorrybHZRtrykZeshHtia176fzTuwdQq6bAjw2\"},{\"__type\":\"pair\",\"data\":{\"firstPrice\":0.00002419,\"lastPrice\":0.00002046,\"low\":0.00002002,\"high\":0.00002464,\"weightedAveragePrice\":0.0000225360286772358,\"volume\":70983.3606095201,\"quoteVolume\":1.59968305030272,\"volumeWaves\":14323.9119277062,\"txsCount\":3268},\"amountAsset\":\"4LHHvYGNKJUg5hj65aGD5vgScvCBmLpdRFtjokvCjSL8\",\"priceAsset\":\"8LQW8f7P5d5PZM7GtZEBgaqRPGSzS3DfPuiXrURJ4AJS\"},{\"__type\":\"pair\",\"data\":{\"firstPrice\":0.14638502,\"lastPrice\":0.14500003,\"low\":0.1395,\"high\":0.14967,\"weightedAveragePrice\":0.144453602693632,\"volume\":89246.9499999998,\"quoteVolume\":12892.0434569184,\"volumeWaves\":12892.0434569184,\"txsCount\":2795},\"amountAsset\":\"DHgwrRvVyqJsepd32YbBqUeDH4GJ1N984X8QoekjgH8J\",\"priceAsset\":\"WAVES\"},{\"__type\":\"pair\"," <> ...,
  headers: [
    {"Date", "Mon, 07 Oct 2019 20:06:35 GMT"},
    {"Content-Type", "application/json; charset=utf-8"},
    {"Transfer-Encoding", "chunked"},
    {"Connection", "keep-alive"},
    {"Set-Cookie",
     "__cfduid=d9231e750fe82d310888154f4f764b65f1570478794; expires=Tue, 06-Oct-20 20:06:34 GMT; path=/; domain=.wavesplatform.com; HttpOnly"},
    {"Vary", "Accept-Encoding"},
    {"X-Request-Id", "cb1c8ff5-5c32-4248-b05b-c5c718b66bf4"},
    {"Vary", "Origin"},
    {"X-Cache-Status", "EXPIRED"},
    {"Access-Control-Allow-Origin", "*"},
    {"Access-Control-Allow-Credentials", "true"},
    {"Access-Control-Allow-Methods", "PUT, GET, POST, OPTIONS"},
    {"Access-Control-Allow-Headers",
     "DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Authorization"},
    {"Strict-Transport-Security", "max-age=15724800; includeSubDomains"},
    {"CF-Cache-Status", "DYNAMIC"},
    {"Expect-CT",
     "max-age=604800, report-uri=\"https://report-uri.cloudflare.com/cdn-cgi/beacon/expect-ct\""},
    {"Server", "cloudflare"},
    {"CF-RAY", "52227f12cf6dc7bd-DEN"}
  ],
  request: %HTTPoison.Request{
    body: "",
    headers: [],
    method: :get,
    options: [],
    params: %{},
    url: "https://api.wavesplatform.com/v0/pairs"
  },
  request_url: "https://api.wavesplatform.com/v0/pairs",
  status_code: 200
}

iex(3)> res.body

"{\"__type\":\"list\",\"data\":[{\"__type\":\"pair\",\"data\":{\"firstPrice\":0.22605,\"lastPrice\":0.183,\"low\":0.182,\"high\":0.22605,\"weightedAveragePrice\":0.199292871612085,\"volume\":732311.857444342,\"quoteVolume\":145944.532985663,\"volumeWaves\":145944.532985663,\"txsCount\":2974},\"amountAsset\":\"4LHHvYGNKJUg5hj65aGD5vgScvCBmLpdRFtjokvCjSL8\",\"priceAsset\":\"WAVES\"},{\"__type\":\"pair\",\"data\":{\"firstPrice\":0.00010967,\"lastPrice\":0.00011121,\"low\":0.0001078,\"high\":0.000113,\"weightedAveragePrice\":0.000111679201769491,\"volume\":138114.26699538,\"quoteVolume\":15.4244910910224,\"volumeWaves\":138114.26699538,\"txsCount\":2192},\"amountAsset\":\"WAVES\",\"priceAsset\":\"8LQW8f7P5d5PZM7GtZEBgaqRPGSzS3DfPuiXrURJ4AJS\"},{\"__type\":\"pair\",\"data\":{\"firstPrice\":8360,\"lastPrice\":8630.71,\"low\":8183,\"high\":8666,\"weightedAveragePrice\":8322.46563502579,\"volume\":8.95597220000001,\"quoteVolume\":74535.7708627464,\"volumeWaves\":78239.1291224059,\"txsCount\":267},\"amountAsset\":\"8LQW8f7P5d5PZM7GtZEBgaqRPGSzS3DfPuiXrURJ4AJS\",\"priceAsset\":\"Ft8X1v1LTa1ABafufpaCWyVj8KkaxUWE6xBhW6sNFJck\"},{\"__type\":\"pair\",\"data\":{\"firstPrice\":196.16698506,\"lastPrice\":197.61817326,\"low\":191.9827021,\"high\":198.35016891,\"weightedAveragePrice\":194.200358923929,\"volume\":306.50228458,\"quoteVolume\":59522.8536764403,\"volumeWaves\":59522.8536764403,\"txsCount\":1083},\"amountAsset\":\"474jTeYx2r2Va35794tCScAXWJG9hU2HcgxzMowaZUnu\",\"priceAsset\":\"WAVES\"},{\"__type\":\"pair\",\"data\":{\"firstPrice\":0.00001699,\"lastPrice\":0.00002001,\"low\":0.000012,\"high\":0.000037,\"weightedAveragePrice\":0.0000182454824214892,\"volume\":2569761604.661,\"quoteVolume\":46886.54018526,\"volumeWaves\":46886.54018526,\"txsCount\":60},\"amountAsset\":\"7x5Efh41w4k2Q2ikxHQtAa9uR91qnmGQMVkqcb2SPfde\",\"priceAsset\":\"WAVES\"},{\"__type\":\"pair\",\"data\":{\"firstPrice\":0.02134005,\"lastPrice\":0.02198548,\"low\":0.02134005,\"high\":0.0220278,\"weightedAveragePrice\":0.0217290690497021,\"volume\":185.14934025,\"quoteVolume\":4.02312279879904,\"volumeWaves\":36023.9215096012,\"txsCount\":549},\"amountAsset\":\"474jTeYx2r2Va35794tCScAXWJG9hU2HcgxzMowaZUnu\",\"priceAsset\":\"8LQW8f7P5d5PZM7GtZEBgaqRPGSzS3DfPuiXrURJ4AJS\"},{\"__type\":\"pair\",\"data\":{\"firstPrice\":0.99,\"lastPrice\":0.99999999,\"low\":0.99,\"high\":1,\"weightedAveragePrice\":0.998652039818104,\"volume\":52032.18850477,\"quoteVolume\":51962.0511864887,\"volumeWaves\":31260.1893633205,\"txsCount\":30},\"amountAsset\":\"725Yv9oceWsB4GsYwyy4A52kEwyVrL5avubkeChSnL46\",\"priceAsset\":\"5dJj4Hn9t2Ve3tRpNGirUHy4yBK6qdJRAJYV21yPPuGz\"},{\"__type\":\"pair\",\"data\":{\"firstPrice\":0.91,\"lastPrice\":0.96,\"low\":0.91,\"high\":0.97,\"weightedAveragePrice\":0.952666162044499,\"volume\":20147.36196732,\"quoteVolume\":19193.7100007281,\"volumeWaves\":20147.36196732,\"txsCount\":272},\"amountAsset\":\"WAVES\",\"priceAsset\":\"Ft8X1v1LTa1ABafufpaCWyVj8KkaxUWE6xBhW6sNFJck\"},{\"__type\":\"pair\",\"data\":{\"firstPrice\":1.00999999,\"lastPrice\":0.11999999,\"low\":0.11999999,\"high\":1.11,\"weightedAveragePrice\":1.03881808932202,\"volume\":15639.51718921,\"quoteVolume\":16246.613364414,\"volumeWaves\":16246.613364414,\"txsCount\":34},\"amountAsset\":\"3k6vM987VAEVKJdD1J9eaXB2qi48Q7iYTEct7g9DMmtv\",\"priceAsset\":\"WAVES\"},{\"__type\":\"pair\",\"data\":{\"firstPrice\":1500,\"lastPrice\":1500,\"low\":1500,\"high\":1501,\"weightedAveragePrice\":1500.01449275362,\"volume\":69,\"quoteVolume\":103501,\"volumeWaves\":14951.0923323936,\"txsCount\":69},\"amountAsset\":\"DHgwrRvVyqJsepd32YbBqUeDH4GJ1N984X8QoekjgH8J\",\"priceAsset\":\"7zoGYmqorrybHZRtrykZeshHtia176fzTuwdQq6bAjw2\"},{\"__type\":\"pair\",\"data\":{\"firstPrice\":0.00002419,\"lastPrice\":0.00002046,\"low\":0.00002002,\"high\":0.00002464,\"weightedAveragePrice\":0.0000225360286772358,\"volume\":70983.3606095201,\"quoteVolume\":1.59968305030272,\"volumeWaves\":14323.9119277062,\"txsCount\":3268},\"amountAsset\":\"4LHHvYGNKJUg5hj65aGD5vgScvCBmLpdRFtjokvCjSL8\",\"priceAsset\":\"8LQW8f7P5d5PZM7GtZEBgaqRPGSzS3DfPuiXrURJ4AJS\"},{\"__type\":\"pair\",\"data\":{\"firstPrice\":0.14638502,\"lastPrice\":0.14500003,\"low\":0.1395,\"high\":0.14967,\"weightedAveragePrice\":0.144453602693632,\"volume\":89246.9499999998,\"quoteVolume\":12892.0434569184,\"volumeWaves\":12892.0434569184,\"txsCount\":2795},\"amountAsset\":\"DHgwrRvVyqJsepd32YbBqUeDH4GJ1N984X8QoekjgH8J\",\"priceAsset\":\"WAVES\"},{\"__type\":\"pair\"," <> ...

iex(4)> body = Poison.decode! res.body, keys: :atoms

%{
  __type: "list",
  data: [
    %{
      __type: "pair",
      amountAsset: "4LHHvYGNKJUg5hj65aGD5vgScvCBmLpdRFtjokvCjSL8",
      data: %{
        firstPrice: 0.22605,
        high: 0.22605,
        lastPrice: 0.183,
        low: 0.182,
        quoteVolume: 145944.532985663,
        txsCount: 2974,
        volume: 732311.857444342,
        volumeWaves: 145944.532985663,
        weightedAveragePrice: 0.199292871612085
      },
      priceAsset: "WAVES"
    },
    %{
      __type: "pair",
      amountAsset: "WAVES", 
      data: %{
        firstPrice: 1.0967e-4,
        high: 1.13e-4,
        lastPrice: 1.1121e-4,
        low: 1.078e-4,
        quoteVolume: 15.4244910910224,
        txsCount: 2192,
        volume: 138114.26699538,
        volumeWaves: 138114.26699538,
        weightedAveragePrice: 1.11679201769491e-4
      },
      priceAsset: "8LQW8f7P5d5PZM7GtZEBgaqRPGSzS3DfPuiXrURJ4AJS"
    },
    %{
      __type: "pair",
      amountAsset: "8LQW8f7P5d5PZM7GtZEBgaqRPGSzS3DfPuiXrURJ4AJS",
      data: %{
        firstPrice: 8360,
        high: 8666,
        lastPrice: 8630.71,
        low: 8183,
        quoteVolume: 74535.7708627464,
        txsCount: 267,
        volume: 8.95597220000001,
        volumeWaves: 78239.1291224059,
        weightedAveragePrice: 8322.46563502579
      },
      priceAsset: "Ft8X1v1LTa1ABafufpaCWyVj8KkaxUWE6xBhW6sNFJck"
    },
    %{
      __type: "pair",
      amountAsset: "474jTeYx2r2Va35794tCScAXWJG9hU2HcgxzMowaZUnu",
      data: %{
        firstPrice: 196.16698506,
        high: 198.35016891,
        lastPrice: 197.61817326,
        low: 191.9827021,
        quoteVolume: 59522.8536764403,
        txsCount: 1083,
        volume: 306.50228458,
        volumeWaves: 59522.8536764403,
        weightedAveragePrice: 194.200358923929
      },
      priceAsset: "WAVES"
    },
    %{
      __type: "pair",
      amountAsset: "7x5Efh41w4k2Q2ikxHQtAa9uR91qnmGQMVkqcb2SPfde",
      data: %{
        firstPrice: 1.699e-5,
        high: 3.7e-5,
        lastPrice: 2.001e-5,
        low: 1.2e-5,
        quoteVolume: 46886.54018526,
        txsCount: 60,
        volume: 2569761604.661,
        volumeWaves: 46886.54018526,
        weightedAveragePrice: 1.82454824214892e-5
      },
      priceAsset: "WAVES"
    },
    %{
      __type: "pair",
      amountAsset: "474jTeYx2r2Va35794tCScAXWJG9hU2HcgxzMowaZUnu",
      data: %{
        firstPrice: 0.02134005,
        high: 0.0220278,
        lastPrice: 0.02198548,
        low: 0.02134005,
        quoteVolume: 4.02312279879904,
        txsCount: 549,
        volume: 185.14934025,
        volumeWaves: 36023.9215096012,
        weightedAveragePrice: 0.0217290690497021
      },
      priceAsset: "8LQW8f7P5d5PZM7GtZEBgaqRPGSzS3DfPuiXrURJ4AJS"
    },
    %{
      __type: "pair",
      amountAsset: "725Yv9oceWsB4GsYwyy4A52kEwyVrL5avubkeChSnL46",
      data: %{
        firstPrice: 0.99,
        high: 1,
        lastPrice: 0.99999999,
        low: 0.99,
        quoteVolume: 51962.0511864887,
        txsCount: 30,
        volume: 52032.18850477,
        volumeWaves: 31260.1893633205,
        weightedAveragePrice: 0.998652039818104
      },
      priceAsset: "5dJj4Hn9t2Ve3tRpNGirUHy4yBK6qdJRAJYV21yPPuGz"
    },
    %{
      __type: "pair",
      amountAsset: "WAVES",
      data: %{
        firstPrice: 0.91,
        high: 0.97,
        lastPrice: 0.96,
        low: 0.91,
        quoteVolume: 19193.7100007281,
        txsCount: 272,
        volume: 20147.36196732,
        volumeWaves: 20147.36196732,
        weightedAveragePrice: 0.952666162044499
      },
      priceAsset: "Ft8X1v1LTa1ABafufpaCWyVj8KkaxUWE6xBhW6sNFJck"
    },
    %{
      __type: "pair",
      amountAsset: "3k6vM987VAEVKJdD1J9eaXB2qi48Q7iYTEct7g9DMmtv",
      data: %{
        firstPrice: 1.00999999,
        high: 1.11,
        lastPrice: 0.11999999,
        low: 0.11999999,
        quoteVolume: 16246.613364414,
        txsCount: 34,
        volume: 15639.51718921,
        volumeWaves: 16246.613364414,
        weightedAveragePrice: 1.03881808932202
      },
      priceAsset: "WAVES"
    },
    %{
      __type: "pair",
      amountAsset: "DHgwrRvVyqJsepd32YbBqUeDH4GJ1N984X8QoekjgH8J",
      data: %{
        firstPrice: 1500,
        high: 1501,
        lastPrice: 1500,
        low: 1500,
        quoteVolume: 103501,
        txsCount: 69,
        volume: 69,
        volumeWaves: 14951.0923323936,
        weightedAveragePrice: 1500.01449275362
      },
      priceAsset: "7zoGYmqorrybHZRtrykZeshHtia176fzTuwdQq6bAjw2"
    },
    %{
      __type: "pair",
      amountAsset: "4LHHvYGNKJUg5hj65aGD5vgScvCBmLpdRFtjokvCjSL8",
      data: %{
        firstPrice: 2.419e-5,
        high: 2.464e-5,
        lastPrice: 2.046e-5,
        low: 2.002e-5,
        quoteVolume: 1.59968305030272,
        txsCount: 3268,
        volume: 70983.3606095201,
        volumeWaves: 14323.9119277062,
        weightedAveragePrice: 2.25360286772358e-5
      },
      priceAsset: "8LQW8f7P5d5PZM7GtZEBgaqRPGSzS3DfPuiXrURJ4AJS"
    },
    %{
      __type: "pair",
      amountAsset: "DHgwrRvVyqJsepd32YbBqUeDH4GJ1N984X8QoekjgH8J",
      data: %{
        firstPrice: 0.14638502,
        high: 0.14967,
        lastPrice: 0.14500003,
        low: 0.1395,
        quoteVolume: 12892.0434569184,
        txsCount: 2795,
        volume: 89246.9499999998,
        volumeWaves: 12892.0434569184,
        weightedAveragePrice: 0.144453602693632
      },
      priceAsset: "WAVES"
    },
    %{
      __type: "pair",
      amountAsset: "3QvxP6YFBKpWJSMAfYtL8Niv8KmmKsnpb9uQwQpg8QN2",
      data: %{
        firstPrice: 0.14161615,
        high: 0.18650499,
        lastPrice: 0.13733208,
        low: 0.10000005,
        quoteVolume: 9284.31574452678,
        txsCount: 5674,
        volume: 71306.6199999999,
        volumeWaves: 9284.31574452678,
        weightedAveragePrice: 0.13020271812809
      },
      priceAsset: "WAVES"
    },
    %{
      __type: "pair",
      amountAsset: "WAVES",
      data: %{ 
        firstPrice: 0.86,
        high: 0.89,
        lastPrice: 0.89,
        low: 0.86,
        quoteVolume: 6152.0900002064,
        txsCount: 74,
        volume: 6965.50440782,
        volumeWaves: 6965.50440782,
        weightedAveragePrice: 0.883222468899682
      },
      priceAsset: "Gtb1WRznfchDnTh37ezoDTJ4wcoKaRsKqKjJjy7nm2zU"
    },
    %{
      __type: "pair",
      amountAsset: "5WvPKSJXzVE2orvbkJ8wsQmmQKqTv9sGBPksV4adViw3",
      data: %{
        firstPrice: 0.00695209,
        high: 0.00701179,
        lastPrice: 0.00692253,
        low: 0.0069058,
        quoteVolume: 0.744231823127807,
        txsCount: 91,
        volume: 106.91282378,
        volumeWaves: 6664.01452854153,
        weightedAveragePrice: 0.00696110903084227
      },
      priceAsset: "8LQW8f7P5d5PZM7GtZEBgaqRPGSzS3DfPuiXrURJ4AJS"
    },
    %{
      __type: "pair",
      amountAsset: "7uncmN7dZfV3fYVvNdYTngrrbamPYMgwpDnYG1bGy6nA",
      data: %{
        firstPrice: 6.5e-7,
        high: 1.45e-6,
        lastPrice: 4.5e-7,
        low: 4.0e-7,
        quoteVolume: 6443.91190275,
        txsCount: 65,
        volume: 10168871041,
        volumeWaves: 6443.91190275,
        weightedAveragePrice: 6.3369000125665e-7
      },
      priceAsset: "WAVES"
    },
    %{
      __type: "pair",
      amountAsset: "8LQW8f7P5d5PZM7GtZEBgaqRPGSzS3DfPuiXrURJ4AJS",
      data: %{
        firstPrice: 7598.19,
        high: 7990.56,
        lastPrice: 7970,
        low: 7350.47,
        quoteVolume: 3931.341608943,
        txsCount: 50,
        volume: 0.52597517,
        volumeWaves: 4451.13405441402,
        weightedAveragePrice: 7474.38630789929
      },
      priceAsset: "Gtb1WRznfchDnTh37ezoDTJ4wcoKaRsKqKjJjy7nm2zU"
    },
    %{
      __type: "pair",
      amountAsset: "HZk1mbfuJpmxU1Fs4AX5MWLVYtctsNcg6e2C6VKqK8zk",
      data: %{
        firstPrice: 62.79331273,
        high: 64,
        lastPrice: 63.29769846,
        low: 61.50326477,
        quoteVolume: 3998.40475546229,
        txsCount: 173,
        volume: 63.91732683,
        volumeWaves: 3998.40475546229,
        weightedAveragePrice: 62.5558820082822
      },
      priceAsset: "WAVES"
    },
    %{
      __type: "pair",
      amountAsset: "EYz8Zvs62D4d7F5ZgXHCWuzuFaZg63FYnfVQrTWQoLSK",
      data: %{
        firstPrice: 0.576495,
        high: 0.5825,
        lastPrice: 0.57099225,
        low: 0.5707614,
        quoteVolume: 3174.90322621713,
        txsCount: 524,
        volume: 5506.2269,
        volumeWaves: 3174.90322621713,
        weightedAveragePrice: 0.576602323855765
      },
      priceAsset: "WAVES"
    },
    %{
      __type: "pair",
      amountAsset: "B3uGHFRpSUuGEDWjqB9LWWxafQj8VTvpMucEyoxzws5H",
      data: %{
        firstPrice: 0.00868693,
        high: 0.00884691,
        lastPrice: 0.00869817,
        low: 0.00866753,
        quoteVolume: 0.34547501345214,
        txsCount: 95,
        volume: 39.60940106,
        volumeWaves: 3093.45883547065,
        weightedAveragePrice: 0.00872204588321892
      },
      priceAsset: "8LQW8f7P5d5PZM7GtZEBgaqRPGSzS3DfPuiXrURJ4AJS"
    },
    %{
      __type: "pair",
      amountAsset: "GSFvcF6ycBfXwPJLLKMExRsHWnvVdZQFHtGiYu4A2kZP",
      data: %{
        firstPrice: 16,
        high: 17,
        lastPrice: 17,
        low: 16,
        quoteVolume: 24800,
        txsCount: 2,
        volume: 1500,
        volumeWaves: 2864.4,
        weightedAveragePrice: 16.5333333333333
      },
      priceAsset: "5f1txDysSx2fVDjgXMdNpuprpdgXKjoHPtebL3SrMGzE"
    },
    %{
      __type: "pair",
      amountAsset: "GSFvcF6ycBfXwPJLLKMExRsHWnvVdZQFHtGiYu4A2kZP",
      data: %{
        firstPrice: 9.3,
        high: 9.4,
        lastPrice: 9.4,
        low: 9.3,
        quoteVolume: 22577.5,
        txsCount: 2,
        volume: 2425,
        volumeWaves: 2607.70125,
        weightedAveragePrice: 9.31030927835052
      },
      priceAsset: "FP2rjWYBQfqBpdLCDBaZvCtzikMozEyDbxsKyaWA76oB"
    },
    %{
      __type: "pair",
      amountAsset: "474jTeYx2r2Va35794tCScAXWJG9hU2HcgxzMowaZUnu",
      data: %{
        firstPrice: 180,
        high: 189,
        lastPrice: 189,
        low: 180,
        quoteVolume: 2449.820040127,
        txsCount: 44,
        volume: 13.15984533,
        volumeWaves: 2571.54094239003,
        weightedAveragePrice: 186.158725934433
      },
      priceAsset: "Ft8X1v1LTa1ABafufpaCWyVj8KkaxUWE6xBhW6sNFJck"
    },
    %{
      __type: "pair",
      amountAsset: "EYz8Zvs62D4d7F5ZgXHCWuzuFaZg63FYnfVQrTWQoLSK",
      data: %{
        firstPrice: 6.299e-5,
        high: 6.56e-5,
        lastPrice: 6.439e-5,
        low: 6.264e-5,
        quoteVolume: 0.263133663575,
        txsCount: 132,
        volume: 4088.603,
        volumeWaves: 2356.15637832115,
        weightedAveragePrice: 6.43578414375277e-5
      },
      priceAsset: "8LQW8f7P5d5PZM7GtZEBgaqRPGSzS3DfPuiXrURJ4AJS"
    },
    %{
      __type: "pair",
      amountAsset: "HZk1mbfuJpmxU1Fs4AX5MWLVYtctsNcg6e2C6VKqK8zk",
      data: %{
        firstPrice: 0.00684655,
        high: 0.00709932,
        lastPrice: 0.00709932,
        low: 0.00684655,
        quoteVolume: 0.200204842927297,
        txsCount: 81,
        volume: 28.7176871,
        volumeWaves: 1792.67795395356,
        weightedAveragePrice: 0.00697148214722687
      },
      priceAsset: "8LQW8f7P5d5PZM7GtZEBgaqRPGSzS3DfPuiXrURJ4AJS"
    },
    %{
      __type: "pair",
      amountAsset: "BrjUWjndUanm5VsJkbUip8VRYy6LWJePtxya3FNv4TQa",
      data: %{
        firstPrice: 0.00450193,
        high: 0.00462602,
        lastPrice: 0.00459854,
        low: 0.00449978,
        quoteVolume: 0.162220171380536,
        txsCount: 59,
        volume: 35.38505513,
        volumeWaves: 1452.55489661686,
        weightedAveragePrice: 0.00458442613087815
      },
      priceAsset: "8LQW8f7P5d5PZM7GtZEBgaqRPGSzS3DfPuiXrURJ4AJS"
    },
    %{
      __type: "pair",
      amountAsset: "zMFqXuoyrn5w17PFurTqxB7GsS71fp9dfk6XFwxbPCy",
      data: %{
        firstPrice: 0.0246938,
        high: 0.0289,
        lastPrice: 0.02863482,
        low: 0.0246938,
        quoteVolume: 0.114129001132226,
        txsCount: 79,
        volume: 3.9819744,
        volumeWaves: 1021.93603933337,
        weightedAveragePrice: 0.028661410061357
      },
      priceAsset: "8LQW8f7P5d5PZM7GtZEBgaqRPGSzS3DfPuiXrURJ4AJS"
    },
    %{
      __type: "pair",
      amountAsset: "5b3UGNZXX5srkHUQWnEWEiaVtnNWmg5aLo5uZMdjWupH",
      data: %{
        firstPrice: 63.505,
        high: 63.505,
        lastPrice: 63.505,
        low: 63.505,
        quoteVolume: 930.52504855505,
        txsCount: 20,
        volume: 14.65278401,
        volumeWaves: 930.52504855505,
        weightedAveragePrice: 63.505
      },
      priceAsset: "WAVES"
    },
    %{
      __type: "pair",
      amountAsset: "4uK8i4ThRGbehENwa6MxyLtxAjAo1Rj9fduborGExarC",
      data: %{
        firstPrice: 0.01,
        high: 0.0123999,
        lastPrice: 0.00995306,
        low: 0.00983301,
        quoteVolume: 772.4827540199,
        txsCount: 158,
        volume: 76900.97,
        volumeWaves: 772.4827540199,
        weightedAveragePrice: 0.0100451626815618
      },
      priceAsset: "WAVES"
    },
    %{
      __type: "pair",
      amountAsset: "B3uGHFRpSUuGEDWjqB9LWWxafQj8VTvpMucEyoxzws5H",
      data: %{
        firstPrice: 79.43395902,
        high: 79.91894041,
        lastPrice: 78.06775212,
        low: 77.68111011,
        quoteVolume: 757.46507706448,
        txsCount: 75,
        volume: 9.63988277,
        volumeWaves: 757.46507706448,
        weightedAveragePrice: 78.5761710113079
      },
      priceAsset: "WAVES"
    },
    %{
      __type: "pair",
      amountAsset: "5dJj4Hn9t2Ve3tRpNGirUHy4yBK6qdJRAJYV21yPPuGz",
      data: %{
        firstPrice: 9.199e-5,
        high: 9.2e-5,
        lastPrice: 6.509e-5,
        low: 5.807e-5,
        quoteVolume: 0.0826308301517678,
        txsCount: 492,
        volume: 1249.20731894,
        volumeWaves: 739.894526845925,
        weightedAveragePrice: 6.61466106537731e-5
      },
      priceAsset: "8LQW8f7P5d5PZM7GtZEBgaqRPGSzS3DfPuiXrURJ4AJS"
    },
    %{
      __type: "pair",
      amountAsset: "zMFqXuoyrn5w17PFurTqxB7GsS71fp9dfk6XFwxbPCy",
      data: %{
        firstPrice: 252.12162161,
        high: 260.06813169,
        lastPrice: 256.62477782,
        low: 250.81545975,
        quoteVolume: 683.076959826616,
        txsCount: 70,
        volume: 2.66364912,
        volumeWaves: 683.076959826616,
        weightedAveragePrice: 256.44404688956
      },
      priceAsset: "WAVES"
    },
    %{
      __type: "pair",
      amountAsset: "BrjUWjndUanm5VsJkbUip8VRYy6LWJePtxya3FNv4TQa",
      data: %{
        firstPrice: 41.14304029,
        high: 41.4438984,
        lastPrice: 41.23528168,
        low: 40.45042107,
        quoteVolume: 625.035763618644,
        txsCount: 58,
        volume: 15.21948921,
        volumeWaves: 625.035763618644,
        weightedAveragePrice: 41.068117004082
      },
      priceAsset: "WAVES"
    },
    %{
      __type: "pair",
      amountAsset: "5WvPKSJXzVE2orvbkJ8wsQmmQKqTv9sGBPksV4adViw3",
      data: %{
        firstPrice: 63.35455619,
        high: 63.35455619,
        lastPrice: 62.13727713,
        low: 61.03366403,
        quoteVolume: 538.271381363297,
        txsCount: 61,
        volume: 8.62395678,
        volumeWaves: 538.271381363297,
        weightedAveragePrice: 62.4158254841459
      },
      priceAsset: "WAVES"
    },
    %{
      __type: "pair",
      amountAsset: "9jJq1tKm5J1bP4V4BBED1KnaYRmGUmTRndXVR9NkE3vY",
      data: %{
        firstPrice: 1.0e-8,
        high: 8.0e-8,
        lastPrice: 5.0e-8,
        low: 1.0e-8,
        quoteVolume: 530.91733368,
        txsCount: 35,
        volume: 12539522439,
        volumeWaves: 530.91733368,
        weightedAveragePrice: 4.23395178135938e-8
      },
      priceAsset: "WAVES"
    },
    %{
      __type: "pair",
      amountAsset: "EbLVSrAi6vS3AkLwBinzZCvAXP2yYiFJEzj1MBVHcwZ5",
      data: %{
        firstPrice: 4.5e-6,
        high: 4.55e-6,
        lastPrice: 4.53e-6,
        low: 4.3e-6,
        quoteVolume: 0.0575634900004158,
        txsCount: 32,
        volume: 12910.00041221,
        volumeWaves: 515.43608020434,
        weightedAveragePrice: 4.45882944712949e-6
      },
      priceAsset: "8LQW8f7P5d5PZM7GtZEBgaqRPGSzS3DfPuiXrURJ4AJS"
    },
    %{
      __type: "pair",
      amountAsset: "EFmBdhoQDy2vkpkC2am33ANwxBFLGeJwAmWGvJeVmWmE",
      data: %{
        firstPrice: 0.01,
        high: 0.01,
        lastPrice: 0.01,
        low: 0.01,
        quoteVolume: 432.58,
        txsCount: 5,
        volume: 43258,
        volumeWaves: 454.073018686471,
        ...
      },
      priceAsset: "Ft8X1v1LTa1ABafufpaCWyVj8KkaxUWE6xBhW6sNFJck"
    },
    %{
      __type: "pair",
      amountAsset: "51LxAtwBXapvvTFSbbh4nLyWFxH6x8ocfNvrXxbTChze",
      data: %{
        firstPrice: 9.7999e-4,
        high: 9.8997e-4,
        lastPrice: 8.1999e-4,
        low: 0.0008,
        quoteVolume: 445.264776097594,
        txsCount: 70,
        volume: 520269.648299,
        ...
      },
      priceAsset: "WAVES"
    },
    %{
      __type: "pair",
      amountAsset: "AgPZuyURTDCT5KGypZjAzKbReiHdKqLWzmUHaHvsYgEJ",
      data: %{
        firstPrice: 1,
        high: 1,
        lastPrice: 1,
        low: 1,
        quoteVolume: 445,
        txsCount: 89,
        ...
      },
      priceAsset: "WAVES"
    },
    %{
      __type: "pair",
      amountAsset: "C9GgiMrWxJpNVR1itPhy834DePjyPtUEv3ERw9qHx7KV",
      data: %{
        firstPrice: 0.0052,
        high: 0.0075,
        lastPrice: 0.0075,
        low: 0.0052,
        quoteVolume: 366.733936640136, 
        ...
      },
      priceAsset: "WAVES"
    },
    %{
      __type: "pair",
      amountAsset: "Gtb1WRznfchDnTh37ezoDTJ4wcoKaRsKqKjJjy7nm2zU",
      data: %{firstPrice: 1.06, high: 1.1, lastPrice: 1.07, low: 1.06, ...},
      priceAsset: "Ft8X1v1LTa1ABafufpaCWyVj8KkaxUWE6xBhW6sNFJck"
    },
    %{
      __type: "pair",
      amountAsset: "DbngchPv6y1an7TQHQPEQ3uMj5ms5Qd46QVTgbgZ6ht3",
      data: %{firstPrice: 5.0e-8, high: 7.0e-8, lastPrice: 7.0e-8, ...},
      priceAsset: "WAVES"
    },
    %{
      __type: "pair",
      amountAsset: "291eANuyaSj9NiZTkMTXhktUudhFuYvR714BfqrshAWa",
      data: %{firstPrice: 0.93110333, high: 0.9511155, ...},
      priceAsset: "WAVES"
    },
    %{
      __type: "pair",
      amountAsset: "62LyMjcr2DtiyF5yVXFhoQ2q414VPPJXjsNYp72SuDCH",
      data: %{firstPrice: 0.01033244, ...},
      priceAsset: "8LQW8f7P5d5PZM7GtZEBgaqRPGSzS3DfPuiXrURJ4AJS"
    },
    %{
      __type: "pair",
      amountAsset: "2AvD9e9XxWaX1R7haCXKEWVEs6wkHpzWP4BCygRg9Q1E",
      data: %{...},
      ...
    },
    %{__type: "pair", amountAsset: "WAVES", ...},
    %{__type: "pair", ...},
    %{...},
    ...
  ]
}

How would I go about extracting amountAsset, priceAsset, volumeWaves, lastPrice for all pairs where volumeWaves >= 500 as quickly as possible?

Thanks in advance for all your input! :slight_smile:

Marked As Solved

pdgonzalez872

pdgonzalez872

Hi @Maxximiliann! Since you said your were starting out, I decided to show you a couple of things about Elixir! Hopefully this helps you in your journey. :slight_smile:

I created a repo here: https://github.com/pdgonzalez872/maxximiliann that has an acceptance_test file. There, I show a couple of things about your problem, how to use some tools to your advantage (tests, pry) and ultimately help you with your question. For completeness, I added the content of the file below. Please read the code and hopefully this helps you in your journey.

PD

defmodule AcceptanceTest do
  use ExUnit.Case

  test "should work" do
    # Since you mentioned you are starting out, here are a couple of things you
    # may not know. If you do, disregard them.
    # You can use `require IEx; IEx.pry` to start a debugging session within a test.
    # You can then run the tests like so: `iex -S mix test`
    # more about Pry here: https://medium.com/@diamondgfx/debugging-phoenix-with-iex-pry-5417256e1d11

    # Uncomment line 20 below to allow pry to run in this test and when the
    # debugger asks you if you want to "Allow" Pry, press "Y" to jump in the
    # session. It is an IEx session, but through tests. Helpful to debug things
    # that you need to go back to later. If you need more than 60 seconds in
    # your debugging session (very common), pass the `trace` flag to the mix
    # command like so: `iex -S mix test --trace` to make the test have a
    # timeout of `infinity`.

    # require IEx; IEx.pry

    # I'm going to use the code you posted to keep things the same. Apples to
    # apples. :)

    res = HTTPoison.get!("https://api.wavesplatform.com/v0/pairs")
    body = Poison.decode!(res.body, keys: :atoms)

    # `body` is a `map` with the following keys:
    # We prove this by having the assertion below pass. If the keys were not
    # the same, this test would fail.
    assert Map.keys(body) == [:__type, :data]

    # we can see that `body.data` is a `list`:
    assert is_list(body.data) == true

    # you can also write the same thing above like this:
    assert is_list(body.data)

    # This is what the first element in your collection looks like:
    first_element = Enum.at(body.data, 0)

    # Using IO.inspect() is a great way to look at the shape your data has:
    msg = "This will print out to the terminal when you run the test, this is what first_element looks like"
    IO.inspect(first_element, label: msg)

    # These are the keys you have in `first_element`
    assert Map.keys(first_element) == [:__type, :amountAsset, :data, :priceAsset]

    # You mentioned you wanted `volumeWaves` for each element. You can see that
    # you don't have that key in that first map.
    # This is what you have inside `data`:
    assert Map.keys(first_element.data) == [:firstPrice, :high, :lastPrice, :low, :quoteVolume, :txsCount, :volume,
     :volumeWaves, :weightedAveragePrice]

    # There is a little hiccup with your data, you are getting floats back from
    # your api call, which is fine, but I suggest using a library when
    # dealing with float values. A great one is this one:
    # https://github.com/ericmj/decimal
    # Here is proof you have a float:
    assert is_float(first_element.data.firstPrice)

    # To answer your original question: When dealing with collections
    # (enumerables), look at the functions in `Enum`:
    # https://github.com/elixir-lang/elixir/blob/master/lib/elixir/lib/enum.ex
    # Here is `map/2`. The number by the function name is the number of
    # arguments it takes (called arity). `Map` iterates through the enumerable
    # you pass and keeps the result of a function you pass in as a second
    # argument:
    all_volume_waves_prices = Enum.map(body.data, fn element -> element.data.volumeWaves end)
    IO.inspect(all_volume_waves_prices)

    # To answer your question, we can also filter enumerables: `Enum.filter/2`
    # will return the element that returns `true` in the function you pass in
    # as a second argument:
    volume_waves_greater_than_500 = Enum.filter(body.data, fn element -> element.data.volumeWaves > 500.0 end)
    IO.inspect(volume_waves_greater_than_500)

    # Hope this helps. Thanks for asking the question and I hope you keep using Elixir.
  end
end

On a side note, here is a guide to markdown: Basic Syntax | Markdown Guide. It’s nice to be able to format things in these forums, helps you get your point across faster.

Also Liked

kokolegorille

kokolegorille

BTW there is a missing attribute in your code. To make it work You need to add a missing data, like this. (data is an internal struct of pair)

iex> body.data |> Enum.filter(fn pair -> pair.data.volumeWaves >= 500 end)
Maxximiliann

Maxximiliann

Oh wow!!

Thank you so very much!!

I am humbled by your kindness and generosity :slight_smile: :slight_smile: :slight_smile:

kokolegorille

kokolegorille

We all started as beginner :slight_smile:

But You are true, Elixir errors are often self explanatory…

except dialyzer messages :slight_smile:

Last Post!

dimitarvp

dimitarvp

Yes, they require PhD-s. :003:

Where Next?

Popular in Questions Top

rms.mrcs
Hi, I need to transform a list of numbers into a map where the keys are the indexes and the values are the original values of the list. ...
New
vonH
In asking this question I am more interested about the expressiveness of the language itself and less concerned about the availability of...
New
skosch
To my knowledge, put_in, Map.update etc. all have the one limitation of not automatically creating intermediate keys when needed (for exa...
New
lanycrost
Hi everyone! I need implement if…else if…else condition from my elixir code, and anymore of this control flow structures not work proper...
New
lessless
I believe there are people here who are dealing with CSV files import on the daily basis, and since Excel is a really popular tool there ...
New
mcarvalho
What is the difference between System.get_env and Application.get_env? For example, what are best practices to use one versus another.
New
Harrisonl
We have an ECS cluster with 4 services, where each task joins a single cluster, via discovery ECS discovery service. Currently when I de...
New

Other popular topics Top

Qqwy
Original source of discussion: This topic on the Pragmatic Programmers’ Functional Web Development with Elixir, OTP, and Phoenix forum. ...
New
vonH
When I run the Plug and I recompile I wind up having to use Ctrl C to quit iex and start again. Witht the help of rlwrap I can use the cu...
New
axelson
This post is a wiki (feel free to hit the edit button near the bottom right of this post to add your own changes!) This post collects co...
239 49134 226
New
sergio_101
I am VERY much an elixir newbie. I have taken one elixir course and one phoenix course on Udemy. During that course, I saw the instructor...
New
alice
Hey, Just curious what are the main benefits of Elixir compared to Clojure? When is Elixir more useful than Clojure and vice versa? Th...
New
jason.o
In the code below, if the create action is not set to accept “extra_key” as an input, it errors out with a message shown above. Is there ...
New

We're in Beta

About us Mission Statement