예제 #1
0
        public void TestGetQuotesFail(string name)
        {
            GetTimeSeries request = PrepareRequest <GetTimeSeries>(name);

            GetTimeSeriesResponse response = Post <GetTimeSeries, GetTimeSeriesResponse>("GetTimeSeries", request);

            Assert.IsFalse(response.Success, "GetTimeSeries succeeded unexpectedly");
        }
예제 #2
0
        public void TestGetQuotesSuccess(string name)
        {
            GetTimeSeries request = PrepareRequest <GetTimeSeries>(name);

            GetTimeSeriesResponse response = Post <GetTimeSeries, GetTimeSeriesResponse>("GetTimeSeries", request);

            Assert.IsTrue(response.Success, "Failed to get quotes");
        }
        public GetTimeSeriesResponse PostGetTimeSeries(GetTimeSeries request)
        {
            var response = Post <GetTimeSeries, GetTimeSeriesResponse>("GetTimeSeries", request);

            return(response);
        }
        public EErrorCodes GetTimeSeries(string country, string ticker, ETimeFrame timeframe, DateTime periodStart, DateTime periodEnd)
        {
            EErrorCodes result = EErrorCodes.GeneralError;

            try
            {
                if (SessionToken != null)
                {
                    GetTimeSeries reqGetTs = new GetTimeSeries();
                    reqGetTs.Ticker       = ticker;
                    reqGetTs.CountryCode  = country;
                    reqGetTs.SessionToken = SessionToken;
                    reqGetTs.PeriodStart  = periodStart != DateTime.MinValue ? periodStart : DateTime.Parse("01/01/1970");
                    reqGetTs.PeriodEnd    = periodEnd != DateTime.MinValue ? periodEnd : DateTime.Now;
                    reqGetTs.TimeFrame    = timeframe;

                    GetTimeSeriesResponse resGetTs = Post <GetTimeSeries, GetTimeSeriesResponse>("/api/timeseries/GetTimeSeries", reqGetTs);
                    if (resGetTs.Success)
                    {
                        // creating new records if needed
                        IndicatorData indData = null;
                        if (Indicators.TryGetValue(ticker, out indData))
                        {
                            for (int i = 0; i < resGetTs.Payload.Values.Quotes.Count; ++i)
                            {
                                QuoteRecord rec = resGetTs.Payload.Values.Quotes[i];
                                for (int v = 0; v < rec.Values.Count; ++v)
                                {
                                    String sTsName = indData.SeriesNames[v];
                                    IndicatorSeriesData indTsData = null;
                                    if (indData.Series.TryGetValue(sTsName, out indTsData))
                                    {
                                        indTsData.Values.Add(
                                            rec.Time,
                                            rec.Values[v]
                                            );
                                    }
                                }
                            }

                            result = EErrorCodes.Success;
                        }
                        else
                        {
                            result = EErrorCodes.TickerNotFound;
                        }
                    }
                    else
                    {
                        _lastError = new Exception(resGetTs.Errors[0].Message);
                        result     = resGetTs.Errors[0].Code;
                    }
                }
                else
                {
                    return(EErrorCodes.SessionClosed);
                }
            }
            catch (Exception ex)
            {
                _lastError = ex;
                result     = EErrorCodes.GeneralError;
            }

            return(result);
        }
        public GetTimeSeriesResponse Any(GetTimeSeries request)
        {
            _logger.Log(EErrorType.Info, " ****** Call start: GetTimeSeries");
            GetTimeSeriesResponse response = new GetTimeSeriesResponse();

            TransferHeader(request, response);

            try
            {
                if (IsValidSessionToken(request))
                {
                    IQuotesDalGetTimeSeriesValuesParams getParams = _dal.CreateGetQuotesParams();
                    getParams.Country = request.CountryCode;
                    getParams.Tickers.Add(request.Ticker);
                    getParams.PeriodEnd   = request.PeriodEnd != null ? (DateTime)request.PeriodEnd : DateTime.Now;
                    getParams.PeriodStart = request.PeriodStart != null ? (DateTime)request.PeriodStart : DateTime.Parse(ConfigurationManager.AppSettings["DefaultPeriodStart"]);
                    getParams.TimeFrame   = (QuotesInterfaces.ETimeFrame)request.TimeFrame;

                    IQuotesDalGetTimeseriesValuesResult getResult = _dal.GetTimseriesValues(getParams);
                    // copying list of errors - there can be also warnings too
                    response.Errors.AddRange(response.Errors);
                    if (getResult.Success)
                    {
                        TranslateToTickerQuotes(response, getResult);
                        if (response.Payload.Values.Quotes.Count == 0)
                        {
                            response.Errors.Add(
                                new Error()
                            {
                                Code    = EErrorCodes.EmptyCollection,
                                Type    = EErrorType.Warning,
                                Message = string.Format("Data not present for {0}, Timeframe - {1}, Dates: {2} - {3}", request.Ticker, request.TimeFrame, getParams.PeriodStart, getParams.PeriodEnd)
                            });
                        }
                        response.Success = true;
                    }
                    else
                    {
                        response.Success = false;
                        response.Errors.AddRange(getResult.Errors);
                    }
                }
                else
                {
                    response.Success = false;
                    response.Errors.Add(new Error()
                    {
                        Code = EErrorCodes.InvalidSession, Type = EErrorType.Error, Message = "Invalid session token"
                    });
                }
            }
            catch (Exception ex)
            {
                _logger.Log(ex);
                response.Success = false;
                response.Errors.Add(new Error()
                {
                    Code    = EErrorCodes.GeneralError,
                    Type    = EErrorType.Error,
                    Message = string.Format("Unpexcted error: {0}", ex.Message)
                });
            }

            _logger.Log(EErrorType.Info, " ****** Call end: GetQuotes");

            return(response);
        }