public List <Security> Create(string data)
        {
            _securities = new List <Security>();

            GetSymbolsResponse symbols = JsonConvert.DeserializeObject <GetSymbolsResponse>(data);

            foreach (var symbol in symbols.data)
            {
                try
                {
                    var security = new Security();

                    security.Name          = symbol.symbol;
                    security.NameFull      = security.Name;
                    security.NameClass     = symbol.quoteCurrency;
                    security.NameId        = symbol.symbol;
                    security.SecurityType  = SecurityType.CurrencyPair;
                    security.Decimals      = symbol.pricePrecision;
                    security.PriceStep     = security.Decimals.GetValueByDecimals();
                    security.PriceStepCost = security.PriceStep;
                    security.State         = symbol.state == "online" ? SecurityStateType.Activ : SecurityStateType.Close;
                    security.Lot           = symbol.amountPrecision.GetValueByDecimals();

                    _securities.Add(security);
                }
                catch
                {
                    throw new Exception("Ошибка создания инструмента");
                }
            }

            return(_securities);
        }
        protected override Task <bool> SearchPage(object searchParameters, ulong offset, int requestId)
        {
            var tcs = new TaskCompletionSource <bool>();

            if (offset >= Convert.ToUInt64(m_ids.Count))
            {
                tcs.SetResult(false);
                return(tcs.Task);
            }

            GetSymbolsResponse.BeginGetSymbols(
                AccountManager.GetAuthInfo,
                async response =>
            {
                GetSymbolsResponse.EndGetSymbols(response);
                var res = response.AsyncState as GetSymbolsResponse;
                if (res.Symbols.Count == 0)
                {
                    tcs.SetResult(false);
                }
                else
                {
                    Results.AddRange(res.Symbols);

                    await Task.Delay(TimeSpan.FromMilliseconds(50));
                    tcs.SetResult(true);
                }
            },
                requestId,
                m_ids.Skip(Convert.ToInt32(offset)).Take(20).ToList(),
                new List <string>()
                );
            return(tcs.Task);
        }
        public void GetSymbolsTest()
        {
            GetSymbolsResponse result = client.GetSymbolsAsync().Result;
            string             strret = JsonConvert.SerializeObject(result, Formatting.Indented);

            Console.WriteLine(strret);
            Assert.Equal("ok", result.status);
        }
Exemple #4
0
        // End Interface Implementations


        private IEnumerable <SymbolData> GetSymbolsById(IEnumerable <ulong> symbolIds)
        {
            var notFound = symbolIds.Where(s => !_symbolCacheById.ContainsKey(s)).ToList();

            if (notFound.Any())
            {
                var response = GetSymbolsResponse.GetSymbols(_tokenManager.GetAuthToken(), notFound, new List <string>());
                AddToCache(response.Symbols);
            }
            return(symbolIds.Select <ulong, SymbolData>(id => _symbolCacheById[id]));
        }
Exemple #5
0
        public IEnumerable <SymbolData> GetSymbols(IEnumerable <Security> securities)
        {
            var notFound = securities.Where(s => !_symbolCacheByName.ContainsKey(BuildSymbolFromSecurity(s))).Select(BuildSymbolFromSecurity).ToList();

            if (notFound.Any())
            {
                var response = GetSymbolsResponse.GetSymbols(_tokenManager.GetAuthToken(), new List <ulong>(), notFound);
                //response.Symbols.ForEach(s => _symbolCacheByName[s.m_symbol.ToUpper()] = s);
                AddToCache(response.Symbols);
            }

            return(securities.Select <Security, SymbolData>(s => _symbolCacheByName[BuildSymbolFromSecurity(s)]));
        }