public static Support.YCurrencyID YCurrencyIDFromString(string id) { string idStr = id.ToUpper(); System.Text.RegularExpressions.Regex regex = new System.Text.RegularExpressions.Regex("[A-Z][A-Z][A-Z][A-Z][A-Z][A-Z]=X"); if (idStr.Length == 8 && regex.Match(idStr).Success) { Support.CurrencyInfo b = null; Support.CurrencyInfo dep = null; string baseStr = idStr.Substring(0, 3); string depStr = idStr.Substring(3, 3); foreach (Support.CurrencyInfo cur in Support.WorldMarket.DefaultCurrencies) { if (baseStr == cur.ID) { b = new Support.CurrencyInfo(cur.ID, cur.Description); } else if (depStr == cur.ID) { dep = new Support.CurrencyInfo(cur.ID, cur.Description); } if (b != null & dep != null) { return(new Support.YCurrencyID(b, dep)); } } return(null); } else { return(null); } }
public void EditPortfolio(string portfolioID, string name, CurrencyInfo currency, bool symbolSorting, bool symbolCollapsing, IEnumerable<YID> items = null, IEnumerable<YIndexID> indices = null) { if (this.IsLoggedIn) { WebFormUpload upl = new WebFormUpload(); upl.Upload(this.GetEditPortfolioDownloadSettings(portfolioID, name, currency, symbolSorting, symbolCollapsing, items, indices)); } else { throw new NotSupportedException("The user is not logged in."); } }
/// <summary> /// Updates exchange informations /// </summary> /// <param name="baseCurrency">The currency all other currencies are depending</param> /// <param name="currencies">The dependent currencies</param> /// <remarks></remarks> public void Update(CurrencyInfo baseCurrency, IEnumerable<CurrencyInfo> currencies) { mDownloader.CancelAsyncAll(); mDonwloadCounter += 1; mExchangeItems = new ExchangeRateData[] { }; ExchangeRateResponse resp = mDownloader.Download(this.GetCurrencyList(baseCurrency, currencies)); if (resp.Connection.State == Base.ConnectionState.Success) mExchangeItems = resp.Result.Items; }
public Response<Portfolio> CreatePortfolio(string name, CurrencyInfo currency, bool symbolSorting, bool symbolCollapsing, IEnumerable<YID> items, IEnumerable<YIndexID> indices) { if (this.IsLoggedIn) { WebFormUpload upl = new WebFormUpload(); Response<XDocument> resp = upl.Upload(this.GetCreatePortfolioDownloadSettings(name, currency, symbolSorting, symbolCollapsing, items, indices)); return ((DefaultResponse<XDocument>)resp).CreateNew(new PortfolioDownload().ConvertHtmlDoc(resp.Result)); } else { throw new NotSupportedException("The user is not logged in."); } }
/// <summary> /// Loads as list of default countries from market.xml /// </summary> /// <returns></returns> /// <remarks></remarks> public static CountryInfo[] GetDefaultCountries() { List <CountryInfo> countries = new List <CountryInfo>(); XDocument xmlDoc = MyHelper.ParseXmlDocument(Properties.Resources.market); XElement[] cntNodes = XPath.GetElements("//Resources/Countries/Country", xmlDoc); System.Globalization.CultureInfo convCulture = new System.Globalization.CultureInfo("en-US"); foreach (XElement cntNode in cntNodes) { for (Country cnt = 0; cnt <= Country.VN; cnt++) { if (cnt.ToString() == MyHelper.GetXmlAttributeValue(cntNode, "ID")) { CurrencyInfo cntCur = null; string curID = MyHelper.GetXmlAttributeValue(cntNode, "Currency"); foreach (CurrencyInfo cur in DefaultCurrencies) { if (cur.ID.ToString() == curID) { cntCur = cur; break; } } XElement dstNodes = XPath.GetElement("DaylightSavingTimes", cntNode); List <DaylightSavingTime> dstList = new List <DaylightSavingTime>(); foreach (XElement dstNode in dstNodes.Elements()) { if (dstNode.Name.LocalName == "DST") { DateTime dstStart = Convert.ToDateTime(MyHelper.GetXmlAttributeValue(dstNode, "Start"), convCulture); DateTime dstEnd = Convert.ToDateTime(MyHelper.GetXmlAttributeValue(dstNode, "End"), convCulture); dstList.Add(new DaylightSavingTime(dstStart, dstEnd)); } } countries.Add(new CountryInfo(cnt, MyHelper.GetXmlAttributeValue(cntNode, "Name"), cntCur, dstList.ToArray())); break; } } } return(countries.ToArray()); }
/// <summary> /// Converts as value of a currency to the ratio value of another currency /// </summary> /// <param name="value"></param> /// <param name="currencyOfValue"></param> /// <param name="returnCurrency"></param> /// <returns></returns> /// <remarks>Returns 0, if the dependency value of one of both currencies is not in the list</remarks> public double ConvertCurrency(double value, CurrencyInfo currencyOfValue, CurrencyInfo returnCurrency) { try { if (currencyOfValue.ID != returnCurrency.ID) { double fromRatio = 0; double toRatio = 0; foreach (ExchangeRateData eiFrom in mExchangeItems) { if (eiFrom.CurrencyRelation.DepCurrency.ID == currencyOfValue.ID) { fromRatio = eiFrom.DependencyValue; foreach (ExchangeRateData eiTo in mExchangeItems) { if (eiTo.CurrencyRelation.DepCurrency.ID == returnCurrency.ID) { toRatio = eiTo.DependencyValue; break; } } break; } } if (fromRatio != 0 & toRatio != 0) { return(value / fromRatio * toRatio); } } else { return(value); } } catch (Exception ex) { } return(0); }
/// <summary> /// Converts as value of a currency to the ratio value of another currency /// </summary> /// <param name="value"></param> /// <param name="currencyOfValue"></param> /// <param name="returnCurrency"></param> /// <returns></returns> /// <remarks>Returns 0, if the dependency value of one of both currencies is not in the list</remarks> public double ConvertCurrency(double value, CurrencyInfo currencyOfValue, CurrencyInfo returnCurrency) { try { if (currencyOfValue.ID != returnCurrency.ID) { double fromRatio = 0; double toRatio = 0; foreach (ExchangeRateData eiFrom in mExchangeItems) { if (eiFrom.CurrencyRelation.DepCurrency.ID == currencyOfValue.ID) { fromRatio = eiFrom.DependencyValue; foreach (ExchangeRateData eiTo in mExchangeItems) { if (eiTo.CurrencyRelation.DepCurrency.ID == returnCurrency.ID) { toRatio = eiTo.DependencyValue; break; } } break; } } if (fromRatio != 0 & toRatio != 0) return (value / fromRatio * toRatio); } else { return value; } } catch (Exception ex) { } return 0; }
/// <summary> /// Default constructor /// </summary> /// <remarks></remarks> public YCurrencyID() { mBaseCurrency = null; mDepCurrency = null; }
/// <summary> /// Overloaded constructor /// </summary> /// <param name="baseCur"></param> /// <param name="depCur"></param> /// <remarks></remarks> public YCurrencyID(CurrencyInfo baseCur, CurrencyInfo depCur) { this.BaseCurrency = baseCur; this.DepCurrency = depCur; }
public static Support.YCurrencyID YCurrencyIDFromString(string id) { string idStr = id.ToUpper(); System.Text.RegularExpressions.Regex regex = new System.Text.RegularExpressions.Regex("[A-Z][A-Z][A-Z][A-Z][A-Z][A-Z]=X"); if (idStr.Length == 8 && regex.Match(idStr).Success) { Support.CurrencyInfo b = null; Support.CurrencyInfo dep = null; string baseStr = idStr.Substring(0, 3); string depStr = idStr.Substring(3, 3); foreach (Support.CurrencyInfo cur in Support.WorldMarket.DefaultCurrencies) { if (baseStr == cur.ID) { b = new Support.CurrencyInfo(cur.ID, cur.Description); } else if (depStr == cur.ID) { dep = new Support.CurrencyInfo(cur.ID, cur.Description); } if (b != null & dep != null) { return new Support.YCurrencyID(b, dep); } } return null; } else { return null; } }
/// <summary> /// Overloaded constructor /// </summary> /// <param name="baseCur">The currency with the ratio value of 1</param> /// <param name="cur">The currency of the dependent value</param> /// <remarks></remarks> public ExchangeRateData(CurrencyInfo baseCur, CurrencyInfo cur) { mCurrencyRelation.BaseCurrency = baseCur; mCurrencyRelation.DepCurrency = cur; base.SetID(mCurrencyRelation.ID); }
/// <summary> /// Starts asynchronous update of exchange rates /// </summary> /// <param name="baseCurrency">The currency all other currencies are depending</param> /// <param name="currencies">The dependent currencies</param> /// <remarks></remarks> public void UpdateAsync(CurrencyInfo baseCurrency, IEnumerable<CurrencyInfo> currencies, object userArgs = null) { mDownloader.CancelAsyncAll(); mDonwloadCounter += 1; mExchangeItems = new ExchangeRateData[] { }; mDownloader.DownloadAsync(this.GetCurrencyList(baseCurrency, currencies), new AsyncDownloadArgs(userArgs, mDonwloadCounter)); }
private List<KeyValuePair<string, string>> GetPortfolioDict(string name, CurrencyInfo currency, bool symbolSorting, bool symbolCollapsing, IEnumerable<YID> items, IEnumerable<YIndexID> indices, string pfID) { List<KeyValuePair<string, string>> lst = new List<KeyValuePair<string, string>>(); lst.Add(new KeyValuePair<string, string>(".yfiuseajax", "0")); lst.Add(new KeyValuePair<string, string>(".yfisrc", "")); lst.Add(new KeyValuePair<string, string>(".yfidone", "")); lst.Add(new KeyValuePair<string, string>("yfi_pf_id", pfID)); lst.Add(new KeyValuePair<string, string>("yfi_pf_name", name)); lst.Add(new KeyValuePair<string, string>("quotes", "")); lst.Add(new KeyValuePair<string, string>("yfi_pf_symbols", "")); lst.Add(new KeyValuePair<string, string>("yfi_pf_default_view", "v1")); lst.Add(new KeyValuePair<string, string>("yfi_pf_view", "v1")); lst.Add(new KeyValuePair<string, string>("yfi_pf_currency", currency.ID)); if (symbolCollapsing) lst.Add(new KeyValuePair<string, string>("yfi_pf_pref_lots", "collapse")); if (symbolSorting) lst.Add(new KeyValuePair<string, string>("yfi_pf_pref_sort", "symbol_ascending")); if (items != null) { string ids = string.Empty; foreach (YID id in items) { ids += "+" + id.ID; } if (ids != string.Empty) { lst.Add(new KeyValuePair<string, string>("yfi_pf_symbols", ids)); } } if (indices != null) { foreach (YIndexID index in indices) { lst.Add(new KeyValuePair<string, string>("yfi_pf_indices[]", index.ID.Replace("@", ""))); } } lst.Add(new KeyValuePair<string, string>("yfi_pf_save", "Save")); return lst; }
private WebFormDownloadSettings GetEditPortfolioDownloadSettings(string portfolioID, string name, CurrencyInfo currency, bool symbolSorting, bool symbolCollapsing, IEnumerable<YID> items, IEnumerable<YIndexID> indices) { List<KeyValuePair<string, string>> lst = this.GetPortfolioDict(name, currency, symbolSorting, symbolCollapsing, items, indices, portfolioID); WebFormDownloadSettings settings = new WebFormDownloadSettings(); settings.Account = this; settings.Url = "http://finance.yahoo.com/portfolio/" + portfolioID + "/edit"; settings.RefererUrlPart = "/portfolio/" + portfolioID + "/save-edit"; settings.AdditionalWebForms = lst; settings.SearchForWebForms = null; settings.FormActionPattern = ""; return settings; }
public void EditPortfolioAsync(string portfolioID, string name, CurrencyInfo currency, bool symbolSorting, bool symbolCollapsing, IEnumerable<YID> items, IEnumerable<YIndexID> indices, object userArgs) { if (this.IsLoggedIn) { WebFormUpload upl = new WebFormUpload(); upl.AsyncUploadCompleted += this.EditPortfolio_DownloadCompleted; upl.UploadAsync(this.GetEditPortfolioDownloadSettings(portfolioID, name, currency, symbolSorting, symbolCollapsing, items, indices), userArgs); } else { throw new NotSupportedException("The user is not logged in."); } }
private YCurrencyID[] GetCurrencyList(CurrencyInfo baseCurrency, IEnumerable<CurrencyInfo> currencies) { List<YCurrencyID> lst = new List<YCurrencyID>(); if (currencies != null) { foreach (CurrencyInfo cur in currencies) { lst.Add(new YCurrencyID(baseCurrency, cur)); } } return lst.ToArray(); }
public CountryInfo(Country id, string name, CurrencyInfo cur) { mID = id; mName = name; mCurrency = cur; }
public CountryInfo(Country id, string name, CurrencyInfo cur, DaylightSavingTime[] dstArray) : this(id, name, cur) { if (dstArray != null) mDaylightSavingTimes = dstArray; }