File tree Expand file tree Collapse file tree 3 files changed +35
-3
lines changed
Expand file tree Collapse file tree 3 files changed +35
-3
lines changed Original file line number Diff line number Diff line change 11(library
22 (name model)
3+ (preprocess (pps ppx_fields_conv))
34 (libraries base calendar unix str validator))
Original file line number Diff line number Diff line change @@ -4,7 +4,6 @@ open Instrumentid
44open Common
55open CalendarLib
66open Market
7- open Validator
87open List
98open Taxfee
109
@@ -24,9 +23,40 @@ module Trade(TaxFeeForMarket: TaxFee) : Trade_sig = struct
2423 value_date : Calendar .t option ;
2524 tax_fees : (TaxFeeForTrade .t * money ) list ;
2625 net_amount : money option ;
26+ } [@@ deriving fields ~getters ]
27+
28+ let build_trade account_no isin market buy_sell unit_price quantity trade_date value_date = {
29+ account_no;
30+ isin;
31+ market;
32+ buy_sell;
33+ unit_price;
34+ quantity;
35+ trade_date;
36+ value_date;
37+ tax_fees = [] ;
38+ net_amount = None ;
2739 }
2840
29- let create_trade ~account_no ~isin ~market ~buy_sell ~unit_price ~quantity ~trade_date ~value_date = failwith " TODO"
41+ let validate_trade ~account_no ~isin ~market ~buy_sell ~unit_price ~quantity ~trade_date ~value_date =
42+ let open Validator in
43+ let open Tvalidator in
44+ let valid = build build_trade
45+ |> keep account_no
46+ |> keep isin
47+ |> keep market
48+ |> keep buy_sell
49+ |> validate unit_price (TradingValidator. float_min 1.0 " Unit price must be > 0" )
50+ |> validate quantity (TradingValidator. float_min 1.0 " Quantity must be > 0" )
51+ |> keep trade_date
52+ |> keep value_date in
53+ match valid with
54+ | Ok trade -> Ok trade
55+ | Error e -> Error e
56+
57+
58+ let create_trade ~account_no ~isin ~market ~buy_sell ~unit_price ~quantity ~trade_date ~value_date =
59+ validate_trade ~account_no ~isin ~market ~buy_sell ~unit_price ~quantity ~trade_date ~value_date
3060
3161 let principal t = t.unit_price *. t.quantity
3262
Original file line number Diff line number Diff line change @@ -8,7 +8,7 @@ open Validator
88
99module type Trade_sig = sig
1010 module TaxFeeForTrade : TaxFee
11- type t
11+ type t
1212 type money
1313
1414 (* create a validated trade *)
@@ -31,6 +31,7 @@ module type Trade_sig = sig
3131 (* get the net amount of the trade *)
3232 val net_amount : t -> money
3333
34+ (* get the tax/fee list along with values for the trade *)
3435 val tax_fees : t -> (TaxFeeForTrade .t * money ) list
3536
3637end
You can’t perform that action at this time.
0 commit comments