public IQuotesDalGetTimeSeriesInfoResult GetTimeSeriesInfo(IQuotesDalGetTimeSeriesInfoParams getTsInfoParams) { IQuotesDalGetTimeSeriesInfoResult result = new QuotesDalMSSQLGetTimeSeriesInfoResult(); string spName = "[SP_GetTimeseries_Info_By_Ticket]"; SqlConnection conn = OpenConnection("ConnectionStringTimeSeries"); SqlCommand cmd = new SqlCommand(); cmd.CommandText = schema + "." + spName; cmd.CommandType = CommandType.StoredProcedure; cmd.Connection = conn; SqlParameter paramTicker = new SqlParameter("@IN_Ticker", SqlDbType.NVarChar, 255, ParameterDirection.Input, false, 0, 0, "", DataRowVersion.Current, getTsInfoParams.Ticker); SqlParameter paramCountryCode = new SqlParameter("@IN_Country_Code", SqlDbType.NVarChar, 255, ParameterDirection.Input, true, 0, 0, "", DataRowVersion.Current, getTsInfoParams.CountryCode); cmd.Parameters.Add(paramTicker); cmd.Parameters.Add(paramCountryCode); DataSet ds = new DataSet(); SqlDataAdapter da = new SqlDataAdapter(); da.SelectCommand = cmd; da.Fill(ds); const int cColumnCount = 10; // TODO: currenty data columns fixed to 10 - need to made it flexible and extandeble if (ds.Tables.Count >= 1 && ds.Tables[0].Rows != null && ds.Tables[0].Rows.Count > 0) { // getting data from the first record result.CountryCode = getTsInfoParams.CountryCode; result.Ticker = getTsInfoParams.Ticker; result.Name = (string)ds.Tables[0].Rows[0][0]; result.Unit = (EUnit)ds.Tables[0].Rows[0][1]; result.Type = (ETimeSeriesType)ds.Tables[0].Rows[0][2]; for (int i = 1; i <= cColumnCount && !DBNull.Value.Equals(ds.Tables[0].Rows[0][string.Format("Column_{0}", i)]); ++i) { result.Columns.Add((string)ds.Tables[0].Rows[0][string.Format("Column_{0}", i)]); } // creating list of available timeframes foreach (DataRow r in ds.Tables[0].Rows) { result.Series.Add(new TimeSeriesInfoListItem() { PeriodStart = (DateTime)r["Period_Start"], PeriodEnd = (DateTime)r["Period_End"], Timeframe = (ETimeFrame)r["PeriodTypeName"] }); } // getting metadata - if exists if (ds.Tables.Count > 1 && ds.Tables[1].Rows.Count > 0) { result.Metadata = new Dictionary <string, string>(); for (int r = 0; r < ds.Tables[1].Rows.Count; ++r) { result.Metadata.Add((string)ds.Tables[1].Rows[r]["Ticker_Meta_Key"], (string)ds.Tables[1].Rows[r]["Ticker_Meta_Value"]); } } } else { result.Success = false; result.Errors.Add(new Interfaces.Error() { Code = Interfaces.EErrorCodes.TickerNotFound, Type = Interfaces.EErrorType.Error, Message = string.Format("Failed to find info for ticker {0}, countrty {1}", getTsInfoParams.Ticker, getTsInfoParams.CountryCode) }); } conn.Close(); return(result); }
public IQuotesDalGetTimeSeriesInfoResult GetTimeSeriesInfo(IQuotesDalGetTimeSeriesInfoParams getTsInfoParams) { throw new NotImplementedException(); }
public GetTimeSeriesInfoResponse Any(GetTimeSeriesInfo request) { _logger.Log(EErrorType.Info, " ****** Call start: GetTimeSeriesInfo"); GetTimeSeriesInfoResponse response = new GetTimeSeriesInfoResponse(); TransferHeader(request, response); try { if (IsValidSessionToken(request)) { IQuotesDalGetTimeSeriesInfoParams getTInfoParams = _dal.CreateGetTimeSeriesInfoParams(); getTInfoParams.CountryCode = request.CountryCode; getTInfoParams.Ticker = request.Ticker; IQuotesDalGetTimeSeriesInfoResult getTInfoResult = _dal.GetTimeSeriesInfo(getTInfoParams); if (getTInfoResult.Success) { response.Payload.Ticker = request.Ticker; response.Payload.Type = getTInfoResult.Type; response.Payload.Unit = getTInfoResult.Unit; response.Payload.Name = getTInfoResult.Name; response.Payload.CountryCode = request.CountryCode; foreach (var t in getTInfoResult.Series) { response.Payload.Series.Add( new TimeSeriesInfoItem() { TimeFrame = (DTO.ETimeFrame)t.Timeframe, PeriodEnd = t.PeriodEnd, PeriodStart = t.PeriodStart } ); } foreach (var c in getTInfoResult.Columns) { response.Payload.Columns.Add(c); } if (getTInfoResult.Metadata != null && getTInfoResult.Metadata.Count > 0) { response.Payload.Metadata = new List <TimeseriesMetadataRecord>(); foreach (var k in getTInfoResult.Metadata.Keys) { TimeseriesMetadataRecord metaRec = new TimeseriesMetadataRecord(); metaRec.Key = k; metaRec.Value = getTInfoResult.Metadata[k]; response.Payload.Metadata.Add(metaRec); } } response.Success = true; } else { response.Errors.AddRange(getTInfoResult.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: GetTimeSeriesList"); return(response); }