static decimal _crossrate(NinjaTrader.Cbi.Currency A, NinjaTrader.Cbi.Currency B) { if (ConversionRate.Count == 0) { FillConversionRate(); } double d = 1.0; ConversionRate.TryGetValue(CurrencyConversion.ISO(A) + CurrencyConversion.ISO(B), out d); return((decimal)d); }
public MoneyString(string input) { try { if (string.IsNullOrEmpty(input)) { return; } // string is number currency string scur = ""; string numberpart = ""; foreach (char c in input) { if (char.IsSymbol(c)) { scur += c; } else if (char.IsLetter(c)) { scur += c; } else { numberpart += c; } } foreach (NinjaTrader.Cbi.Currency cur in Enum.GetValues(typeof(NinjaTrader.Cbi.Currency))) { string tmp = CurrencyConversion.ISO(cur); if (scur.ToUpper().Contains(tmp.ToUpper())) { currency = cur; break; } if (scur.Contains(Symbol(cur))) { currency = cur; break; } } amount = Convert.ToDouble(numberpart, CultureInfo.CurrentCulture); } catch { } }
public static string Symbol(NinjaTrader.Cbi.Currency currency) { string cur = CurrencyConversion.ISO(currency); if (cur == "EUR") { return("€"); // "EUR"; } if (cur == "USD") { return("$"); //prefix } // CHF prefix if (cur == "GBP") { return("£"); //prefix } if (cur == "JPY") { return("¥"); // prefix "YEN"; } if (cur == "RUB") { return("₽"); } if (cur == "ILS") { return("₪"); // prefix } if (cur == "CZK") { return("Kč"); } if (cur == "DKK") { return("kr."); } if (cur == "BRL") { return("R$"); } if (cur == "TWD") { return("NT$"); } if (cur == "ZAR") { return("R"); //prefix } if (cur == "TRY") { return("₺"); //prefix } if (cur == "PLN") { return("zł"); } //if (cur == "CNY") return "¥"; //prefix same as JPY if (cur == "MYR") { return("RM"); //prefix } if (cur == "NOK") { return("kr"); } if (cur == "INR") { return("₹"); } if (cur == "HUF") { return("Ft"); } return(cur); }
public static void FillConversionRate() { if (rates == null) { UpdateRates(); } foreach (NinjaTrader.Cbi.Currency a in Enum.GetValues(typeof(NinjaTrader.Cbi.Currency))) { string iso = CurrencyConversion.ISO(a); string key = iso + iso; ConversionRate.Add(key, 1.0); } foreach (string r in rates) { KeyValuePair <string, double> kvp = FromString(r); ConversionRate.Add(kvp.Key, kvp.Value); KeyValuePair <string, double> pvk = Reverse(kvp); ConversionRate.Add(pvk.Key, pvk.Value); } foreach (NinjaTrader.Cbi.Currency a in Enum.GetValues(typeof(NinjaTrader.Cbi.Currency))) { foreach (NinjaTrader.Cbi.Currency b in Enum.GetValues(typeof(NinjaTrader.Cbi.Currency))) { double d = 1.0; string ab = CurrencyConversion.ISO(a) + CurrencyConversion.ISO(b); if (!ConversionRate.TryGetValue(ab, out d)) { // ab not exist, search ac and cb or also ac and bc foreach (NinjaTrader.Cbi.Currency c in Enum.GetValues(typeof(NinjaTrader.Cbi.Currency))) { if (c == a) { continue; } if (c == b) { continue; } string ac = CurrencyConversion.ISO(a) + CurrencyConversion.ISO(c); double d2 = 1.0; if (ConversionRate.TryGetValue(ac, out d2)) { // found ac, so check for bc double d3 = 1.0; string cb = CurrencyConversion.ISO(c) + CurrencyConversion.ISO(b); if (ConversionRate.TryGetValue(cb, out d3)) { // so we have ac and cb // means ab = ac*cb // so save ab and ba ConversionRate.Add(ab, d2 * d3); string t1 = ab.Substring(0, 3); string t2 = ab.Substring(3, 3); ConversionRate.Add(t2 + t1, 1.0 / (d2 * d3)); break; } } } } } } }