{-# LANGUAGE DataKinds         #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE TypeFamilies      #-}
{-# LANGUAGE TypeOperators     #-}

module CoinbasePro.Authenticated
  ( accounts
  , account
  , accountHistory
  , accountHolds
  , listOrders
  , getOrder
  , getClientOrder
  , placeOrder
  , cancelOrder
  , cancelAll
  , fills
  , fees
  , trailingVolume
  , limits
  , deposits
  , withdrawals
  , transfer
  , makeDeposit
  , makeCoinbaseDeposit
  , cryptoDepositAddress
  , makeWithdrawal
  , makeCoinbaseWithdrawal
  , makeCryptoWithdrawal
  , withdrawalFeeEstimate
  , paymentMethods
  , coinbaseAccounts
  ) where

import           Control.Monad                              (void)
import           Data.Aeson                                 (encode)
import qualified Data.ByteString.Builder                    as BB
import qualified Data.ByteString.Lazy.Char8                 as LC8
import           Data.Maybe                                 (fromMaybe)
import qualified Data.Set                                   as S
import           Data.Text                                  (Text, pack)
import           Data.Text.Encoding                         (encodeUtf8)
import           Data.Time.Clock                            (UTCTime)
import           Data.UUID                                  (toText)
import           Network.HTTP.Types                         (SimpleQuery,
                                                             SimpleQueryItem,
                                                             encodePathSegments,
                                                             methodDelete,
                                                             methodGet,
                                                             methodPost,
                                                             renderQuery,
                                                             simpleQueryToQuery)
import           Servant.Client                             (ClientM)

import qualified CoinbasePro.Authenticated.API              as API
import           CoinbasePro.Authenticated.Accounts         (Account,
                                                             AccountHistory,
                                                             AccountId (..),
                                                             Fees, Hold,
                                                             TrailingVolume (..))
import           CoinbasePro.Authenticated.CoinbaseAccounts (CoinbaseAccount)
import           CoinbasePro.Authenticated.Deposit          (CoinbaseDepositRequest (..),
                                                             CryptoDepositAddress,
                                                             DepositRequest (..),
                                                             DepositResponse)
import           CoinbasePro.Authenticated.Fills            (Fill)
import           CoinbasePro.Authenticated.Limits           (Limits)
import           CoinbasePro.Authenticated.Orders           (Order,
                                                             PlaceOrderBody (..),
                                                             STP, Status (..),
                                                             Statuses (..),
                                                             TimeInForce,
                                                             statuses)
import           CoinbasePro.Authenticated.Payment          (PaymentMethod,
                                                             PaymentMethodId (..))
import           CoinbasePro.Authenticated.Request          (CBAuthT (..),
                                                             authRequest)
import           CoinbasePro.Authenticated.Transfer         (Transfer,
                                                             TransferType (..))
import           CoinbasePro.Authenticated.Withdrawal       (CoinbaseWithdrawalRequest (..),
                                                             CryptoWithdrawalRequest (..),
                                                             CryptoWithdrawalResponse,
                                                             WithdrawalFeeEstimateResponse (..),
                                                             WithdrawalRequest (..),
                                                             WithdrawalResponse)
import           CoinbasePro.Request                        (RequestPath,
                                                             emptyBody)


import           CoinbasePro.Types                          (ClientOrderId (..),
                                                             CryptoAddress (..),
                                                             CurrencyType (..),
                                                             OrderId (..),
                                                             OrderType, Price,
                                                             ProductId (..),
                                                             ProfileId, Side,
                                                             Size)

accountsPath :: Text
accountsPath :: Text
accountsPath = Text
"accounts"


ordersPath :: Text
ordersPath :: Text
ordersPath = Text
"orders"


encodeRequestPath :: [Text] -> RequestPath
encodeRequestPath :: [Text] -> RequestPath
encodeRequestPath = ByteString -> RequestPath
LC8.toStrict (ByteString -> RequestPath)
-> ([Text] -> ByteString) -> [Text] -> RequestPath
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Builder -> ByteString
BB.toLazyByteString (Builder -> ByteString)
-> ([Text] -> Builder) -> [Text] -> ByteString
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Text] -> Builder
encodePathSegments


mkSimpleQueryItem :: Show a => Text -> a -> SimpleQueryItem
mkSimpleQueryItem :: Text -> a -> SimpleQueryItem
mkSimpleQueryItem Text
s a
a = (Text -> RequestPath
encodeUtf8 Text
s, Text -> RequestPath
encodeUtf8 (Text -> RequestPath) -> Text -> RequestPath
forall a b. (a -> b) -> a -> b
$ String -> Text
pack (a -> String
forall a. Show a => a -> String
show a
a))


optionalQuery :: Show a => Text -> Maybe a -> [SimpleQueryItem]
optionalQuery :: Text -> Maybe a -> [SimpleQueryItem]
optionalQuery Text
t = [SimpleQueryItem]
-> (a -> [SimpleQueryItem]) -> Maybe a -> [SimpleQueryItem]
forall b a. b -> (a -> b) -> Maybe a -> b
maybe [] (SimpleQueryItem -> [SimpleQueryItem]
forall (m :: * -> *) a. Monad m => a -> m a
return (SimpleQueryItem -> [SimpleQueryItem])
-> (a -> SimpleQueryItem) -> a -> [SimpleQueryItem]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> a -> SimpleQueryItem
forall a. Show a => Text -> a -> SimpleQueryItem
mkSimpleQueryItem Text
t)


mkProductQuery :: Maybe ProductId -> [SimpleQueryItem]
mkProductQuery :: Maybe ProductId -> [SimpleQueryItem]
mkProductQuery = Text -> Maybe ProductId -> [SimpleQueryItem]
forall a. Show a => Text -> Maybe a -> [SimpleQueryItem]
optionalQuery Text
"product_id"


mkOrderIdQuery :: Maybe OrderId -> SimpleQuery
mkOrderIdQuery :: Maybe OrderId -> [SimpleQueryItem]
mkOrderIdQuery = Text -> Maybe OrderId -> [SimpleQueryItem]
forall a. Show a => Text -> Maybe a -> [SimpleQueryItem]
optionalQuery Text
"order_id"


-- | https://docs.pro.coinbase.com/#accounts
accounts :: CBAuthT ClientM [Account]
accounts :: CBAuthT ClientM [Account]
accounts = RequestPath
-> RequestPath
-> RequestPath
-> (AuthenticatedRequest (AuthProtect "CBAuth")
    -> ClientM [Account])
-> CBAuthT ClientM [Account]
forall b.
RequestPath
-> RequestPath
-> RequestPath
-> (AuthenticatedRequest (AuthProtect "CBAuth") -> ClientM b)
-> CBAuthT ClientM b
authRequest RequestPath
methodGet RequestPath
requestPath RequestPath
emptyBody AuthenticatedRequest (AuthProtect "CBAuth") -> ClientM [Account]
API.accounts
  where
    requestPath :: RequestPath
requestPath = [Text] -> RequestPath
encodeRequestPath [Text
accountsPath]


-- | https://docs.pro.coinbase.com/#get-an-account
account :: AccountId -> CBAuthT ClientM Account
account :: AccountId -> CBAuthT ClientM Account
account aid :: AccountId
aid@(AccountId Text
t) = RequestPath
-> RequestPath
-> RequestPath
-> (AuthenticatedRequest (AuthProtect "CBAuth") -> ClientM Account)
-> CBAuthT ClientM Account
forall b.
RequestPath
-> RequestPath
-> RequestPath
-> (AuthenticatedRequest (AuthProtect "CBAuth") -> ClientM b)
-> CBAuthT ClientM b
authRequest RequestPath
methodGet RequestPath
requestPath RequestPath
emptyBody ((AuthenticatedRequest (AuthProtect "CBAuth") -> ClientM Account)
 -> CBAuthT ClientM Account)
-> (AuthenticatedRequest (AuthProtect "CBAuth") -> ClientM Account)
-> CBAuthT ClientM Account
forall a b. (a -> b) -> a -> b
$ AccountId
-> AuthenticatedRequest (AuthProtect "CBAuth") -> ClientM Account
API.singleAccount AccountId
aid
  where
    requestPath :: RequestPath
requestPath = [Text] -> RequestPath
encodeRequestPath [Text
accountsPath, Text
t]


-- | https://docs.pro.coinbase.com/#get-account-history
accountHistory :: AccountId -> CBAuthT ClientM [AccountHistory]
accountHistory :: AccountId -> CBAuthT ClientM [AccountHistory]
accountHistory aid :: AccountId
aid@(AccountId Text
t) = RequestPath
-> RequestPath
-> RequestPath
-> (AuthenticatedRequest (AuthProtect "CBAuth")
    -> ClientM [AccountHistory])
-> CBAuthT ClientM [AccountHistory]
forall b.
RequestPath
-> RequestPath
-> RequestPath
-> (AuthenticatedRequest (AuthProtect "CBAuth") -> ClientM b)
-> CBAuthT ClientM b
authRequest RequestPath
methodGet RequestPath
requestPath RequestPath
emptyBody ((AuthenticatedRequest (AuthProtect "CBAuth")
  -> ClientM [AccountHistory])
 -> CBAuthT ClientM [AccountHistory])
-> (AuthenticatedRequest (AuthProtect "CBAuth")
    -> ClientM [AccountHistory])
-> CBAuthT ClientM [AccountHistory]
forall a b. (a -> b) -> a -> b
$ AccountId
-> AuthenticatedRequest (AuthProtect "CBAuth")
-> ClientM [AccountHistory]
API.accountHistory AccountId
aid
  where
    ledgerPath :: Text
ledgerPath  = Text
"ledger"
    requestPath :: RequestPath
requestPath = [Text] -> RequestPath
encodeRequestPath [Text
accountsPath, Text
t, Text
ledgerPath]


-- | https://docs.pro.coinbase.com/#get-holds
accountHolds :: AccountId -> CBAuthT ClientM [Hold]
accountHolds :: AccountId -> CBAuthT ClientM [Hold]
accountHolds aid :: AccountId
aid@(AccountId Text
t) = RequestPath
-> RequestPath
-> RequestPath
-> (AuthenticatedRequest (AuthProtect "CBAuth") -> ClientM [Hold])
-> CBAuthT ClientM [Hold]
forall b.
RequestPath
-> RequestPath
-> RequestPath
-> (AuthenticatedRequest (AuthProtect "CBAuth") -> ClientM b)
-> CBAuthT ClientM b
authRequest RequestPath
methodGet RequestPath
requestPath RequestPath
emptyBody ((AuthenticatedRequest (AuthProtect "CBAuth") -> ClientM [Hold])
 -> CBAuthT ClientM [Hold])
-> (AuthenticatedRequest (AuthProtect "CBAuth") -> ClientM [Hold])
-> CBAuthT ClientM [Hold]
forall a b. (a -> b) -> a -> b
$ AccountId
-> AuthenticatedRequest (AuthProtect "CBAuth") -> ClientM [Hold]
API.accountHolds AccountId
aid
  where
    holdsPath :: Text
holdsPath   = Text
"holds"
    requestPath :: RequestPath
requestPath = [Text] -> RequestPath
encodeRequestPath [Text
accountsPath, Text
t, Text
holdsPath]


-- | https://docs.pro.coinbase.com/#list-orders
listOrders :: Maybe [Status] -> Maybe ProductId -> CBAuthT ClientM [Order]
listOrders :: Maybe [Status] -> Maybe ProductId -> CBAuthT ClientM [Order]
listOrders Maybe [Status]
st Maybe ProductId
prid = RequestPath
-> RequestPath
-> RequestPath
-> (AuthenticatedRequest (AuthProtect "CBAuth") -> ClientM [Order])
-> CBAuthT ClientM [Order]
forall b.
RequestPath
-> RequestPath
-> RequestPath
-> (AuthenticatedRequest (AuthProtect "CBAuth") -> ClientM b)
-> CBAuthT ClientM b
authRequest RequestPath
methodGet RequestPath
requestPath RequestPath
emptyBody ((AuthenticatedRequest (AuthProtect "CBAuth") -> ClientM [Order])
 -> CBAuthT ClientM [Order])
-> (AuthenticatedRequest (AuthProtect "CBAuth") -> ClientM [Order])
-> CBAuthT ClientM [Order]
forall a b. (a -> b) -> a -> b
$ [Status]
-> Maybe ProductId
-> AuthenticatedRequest (AuthProtect "CBAuth")
-> ClientM [Order]
API.listOrders (Maybe [Status] -> [Status]
defaultStatus Maybe [Status]
st) Maybe ProductId
prid
  where
    query :: RequestPath
query       = Bool -> Query -> RequestPath
renderQuery Bool
True (Query -> RequestPath)
-> ([SimpleQueryItem] -> Query) -> [SimpleQueryItem] -> RequestPath
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [SimpleQueryItem] -> Query
simpleQueryToQuery ([SimpleQueryItem] -> RequestPath)
-> [SimpleQueryItem] -> RequestPath
forall a b. (a -> b) -> a -> b
$ Maybe [Status] -> Maybe ProductId -> [SimpleQueryItem]
orderQuery Maybe [Status]
st Maybe ProductId
prid
    requestPath :: RequestPath
requestPath = [Text] -> RequestPath
encodeRequestPath [Text
ordersPath] RequestPath -> RequestPath -> RequestPath
forall a. Semigroup a => a -> a -> a
<> RequestPath
query

    orderQuery :: Maybe [Status] -> Maybe ProductId -> SimpleQuery
    orderQuery :: Maybe [Status] -> Maybe ProductId -> [SimpleQueryItem]
orderQuery Maybe [Status]
ss Maybe ProductId
p = Maybe [Status] -> [SimpleQueryItem]
statusQuery Maybe [Status]
ss [SimpleQueryItem] -> [SimpleQueryItem] -> [SimpleQueryItem]
forall a. Semigroup a => a -> a -> a
<> Maybe ProductId -> [SimpleQueryItem]
mkProductQuery Maybe ProductId
p

    statusQuery :: Maybe [Status] -> [SimpleQueryItem]
    statusQuery :: Maybe [Status] -> [SimpleQueryItem]
statusQuery Maybe [Status]
ss = Text -> Status -> SimpleQueryItem
forall a. Show a => Text -> a -> SimpleQueryItem
mkSimpleQueryItem Text
"status" (Status -> SimpleQueryItem) -> [Status] -> [SimpleQueryItem]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Set Status -> [Status]
forall a. Set a -> [a]
S.toList (Statuses -> Set Status
unStatuses (Statuses -> Set Status)
-> ([Status] -> Statuses) -> [Status] -> Set Status
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Status] -> Statuses
statuses ([Status] -> Set Status) -> [Status] -> Set Status
forall a b. (a -> b) -> a -> b
$ Maybe [Status] -> [Status]
defaultStatus Maybe [Status]
ss)

    defaultStatus :: Maybe [Status] -> [Status]
    defaultStatus :: Maybe [Status] -> [Status]
defaultStatus = [Status] -> Maybe [Status] -> [Status]
forall a. a -> Maybe a -> a
fromMaybe [Status
All]


-- | https://docs.pro.coinbase.com/#get-an-order
getOrder :: OrderId -> CBAuthT ClientM Order
getOrder :: OrderId -> CBAuthT ClientM Order
getOrder OrderId
oid = RequestPath
-> RequestPath
-> RequestPath
-> (AuthenticatedRequest (AuthProtect "CBAuth") -> ClientM Order)
-> CBAuthT ClientM Order
forall b.
RequestPath
-> RequestPath
-> RequestPath
-> (AuthenticatedRequest (AuthProtect "CBAuth") -> ClientM b)
-> CBAuthT ClientM b
authRequest RequestPath
methodGet RequestPath
requestPath RequestPath
emptyBody ((AuthenticatedRequest (AuthProtect "CBAuth") -> ClientM Order)
 -> CBAuthT ClientM Order)
-> (AuthenticatedRequest (AuthProtect "CBAuth") -> ClientM Order)
-> CBAuthT ClientM Order
forall a b. (a -> b) -> a -> b
$ OrderId
-> AuthenticatedRequest (AuthProtect "CBAuth") -> ClientM Order
API.getOrder OrderId
oid
  where
    requestPath :: RequestPath
requestPath = [Text] -> RequestPath
encodeRequestPath [Text
ordersPath, OrderId -> Text
unOrderId OrderId
oid]


-- | https://docs.pro.coinbase.com/#get-an-order
getClientOrder :: ClientOrderId -> CBAuthT ClientM Order
getClientOrder :: ClientOrderId -> CBAuthT ClientM Order
getClientOrder ClientOrderId
cloid = RequestPath
-> RequestPath
-> RequestPath
-> (AuthenticatedRequest (AuthProtect "CBAuth") -> ClientM Order)
-> CBAuthT ClientM Order
forall b.
RequestPath
-> RequestPath
-> RequestPath
-> (AuthenticatedRequest (AuthProtect "CBAuth") -> ClientM b)
-> CBAuthT ClientM b
authRequest RequestPath
methodGet RequestPath
requestPath RequestPath
emptyBody ((AuthenticatedRequest (AuthProtect "CBAuth") -> ClientM Order)
 -> CBAuthT ClientM Order)
-> (AuthenticatedRequest (AuthProtect "CBAuth") -> ClientM Order)
-> CBAuthT ClientM Order
forall a b. (a -> b) -> a -> b
$ ClientOrderId
-> AuthenticatedRequest (AuthProtect "CBAuth") -> ClientM Order
API.getClientOrder ClientOrderId
cloid
  where
    oid :: Text
oid         = UUID -> Text
toText (UUID -> Text) -> UUID -> Text
forall a b. (a -> b) -> a -> b
$ ClientOrderId -> UUID
unClientOrderId ClientOrderId
cloid
    requestPath :: RequestPath
requestPath = [Text] -> RequestPath
encodeRequestPath [Text
ordersPath, Text
"client:" Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
oid]


-- | https://docs.pro.coinbase.com/#place-a-new-order
placeOrder :: Maybe ClientOrderId
           -> ProductId
           -> Side
           -> Size
           -> Price
           -> Bool
           -> Maybe OrderType
           -> Maybe STP
           -> Maybe TimeInForce
           -> CBAuthT ClientM Order
placeOrder :: Maybe ClientOrderId
-> ProductId
-> Side
-> Size
-> Price
-> Bool
-> Maybe OrderType
-> Maybe STP
-> Maybe TimeInForce
-> CBAuthT ClientM Order
placeOrder Maybe ClientOrderId
clordid ProductId
prid Side
sd Size
sz Price
price Bool
po Maybe OrderType
ot Maybe STP
stp Maybe TimeInForce
tif =
    RequestPath
-> RequestPath
-> RequestPath
-> (AuthenticatedRequest (AuthProtect "CBAuth") -> ClientM Order)
-> CBAuthT ClientM Order
forall b.
RequestPath
-> RequestPath
-> RequestPath
-> (AuthenticatedRequest (AuthProtect "CBAuth") -> ClientM b)
-> CBAuthT ClientM b
authRequest RequestPath
methodPost RequestPath
requestPath RequestPath
seBody ((AuthenticatedRequest (AuthProtect "CBAuth") -> ClientM Order)
 -> CBAuthT ClientM Order)
-> (AuthenticatedRequest (AuthProtect "CBAuth") -> ClientM Order)
-> CBAuthT ClientM Order
forall a b. (a -> b) -> a -> b
$ PlaceOrderBody
-> AuthenticatedRequest (AuthProtect "CBAuth") -> ClientM Order
API.placeOrder PlaceOrderBody
body
  where
    requestPath :: RequestPath
requestPath = [Text] -> RequestPath
encodeRequestPath [Text
ordersPath]
    body :: PlaceOrderBody
body        = Maybe ClientOrderId
-> ProductId
-> Side
-> Size
-> Price
-> Bool
-> Maybe OrderType
-> Maybe STP
-> Maybe TimeInForce
-> PlaceOrderBody
PlaceOrderBody Maybe ClientOrderId
clordid ProductId
prid Side
sd Size
sz Price
price Bool
po Maybe OrderType
ot Maybe STP
stp Maybe TimeInForce
tif
    seBody :: RequestPath
seBody      = ByteString -> RequestPath
LC8.toStrict (ByteString -> RequestPath) -> ByteString -> RequestPath
forall a b. (a -> b) -> a -> b
$ PlaceOrderBody -> ByteString
forall a. ToJSON a => a -> ByteString
encode PlaceOrderBody
body


-- | https://docs.pro.coinbase.com/#cancel-an-order
cancelOrder :: OrderId -> CBAuthT ClientM ()
cancelOrder :: OrderId -> CBAuthT ClientM ()
cancelOrder OrderId
oid = CBAuthT ClientM NoContent -> CBAuthT ClientM ()
forall (f :: * -> *) a. Functor f => f a -> f ()
void (CBAuthT ClientM NoContent -> CBAuthT ClientM ())
-> ((AuthenticatedRequest (AuthProtect "CBAuth")
     -> ClientM NoContent)
    -> CBAuthT ClientM NoContent)
-> (AuthenticatedRequest (AuthProtect "CBAuth")
    -> ClientM NoContent)
-> CBAuthT ClientM ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. RequestPath
-> RequestPath
-> RequestPath
-> (AuthenticatedRequest (AuthProtect "CBAuth")
    -> ClientM NoContent)
-> CBAuthT ClientM NoContent
forall b.
RequestPath
-> RequestPath
-> RequestPath
-> (AuthenticatedRequest (AuthProtect "CBAuth") -> ClientM b)
-> CBAuthT ClientM b
authRequest RequestPath
methodDelete RequestPath
requestPath RequestPath
emptyBody ((AuthenticatedRequest (AuthProtect "CBAuth") -> ClientM NoContent)
 -> CBAuthT ClientM ())
-> (AuthenticatedRequest (AuthProtect "CBAuth")
    -> ClientM NoContent)
-> CBAuthT ClientM ()
forall a b. (a -> b) -> a -> b
$ OrderId
-> AuthenticatedRequest (AuthProtect "CBAuth") -> ClientM NoContent
API.cancelOrder OrderId
oid
  where
    requestPath :: RequestPath
requestPath = [Text] -> RequestPath
encodeRequestPath [Text
ordersPath, OrderId -> Text
unOrderId OrderId
oid]


-- | https://docs.pro.coinbase.com/#cancel-all
cancelAll :: Maybe ProductId -> CBAuthT ClientM [OrderId]
cancelAll :: Maybe ProductId -> CBAuthT ClientM [OrderId]
cancelAll Maybe ProductId
prid = RequestPath
-> RequestPath
-> RequestPath
-> (AuthenticatedRequest (AuthProtect "CBAuth")
    -> ClientM [OrderId])
-> CBAuthT ClientM [OrderId]
forall b.
RequestPath
-> RequestPath
-> RequestPath
-> (AuthenticatedRequest (AuthProtect "CBAuth") -> ClientM b)
-> CBAuthT ClientM b
authRequest RequestPath
methodDelete RequestPath
requestPath RequestPath
emptyBody (Maybe ProductId
-> AuthenticatedRequest (AuthProtect "CBAuth") -> ClientM [OrderId]
API.cancelAll Maybe ProductId
prid)
  where
    query :: RequestPath
query       = Bool -> Query -> RequestPath
renderQuery Bool
True (Query -> RequestPath)
-> ([SimpleQueryItem] -> Query) -> [SimpleQueryItem] -> RequestPath
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [SimpleQueryItem] -> Query
simpleQueryToQuery ([SimpleQueryItem] -> RequestPath)
-> [SimpleQueryItem] -> RequestPath
forall a b. (a -> b) -> a -> b
$ Maybe ProductId -> [SimpleQueryItem]
mkProductQuery Maybe ProductId
prid
    requestPath :: RequestPath
requestPath = [Text] -> RequestPath
encodeRequestPath [Text
ordersPath] RequestPath -> RequestPath -> RequestPath
forall a. Semigroup a => a -> a -> a
<> RequestPath
query


-- | https://docs.pro.coinbase.com/#fills
fills :: Maybe ProductId -> Maybe OrderId -> CBAuthT ClientM [Fill]
fills :: Maybe ProductId -> Maybe OrderId -> CBAuthT ClientM [Fill]
fills Maybe ProductId
prid Maybe OrderId
oid = RequestPath
-> RequestPath
-> RequestPath
-> (AuthenticatedRequest (AuthProtect "CBAuth") -> ClientM [Fill])
-> CBAuthT ClientM [Fill]
forall b.
RequestPath
-> RequestPath
-> RequestPath
-> (AuthenticatedRequest (AuthProtect "CBAuth") -> ClientM b)
-> CBAuthT ClientM b
authRequest RequestPath
methodGet RequestPath
requestPath RequestPath
emptyBody (Maybe ProductId
-> Maybe OrderId
-> AuthenticatedRequest (AuthProtect "CBAuth")
-> ClientM [Fill]
API.fills Maybe ProductId
prid Maybe OrderId
oid)
  where
    fillsPath :: Text
fillsPath   = Text
"fills"
    query :: RequestPath
query       = Bool -> Query -> RequestPath
renderQuery Bool
True (Query -> RequestPath)
-> ([SimpleQueryItem] -> Query) -> [SimpleQueryItem] -> RequestPath
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [SimpleQueryItem] -> Query
simpleQueryToQuery ([SimpleQueryItem] -> RequestPath)
-> [SimpleQueryItem] -> RequestPath
forall a b. (a -> b) -> a -> b
$ Maybe ProductId -> Maybe OrderId -> [SimpleQueryItem]
mkSimpleQuery Maybe ProductId
prid Maybe OrderId
oid
    requestPath :: RequestPath
requestPath = [Text] -> RequestPath
encodeRequestPath [Text
fillsPath] RequestPath -> RequestPath -> RequestPath
forall a. Semigroup a => a -> a -> a
<> RequestPath
query

    mkSimpleQuery :: Maybe ProductId -> Maybe OrderId -> SimpleQuery
    mkSimpleQuery :: Maybe ProductId -> Maybe OrderId -> [SimpleQueryItem]
mkSimpleQuery Maybe ProductId
p Maybe OrderId
o = Maybe ProductId -> [SimpleQueryItem]
mkProductQuery Maybe ProductId
p [SimpleQueryItem] -> [SimpleQueryItem] -> [SimpleQueryItem]
forall a. Semigroup a => a -> a -> a
<> Maybe OrderId -> [SimpleQueryItem]
mkOrderIdQuery Maybe OrderId
o


-- | https://docs.pro.coinbase.com/#get-current-fees
fees :: CBAuthT ClientM Fees
fees :: CBAuthT ClientM Fees
fees = RequestPath
-> RequestPath
-> RequestPath
-> (AuthenticatedRequest (AuthProtect "CBAuth") -> ClientM Fees)
-> CBAuthT ClientM Fees
forall b.
RequestPath
-> RequestPath
-> RequestPath
-> (AuthenticatedRequest (AuthProtect "CBAuth") -> ClientM b)
-> CBAuthT ClientM b
authRequest RequestPath
methodGet RequestPath
feesRequestPath RequestPath
emptyBody AuthenticatedRequest (AuthProtect "CBAuth") -> ClientM Fees
API.fees
  where
    feesPath :: Text
feesPath        = Text
"fees"
    feesRequestPath :: RequestPath
feesRequestPath = [Text] -> RequestPath
encodeRequestPath [Text
feesPath]


-- | https://docs.pro.coinbase.com/#trailing-volume
trailingVolume :: CBAuthT ClientM [TrailingVolume]
trailingVolume :: CBAuthT ClientM [TrailingVolume]
trailingVolume = RequestPath
-> RequestPath
-> RequestPath
-> (AuthenticatedRequest (AuthProtect "CBAuth")
    -> ClientM [TrailingVolume])
-> CBAuthT ClientM [TrailingVolume]
forall b.
RequestPath
-> RequestPath
-> RequestPath
-> (AuthenticatedRequest (AuthProtect "CBAuth") -> ClientM b)
-> CBAuthT ClientM b
authRequest RequestPath
methodGet RequestPath
requestPath RequestPath
emptyBody AuthenticatedRequest (AuthProtect "CBAuth")
-> ClientM [TrailingVolume]
API.trailingVolume
  where
    requestPath :: RequestPath
requestPath = [Text] -> RequestPath
encodeRequestPath [Text
"users", Text
"self", Text
"trailing-volume"]


-- | https://docs.pro.coinbase.com/#get-current-exchange-limits
limits :: CBAuthT ClientM Limits
limits :: CBAuthT ClientM Limits
limits = RequestPath
-> RequestPath
-> RequestPath
-> (AuthenticatedRequest (AuthProtect "CBAuth") -> ClientM Limits)
-> CBAuthT ClientM Limits
forall b.
RequestPath
-> RequestPath
-> RequestPath
-> (AuthenticatedRequest (AuthProtect "CBAuth") -> ClientM b)
-> CBAuthT ClientM b
authRequest RequestPath
methodGet RequestPath
requestPath RequestPath
emptyBody AuthenticatedRequest (AuthProtect "CBAuth") -> ClientM Limits
API.limits
  where
    requestPath :: RequestPath
requestPath = [Text] -> RequestPath
encodeRequestPath [Text
"users", Text
"self", Text
"exchange-limits"]


-- | https://docs.pro.coinbase.com/#list-deposits
deposits :: Maybe ProfileId
         -> Maybe UTCTime
         -> Maybe UTCTime
         -> Maybe Int
         -> CBAuthT ClientM [Transfer]
deposits :: Maybe Text
-> Maybe UTCTime
-> Maybe UTCTime
-> Maybe Int
-> CBAuthT ClientM [Transfer]
deposits = TransferType
-> Maybe Text
-> Maybe UTCTime
-> Maybe UTCTime
-> Maybe Int
-> CBAuthT ClientM [Transfer]
transfers TransferType
DepositTransferType


-- | https://docs.pro.coinbase.com/#list-withdrawals
withdrawals :: Maybe ProfileId
            -> Maybe UTCTime
            -> Maybe UTCTime
            -> Maybe Int
            -> CBAuthT ClientM [Transfer]
withdrawals :: Maybe Text
-> Maybe UTCTime
-> Maybe UTCTime
-> Maybe Int
-> CBAuthT ClientM [Transfer]
withdrawals = TransferType
-> Maybe Text
-> Maybe UTCTime
-> Maybe UTCTime
-> Maybe Int
-> CBAuthT ClientM [Transfer]
transfers TransferType
WithdrawTransferType


transfers :: TransferType
          -> Maybe ProfileId
          -> Maybe UTCTime
          -> Maybe UTCTime
          -> Maybe Int
          -> CBAuthT ClientM [Transfer]
transfers :: TransferType
-> Maybe Text
-> Maybe UTCTime
-> Maybe UTCTime
-> Maybe Int
-> CBAuthT ClientM [Transfer]
transfers TransferType
tt Maybe Text
prof Maybe UTCTime
before Maybe UTCTime
after Maybe Int
lm = RequestPath
-> RequestPath
-> RequestPath
-> (AuthenticatedRequest (AuthProtect "CBAuth")
    -> ClientM [Transfer])
-> CBAuthT ClientM [Transfer]
forall b.
RequestPath
-> RequestPath
-> RequestPath
-> (AuthenticatedRequest (AuthProtect "CBAuth") -> ClientM b)
-> CBAuthT ClientM b
authRequest RequestPath
methodGet RequestPath
requestPath RequestPath
emptyBody ((AuthenticatedRequest (AuthProtect "CBAuth")
  -> ClientM [Transfer])
 -> CBAuthT ClientM [Transfer])
-> (AuthenticatedRequest (AuthProtect "CBAuth")
    -> ClientM [Transfer])
-> CBAuthT ClientM [Transfer]
forall a b. (a -> b) -> a -> b
$
    TransferType
-> Maybe Text
-> Maybe UTCTime
-> Maybe UTCTime
-> Maybe Int
-> AuthenticatedRequest (AuthProtect "CBAuth")
-> ClientM [Transfer]
API.transfers TransferType
tt Maybe Text
prof Maybe UTCTime
before Maybe UTCTime
after Maybe Int
lm
  where
    typeQ :: [SimpleQueryItem]
typeQ   = SimpleQueryItem -> [SimpleQueryItem]
forall (m :: * -> *) a. Monad m => a -> m a
return (SimpleQueryItem -> [SimpleQueryItem])
-> SimpleQueryItem -> [SimpleQueryItem]
forall a b. (a -> b) -> a -> b
$ Text -> TransferType -> SimpleQueryItem
forall a. Show a => Text -> a -> SimpleQueryItem
mkSimpleQueryItem Text
"type" TransferType
tt
    profQ :: [SimpleQueryItem]
profQ   = Text -> Maybe Text -> [SimpleQueryItem]
forall a. Show a => Text -> Maybe a -> [SimpleQueryItem]
optionalQuery Text
"profile_id" Maybe Text
prof
    beforeQ :: [SimpleQueryItem]
beforeQ = Text -> Maybe UTCTime -> [SimpleQueryItem]
forall a. Show a => Text -> Maybe a -> [SimpleQueryItem]
optionalQuery Text
"before" Maybe UTCTime
before
    afterQ :: [SimpleQueryItem]
afterQ  = Text -> Maybe UTCTime -> [SimpleQueryItem]
forall a. Show a => Text -> Maybe a -> [SimpleQueryItem]
optionalQuery Text
"after" Maybe UTCTime
after
    lmQ :: [SimpleQueryItem]
lmQ     = Text -> Maybe Int -> [SimpleQueryItem]
forall a. Show a => Text -> Maybe a -> [SimpleQueryItem]
optionalQuery Text
"limit" Maybe Int
lm

    query :: RequestPath
query       = Bool -> Query -> RequestPath
renderQuery Bool
True (Query -> RequestPath)
-> ([SimpleQueryItem] -> Query) -> [SimpleQueryItem] -> RequestPath
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [SimpleQueryItem] -> Query
simpleQueryToQuery ([SimpleQueryItem] -> RequestPath)
-> [SimpleQueryItem] -> RequestPath
forall a b. (a -> b) -> a -> b
$ [SimpleQueryItem]
typeQ [SimpleQueryItem] -> [SimpleQueryItem] -> [SimpleQueryItem]
forall a. Semigroup a => a -> a -> a
<> [SimpleQueryItem]
profQ [SimpleQueryItem] -> [SimpleQueryItem] -> [SimpleQueryItem]
forall a. Semigroup a => a -> a -> a
<> [SimpleQueryItem]
beforeQ [SimpleQueryItem] -> [SimpleQueryItem] -> [SimpleQueryItem]
forall a. Semigroup a => a -> a -> a
<> [SimpleQueryItem]
afterQ [SimpleQueryItem] -> [SimpleQueryItem] -> [SimpleQueryItem]
forall a. Semigroup a => a -> a -> a
<> [SimpleQueryItem]
lmQ
    requestPath :: RequestPath
requestPath = [Text] -> RequestPath
encodeRequestPath [Text
"transfers"] RequestPath -> RequestPath -> RequestPath
forall a. Semigroup a => a -> a -> a
<> RequestPath
query


-- | https://docs.pro.coinbase.com/#single-deposit
-- | https://docs.pro.coinbase.com/#single-withdrawal
transfer :: PaymentMethodId -> CBAuthT ClientM Transfer
transfer :: PaymentMethodId -> CBAuthT ClientM Transfer
transfer pmt :: PaymentMethodId
pmt@(PaymentMethodId Text
p) = RequestPath
-> RequestPath
-> RequestPath
-> (AuthenticatedRequest (AuthProtect "CBAuth")
    -> ClientM Transfer)
-> CBAuthT ClientM Transfer
forall b.
RequestPath
-> RequestPath
-> RequestPath
-> (AuthenticatedRequest (AuthProtect "CBAuth") -> ClientM b)
-> CBAuthT ClientM b
authRequest RequestPath
methodGet RequestPath
requestPath RequestPath
emptyBody ((AuthenticatedRequest (AuthProtect "CBAuth") -> ClientM Transfer)
 -> CBAuthT ClientM Transfer)
-> (AuthenticatedRequest (AuthProtect "CBAuth")
    -> ClientM Transfer)
-> CBAuthT ClientM Transfer
forall a b. (a -> b) -> a -> b
$ PaymentMethodId
-> AuthenticatedRequest (AuthProtect "CBAuth") -> ClientM Transfer
API.transfer PaymentMethodId
pmt
  where
    requestPath :: RequestPath
requestPath = [Text] -> RequestPath
encodeRequestPath [Text
"transfers", Text
p]


-- | https://docs.pro.coinbase.com/#payment-method
makeDeposit :: Double
            -> Text
            -> PaymentMethodId
            -> CBAuthT ClientM DepositResponse
makeDeposit :: Double
-> Text -> PaymentMethodId -> CBAuthT ClientM DepositResponse
makeDeposit Double
amt Text
cur PaymentMethodId
pmi =
    RequestPath
-> RequestPath
-> RequestPath
-> (AuthenticatedRequest (AuthProtect "CBAuth")
    -> ClientM DepositResponse)
-> CBAuthT ClientM DepositResponse
forall b.
RequestPath
-> RequestPath
-> RequestPath
-> (AuthenticatedRequest (AuthProtect "CBAuth") -> ClientM b)
-> CBAuthT ClientM b
authRequest RequestPath
methodPost RequestPath
requestPath RequestPath
seBody ((AuthenticatedRequest (AuthProtect "CBAuth")
  -> ClientM DepositResponse)
 -> CBAuthT ClientM DepositResponse)
-> (AuthenticatedRequest (AuthProtect "CBAuth")
    -> ClientM DepositResponse)
-> CBAuthT ClientM DepositResponse
forall a b. (a -> b) -> a -> b
$ DepositRequest
-> AuthenticatedRequest (AuthProtect "CBAuth")
-> ClientM DepositResponse
API.makeDeposit DepositRequest
body
  where
    requestPath :: RequestPath
requestPath = [Text] -> RequestPath
encodeRequestPath [Text
"deposits", Text
"payment-method"]
    body :: DepositRequest
body        = Double -> Text -> PaymentMethodId -> DepositRequest
DepositRequest Double
amt Text
cur PaymentMethodId
pmi
    seBody :: RequestPath
seBody      = ByteString -> RequestPath
LC8.toStrict (ByteString -> RequestPath) -> ByteString -> RequestPath
forall a b. (a -> b) -> a -> b
$ DepositRequest -> ByteString
forall a. ToJSON a => a -> ByteString
encode DepositRequest
body


-- | https://docs.pro.coinbase.com/#coinbase
makeCoinbaseDeposit :: Double
                    -> Text
                    -> AccountId
                    -> CBAuthT ClientM DepositResponse
makeCoinbaseDeposit :: Double -> Text -> AccountId -> CBAuthT ClientM DepositResponse
makeCoinbaseDeposit Double
amt Text
cur AccountId
act =
    RequestPath
-> RequestPath
-> RequestPath
-> (AuthenticatedRequest (AuthProtect "CBAuth")
    -> ClientM DepositResponse)
-> CBAuthT ClientM DepositResponse
forall b.
RequestPath
-> RequestPath
-> RequestPath
-> (AuthenticatedRequest (AuthProtect "CBAuth") -> ClientM b)
-> CBAuthT ClientM b
authRequest RequestPath
methodPost RequestPath
requestPath RequestPath
seBody ((AuthenticatedRequest (AuthProtect "CBAuth")
  -> ClientM DepositResponse)
 -> CBAuthT ClientM DepositResponse)
-> (AuthenticatedRequest (AuthProtect "CBAuth")
    -> ClientM DepositResponse)
-> CBAuthT ClientM DepositResponse
forall a b. (a -> b) -> a -> b
$ CoinbaseDepositRequest
-> AuthenticatedRequest (AuthProtect "CBAuth")
-> ClientM DepositResponse
API.makeCoinbaseDeposit CoinbaseDepositRequest
body
  where
    requestPath :: RequestPath
requestPath = [Text] -> RequestPath
encodeRequestPath [Text
"deposits", Text
"coinbase-account"]
    body :: CoinbaseDepositRequest
body        = Double -> Text -> AccountId -> CoinbaseDepositRequest
CoinbaseDepositRequest Double
amt Text
cur AccountId
act
    seBody :: RequestPath
seBody      = ByteString -> RequestPath
LC8.toStrict (ByteString -> RequestPath) -> ByteString -> RequestPath
forall a b. (a -> b) -> a -> b
$ CoinbaseDepositRequest -> ByteString
forall a. ToJSON a => a -> ByteString
encode CoinbaseDepositRequest
body


-- | https://docs.pro.coinbase.com/#generate-a-crypto-deposit-address
cryptoDepositAddress :: AccountId -> CBAuthT ClientM CryptoDepositAddress
cryptoDepositAddress :: AccountId -> CBAuthT ClientM CryptoDepositAddress
cryptoDepositAddress AccountId
act =
    RequestPath
-> RequestPath
-> RequestPath
-> (AuthenticatedRequest (AuthProtect "CBAuth")
    -> ClientM CryptoDepositAddress)
-> CBAuthT ClientM CryptoDepositAddress
forall b.
RequestPath
-> RequestPath
-> RequestPath
-> (AuthenticatedRequest (AuthProtect "CBAuth") -> ClientM b)
-> CBAuthT ClientM b
authRequest RequestPath
methodPost RequestPath
requestPath RequestPath
emptyBody ((AuthenticatedRequest (AuthProtect "CBAuth")
  -> ClientM CryptoDepositAddress)
 -> CBAuthT ClientM CryptoDepositAddress)
-> (AuthenticatedRequest (AuthProtect "CBAuth")
    -> ClientM CryptoDepositAddress)
-> CBAuthT ClientM CryptoDepositAddress
forall a b. (a -> b) -> a -> b
$ AccountId
-> AuthenticatedRequest (AuthProtect "CBAuth")
-> ClientM CryptoDepositAddress
API.cryptoDepositAddress AccountId
act
  where
    requestPath :: RequestPath
requestPath = [Text] -> RequestPath
encodeRequestPath [Text
"coinbase-accounts", String -> Text
pack (String -> Text) -> String -> Text
forall a b. (a -> b) -> a -> b
$ AccountId -> String
forall a. Show a => a -> String
show AccountId
act, Text
"addresses"]


-- | https://docs.pro.coinbase.com/#payment-method55
makeWithdrawal :: Double
               -> Text
               -> PaymentMethodId
               -> CBAuthT ClientM WithdrawalResponse
makeWithdrawal :: Double
-> Text -> PaymentMethodId -> CBAuthT ClientM WithdrawalResponse
makeWithdrawal Double
amt Text
cur PaymentMethodId
pmi =
    RequestPath
-> RequestPath
-> RequestPath
-> (AuthenticatedRequest (AuthProtect "CBAuth")
    -> ClientM WithdrawalResponse)
-> CBAuthT ClientM WithdrawalResponse
forall b.
RequestPath
-> RequestPath
-> RequestPath
-> (AuthenticatedRequest (AuthProtect "CBAuth") -> ClientM b)
-> CBAuthT ClientM b
authRequest RequestPath
methodPost RequestPath
requestPath RequestPath
seBody ((AuthenticatedRequest (AuthProtect "CBAuth")
  -> ClientM WithdrawalResponse)
 -> CBAuthT ClientM WithdrawalResponse)
-> (AuthenticatedRequest (AuthProtect "CBAuth")
    -> ClientM WithdrawalResponse)
-> CBAuthT ClientM WithdrawalResponse
forall a b. (a -> b) -> a -> b
$ WithdrawalRequest
-> AuthenticatedRequest (AuthProtect "CBAuth")
-> ClientM WithdrawalResponse
API.makeWithdrawal WithdrawalRequest
body
  where
    requestPath :: RequestPath
requestPath = [Text] -> RequestPath
encodeRequestPath [Text
"withdrawals", Text
"payment-method"]
    body :: WithdrawalRequest
body        = Double -> Text -> PaymentMethodId -> WithdrawalRequest
WithdrawalRequest Double
amt Text
cur PaymentMethodId
pmi
    seBody :: RequestPath
seBody      = ByteString -> RequestPath
LC8.toStrict (ByteString -> RequestPath) -> ByteString -> RequestPath
forall a b. (a -> b) -> a -> b
$ WithdrawalRequest -> ByteString
forall a. ToJSON a => a -> ByteString
encode WithdrawalRequest
body


-- | https://docs.pro.coinbase.com/#coinbase56
makeCoinbaseWithdrawal :: Double
                       -> Text
                       -> AccountId
                       -> CBAuthT ClientM WithdrawalResponse
makeCoinbaseWithdrawal :: Double -> Text -> AccountId -> CBAuthT ClientM WithdrawalResponse
makeCoinbaseWithdrawal Double
amt Text
cur AccountId
act =
    RequestPath
-> RequestPath
-> RequestPath
-> (AuthenticatedRequest (AuthProtect "CBAuth")
    -> ClientM WithdrawalResponse)
-> CBAuthT ClientM WithdrawalResponse
forall b.
RequestPath
-> RequestPath
-> RequestPath
-> (AuthenticatedRequest (AuthProtect "CBAuth") -> ClientM b)
-> CBAuthT ClientM b
authRequest RequestPath
methodPost RequestPath
requestPath RequestPath
seBody ((AuthenticatedRequest (AuthProtect "CBAuth")
  -> ClientM WithdrawalResponse)
 -> CBAuthT ClientM WithdrawalResponse)
-> (AuthenticatedRequest (AuthProtect "CBAuth")
    -> ClientM WithdrawalResponse)
-> CBAuthT ClientM WithdrawalResponse
forall a b. (a -> b) -> a -> b
$ CoinbaseWithdrawalRequest
-> AuthenticatedRequest (AuthProtect "CBAuth")
-> ClientM WithdrawalResponse
API.makeCoinbaseWithdrawal CoinbaseWithdrawalRequest
body
  where
    requestPath :: RequestPath
requestPath = [Text] -> RequestPath
encodeRequestPath [Text
"withdrawals", Text
"coinbase-account"]
    body :: CoinbaseWithdrawalRequest
body        = Double -> Text -> AccountId -> CoinbaseWithdrawalRequest
CoinbaseWithdrawalRequest Double
amt Text
cur AccountId
act
    seBody :: RequestPath
seBody      = ByteString -> RequestPath
LC8.toStrict (ByteString -> RequestPath) -> ByteString -> RequestPath
forall a b. (a -> b) -> a -> b
$ CoinbaseWithdrawalRequest -> ByteString
forall a. ToJSON a => a -> ByteString
encode CoinbaseWithdrawalRequest
body


-- | https://docs.pro.coinbase.com/#crypto
makeCryptoWithdrawal :: Double
                     -> Text
                     -> Text
                     -> CBAuthT ClientM CryptoWithdrawalResponse
makeCryptoWithdrawal :: Double -> Text -> Text -> CBAuthT ClientM CryptoWithdrawalResponse
makeCryptoWithdrawal Double
amt Text
cur Text
addr =
    RequestPath
-> RequestPath
-> RequestPath
-> (AuthenticatedRequest (AuthProtect "CBAuth")
    -> ClientM CryptoWithdrawalResponse)
-> CBAuthT ClientM CryptoWithdrawalResponse
forall b.
RequestPath
-> RequestPath
-> RequestPath
-> (AuthenticatedRequest (AuthProtect "CBAuth") -> ClientM b)
-> CBAuthT ClientM b
authRequest RequestPath
methodPost RequestPath
requestPath RequestPath
seBody ((AuthenticatedRequest (AuthProtect "CBAuth")
  -> ClientM CryptoWithdrawalResponse)
 -> CBAuthT ClientM CryptoWithdrawalResponse)
-> (AuthenticatedRequest (AuthProtect "CBAuth")
    -> ClientM CryptoWithdrawalResponse)
-> CBAuthT ClientM CryptoWithdrawalResponse
forall a b. (a -> b) -> a -> b
$ CryptoWithdrawalRequest
-> AuthenticatedRequest (AuthProtect "CBAuth")
-> ClientM CryptoWithdrawalResponse
API.makeCryptoWithdrawal CryptoWithdrawalRequest
body
  where
    requestPath :: RequestPath
requestPath = [Text] -> RequestPath
encodeRequestPath [Text
"withdrawals", Text
"crypto"]
    body :: CryptoWithdrawalRequest
body        = Double -> Text -> Text -> CryptoWithdrawalRequest
CryptoWithdrawalRequest Double
amt Text
cur Text
addr
    seBody :: RequestPath
seBody      = ByteString -> RequestPath
LC8.toStrict (ByteString -> RequestPath) -> ByteString -> RequestPath
forall a b. (a -> b) -> a -> b
$ CryptoWithdrawalRequest -> ByteString
forall a. ToJSON a => a -> ByteString
encode CryptoWithdrawalRequest
body


-- | https://docs.pro.coinbase.com/#fee-estimate
withdrawalFeeEstimate :: CurrencyType
                      -> CryptoAddress
                      -> CBAuthT ClientM WithdrawalFeeEstimateResponse
withdrawalFeeEstimate :: CurrencyType
-> CryptoAddress -> CBAuthT ClientM WithdrawalFeeEstimateResponse
withdrawalFeeEstimate CurrencyType
cur CryptoAddress
addr =
    RequestPath
-> RequestPath
-> RequestPath
-> (AuthenticatedRequest (AuthProtect "CBAuth")
    -> ClientM WithdrawalFeeEstimateResponse)
-> CBAuthT ClientM WithdrawalFeeEstimateResponse
forall b.
RequestPath
-> RequestPath
-> RequestPath
-> (AuthenticatedRequest (AuthProtect "CBAuth") -> ClientM b)
-> CBAuthT ClientM b
authRequest RequestPath
methodGet RequestPath
requestPath RequestPath
emptyBody ((AuthenticatedRequest (AuthProtect "CBAuth")
  -> ClientM WithdrawalFeeEstimateResponse)
 -> CBAuthT ClientM WithdrawalFeeEstimateResponse)
-> (AuthenticatedRequest (AuthProtect "CBAuth")
    -> ClientM WithdrawalFeeEstimateResponse)
-> CBAuthT ClientM WithdrawalFeeEstimateResponse
forall a b. (a -> b) -> a -> b
$ CurrencyType
-> CryptoAddress
-> AuthenticatedRequest (AuthProtect "CBAuth")
-> ClientM WithdrawalFeeEstimateResponse
API.withdrawalFeeEstimate CurrencyType
cur CryptoAddress
addr
  where
    curQ :: [SimpleQueryItem]
curQ  = SimpleQueryItem -> [SimpleQueryItem]
forall (m :: * -> *) a. Monad m => a -> m a
return (SimpleQueryItem -> [SimpleQueryItem])
-> SimpleQueryItem -> [SimpleQueryItem]
forall a b. (a -> b) -> a -> b
$ Text -> CurrencyType -> SimpleQueryItem
forall a. Show a => Text -> a -> SimpleQueryItem
mkSimpleQueryItem Text
"currency" CurrencyType
cur
    addrQ :: [SimpleQueryItem]
addrQ = SimpleQueryItem -> [SimpleQueryItem]
forall (m :: * -> *) a. Monad m => a -> m a
return (SimpleQueryItem -> [SimpleQueryItem])
-> SimpleQueryItem -> [SimpleQueryItem]
forall a b. (a -> b) -> a -> b
$ Text -> CryptoAddress -> SimpleQueryItem
forall a. Show a => Text -> a -> SimpleQueryItem
mkSimpleQueryItem Text
"crypto_address" CryptoAddress
addr

    query :: RequestPath
query       = Bool -> Query -> RequestPath
renderQuery Bool
True (Query -> RequestPath)
-> ([SimpleQueryItem] -> Query) -> [SimpleQueryItem] -> RequestPath
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [SimpleQueryItem] -> Query
simpleQueryToQuery ([SimpleQueryItem] -> RequestPath)
-> [SimpleQueryItem] -> RequestPath
forall a b. (a -> b) -> a -> b
$ [SimpleQueryItem]
curQ [SimpleQueryItem] -> [SimpleQueryItem] -> [SimpleQueryItem]
forall a. Semigroup a => a -> a -> a
<> [SimpleQueryItem]
addrQ
    requestPath :: RequestPath
requestPath = [Text] -> RequestPath
encodeRequestPath [Text
"withdrawals", Text
"fee-estimate"] RequestPath -> RequestPath -> RequestPath
forall a. Semigroup a => a -> a -> a
<> RequestPath
query


-- | https://docs.pro.coinbase.com/#list-payment-methods
paymentMethods :: CBAuthT ClientM [PaymentMethod]
paymentMethods :: CBAuthT ClientM [PaymentMethod]
paymentMethods = RequestPath
-> RequestPath
-> RequestPath
-> (AuthenticatedRequest (AuthProtect "CBAuth")
    -> ClientM [PaymentMethod])
-> CBAuthT ClientM [PaymentMethod]
forall b.
RequestPath
-> RequestPath
-> RequestPath
-> (AuthenticatedRequest (AuthProtect "CBAuth") -> ClientM b)
-> CBAuthT ClientM b
authRequest RequestPath
methodGet RequestPath
requestPath RequestPath
emptyBody AuthenticatedRequest (AuthProtect "CBAuth")
-> ClientM [PaymentMethod]
API.paymentMethods
  where
    requestPath :: RequestPath
requestPath = [Text] -> RequestPath
encodeRequestPath [Text
"payment-methods"]


-- | https://docs.pro.coinbase.com/#list-accounts64
coinbaseAccounts :: CBAuthT ClientM [CoinbaseAccount]
coinbaseAccounts :: CBAuthT ClientM [CoinbaseAccount]
coinbaseAccounts = RequestPath
-> RequestPath
-> RequestPath
-> (AuthenticatedRequest (AuthProtect "CBAuth")
    -> ClientM [CoinbaseAccount])
-> CBAuthT ClientM [CoinbaseAccount]
forall b.
RequestPath
-> RequestPath
-> RequestPath
-> (AuthenticatedRequest (AuthProtect "CBAuth") -> ClientM b)
-> CBAuthT ClientM b
authRequest RequestPath
methodGet RequestPath
requestPath RequestPath
emptyBody AuthenticatedRequest (AuthProtect "CBAuth")
-> ClientM [CoinbaseAccount]
API.coinbaseAccounts
  where
    requestPath :: RequestPath
requestPath = [Text] -> RequestPath
encodeRequestPath [Text
"coinbase-accounts"]