crazyFakir
crazyFakir личный блог
10 ноября 2017, 11:15

#пора_граммировать [5] ... цена последней сделки по Si с биржи.

Для получения последней сделки нужно изменить порядок запроса на обратный добавив
reversed=1
и оставить только строчку номер 15 в запросе
limit=1
получим запрос вида
https://iss.moex.com/iss/engines/futures/markets/forts/securities/SiZ7/trades.json?reversed=1&limit=1
Вариант автоматизации упрощенно:
using System;
using System.Net;
using System.IO;
using System.Text;

namespace GetLastPrice
{
    class Program
    {
        static void Main(string[] args)
        { 
            string newLine;
            string[] lastLine;
            string link = "https://iss.moex.com/iss/engines/futures/markets/forts/securities/SiZ7/trades.json?reversed=1&limit=1";
            int count = 0;           
            for (;;) {
                HttpWebRequest request = (HttpWebRequest)WebRequest.Create(link);
                request.ContentType = "text/plain; charset=utf-8";
                HttpWebResponse response = request.GetResponse() as HttpWebResponse;        
                using (Stream responseStream = response.GetResponseStream())
                {                    
                    StreamReader sr = new StreamReader(responseStream, Encoding.UTF8);                   
                    while ((newLine = sr.ReadLine()) != null) {                        
                        if (count == 14) {
                            if (newLine =="") break;
                            else {                        
                                lastLine =  newLine.Split(",");
                                Console.WriteLine("Volume is " + lastLine[6] +" at Price " + lastLine[5]);
                            }                                                   
                        }
                        count++;                                            
                    }                                                               
                }
                count = 0;
                response.Close();
            }            
        }
    }
}
 
D:\devel\net\GetLastPrice>dotnet run
Volume is  1 at Price  59686
Volume is  1 at Price  59689
Volume is  1 at Price  59689
Volume is  1 at Price  59689
Volume is  1 at Price  59689
Volume is  3 at Price  59689
Volume is  3 at Price  59689
Volume is  3 at Price  59689
Volume is  3 at Price  59689
Volume is  2 at Price  59688
Volume is  3 at Price  59688


#учусьучить
15 Комментариев
  • Андрей К
    10 ноября 2017, 11:31
    dotnet под виндой? не знал
  • задержку побороть бы
  • tranquility
    12 ноября 2017, 00:12
    А есть возможность получать тип сделки (купля/продажа)?
    Можно ли получать сделки частями в обратном (хронологическом) порядке? Например, по тысячи в несколько итераций…

Активные форумы
Что сейчас обсуждают

Старый дизайн
Старый
дизайн