/// <summary> /// Checks if the MEFF service is reachable /// and answers to requests correctly. /// </summary> /// <remarks> /// This is done by requesting a well known quote and checking if data is returned, /// the sanity of the data is not checked. /// </remarks> /// <returns> /// A <see cref="Status"/> indicating if the /// MEFF service is working. /// </returns> public Status TestConnectivity() { // Prepare the default result, in case everything will go well. Status state = new Status(); state.HasErrors = false; state.ErrorMessage = string.Empty; try { // Try simply requesting a single data series known to exist // and to produce 1 result (we use GRF at 31 jan 2011). List <MEFFHistoricalQuote> quotes = MEFFAPI.GetHistoricalQuotes("GRF", new DateTime(2011, 1, 31), new DateTime(2011, 1, 31)); if (quotes.Count != 1) { // If there is a number of results different than 1, // it means the service is not answering as expected, // so fail the test. state.HasErrors = true; state.ErrorMessage = "Data from MEFF not available or unreliable."; } } catch (Exception e) { // If an exception was thrown during data fetching it means // there is a problem with the service (either timeout, // connection failure, or MEFF changed data format). state.HasErrors = true; state.ErrorMessage = "Unable to connect to MEFF service: " + e.Message; } return(state); }
/// <summary> /// Gets a series of Historical Market Data from the starting date /// to the end date. /// </summary> /// <param name="mdq"> /// A <see cref="MarketDataQuery"/> with the data request. /// </param> /// <param name="end"> /// A <see cref="DateTime"/> with the ending date of the period to fetch data from. /// </param> /// <param name="dates"> /// In case of success, a list of the dates data was fetched from in the requested period. /// </param> /// <param name="marketData"> /// In case of success, a list of the fetched market data day /// by day corresponding to <see cref="dates"/>. /// </param> /// <returns> /// A <see cref="RefreshStatus"/> indicating if the query was successful. /// </returns> public RefreshStatus GetTimeSeries(MarketDataQuery mdq, DateTime end, out DateTime[] dates, out IMarketData[] marketData) { RefreshStatus status = new RefreshStatus(); // Check if close value was requested. switch (mdq.Field) { case "close": { break; } default: { // In case the request is not close return an error. marketData = null; dates = null; status.HasErrors = true; status.ErrorMessage += "GetTimeSeries: Market data not available (only " + "close values are available, " + mdq.Field + " was requested)."; return(status); } } // For now only Scalar requests are handled. if (mdq.MarketDataType == typeof(Scalar).ToString()) { List <MEFFHistoricalQuote> quotes = null; try { // Request the data to the Market Data Provider. quotes = MEFFAPI.GetHistoricalQuotes(TickerUtility.PreparseSymbol(mdq.Ticker), mdq.Date, end); } catch (Exception e) { // There can be conversion, server availability // and other exceptions during this request. marketData = null; dates = null; status.HasErrors = true; status.ErrorMessage += "GetTimeSeries: Market data not available due " + "to problems with MEFF service: " + e.Message; return(status); } // Check if there is at least one result. if (quotes.Count >= 1) { // Allocate the structures for the output. marketData = new Scalar[quotes.Count]; dates = new DateTime[quotes.Count]; // Scan the list of quotes to prepare the data for Fairmat. for (int i = 0; i < quotes.Count; i++) { // Fill the dates array from the date field of each quote. dates[i] = quotes[i].SessionDate; // Prepare the single scalar data. Scalar val = new Scalar(); val.TimeStamp = quotes[i].SessionDate; val.Value = quotes[i].SettlPrice; // Put it in the output structure. marketData[i] = val; } return(status); } else { // If there isn't at least one result return an error. marketData = null; dates = null; status.HasErrors = true; status.ErrorMessage += "GetTimeSeries: Market data not available: " + "empty data set for the request."; return(status); } } else { // If control falls through here it means the request type was not supported. marketData = null; dates = null; status.HasErrors = true; status.ErrorMessage += "GetTimeSeries: Market data request type (" + mdq.MarketDataType + ") not supported by the Market Data Provider."; return(status); } }