Example #1
0
        public static RefreshStatus addProviderAccount(Providers providers)
        {
            JsonSerializer serialiser = new JsonSerializer();

            serialiser.NullValueHandling = NullValueHandling.Ignore;

            String providerJson = "{\"provider\":[" + JsonConvert.SerializeObject(providers.getProvider()[0], Formatting.Indented, new JsonSerializerSettings

            {
                NullValueHandling     = NullValueHandling.Ignore,
                ReferenceLoopHandling = ReferenceLoopHandling.Ignore
            });

            providerJson = providerJson.Replace("\r\n", "");
            providerJson = providerJson.Replace(" ", "");
            providerJson = providerJson + "]}";

            string aa = providerJson;

            Console.WriteLine(aa);
            String addSiteURL = LoginApp.localURLVer1 + "providers/" + providers.getProvider()[0].getId();

            List <string> headers         = new List <string>();
            string        usersessionid   = LoginApp.usession;
            string        cbrandsessionid = LoginApp.cbsession;

            headers.Add("Authorization:{userSession= " + usersessionid + ",cobSession=" + cbrandsessionid + "}");
            String        jsonResponse  = HTTP.doPost(addSiteURL, providerJson, headers);
            RefreshStatus refreshStatus = (RefreshStatus)GSONParser.handleJson(jsonResponse, typeof(RefreshStatus));

            //Console.WriteLine(refreshStatus.ToString());
            return(refreshStatus);
        }
        public static void AddAccount(int type)
        {
            Providers     providers     = null;
            RefreshStatus refreshStatus = null;

            Console.WriteLine("Add Provider Account App - TEST - START");
            Console.WriteLine("Enter the name of the  Provider you want to search : ");
            String searchString = Console.ReadLine();

            //String searchString = "Dag";
            ProviderApp.searchProvider(searchString);
            if (type == 2)
            {
                Console.WriteLine("Enter the Provider Id : ");
                String providerId = Console.ReadLine();
                //String providerId = "16442";
                providers = ProviderApp.getProviderLoginForm(providerId);
                addMFA_Account(providers);
            }
            if (type == 1)
            {
                Console.WriteLine("Enter the Provider Id : ");
                String providerId = Console.ReadLine();
                //String providerId = "16441";
                providers = ProviderApp.getProviderLoginForm(providerId);
                addNonMFA_Account(providers);
            }
            //Console.ReadLine();
            LoginApp.readValue();
        }
Example #3
0
 public static void getRefreshStatus(RefreshStatus refreshStatus)
 {
     Console.WriteLine(refreshStatus.toString());
     //Keep Polling this api to get RefreshStatus :
     for (int i = 0; i < 10; i++)
     {
         getRefreshStatus(refreshStatus.getProviderAccountId());
     }
 }
Example #4
0
 /**
  * Refreshes the specified item
  *
  */
 public void refreshAll(UserContext userContext)
 {
     System.Console.WriteLine("Attempting to start refresh");
     try
     {
         Entry[] refreshStatus = refresh.startRefresh2(userContext, REFRESH_PRIORITY_HIGH, true);
         for (int i = 0; i < refreshStatus.Length; i++)
         {
             Entry       status    = refreshStatus[i];
             long        itemId    = (long)status.key;
             RefreshItem ri        = new RefreshItem();
             String      mfaTypeId = ri.getMFATypeId(userContext, itemId);
             if (mfaTypeId != null)
             {
                 MFARefreshInfo mfaInfo   = refresh.getMFAResponse(userContext, itemId, true);
                 MFA            mfa       = new MFA();
                 long           errorCode = mfa.processMFA(userContext, mfaInfo, itemId);
                 if (errorCode == 0)
                 {
                     System.Console.WriteLine("MFA Account has been added successfully");
                 }
                 else
                 {
                     System.Console.WriteLine("Error while adding this account with an error code " + errorCode);
                 }
             }
             RefreshStatus refStatus = (RefreshStatus)status.value;
             if (refStatus.Equals(RefreshStatus.SUCCESS_START_REFRESH))
             {
                 System.Console.WriteLine("\tStarted refresh for " + itemId);
             }
             else if (refStatus.Equals(RefreshStatus.REFRESH_ALREADY_IN_PROGRESS))
             {
                 System.Console.WriteLine("\tThe refresh is already in progress for " + itemId);
             }
             else if (refStatus.Equals(RefreshStatus.ALREADY_REFRESHED_RECENTLY))
             {
                 System.Console.WriteLine("\tItem " + itemId + " has been refreshed very recently. Please try again later.");
             }
             else if (refStatus.Equals(RefreshStatus.ITEM_CANNOT_BE_REFRESHED))
             {
                 System.Console.WriteLine("The refresh on item " + itemId + " is not permitted.");
             }
             else
             {
                 System.Console.WriteLine("Unbale to refresh the item " + itemId + "\nRefreshStatus:" + status);
             }
         }
     }
     catch (SoapException se)
     {
         System.Console.WriteLine("The given item is invalid\nException:\n" + se.ToString());
     }
 }
		public void SetStatus (RefreshStatus status)
		{
			switch (status) {
			case RefreshStatus.LoadingStatus:
				this.statusLabel.Text = "Loading...";
				break;
			
			case RefreshStatus.PullToReloadStatus:
				this.statusLabel.Text = "Pull down to refresh...";
				break;
			case RefreshStatus.ReleaseToReloadStatus:
				this.statusLabel.Text = "Release to refresh...";
				break;
			}
		}
        public RefreshStatus parseJSON(String json)
        {
            //String mn = "parseJSON(" + json + ")";
            //System.out.println(fqcn + " :: " + mn);
            //Gson gson = new Gson();
            //return (RefreshStatus)gson.fromJson(json, RefreshStatus.class);
            // json = json.Substring(json.IndexOf("["));
            // json = json.Substring(0, json.LastIndexOf("]") + 1);
            RefreshStatus refreshstatus = JsonConvert.DeserializeObject <RefreshStatus>(json);//deserializing the values for Account app.

            // Accounts a = new Accounts();
            // a.account = account;
            //return a;
            return(refreshstatus);
        }
Example #7
0
        public void SetStatus(RefreshStatus status)
        {
            switch (status)
            {
            case RefreshStatus.LoadingStatus:
                this.statusLabel.Text = "Loading...";
                break;

            case RefreshStatus.PullToReloadStatus:
                this.statusLabel.Text = "Pull down to refresh...";
                break;

            case RefreshStatus.ReleaseToReloadStatus:
                this.statusLabel.Text = "Release to refresh...";
                break;
            }
        }
Example #8
0
        public static RefreshStatus getRefreshStatus(String providerAccountId)
        {
            //String mn = "getRefreshStatus( " + providerAccountId.ToString() + " )";
            //Console.WriteLine(fqcn + " :: " + mn);
            String        getRefreshStatusURL = LoginApp.localURLVer1 + "refresh/" + providerAccountId.ToString();
            List <string> headers             = new List <string>();
            string        usersessionid       = LoginApp.usession;
            string        cbrandsessionid     = LoginApp.cbsession;

            headers.Add("Authorization:{userSession= " + usersessionid + ",cobSession=" + cbrandsessionid + "}");
            String jsonResponse = HTTP.doGet(getRefreshStatusURL, headers);
            // Console.WriteLine(jsonResponse);
            RefreshStatus refreshStatus = (RefreshStatus)GSONParser.handleJson(jsonResponse, typeof(RefreshStatus));

            Console.WriteLine(refreshStatus.toString());
            return(refreshStatus);
        }
Example #9
0
        public static RefreshStatus addNonMFA_Account(Providers providers)
        {
            Console.WriteLine(" Add Non_MFA_Account:  ");
            Console.WriteLine("Enter your provider userName : "******"ysldemo.site16442.1";
            // For internal Yodlee Dag tool use this hardcoded user Name = "DBmet1.site16441.1"
            providers.getProvider()[0].getLoginForm().getRow()[0].getField()[0].setValue(userName);

            Console.WriteLine("Enter provider password : "******"site16442.1";
            //String password = con.readLine("Enter provider password : "******"site16441.1"
            providers.getProvider()[0].getLoginForm().getRow()[1].getField()[0].setValue(password);
            RefreshStatus refreshStatus = AddProviderAccount.addProviderAccount(providers);
            string        refMsg;
            RefreshStatus rstatus;

            do
            {
                rstatus = AddProviderAccount.getRefreshStatus(refreshStatus.providerAccountId);
                //RefreshStatus rstatus = (RefreshStatus)GSONParser.handleJson(jsonResponse, typeof(RefreshStatus));
                refMsg = rstatus.refreshInfo.refreshStatus;
                if (refMsg == "LOGIN_FAILURE" || refMsg == "REFRESH_TIMED_OUT" || refMsg == "REFRESH_CANCELLED" || refMsg == "SITE_CANNOT_BE_REFRESHED")
                {
                    Console.WriteLine("login failed please try again" + refMsg);
                    break;
                }
                if (refMsg == "REFRESH_COMPLETED_ACCOUNTS_ALREADY_AGGREGATED")
                {
                    Console.WriteLine("Account already added" + refMsg);
                    break;
                }
                // Console.WriteLine("login failed please try again" + refMsg);
                // }
            } while (refMsg != "REFRESH_COMPLETED");
            if (refMsg == "REFRESH_COMPLETED")
            {
                Console.WriteLine("Account added successfully");
            }
            return(rstatus);
        }
		public virtual void SetStatus(RefreshStatus status)
		{
			if (this.status == status)
				return;
			
			string s = "Release to refresh";
	
			switch (status)
			{
				case RefreshStatus.Loading:
					s = "Loading..."; 
					break;
					
				case RefreshStatus.PullToReload:
					s = "Pull down to refresh...";
					break;
			}
			_StatusLabel.Text = s;
		}
        /// <summary>
        /// Gets the market data from a single day.
        /// </summary>
        /// <param name="mdq">
        /// A <see cref="MarketDataQuery"/> with the data request.
        /// </param>
        /// <param name="marketData">
        /// In case of success, the requested market data as <see cref="IMarketData"/>.
        /// </param>
        /// <returns>
        /// A <see cref="RefreshStatus"/> indicating if the query was successful.
        /// </returns>
        public RefreshStatus GetMarketData(MarketDataQuery mdq, out IMarketData marketData)
        {
            if (mdq.MarketDataType == typeof(Fairmat.MarketData.CallPriceMarketData).ToString())
            {
                return(GetCallPriceMarketData(mdq, out marketData));
            }

            // Reuse the Historical time series to get the single quote
            // (Equal start/end date = get the quote of the day).
            DateTime[]    dates;
            IMarketData[] marketDataArray;
            RefreshStatus status = GetTimeSeries(mdq, mdq.Date, out dates, out marketDataArray);

            // If there were errors already just report them back.
            if (status.HasErrors)
            {
                marketData = null;
            }
            else
            {
                // If all was succesful try to prepare data for this type of query.
                status = new RefreshStatus();

                // Do some sanity check on the gathered data.
                if (marketDataArray.Length != 1 && dates.Length != 1 && dates[0] != mdq.Date)
                {
                    status.HasErrors     = true;
                    status.ErrorMessage += "GetMarketData: Requested date " +
                                           "or Market Data not available.";
                    marketData = null;
                }
                else
                {
                    // If they pass just take the first element as result
                    // (which must be also the only one).
                    marketData = marketDataArray[0];
                }
            }

            return(status);
        }
        public virtual void SetStatus(RefreshStatus status)
        {
            if (this.status == status)
            {
                return;
            }

            string s = "Release to refresh";

            switch (status)
            {
            case RefreshStatus.Loading:
                s = "Loading...";
                break;

            case RefreshStatus.PullToReload:
                s = "Pull down to refresh...";
                break;
            }
            _StatusLabel.Text = s;
        }
        /// <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);
            }
        }
Example #14
0
        /// <summary>
        /// Refresh feature mapping from target filter ruleGroup to mapping filter ruleGroup
        /// </summary>
        private void RefreshFeatureMapping()
        {
            // Not to refresh feature mapping when loading profile or the result of filtering cases will be changed
            if (!isLoadingProfile)
            {
                // If feature mapping table exists and we are updating from target filter to mapping filter
                if (featureMappingTable != null && !refreshStatus.HasFlag(RefreshStatus.ReverseFeatureMapping))
                {
                    refreshStatus |= RefreshStatus.FeatureMapping;

                    // Get selected categories only to avoid refreshing for rule with partial selection
                    List <string> categories = GetSelectedCategories(RuleGroupType == RuleType.Selector);

                    // Unselect all features in mappingFilter
                    mappingRuleGroup.SelectStatus = RuleSelectStatus.UnSelected;

                    // Select mapping features in mappingFilter based on featureMappingTable
                    foreach (string category in categories)
                    {
                        if (featureMappingTable.ContainsKey(category))
                        {
                            List <Rule> ruleList = featureMappingTable[category];
                            foreach (Rule rule in ruleList)
                            {
                                // Check selection status from reverse feature mapping table
                                string           key = rule.CategoryList[0];
                                RuleSelectStatus currentSelectStatus = RuleSelectStatus.Selected;
                                foreach (var r in mappingRuleGroup.reverseFeatureMappingTable[key])
                                {
                                    if (r.SelectStatus == RuleSelectStatus.UnSelected)
                                    {
                                        currentSelectStatus = RuleSelectStatus.Partial;
                                        break;
                                    }
                                }
                                rule.SelectStatus = currentSelectStatus;
                            }
                        }
                    }
                    refreshStatus &= ~RefreshStatus.FeatureMapping;
                }
                // If reverse feature mapping table exists and we are updating from mapping filter to target filter
                else if (reverseFeatureMappingTable != null && !targetRuleGroup.refreshStatus.HasFlag(RefreshStatus.FeatureMapping))
                {
                    List <string> categories = GetCategories(RuleGroupType == RuleType.Selector);

                    targetRuleGroup.refreshStatus |= RefreshStatus.ReverseFeatureMapping;

                    // Unselect all features in targetFilter
                    targetRuleGroup.SelectStatus = RuleSelectStatus.UnSelected;

                    // Set select status to partial for rule in target filter
                    foreach (string category in categories)
                    {
                        if (reverseFeatureMappingTable.ContainsKey(category))
                        {
                            List <Rule> ruleList = reverseFeatureMappingTable[category];

                            foreach (Rule rule in ruleList)
                            {
                                // Check selection status from feature mapping table
                                bool             noCaseSelected      = true;
                                RuleSelectStatus currentSelectStatus = RuleSelectStatus.Selected;
                                string           key = rule.CategoryList[0];
                                foreach (var r in targetRuleGroup.featureMappingTable[key])
                                {
                                    if (r.SelectStatus == RuleSelectStatus.UnSelected)
                                    {
                                        currentSelectStatus = RuleSelectStatus.Partial;
                                    }
                                    else
                                    {
                                        // RuleSelectStatus.Selected or RuleSelectStatus.Partial
                                        noCaseSelected = false;
                                    }
                                }
                                if (noCaseSelected)
                                {
                                    rule.SelectStatus = RuleSelectStatus.UnSelected;
                                }
                                else
                                {
                                    rule.SelectStatus = currentSelectStatus;
                                }
                            }
                        }
                    }
                    targetRuleGroup.refreshStatus &= ~RefreshStatus.ReverseFeatureMapping;
                }
            }
            isLoadingProfile = false;
        }
Example #15
0
 public ClientWrapper(string name, object fleets, RefreshStatus refreshStatus)
 {
     Name          = name;
     Fleets        = fleets;
     RefreshStatus = refreshStatus;
 }
        /// <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();

            // Holds whathever we should take market close or market open values.
            bool closeRequest;

            // Holds the currency conversion target in case a market different than
            // US is choosen. This handles conversion from USD values provided by yahoo.
            string targetMarket = null;

            string ticker = TickerUtility.PreparseSymbol(mdq.Ticker);
            bool   divisionTransformation = false;
            bool   inverseTransformation  = false;

            // Check if open or close value was requested.
            switch (mdq.Field)
            {
            case "open":
            {
                closeRequest = false;
                break;
            }

            case "close":
            {
                closeRequest = true;
                break;
            }

            default:
            {
                // In case the request is neither open or close return an error.
                marketData           = null;
                dates                = null;
                status.HasErrors     = true;
                status.ErrorMessage += "GetTimeSeries: Market data not available (only " +
                                       "open and close values are available, " +
                                       mdq.Field + " was requested).";
                return(status);
            }
            }

            // Gather in which currency to get the data, this will require
            // an additional data fetching for the target currency for the same time period.
            if (mdq.Market.Length > 0 && mdq.Market != "US")
            {
                // Try to convert the entries in the Fairmat drop down box,
                // for the rest rely on the user.
                switch (mdq.Market)
                {
                case "EU":
                {
                    targetMarket = "EUR";
                    break;
                }

                case "GB":
                {
                    targetMarket = "GBP";
                    break;
                }

                case "JP":
                {
                    targetMarket = "JPY";
                    break;
                }

                case "CH":
                {
                    targetMarket = "CHF";
                    break;
                }

                case "HK":
                {
                    targetMarket = "HKD";
                    break;
                }

                default:
                {
                    // In the fallback scenario just use directly the provided string.
                    targetMarket = mdq.Market;
                    break;
                }
                }
            }

            // Check for currencies and handle them in a special way.
            // Check the single currency only (eg: EUR for USDEUR).
            if (GetCurrencyList().Contains(ticker))
            {
                ticker += "=X";

                // Disable the feature for this for now.
                targetMarket = null;
            }
            else
            {
                // Attempt a more throughout parsing. Check for <currency><currency> formats.
                foreach (string currency in GetCurrencyList())
                {
                    if (ticker.StartsWith(currency))
                    {
                        if (currency == "USD")
                        {
                            // If usd is in the ticker name it's a special case due to the way
                            // Yahoo! Finance keeps currencies.
                            ticker       = ticker.Remove(0, 3) + "=X";
                            targetMarket = null;
                        }
                        else if (ticker.Remove(0, 3) == "USD")
                        {
                            // This is the inverse of the previous case.
                            // From other currency to USD. Similarly to above it's a special case.
                            ticker                = currency + "=X";
                            targetMarket          = null;
                            inverseTransformation = true;
                        }
                        else
                        {
                            // Normal not USD to not USD currency conversions.
                            targetMarket           = currency;
                            ticker                 = ticker.Remove(0, 3) + "=X";
                            divisionTransformation = true;
                        }

                        break;
                    }
                }
            }

            // For now only Scalar requests are handled.
            if (mdq.MarketDataType == typeof(Scalar).ToString())
            {
                List <YahooHistoricalQuote> quotes = null;
                Dictionary <DateTime, YahooHistoricalQuote> currencyQuotes = new Dictionary <DateTime, YahooHistoricalQuote>();

                try
                {
                    // Request the data to the Market Data Provider.
                    quotes = YahooFinanceAPI.GetHistoricalQuotes(ticker, mdq.Date, end);

                    if (targetMarket != null)
                    {
                        // If we need currency quotes in order to handle currency conversions
                        // fetch them now.
                        List <YahooHistoricalQuote> fetchedCurrencyQuotes = YahooFinanceAPI.GetHistoricalQuotes(targetMarket + "=X", mdq.Date, end);

                        // Put all items in a dictionary for easy fetching.
                        fetchedCurrencyQuotes.ForEach(x => currencyQuotes.Add(x.Date, x));
                    }
                }
                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 Yahoo! Finance: " + e.Message;
                    return(status);
                }

                // Check if there is at least one result.
                if (quotes.Count >= 1)
                {
                    // Allocate the structures for the output.
                    List <Scalar>   readyMarketData = new List <Scalar>();
                    List <DateTime> readyDates      = new List <DateTime>();

                    // Scan the list of quotes to prepare the data for Fairmat.
                    for (int i = 0; i < quotes.Count; i++)
                    {
                        // Prepare the single scalar data.
                        Scalar val = new Scalar();
                        val.TimeStamp = quotes[i].Date;
                        val.Value     = (closeRequest == true) ? quotes[i].Close : quotes[i].Open;

                        // Handle currency conversions if needed.
                        if (currencyQuotes != null)
                        {
                            // Check if the entry in a date exists also for the
                            // currency conversion, if not discard the data.
                            if (!currencyQuotes.ContainsKey(quotes[i].Date))
                            {
                                // We skip this entry.
                                continue;
                            }

                            YahooHistoricalQuote currencyQuote = currencyQuotes[quotes[i].Date];

                            //if (divisionTransformation)
                            //{
                            //    val.Value /= (closeRequest == true) ? currencyQuote.Close : currencyQuote.Open;
                            //}
                            //else
                            //{
                            //    val.Value *= (closeRequest == true) ? currencyQuote.Close : currencyQuote.Open;
                            //}
                        }

                        // Apply an inverse transformation, used for currency values when going
                        // from a not USD currency to USD.
                        //if (inverseTransformation)
                        //{
                        //    val.Value = 1 / val.Value;
                        //}

                        // Put it in the output structure.
                        readyMarketData.Add(val);

                        // Fill the dates array from the date field of each quote.
                        readyDates.Add(quotes[i].Date);
                    }

                    // Put in the output data.
                    marketData = readyMarketData.ToArray();
                    dates      = readyDates.ToArray();

                    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);
            }
        }
        /// <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();

            string currency;
            bool   invertedRequest = false;

            // Check if it's a close request.
            if (mdq.Field != "close")
            {
                // 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);
            }

            string ticker = RemoveTrailers(mdq.Ticker);

            // Check that the requested value is available.
            if (ticker.StartsWith("EUCF"))
            {
                // Extract the target currency name as that's used to request the data.
                currency = ticker.Remove(0, 4);
            }
            else if (ticker.StartsWith("EUR"))
            {
                // Extract the target currency name as that's used to request the data.
                currency = ticker.Remove(0, 3);
            }
            else if (ticker.EndsWith("EUR"))
            {
                // As EUR is the target currency this request is inverted compared to ECB data.
                invertedRequest = true;
                currency        = ticker.Remove(ticker.LastIndexOf("EUR"), 3);
            }
            else
            {
                // Only EUR TO TARGET CURRENCY is supported using the format EUCF<TARGET CURRENCY>
                marketData           = null;
                dates                = null;
                status.HasErrors     = true;
                status.ErrorMessage += "GetTimeSeries: Market data not available (only " +
                                       "conversion rates from EUR to another currency are " +
                                       "available, " + mdq.Ticker + " was requested).";
                return(status);
            }

            // For now only Scalar requests are handled.
            if (mdq.MarketDataType == typeof(Scalar).ToString())
            {
                List <EuropeanCentralBankQuote> quotes = null;

                try
                {
                    // Request the data to the Market Data Provider.
                    quotes = EuropeanCentralBankAPI.GetHistoricalQuotes(currency, 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 the European Central Bank 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].Date;

                        // Prepare the single scalar data.
                        Scalar val = new Scalar();
                        val.TimeStamp = quotes[i].Date;

                        if (invertedRequest)
                        {
                            // Handle the conversion from other currencies to EUR.
                            val.Value = 1 / quotes[i].Value;
                        }
                        else
                        {
                            val.Value = quotes[i].Value;
                        }

                        // 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);
            }
        }
Example #18
0
 public RefreshYodleeException(RefreshStatus refreshStatus)
     : base(refreshStatus.ToString())
 {
     RefreshStatus = refreshStatus;
 }