Skip to content

Commit 258c236

Browse files
committed
More validation on trade
1 parent a2e06c0 commit 258c236

File tree

3 files changed

+9
-15
lines changed

3 files changed

+9
-15
lines changed

lib/model/trade.ml

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,32 +18,28 @@ module Trade(TaxFeeForMarket: TaxFee) : Trade_sig = struct
1818
buy_sell: buy_sell;
1919
unit_price: unit_price;
2020
quantity: quantity;
21-
trade_date: Calendar.t;
22-
value_date: Calendar.t option;
21+
trade_value_date: (Calendar.t * Calendar.t option);
2322
tax_fees: (TaxFeeForTrade.t * money) list;
2423
net_amount: money option;
2524
} [@@deriving fields ~getters]
2625

27-
let build_trade account_no isin market buy_sell unit_price quantity trade_date value_date = {
26+
let build_trade account_no isin market buy_sell unit_price quantity trade_value_date = {
2827
account_no;
2928
isin;
3029
market;
3130
buy_sell;
3231
unit_price;
3332
quantity;
34-
trade_date;
35-
value_date;
33+
trade_value_date;
3634
tax_fees = [];
3735
net_amount = None;
3836
}
3937

40-
(*
4138
let validate_trade_value_date =
4239
let open Tvalidator in
4340
TradingValidator.date_order "Trade date must be before value date"
44-
*)
4541

46-
let validate_trade ~account_no ~isin ~market ~buy_sell ~unit_price ~quantity ~trade_date ~value_date =
42+
let validate_trade ~account_no ~isin ~market ~buy_sell ~unit_price ~quantity ~trade_value_date =
4743
let open Validator in
4844
let open Tvalidator in
4945
let valid = build build_trade
@@ -53,15 +49,14 @@ module Trade(TaxFeeForMarket: TaxFee) : Trade_sig = struct
5349
|> keep buy_sell
5450
|> validate unit_price (TradingValidator.float_min 1.0 "Unit price must be > 0")
5551
|> validate quantity (TradingValidator.float_min 1.0 "Quantity must be > 0")
56-
|> keep trade_date
57-
|> keep value_date in
52+
|> validate trade_value_date validate_trade_value_date in
5853
match valid with
5954
| Ok trade -> Ok trade
6055
| Error e -> Error e
6156

6257

63-
let create_trade ~account_no ~isin ~market ~buy_sell ~unit_price ~quantity ~trade_date ~value_date =
64-
validate_trade ~account_no ~isin ~market ~buy_sell ~unit_price ~quantity ~trade_date ~value_date
58+
let create_trade ~account_no ~isin ~market ~buy_sell ~unit_price ~quantity ~trade_value_date =
59+
validate_trade ~account_no ~isin ~market ~buy_sell ~unit_price ~quantity ~trade_value_date
6560

6661
let principal t = t.unit_price *. t.quantity
6762

lib/model/trade_sig.ml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ module type Trade_sig = sig
1919
-> buy_sell: buy_sell
2020
-> unit_price: unit_price
2121
-> quantity: quantity
22-
-> trade_date: Calendar.t
23-
-> value_date: Calendar.t option -> (t, string) validator_result
22+
-> trade_value_date: (Calendar.t * Calendar.t option)
23+
-> (t, string) validator_result
2424

2525
(* decorate a trade with tax/fees and net amount *)
2626
val with_tax_fees: t -> t

lib/model/tvalidator.ml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,5 @@ module TradingValidator = struct
6060
else
6161
Some value
6262

63-
6463
let float_min min = custom (float_min_check min)
6564
end

0 commit comments

Comments
 (0)