예제 #1
0
        private static IEnumerable <SecurityInfo> EnsureDownload(string code)
        {
            //System.Diagnostics.Debug.WriteLine(code);

            var tiker = new SecurityInfo {
                Code = code
            };
            dynamic tikerInfo = JsonConvert.DeserializeObject(DownloadMicex($"https://iss.moex.com/iss/securities/{tiker.Code}.jsonp"));

            foreach (var item in tikerInfo.description.data)
            {
                var value = item[2];

                switch (((string)item[0]).ToUpperInvariant())
                {
                case "NAME":
                    tiker.Name = value;
                    break;

                case "SHORTNAME":
                    tiker.ShortName = value;
                    break;

                case "ASSETCODE":
                    tiker.Asset = value;
                    break;

                case "ISIN":
                    tiker.Isin = value;
                    break;

                case "LSTTRADE":
                    tiker.LastDate = ((string)value).TryToDateTime("yyyy-MM-dd", CultureInfo.InvariantCulture);
                    break;

                case "ISSUEDATE":
                    tiker.IssueDate = ((string)value).TryToDateTime("yyyy-MM-dd", CultureInfo.InvariantCulture);
                    break;

                case "ISSUESIZE":
                    tiker.IssueSize = (decimal)value;
                    break;

                case "TYPE":
                    tiker.Type = value;
                    break;
                }
            }

            var boardIdIdx = -1;
            var marketIdx  = -1;
            var engineIdx  = -1;

            var idx = 0;

            foreach (var item in tikerInfo.boards.columns)
            {
                switch (((string)item).ToLowerInvariant())
                {
                case "boardid":
                    boardIdIdx = idx;
                    break;

                case "market":
                    marketIdx = idx;
                    break;

                case "engine":
                    engineIdx = idx;
                    break;
                }

                idx++;
            }

            var securities = new List <SecurityInfo>();

            foreach (var boardItem in tikerInfo.boards.data)
            {
                dynamic secInfo = JsonConvert.DeserializeObject(DownloadMicex($"https://iss.moex.com/iss/engines/{boardItem[engineIdx]}/markets/{boardItem[marketIdx]}/boards/{boardItem[boardIdIdx]}/securities/{code}.jsonp"));

                var security = tiker.Clone();
                security.Board = (string)boardItem[boardIdIdx];

                if (secInfo.securities.data.Count > 0)
                {
                    var data = secInfo.securities.data[0];

                    idx = 0;

                    foreach (var item in secInfo.securities.columns)
                    {
                        var value = data[idx];

                        switch (((string)item).ToUpperInvariant())
                        {
                        case "LOTSIZE":
                            security.Multiplier = (int)value;
                            break;

                        case "DECIMALS":
                            security.Decimals = (int)value;
                            break;

                        case "NAME":
                            if (security.Name.IsEmpty())
                            {
                                security.Name = (string)value;
                            }
                            break;

                        case "SHORTNAME":
                            if (security.ShortName.IsEmpty())
                            {
                                security.ShortName = (string)value;
                            }
                            break;

                        case "ASSETCODE":
                            if (security.Asset.IsEmpty())
                            {
                                security.Asset = (string)value;
                            }
                            break;

                        case "MINSTEP":
                            // http://stocksharp.com/forum/yaf_postsm8573_Gidra-i-Finam.aspx#post8573
                            // can be either 0.1 or 1e-6. so parse it as a double
                            security.PriceStep = (decimal)double.Parse((string)value, CultureInfo.InvariantCulture);
                            break;

                        case "CURRENCYID":
                            security.Currency = (string)value;
                            break;
                        }

                        idx++;
                    }
                }

                SecurityInfoCache.Add(security);

                securities.Add(security);
            }

            //if (securities.Count == 0)
            //	System.Diagnostics.Debug.WriteLine(code);

            return(securities);
        }