Mercurial > silverbladetech
comparison MetroWpf/FxRates.Service/PriceFactory.cs @ 24:a8b50a087544
Stocks and FxRates working, new menu introduced. Working nicely so far
author | adminsh@apollo |
---|---|
date | Tue, 20 Mar 2012 20:18:35 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
23:399398841fd0 | 24:a8b50a087544 |
---|---|
1 using System; | |
2 using System.Collections.Generic; | |
3 using System.Linq; | |
4 using FxRates.Common; | |
5 | |
6 namespace FxRates.Service | |
7 { | |
8 class PriceFactory | |
9 { | |
10 private int _numberOfCcys; | |
11 | |
12 public PriceFactory() | |
13 { | |
14 _numberOfCcys = (int) Enum.GetValues(typeof(Ccy)).Cast<Ccy>().Max() + 1; | |
15 } | |
16 | |
17 public readonly List<FxRate> CurrentPrices = new List<FxRate> | |
18 { | |
19 FxRate.Create(Ccy.AUDtoUSD, (decimal) 1.0724, (decimal) 1.0731, DateTime.Now), | |
20 FxRate.Create(Ccy.EURtoCHF, (decimal) 1.2075, (decimal) 1.2094, DateTime.Now), | |
21 FxRate.Create(Ccy.EURtoGBP, (decimal) 0.8375, (decimal) 0.8401, DateTime.Now), | |
22 FxRate.Create(Ccy.EURtoJPY, (decimal) 103.2930, (decimal) 103.3180, DateTime.Now), | |
23 FxRate.Create(Ccy.EURtoUSD, (decimal) 1.3154, (decimal) 1.3276, DateTime.Now), | |
24 FxRate.Create(Ccy.GBPtoJPY, (decimal) 123.3250, (decimal) 123.3350, DateTime.Now), | |
25 FxRate.Create(Ccy.GBPtoUSD, (decimal) 1.5707, (decimal) 1.5723, DateTime.Now), | |
26 FxRate.Create(Ccy.USDtoCAD, (decimal) 0.9974, (decimal) 0.9999, DateTime.Now), | |
27 FxRate.Create(Ccy.USDtoCHF, (decimal) 0.9179, (decimal) 0.9191, DateTime.Now), | |
28 FxRate.Create(Ccy.USDtoJPY, (decimal) 78.5090, (decimal) 78.5187, DateTime.Now) | |
29 }; | |
30 | |
31 public FxRate GetNextPrice() | |
32 { | |
33 Random random = new Random(); | |
34 | |
35 var ccyIndex = random.Next(0, _numberOfCcys); | |
36 var rate = CurrentPrices[ccyIndex]; | |
37 | |
38 int randomSpread = random.Next(-100, 100); | |
39 decimal deltaPercentage = (decimal) randomSpread / 10000; | |
40 if (deltaPercentage != 0) | |
41 { | |
42 var bid = Math.Round(rate.Bid * (1 + deltaPercentage), 4); | |
43 var offer = Math.Round(rate.Offer * (1 + deltaPercentage), 4); | |
44 rate.UpdatePrice(bid, offer, DateTime.Now); | |
45 } | |
46 return rate; | |
47 } | |
48 } | |
49 } |