Example #1
0
        public static async Task <List <FinamCsvRecord> > DownloadQuotes(FinamTickerId ticker)
        {
            var dateFrom = new DateTime(1970, 1, 1);
            var dateTo   = DateTime.Now.AddDays(-1);

            var url = string.Format(
                "http://export.finam.ru/quote.txt?" +
                "market={5}&em={4}&code={3}&apply=0&" +
                "df={0}&mf={1}&yf={2}&from={9:dd.mm.yy}&" +
                "dt={6}&mt={7}&yt={8}&to={10:dd.mm.yy}&" +
                "p=8&f=quote&e=.txt&cn={3}&dtf=1&tmf=1&" +
                "MSOR=1&mstime=on&mstimever=1&sep=1&sep2=1&datf=1&at=1",
                dateFrom.Day,
                dateFrom.Month - 1,
                dateFrom.Year,
                ticker.Ticker,
                ticker.Id,
                ticker.Market,
                dateTo.Day,
                dateTo.Month - 1,
                dateTo.Year,
                dateFrom,
                dateTo);

            var downloader = new WebDownloader();
            var content    = await downloader.DownloadStringTaskAsync(url);

            var csv = new CsvReader(new StringReader(content));

            csv.Configuration.RegisterClassMap <FinamCsvRecordMap>();

            var quotes = csv.GetRecords <FinamCsvRecord>().ToList();

            return(quotes);
        }
Example #2
0
        public static async Task <List <Ticker> > DownloadTickers()
        {
            var downloader = new WebDownloader {
                Encoding = Encoding.GetEncoding(1251)
            };

            var donwloadedContent = await downloader.DownloadStringTaskAsync(Url);

            using (var file = new StringReader(donwloadedContent))
            {
                var inMemoryFile = new StringWriter();

                // skip first 2 lines
                file.ReadLine();
                file.ReadLine();
                string line;
                while ((line = file.ReadLine()) != null)
                {
                    if (line.Trim().Length == 0)
                    {
                        break;
                    }
                    inMemoryFile.WriteLine(line);
                }

                var csv = new CsvReader(new StringReader(inMemoryFile.ToString()));
                csv.Configuration.RegisterClassMap <TickerMoexCsvMap>();
                csv.Configuration.Delimiter = ";";
                var records = csv.GetRecords <Ticker>().ToList();

                return(records);
            }
        }
Example #3
0
        public static async Task <List <FinamTickerId> > DownloadMapping()
        {
            var downloader = new WebDownloader();

            var jsdata = await downloader.DownloadStringTaskAsync("http://www.finam.ru/cache/icharts/icharts.js");

            string[] responseVars   = jsdata.Split('\n');
            string[] emitentIDs     = { };
            string[] emitentCodes   = { };
            string[] emitentMarkets = { };
            for (var i = 0; i < responseVars.Length; i++)
            {
                switch (i)
                {
                case 0:
                    emitentIDs = ClearBrakes(responseVars[i].Split(','));
                    break;

                case 2:
                    emitentCodes = ClearBrakes(responseVars[i].Split(','));
                    break;

                case 3:
                    emitentMarkets = ClearBrakes(responseVars[i].Split(','));
                    break;
                }
            }

            var tickerMapping = new List <FinamTickerId>();

            for (int i = 0; i < emitentIDs.Length; i++)
            {
                FinamTickerId emitent = new FinamTickerId()
                {
                    Id     = emitentIDs[i],
                    Ticker = emitentCodes[i].Trim('\''),
                    Market = emitentMarkets[i]
                };
                tickerMapping.Add(emitent);
            }

            return(tickerMapping);
        }