module OANDA.Accounts
( Account (..)
, accounts
, AccountInfo (..)
, accountInfo
) where
import Data.Aeson
import Data.Decimal
import qualified Data.Vector as V
import GHC.Generics (Generic)
import OANDA.Util
import OANDA.Types
data Account = Account
{ accountAccountId :: Int
, accountAccountName :: String
, accountAccountCurrency :: String
, accountMarginRate :: Decimal
} deriving (Show, Generic)
instance FromJSON Account where
parseJSON = genericParseJSON $ jsonOpts "account"
accounts :: OandaEnv -> IO (V.Vector Account)
accounts od = do
let url = baseURL od ++ "/v1/accounts"
opts = constructOpts od []
jsonResponseArray url opts "accounts"
accountInfo :: OandaEnv -> AccountID -> IO AccountInfo
accountInfo od (AccountID aid) =
do let url = baseURL od ++ "/v1/accounts/" ++ show aid
opts = constructOpts od []
jsonResponse url opts
data AccountInfo = AccountInfo
{ accountInfoAccountId :: Integer
, accountInfoAccountName :: String
, accountInfoBalance :: Decimal
, accountInfoUnrealizedPl :: Decimal
, accountInfoRealizedPl :: Decimal
, accountInfoMarginUsed :: Decimal
, accountInfoMarginAvail :: Decimal
, accountInfoOpenTrades :: Integer
, accountInfoOpenOrders :: Integer
, accountInfoMarginRate :: Decimal
, accountInfoAccountCurrency :: String
} deriving (Show, Generic)
instance FromJSON AccountInfo where
parseJSON = genericParseJSON $ jsonOpts "accountInfo"