1
1
using System ;
2
2
using System . Collections . Generic ;
3
- using System . Runtime . CompilerServices ;
4
3
using Model ;
5
4
using Repository ;
6
5
7
6
namespace Services
8
7
{
9
8
public interface IMarketOrderService
10
9
{
10
+ /// <summary>
11
+ /// Creates a new market order and adds it to a repository
12
+ /// </summary>
13
+ /// <param name="filledPrice">The agreed price per one piece of the traded asset</param>
14
+ /// <param name="fee">Fee for trade</param>
15
+ /// <param name="size">Size of the trade</param>
16
+ /// <param name="date">Date the trade was made</param>
17
+ /// <param name="buy">A flag indicating whether the trade is a buy</param>
18
+ /// <param name="portfolioEntryId">ID of the portfolio entry the trade belongs to</param>
19
+ /// <returns>Created instance of the `MarketOrder` class</returns>
11
20
MarketOrder CreateMarketOrder ( decimal filledPrice , decimal fee , decimal size ,
12
21
DateTime date , bool buy , int portfolioEntryId ) ;
13
22
23
+ /// <summary>
24
+ /// Deletes the given order from the repository
25
+ /// </summary>
26
+ /// <param name="order">Order to be deleted from the repository</param>
27
+ /// <returns>A flag indicating whether an order was deleted</returns>
14
28
bool DeleteMarketOrder ( MarketOrder order ) ;
15
29
30
+ /// <summary>
31
+ /// Updates the given order in the repository. An order with the same ID in the repository is replaced with the one
32
+ /// passed.
33
+ /// </summary>
34
+ /// <param name="order">Updated order</param>
35
+ /// <returns>A flag indicating whether an order was updated</returns>
16
36
bool UpdateMarketOrder ( MarketOrder order ) ;
17
37
38
+ /// <summary>
39
+ /// Loads and returns a market order from a repository
40
+ /// </summary>
41
+ /// <param name="id">ID of the order to be loaded</param>
42
+ /// <returns>Loaded order from the repository or `null` when no order with the given ID was found in the repository</returns>
18
43
MarketOrder GetMarketOrder ( int id ) ;
19
44
45
+ /// <summary>
46
+ /// Gets all orders of a portfolio entry given by an ID.
47
+ /// </summary>
48
+ /// <param name="portfolioEntryId">ID of the entry whose orders are to be found</param>
49
+ /// <returns>List of all orders belonging to the order specified by the given ID</returns>
20
50
List < MarketOrder > GetPortfolioEntryOrders ( int portfolioEntryId ) ;
21
51
52
+ /// <summary>
53
+ /// Deletes all orders belonging to the portfolio entry given by it's ID
54
+ /// </summary>
55
+ /// <param name="portfolioEntryId">ID of the portfolio entry whose orders are to be deleted</param>
56
+ /// <returns>Number of deleted orders</returns>
22
57
int DeletePortfolioEntryOrders ( int portfolioEntryId ) ;
23
58
}
24
59
25
60
public class MarketOrderServiceImpl : IMarketOrderService
26
61
{
27
- private IMarketOrderRepository _marketOrderRepository ;
62
+ private readonly IMarketOrderRepository _marketOrderRepository ;
28
63
29
64
public MarketOrderServiceImpl ( IMarketOrderRepository marketOrderRepository )
30
65
{
@@ -34,8 +69,13 @@ public MarketOrderServiceImpl(IMarketOrderRepository marketOrderRepository)
34
69
public MarketOrder CreateMarketOrder ( decimal filledPrice , decimal fee , decimal size , DateTime date , bool buy ,
35
70
int portfolioEntryId )
36
71
{
72
+ // create a MarketOrder instance
37
73
var order = new MarketOrder ( filledPrice , fee , size , date , buy , PortfolioEntryId : portfolioEntryId ) ;
74
+
75
+ // add it to the repository
38
76
var id = _marketOrderRepository . Add ( order ) ;
77
+
78
+ // return the created instance with the ID generated by the repository
39
79
return order with { Id = id } ;
40
80
}
41
81
0 commit comments