-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDemoDataService.cs
More file actions
46 lines (39 loc) · 1.57 KB
/
DemoDataService.cs
File metadata and controls
46 lines (39 loc) · 1.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Extensions.Hosting;
using StockTrading.BusinessLogic;
using StockTrading.DataAccess.Models;
namespace StockTrading.API
{
internal class DemoDataService: IHostedService
{
private readonly ICompanyService _companyService;
private readonly IOrderService _orderService;
public DemoDataService(ICompanyService companyService, IOrderService orderService)
{
_companyService = companyService;
_orderService = orderService;
}
public Task StartAsync(CancellationToken cancellationToken)
{
// Set up companies
_companyService.AddCompany(new Company("AMZN"));
_companyService.AddCompany(new Company("TSLA"));
_companyService.AddCompany(new Company("BLKFNCH"));
// Set up company initial shares
_companyService.IssueShares("AMZN", 100000, 40);
_companyService.IssueShares("TSLA", 10000, 200);
_companyService.IssueShares("BLKFNCH", 600, 60);
// Set up starting orders
_orderService.AddOrder(new Order("AMZN", 40, 40, 100, OrderType.Buy));
_orderService.AddOrder(new Order("TSLA", 200, 200, 2000, OrderType.Buy));
_orderService.AddOrder(new Order("BLKFNCH", 60, 60, 300, OrderType.Buy));
return Task.CompletedTask;
}
public Task StopAsync(CancellationToken cancellationToken)
{
// No need to do anything
return Task.CompletedTask;
}
}
}