public static void Run() { WriteLine("Enter a currency pair like 'EURUSD', or 'q' to quit"); for (string input; (input = ReadLine().ToUpper()) != "Q";) { WriteLine(FxApi.GetRate(input)); } }
public static void _main() { WriteLine("Enter a currency pair like 'EURUSD' to get a quote, or 'q' to quit"); for (string input; (input = ReadLine().ToUpper()) != "Q";) { WriteLine(FxApi.GetRate(input).Map(Decimal.ToString) .Recover(ex => ex.Message).Result); // what to do in case of failure } }
static (decimal, Rates) GetRate(string ccyPair, Rates cache) { if (cache.ContainsKey(ccyPair)) { return(cache[ccyPair], cache); } var rate = FxApi.GetRate(ccyPair); return(rate, cache.Add(ccyPair, rate)); }
static void MainRec(string message, Rates cache) { WriteLine(message); var input = ReadLine().ToUpper(); if (input == "Q") { return; } GetRate(pair => () => FxApi.GetRate(pair), input, cache).Run().Match( ex => MainRec($"Error: {ex.Message}", cache), result => MainRec(result.Quote.ToString(), result.NewState)); }
public static void _main() { Retry(10, 100, () => FxApi.GetRate("GBPUSD")); }