Skip to content

Commit 70e77ae

Browse files
committed
Merge branch 'dev/interProcCom' into 'master'
2 parents 6c56e13 + e2b67fe commit 70e77ae

2 files changed

Lines changed: 19 additions & 31 deletions

File tree

InterProcessCommunication/TradingApp/Modules/Quotations/Quotation.Services/QuotationService.cs

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,20 @@
66
namespace Quotations.Services
77
{
88
[Service(typeof(IQuotationService))]
9-
class QuotationService : IQuotationService
9+
internal class QuotationService : IQuotationService
1010
{
11-
private readonly Quotation[] array =
12-
{
13-
new Quotation {AskPrice = 10.50m, BidPrice = 10.55m, SecurityCode = "ING.S.NYSE"},
14-
new Quotation {AskPrice = 12.50m, BidPrice = 12.55m, SecurityCode = "ING.B.NYSE"},
15-
new Quotation {AskPrice = 10.70m, BidPrice = 10.75m, SecurityCode = "AAPL.B.NASDAQ"},
16-
new Quotation {AskPrice = 11.50m, BidPrice = 11.55m, SecurityCode = "AAPL.S.NASDAQ"},
17-
new Quotation {AskPrice = 16.50m, BidPrice = 16.55m, SecurityCode = "MSFT.B.NASDAQ"},
18-
new Quotation {AskPrice = 17.50m, BidPrice = 17.55m, SecurityCode = "ING.B.AEX"},
19-
new Quotation {AskPrice = 10.51m, BidPrice = 10.59m, SecurityCode = "ING.S.AEX"},
20-
};
21-
22-
public Quotation[] GetQuotations(string exchange, string instrument, DateTime @from, DateTime to)
11+
private readonly Quotation[] array =
12+
{
13+
new Quotation {AskPrice = 10.50m, BidPrice = 10.55m, SecurityCode = "ING.S.NYSE"},
14+
new Quotation {AskPrice = 12.50m, BidPrice = 12.55m, SecurityCode = "ING.B.NYSE"},
15+
new Quotation {AskPrice = 10.70m, BidPrice = 10.75m, SecurityCode = "AAPL.B.NASDAQ"},
16+
new Quotation {AskPrice = 11.50m, BidPrice = 11.55m, SecurityCode = "AAPL.S.NASDAQ"},
17+
new Quotation {AskPrice = 16.50m, BidPrice = 16.55m, SecurityCode = "MSFT.B.NASDAQ"},
18+
new Quotation {AskPrice = 17.50m, BidPrice = 17.55m, SecurityCode = "ING.B.AEX"},
19+
new Quotation {AskPrice = 10.51m, BidPrice = 10.59m, SecurityCode = "ING.S.AEX"}
20+
};
21+
22+
public Quotation[] GetQuotations(string exchange, string instrument, DateTime from, DateTime to)
2323
{
2424
var result = array.Where(q => q.SecurityCode.Contains(exchange));
2525

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
using System;
22
using System.Collections.Generic;
3-
using System.Linq;
43
using System.Threading.Tasks;
54
using Contracts.Quotations.Services;
65
using Contracts.Sales.Services;
@@ -9,25 +8,23 @@
98
namespace Sales.Services
109
{
1110
[Service(typeof(IOrdersService))]
12-
class OrderingService : IOrdersService
11+
public class OrderingService : IOrdersService
1312
{
1413
private readonly IQuotationService quotationService;
15-
private readonly IRepository repository;
1614

17-
public OrderingService(IQuotationService quotationService, IRepository repository)
15+
private readonly List<LimitOrder> limitOrders = new List<LimitOrder>();
16+
17+
public OrderingService(IQuotationService quotationService)
1818
{
1919
this.quotationService = quotationService;
20-
this.repository = repository;
2120
}
2221

2322
public void PlaceSellLimitOrder(string securityCode, decimal sellingPrice, DateTime validUntil)
2423
{
25-
List<LimitOrder> limitOrders = new List<LimitOrder>();
2624
var todayQuotations = quotationService.GetQuotations(securityCode, DateTime.Today.AddDays(-1), DateTime.Today);
2725
foreach (var quotation in todayQuotations)
2826
{
2927
if (quotation.AskPrice >= sellingPrice)
30-
{
3128
limitOrders.Add(new LimitOrder
3229
{
3330
SecurityCode = securityCode,
@@ -36,21 +33,15 @@ public void PlaceSellLimitOrder(string securityCode, decimal sellingPrice, DateT
3633
Price = sellingPrice,
3734
ValidUntil = validUntil
3835
});
39-
}
4036
}
41-
42-
repository.SaveAll(limitOrders);
4337
}
4438

4539
public void PlaceBuyLimitOrder(string securityCode, decimal buyingPrice, DateTime validUntil)
4640
{
47-
List<LimitOrder> limitOrders= new List<LimitOrder>();
4841
var todayQuotations = quotationService.GetQuotations(securityCode, DateTime.Today.AddDays(-1), DateTime.Today);
4942
foreach (var quotation in todayQuotations)
5043
{
5144
if (quotation.BidPrice <= buyingPrice)
52-
{
53-
5445
limitOrders.Add(new LimitOrder
5546
{
5647
SecurityCode = securityCode,
@@ -59,15 +50,12 @@ public void PlaceBuyLimitOrder(string securityCode, decimal buyingPrice, DateTim
5950
Price = buyingPrice,
6051
ValidUntil = validUntil
6152
});
62-
}
6353
}
64-
65-
repository.SaveAll(limitOrders);
6654
}
6755

6856
public LimitOrder[] GetLimitOrders()
6957
{
70-
return repository.GetEntities<LimitOrder>().ToArray();
58+
return limitOrders.ToArray();
7159
}
7260
}
73-
}
61+
}

0 commit comments

Comments
 (0)