1
+ @page " /newmarketorder"
2
+ @using Model
3
+ @using Services
4
+ @using Utils
5
+ @using System .ComponentModel .DataAnnotations
6
+ @inject IPortfolioService PortfolioService
7
+ @inject IMatDialogService MatDialogService
8
+ @inject IMatToaster Toaster
9
+ @inject Microsoft .AspNetCore .Components .NavigationManager NavigationManager
10
+
11
+
12
+ <style >
13
+ .demo-mat-card {
14
+ margin-bottom : 2em ;
15
+ }
16
+
17
+ .demo-mat-card-content {
18
+ padding : 1rem ;
19
+ }
20
+
21
+ .clear-margin {
22
+ margin : 0px ;
23
+ }
24
+ </style >
25
+
26
+ <div class =" mat-layout-grid" >
27
+ <div class =" mat-layout-grid-inner" >
28
+ <div class =" mat-layout-grid-cell" >
29
+ <MatCard >
30
+ <MatCardContent class =" demo-mat-card-content" >
31
+ <h2 >Create a new market order</h2 >
32
+ <EditForm Model =" FormModel" OnValidSubmit =" OnCreateOrderFormSubmit" >
33
+ <DataAnnotationsValidator />
34
+ <p >
35
+ <MatTextField FullWidth =" true" Label =" @(" Price per coin ( " + CurrencyUtils.GetCurrencyLabel(ActivePortfolio.Currency) + " ) " )"
36
+ @bind-Value =@FormModel.FilledPrice >
37
+ </MatTextField >
38
+ <ValidationMessage For =" @(() => FormModel.FilledPrice)" />
39
+ </p >
40
+
41
+ <p >
42
+ <MatTextField FullWidth =" true" Label =" @(" Traded size ( " + ActiveEntry.Symbol.ToUpper() + " ) " )"
43
+ @bind-Value =@FormModel.Size >
44
+ </MatTextField >
45
+ <ValidationMessage For =" @(() => FormModel.Size)" />
46
+ </p >
47
+
48
+ <p >
49
+ <MatTextField FullWidth =" true" Label =" @(" Fee ( " + CurrencyUtils.GetCurrencyLabel(ActivePortfolio.Currency) + " ) " )"
50
+ @bind-Value =@FormModel.Fee >
51
+ </MatTextField >
52
+ <ValidationMessage For =" @(() => FormModel.Fee)" />
53
+
54
+ </p >
55
+
56
+ <p >
57
+ <br >
58
+ <b >Order date</b >
59
+ </p >
60
+ <p >
61
+ <MatDatePicker FullWidth =" true" @bind-Value =" @FormModel.OrderDate" Enable24hours =" true" Required =" true" Format =" MM.dd.yy H:mm:ss" EnableTime =" true" ></MatDatePicker >
62
+ <ValidationMessage For =" @(() => FormModel.OrderDate)" />
63
+ </p >
64
+ <MatCardActions >
65
+ <MatCardActionButtons >
66
+ <MatButton Type =" submit" >Create</MatButton >
67
+ </MatCardActionButtons >
68
+
69
+ <MatCardActionIcons >
70
+ <MatIconButton Icon =" @MatIconNames.Refresh" OnClick =" (_) => FormModel.Reset()" ></MatIconButton >
71
+ </MatCardActionIcons >
72
+ </MatCardActions >
73
+ </EditForm >
74
+ </MatCardContent >
75
+ </MatCard >
76
+ </div >
77
+ </div >
78
+ </div >
79
+
80
+
81
+ @code
82
+ {
83
+ protected Portfolio ActivePortfolio = new (" " , " " , Currency .Usd );
84
+ protected PortfolioEntry ActiveEntry = new (" btc" , 1 );
85
+ protected NewOrderModel FormModel = new ();
86
+
87
+ public class NewOrderModel
88
+ {
89
+ [Required ]
90
+ [CustomValidation (typeof (NewOrderModel ), nameof (NonZeroValue ))]
91
+ public decimal FilledPrice { get ; set ; }
92
+
93
+ [Required ]
94
+ [CustomValidation (typeof (NewOrderModel ), nameof (NonZeroValue ))]
95
+ public decimal Size { get ; set ; }
96
+
97
+ [Required ]
98
+ [CustomValidation (typeof (NewOrderModel ), nameof (NonNegativeValue ))]
99
+ public decimal Fee { get ; set ; }
100
+
101
+ [Required ] public DateTime OrderDate = DateTime .Now ;
102
+
103
+ public void Reset ()
104
+ {
105
+ FilledPrice = 0 m ;
106
+ Size = 0 m ;
107
+ Fee = 0 m ;
108
+ OrderDate = DateTime .Now ;
109
+ }
110
+
111
+ public static ValidationResult NonZeroValue (decimal value , ValidationContext vc )
112
+ {
113
+ return value > 0
114
+ ? ValidationResult .Success
115
+ : new ValidationResult (" Value must be non-zero" , new [] {vc .MemberName });
116
+ }
117
+
118
+ public static ValidationResult NonNegativeValue (decimal value , ValidationContext vc )
119
+ {
120
+ return value >= 0
121
+ ? ValidationResult .Success
122
+ : new ValidationResult (" Value must be positive" , new [] {vc .MemberName });
123
+ }
124
+ }
125
+
126
+ protected override async Task OnInitializedAsync ()
127
+ {
128
+ }
129
+
130
+ private void onCreateOrderClicked ()
131
+ {
132
+ Toaster .Add (" New order successfully added" , MatToastType .Success , " " , " " );
133
+ }
134
+
135
+ private void onCreateAndContinueOrderClicked ()
136
+ {
137
+ Toaster .Add (" New order successfully added" , MatToastType .Danger , " " , " " );
138
+ }
139
+
140
+ private void OnCreateOrderFormSubmit ()
141
+ {
142
+ Console .WriteLine (FormModel .OrderDate .ToLongDateString ());
143
+ Toaster .Add (" New order successfully added" , MatToastType .Warning , " " , " " );
144
+ }
145
+ }
0 commit comments