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