summaryrefslogtreecommitdiff
path: root/src/FundLab.Domain/Capital.fs
blob: b2ae697df45f3b658821bb53eb0499e8d99a3da2 (plain)
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
namespace FundLab.Domain

open System

module CapitalPolicy =
    let cashMaximum = 999999999999999999.99m

    let validateDeposit (amount: decimal) : Result<unit, string> =
        if amount <= 0m then
            Error "deposit amount must be positive"
        elif Decimal.Round(amount, 2) <> amount then
            Error "deposit amount exceeds cash precision"
        elif amount > cashMaximum then
            Error "deposit amount exceeds database precision"
        else
            Ok ()

    let settle (availableCash: decimal) (amount: decimal) : Result<decimal, string> =
        match validateDeposit amount with
        | Error message -> Error message
        | Ok() ->
            let updated = availableCash + amount

            if updated > cashMaximum then
                Error "available cash exceeds database precision"
            else
                Ok updated