Ejemplo n.º 1
0
        void DownloadHistory(ExchangeInfo e)
        {
            string url = "https://min-api.cryptocompare.com/data/histoday?fsym=" + e.Base +
                         "&tsym=" + e.Market + "&toTs=" + Exchange.ToUnixTimestamp(DateTime.Now) +
                         "&limit=20000" + "&e=" + e.Exchange;
            WebClient wc   = new WebClient();
            string    text = wc.DownloadString(url);

            e.History = new List <TradeInfo>();

            JObject res = JsonConvert.DeserializeObject <JObject>(text);

            if (res.Value <string>("Response") == "Error")
            {
                return;
            }

            JArray data = res.Value <JArray>("Data");

            for (int i = 0; i < data.Count; i++)
            {
                JObject   item = (JObject)data[i];
                TradeInfo info = new TradeInfo();
                info.Time = Exchange.FromUnixTime(item.Value <long>("time"));
                if (info.Open == 0)
                {
                    continue;
                }
                info.Open       = item.Value <double>("open");
                info.Close      = item.Value <double>("close");
                info.High       = item.Value <double>("high");
                info.Close      = item.Value <double>("close");
                info.VolumeFrom = item.Value <double>("volumefrom");
                info.VolumeTo   = item.Value <double>("volumeto");
                e.History.Add(info);
            }
            e.Downloaded = true;
            List <ExchangeInfo> list = (List <ExchangeInfo>) this.gcDownExchanges.DataSource;
            int index     = list.IndexOf(e);
            int rowHandle = this.gvDownExchanges.GetRowHandle(index);

            this.gvDownExchanges.RefreshRow(rowHandle);
            Application.DoEvents();
        }