0

I am loading data from https://min-api.cryptocompare.com/data/histominute?fsym=BTC&tsym=ETH&limit=30&aggregate=1&e=CCCAGG

This is the return:

{"Response":"Success","Type":100,"Aggregated":false,"Data":[{"time":1504979760,"high":14.26,"low":14.26,"open":14.26,"volumefrom":4.8,"volumeto":68.49,"close":14.26},{"time":1504979820,"high":14.26,"low":14.27,"open":14.26,"volumefrom":2.57,"volumeto":36.77,"close":14.27},{"time":1504979880,"high":14.26,"low":14.27,"open":14.27,"volumefrom":7.41,"volumeto":105.66,"close":14.26},{"time":1504979940,"high":14.26,"low":14.26,"open":14.26,"volumefrom":3.69,"volumeto":52.61,"close":14.26},{"time":1504980000,"high":14.26,"low":14.27,"open":14.26,"volumefrom":11.23,"volumeto":160.79,"close":14.27},{"time":1504980060,"high":14.27,"low":14.28,"open":14.27,"volumefrom":7.29,"volumeto":104.76,"close":14.27},{"time":1504980120,"high":14.27,"low":14.27,"open":14.27,"volumefrom":4.75,"volumeto":67.76,"close":14.27},{"time":1504980180,"high":14.25,"low":14.28,"open":14.27,"volumefrom":8.25,"volumeto":117.58,"close":14.26},{"time":1504980240,"high":14.26,"low":14.27,"open":14.26,"volumefrom":12.54,"volumeto":178.73,"close":14.26},{"time":1504980300,"high":14.26,"low":14.26,"open":14.26,"volumefrom":7.65,"volumeto":109.08,"close":14.26},{"time":1504980360,"high":14.26,"low":14.26,"open":14.26,"volumefrom":6.88,"volumeto":98.26,"close":14.26},{"time":1504980420,"high":14.25,"low":14.26,"open":14.26,"volumefrom":9.28,"volumeto":132.44,"close":14.25},{"time":1504980480,"high":14.25,"low":14.26,"open":14.25,"volumefrom":80.94,"volumeto":1148.05,"close":14.26},{"time":1504980540,"high":14.22,"low":14.26,"open":14.26,"volumefrom":15.4,"volumeto":219.62,"close":14.26},{"time":1504980600,"high":14.24,"low":14.26,"open":14.26,"volumefrom":7.68,"volumeto":109.25,"close":14.24},{"time":1504980660,"high":14.22,"low":14.25,"open":14.24,"volumefrom":11.51,"volumeto":163.89,"close":14.23},{"time":1504980720,"high":14.23,"low":14.24,"open":14.23,"volumefrom":10.4,"volumeto":147.78,"close":14.24},{"time":1504980780,"high":14.23,"low":14.24,"open":14.24,"volumefrom":2.26,"volumeto":32.23,"close":14.24},{"time":1504980840,"high":14.23,"low":14.24,"open":14.24,"volumefrom":11.45,"volumeto":162.77,"close":14.24},{"time":1504980900,"high":14.23,"low":14.25,"open":14.24,"volumefrom":5.08,"volumeto":72.42,"close":14.24},{"time":1504980960,"high":14.24,"low":14.25,"open":14.24,"volumefrom":7.28,"volumeto":103.57,"close":14.24},{"time":1504981020,"high":14.24,"low":14.25,"open":14.24,"volumefrom":2.22,"volumeto":31.73,"close":14.25},{"time":1504981080,"high":14.25,"low":14.26,"open":14.25,"volumefrom":19.34,"volumeto":275.78,"close":14.26},{"time":1504981140,"high":14.26,"low":14.27,"open":14.26,"volumefrom":13.05,"volumeto":186.2,"close":14.27},{"time":1504981200,"high":14.27,"low":14.28,"open":14.27,"volumefrom":4.95,"volumeto":70.65,"close":14.27},{"time":1504981260,"high":14.26,"low":14.27,"open":14.27,"volumefrom":3.1,"volumeto":44.26,"close":14.27},{"time":1504981320,"high":14.26,"low":14.27,"open":14.27,"volumefrom":8.56,"volumeto":122.21,"close":14.27},{"time":1504981380,"high":14.27,"low":14.27,"open":14.27,"volumefrom":10.8,"volumeto":154.01,"close":14.27},{"time":1504981440,"high":14.27,"low":14.27,"open":14.27,"volumefrom":4.18,"volumeto":59.67,"close":14.27},{"time":1504981500,"high":14.27,"low":14.27,"open":14.27,"volumefrom":0.638,"volumeto":9.11,"close":14.27},{"time":1504981560,"high":14.27,"low":14.27,"open":14.27,"volumefrom":0,"volumeto":0,"close":14.27}],"TimeTo":1504981560,"TimeFrom":1504979760,"FirstValueInArray":true,"ConversionType":{"type":"invert","conversionSymbol":""}}

I'd like to parse the data in c#. Mainly doing something with each of the 'data' list entries (time, high, low, ...) Any suggestions?

EDIT:

I have this json package installed. This is the code.

    string url_kraken = @"https://min-api.cryptocompare.com/data/histominute?fsym=ETH&tsym=EUR&limit=2000&aggregate=15&e=Kraken&extraParams=yeahnoworries";
var client_kraken = new WebClient();
var content_kraken = client_kraken.DownloadString(url_kraken);
var results_kraken = JsonConvert.DeserializeObject<List<CoinMarketCap_API_JSON>>(content_kraken);
Yeahson
  • 139
  • 6

2 Answers2

1

Just use Json.Net:

https://www.nuget.org/packages/Newtonsoft.Json/

To install it using nuget use the following command in package console:

Install-Package Newtonsoft.Json

If you have a specific class that json can map to (for example JsonMapClass), you can use it like:

JsonMapClass json = JsonConvert.DeserializeObject<JsonMapClass>(jsonstring);

otherwise you may use dynamic object:

dynamic jsonjson = JsonConvert.DeserializeObject(jsonstring);
Ashkan Mobayen Khiabani
  • 33,575
  • 33
  • 102
  • 171
1

Create two objects. For example:

First:
public class JsonData {
public string time {get; set;}
public string high {get; set;}
etc...
}

Second:
public class DataRoot {
public string Response {get; set:}
public string Type {get; set:}
public bool Aggregated{get; set:}
public List<JsonData> Data{get; set:}
}

var root = JsonConvert.DeserializeObject<DataRoot>(YOUR JSON STRING HERE);
var rootData = root.Data;

Done...

Alex Kvitchastyi
  • 250
  • 2
  • 11
  • Great! You got me confused (and frustrated for a while) but the above code has a slight error, being the : after the set which should be a ;. Second: public class DataRoot { public string Response {get; set;} public string Type {get; set;} public bool Aggregated{get; set;} public List Data{get; set;} – Yeahson Sep 10 '17 at 17:16
  • Do you have any suggestions on how to access the time, high, low etc? – Yeahson Sep 10 '17 at 17:43
  • Got it: rootData[i].close – Yeahson Sep 10 '17 at 18:07
  • Do you have any idea how to do the above with this json? https://api.kraken.com/0/public/OHLC?pair=ETHUSD&interval=30 (i feel dumb) @alex-kvitchastiy – Yeahson Mar 08 '18 at 18:32