-- | Project HashFlare.io user account balance given the ExchangeRates, MEF and actual Payouts tables. module Data.HashFlare.Projection where import Data.HashFlare import Data.Money import Data.Maybe -- -- XXX stupid linear projection. Again, cryptocurrencies have network difficulty... -- -- | Given rates, mef, and payouts tables, project the account once projectAccountOnce :: ExchangeRates -> MEFTable -> PayoutTable -> UserAccount -> UserAccount projectAccountOnce et mt pt u = makeUserAccount b' cs where cs = accountContracts u b = accountBalance u b' = b ^+^ ptot ^-^ (fromJust $ exchangeTo et mtot BTC) ptot = userAccountPayout pt u mtot = userAccountMEF mt u -- | Given rates, mef, and payouts tables, project the account over given number of steps (days) projectAccount :: Int -> ExchangeRates -> MEFTable -> PayoutTable -> UserAccount -> UserAccount projectAccount n et mt pt u = iterate (projectAccountOnce et mt pt) u !! n -- | Project the account and return its balance exchanged into sym projectAccountExchangeTo :: (CurrencySymbol a) => a -> Int -> ExchangeRates -> MEFTable -> PayoutTable -> UserAccount -> Maybe (Money a) projectAccountExchangeTo sy n et mt pt u = exchangeTo et b sy where b = accountBalance $ projectAccount n et mt pt u projectAccountUSD = projectAccountExchangeTo USD projectAccountBTC = projectAccountExchangeTo BTC projectAccountRUB = projectAccountExchangeTo RUB