public void TestGetQuotesFail(string name) { GetTimeSeries request = PrepareRequest <GetTimeSeries>(name); GetTimeSeriesResponse response = Post <GetTimeSeries, GetTimeSeriesResponse>("GetTimeSeries", request); Assert.IsFalse(response.Success, "GetTimeSeries succeeded unexpectedly"); }
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"); }
private void TranslateToTickerQuotes(GetTimeSeriesResponse response, IQuotesDalGetTimeseriesValuesResult getResult) { IQuotesData quotesData = getResult.Quotes[0]; ITimeSeriesRecord rcFirst = quotesData.Quotes.FirstOrDefault(); ITimeSeriesRecord rcLast = quotesData.Quotes.LastOrDefault(); TickerQuotes tickerQuotes = new TickerQuotes(); tickerQuotes.Code = quotesData.Ticker; tickerQuotes.TimePeriod = quotesData.TimeFrame; tickerQuotes.PeriodStart = rcFirst != null ? rcFirst.Time : DateTime.MinValue; tickerQuotes.PeriodEnd = rcLast != null ? rcLast.Time : DateTime.MinValue; tickerQuotes.Quotes.AddRange(quotesData.Quotes.Select(x => new QuoteRecord(x.Time, x.Values)).ToList()); response.Payload.Values = tickerQuotes; }
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); }