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

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

import           Control.Monad                              (void)
import           Data.Aeson                                 (ToJSON, encode)
import           Data.ByteString                            (ByteString)
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,
                                                             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.Conversion       (StablecoinConversionRequest (..),
                                                             StablecoinConversionResponse)
import           CoinbasePro.Authenticated.Deposit          (CoinbaseDepositRequest (..),
                                                             CryptoDepositAddress,
                                                             DepositRequest (..),
                                                             DepositResponse)
import           CoinbasePro.Authenticated.Fills            (Fill)
import           CoinbasePro.Authenticated.Limits           (Limits)
import           CoinbasePro.Authenticated.Oracle           (OracleResponse)
import           CoinbasePro.Authenticated.Orders           (Order,
                                                             PlaceOrderBody (..),
                                                             STP, Status (..),
                                                             Statuses (..),
                                                             TimeInForce,
                                                             statuses)
import           CoinbasePro.Authenticated.Payment          (PaymentMethod,
                                                             PaymentMethodId (..))
import           CoinbasePro.Authenticated.Profile          (Profile,
                                                             ProfileTransfer (..))
import           CoinbasePro.Authenticated.Report           (ReportId (..),
                                                             ReportRequest (..),
                                                             ReportResponse)
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                        (emptyBody,
                                                             encodeRequestPath)


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"


depositsPath :: Text
depositsPath :: Text
depositsPath = Text
"deposits"


withdrawalsPath :: Text
withdrawalsPath :: Text
withdrawalsPath = Text
"withdrawals"


coinbaseAccountPath :: Text
coinbaseAccountPath :: Text
coinbaseAccountPath = Text
"coinbase-account"


profilesPath :: Text
profilesPath :: Text
profilesPath = Text
"profiles"


transferPath :: Text
transferPath :: Text
transferPath = Text
"transfer"


usersPath :: Text
usersPath :: Text
usersPath = Text
"users"


selfPath :: Text
selfPath :: Text
selfPath = Text
"self"


reportsPath :: Text
reportsPath :: Text
reportsPath = Text
"reports"


mkSimpleQueryItem :: Show a => Text -> a -> SimpleQueryItem
mkSimpleQueryItem :: Text -> a -> SimpleQueryItem
mkSimpleQueryItem Text
s a
a = (Text -> ByteString
encodeUtf8 Text
s, Text -> ByteString
encodeUtf8 (Text -> ByteString) -> Text -> ByteString
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"


encodeBody :: (ToJSON b) => b -> ByteString
encodeBody :: b -> ByteString
encodeBody = ByteString -> ByteString
LC8.toStrict (ByteString -> ByteString) -> (b -> ByteString) -> b -> ByteString
forall b c a. (b -> c) -> (a -> b) -> a -> c
. b -> ByteString
forall a. ToJSON a => a -> ByteString
encode


-- | https://docs.pro.coinbase.com/#accounts
accounts :: CBAuthT ClientM [Account]
accounts :: CBAuthT ClientM [Account]
accounts = ByteString
-> ByteString
-> ByteString
-> (AuthenticatedRequest (AuthProtect "CBAuth")
    -> ClientM [Account])
-> CBAuthT ClientM [Account]
forall b.
ByteString
-> ByteString
-> ByteString
-> (AuthenticatedRequest (AuthProtect "CBAuth") -> ClientM b)
-> CBAuthT ClientM b
authRequest ByteString
methodGet ByteString
requestPath ByteString
emptyBody AuthenticatedRequest (AuthProtect "CBAuth") -> ClientM [Account]
API.accounts
  where
    requestPath :: ByteString
requestPath = [Text] -> ByteString
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) = ByteString
-> ByteString
-> ByteString
-> (AuthenticatedRequest (AuthProtect "CBAuth") -> ClientM Account)
-> CBAuthT ClientM Account
forall b.
ByteString
-> ByteString
-> ByteString
-> (AuthenticatedRequest (AuthProtect "CBAuth") -> ClientM b)
-> CBAuthT ClientM b
authRequest ByteString
methodGet ByteString
requestPath ByteString
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 :: ByteString
requestPath = [Text] -> ByteString
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) = ByteString
-> ByteString
-> ByteString
-> (AuthenticatedRequest (AuthProtect "CBAuth")
    -> ClientM [AccountHistory])
-> CBAuthT ClientM [AccountHistory]
forall b.
ByteString
-> ByteString
-> ByteString
-> (AuthenticatedRequest (AuthProtect "CBAuth") -> ClientM b)
-> CBAuthT ClientM b
authRequest ByteString
methodGet ByteString
requestPath ByteString
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 :: ByteString
requestPath = [Text] -> ByteString
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) = ByteString
-> ByteString
-> ByteString
-> (AuthenticatedRequest (AuthProtect "CBAuth") -> ClientM [Hold])
-> CBAuthT ClientM [Hold]
forall b.
ByteString
-> ByteString
-> ByteString
-> (AuthenticatedRequest (AuthProtect "CBAuth") -> ClientM b)
-> CBAuthT ClientM b
authRequest ByteString
methodGet ByteString
requestPath ByteString
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 :: ByteString
requestPath = [Text] -> ByteString
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 = ByteString
-> ByteString
-> ByteString
-> (AuthenticatedRequest (AuthProtect "CBAuth") -> ClientM [Order])
-> CBAuthT ClientM [Order]
forall b.
ByteString
-> ByteString
-> ByteString
-> (AuthenticatedRequest (AuthProtect "CBAuth") -> ClientM b)
-> CBAuthT ClientM b
authRequest ByteString
methodGet ByteString
requestPath ByteString
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 :: ByteString
query       = Bool -> Query -> ByteString
renderQuery Bool
True (Query -> ByteString)
-> ([SimpleQueryItem] -> Query) -> [SimpleQueryItem] -> ByteString
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [SimpleQueryItem] -> Query
simpleQueryToQuery ([SimpleQueryItem] -> ByteString)
-> [SimpleQueryItem] -> ByteString
forall a b. (a -> b) -> a -> b
$ Maybe [Status] -> Maybe ProductId -> [SimpleQueryItem]
orderQuery Maybe [Status]
st Maybe ProductId
prid
    requestPath :: ByteString
requestPath = [Text] -> ByteString
encodeRequestPath [Text
ordersPath] ByteString -> ByteString -> ByteString
forall a. Semigroup a => a -> a -> a
<> ByteString
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 = ByteString
-> ByteString
-> ByteString
-> (AuthenticatedRequest (AuthProtect "CBAuth") -> ClientM Order)
-> CBAuthT ClientM Order
forall b.
ByteString
-> ByteString
-> ByteString
-> (AuthenticatedRequest (AuthProtect "CBAuth") -> ClientM b)
-> CBAuthT ClientM b
authRequest ByteString
methodGet ByteString
requestPath ByteString
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 :: ByteString
requestPath = [Text] -> ByteString
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 = ByteString
-> ByteString
-> ByteString
-> (AuthenticatedRequest (AuthProtect "CBAuth") -> ClientM Order)
-> CBAuthT ClientM Order
forall b.
ByteString
-> ByteString
-> ByteString
-> (AuthenticatedRequest (AuthProtect "CBAuth") -> ClientM b)
-> CBAuthT ClientM b
authRequest ByteString
methodGet ByteString
requestPath ByteString
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 :: ByteString
requestPath = [Text] -> ByteString
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 =
    ByteString
-> ByteString
-> ByteString
-> (AuthenticatedRequest (AuthProtect "CBAuth") -> ClientM Order)
-> CBAuthT ClientM Order
forall b.
ByteString
-> ByteString
-> ByteString
-> (AuthenticatedRequest (AuthProtect "CBAuth") -> ClientM b)
-> CBAuthT ClientM b
authRequest ByteString
methodPost ByteString
requestPath (PlaceOrderBody -> ByteString
forall b. ToJSON b => b -> ByteString
encodeBody PlaceOrderBody
body) ((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 :: ByteString
requestPath = [Text] -> ByteString
encodeRequestPath [Text
ordersPath]
    body :: PlaceOrderBody
body        = Maybe ClientOrderId
-> ProductId
-> Side
-> Size
-> Price
-> Bool
-> Maybe OrderType
-> Maybe STP
-> Maybe TimeInForce
-> Maybe StopLossSide
-> Maybe Price
-> PlaceOrderBody
PlaceOrderBody Maybe ClientOrderId
clordid ProductId
prid Side
sd Size
sz Price
price Bool
po Maybe OrderType
ot Maybe STP
stp Maybe TimeInForce
tif Maybe StopLossSide
forall a. Maybe a
Nothing Maybe Price
forall a. Maybe a
Nothing


-- | https://docs.pro.coinbase.com/#place-a-new-order
-- Use the underlying post body record
placeOrderBody :: PlaceOrderBody -> CBAuthT ClientM Order
placeOrderBody :: PlaceOrderBody -> CBAuthT ClientM Order
placeOrderBody PlaceOrderBody
body =
    ByteString
-> ByteString
-> ByteString
-> (AuthenticatedRequest (AuthProtect "CBAuth") -> ClientM Order)
-> CBAuthT ClientM Order
forall b.
ByteString
-> ByteString
-> ByteString
-> (AuthenticatedRequest (AuthProtect "CBAuth") -> ClientM b)
-> CBAuthT ClientM b
authRequest ByteString
methodPost ByteString
requestPath (PlaceOrderBody -> ByteString
forall b. ToJSON b => b -> ByteString
encodeBody PlaceOrderBody
body) ((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 :: ByteString
requestPath = [Text] -> ByteString
encodeRequestPath [Text
ordersPath]


-- | 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
. ByteString
-> ByteString
-> ByteString
-> (AuthenticatedRequest (AuthProtect "CBAuth")
    -> ClientM NoContent)
-> CBAuthT ClientM NoContent
forall b.
ByteString
-> ByteString
-> ByteString
-> (AuthenticatedRequest (AuthProtect "CBAuth") -> ClientM b)
-> CBAuthT ClientM b
authRequest ByteString
methodDelete ByteString
requestPath ByteString
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 :: ByteString
requestPath = [Text] -> ByteString
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 = ByteString
-> ByteString
-> ByteString
-> (AuthenticatedRequest (AuthProtect "CBAuth")
    -> ClientM [OrderId])
-> CBAuthT ClientM [OrderId]
forall b.
ByteString
-> ByteString
-> ByteString
-> (AuthenticatedRequest (AuthProtect "CBAuth") -> ClientM b)
-> CBAuthT ClientM b
authRequest ByteString
methodDelete ByteString
requestPath ByteString
emptyBody (Maybe ProductId
-> AuthenticatedRequest (AuthProtect "CBAuth") -> ClientM [OrderId]
API.cancelAll Maybe ProductId
prid)
  where
    query :: ByteString
query       = Bool -> Query -> ByteString
renderQuery Bool
True (Query -> ByteString)
-> ([SimpleQueryItem] -> Query) -> [SimpleQueryItem] -> ByteString
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [SimpleQueryItem] -> Query
simpleQueryToQuery ([SimpleQueryItem] -> ByteString)
-> [SimpleQueryItem] -> ByteString
forall a b. (a -> b) -> a -> b
$ Maybe ProductId -> [SimpleQueryItem]
mkProductQuery Maybe ProductId
prid
    requestPath :: ByteString
requestPath = [Text] -> ByteString
encodeRequestPath [Text
ordersPath] ByteString -> ByteString -> ByteString
forall a. Semigroup a => a -> a -> a
<> ByteString
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 = ByteString
-> ByteString
-> ByteString
-> (AuthenticatedRequest (AuthProtect "CBAuth") -> ClientM [Fill])
-> CBAuthT ClientM [Fill]
forall b.
ByteString
-> ByteString
-> ByteString
-> (AuthenticatedRequest (AuthProtect "CBAuth") -> ClientM b)
-> CBAuthT ClientM b
authRequest ByteString
methodGet ByteString
requestPath ByteString
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 :: ByteString
query       = Bool -> Query -> ByteString
renderQuery Bool
True (Query -> ByteString)
-> ([SimpleQueryItem] -> Query) -> [SimpleQueryItem] -> ByteString
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [SimpleQueryItem] -> Query
simpleQueryToQuery ([SimpleQueryItem] -> ByteString)
-> [SimpleQueryItem] -> ByteString
forall a b. (a -> b) -> a -> b
$ Maybe ProductId -> Maybe OrderId -> [SimpleQueryItem]
mkSimpleQuery Maybe ProductId
prid Maybe OrderId
oid
    requestPath :: ByteString
requestPath = [Text] -> ByteString
encodeRequestPath [Text
fillsPath] ByteString -> ByteString -> ByteString
forall a. Semigroup a => a -> a -> a
<> ByteString
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 = ByteString
-> ByteString
-> ByteString
-> (AuthenticatedRequest (AuthProtect "CBAuth") -> ClientM Fees)
-> CBAuthT ClientM Fees
forall b.
ByteString
-> ByteString
-> ByteString
-> (AuthenticatedRequest (AuthProtect "CBAuth") -> ClientM b)
-> CBAuthT ClientM b
authRequest ByteString
methodGet ByteString
feesRequestPath ByteString
emptyBody AuthenticatedRequest (AuthProtect "CBAuth") -> ClientM Fees
API.fees
  where
    feesPath :: Text
feesPath        = Text
"fees"
    feesRequestPath :: ByteString
feesRequestPath = [Text] -> ByteString
encodeRequestPath [Text
feesPath]


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


-- | https://docs.pro.coinbase.com/#get-current-exchange-limits
limits :: CBAuthT ClientM Limits
limits :: CBAuthT ClientM Limits
limits = ByteString
-> ByteString
-> ByteString
-> (AuthenticatedRequest (AuthProtect "CBAuth") -> ClientM Limits)
-> CBAuthT ClientM Limits
forall b.
ByteString
-> ByteString
-> ByteString
-> (AuthenticatedRequest (AuthProtect "CBAuth") -> ClientM b)
-> CBAuthT ClientM b
authRequest ByteString
methodGet ByteString
requestPath ByteString
emptyBody AuthenticatedRequest (AuthProtect "CBAuth") -> ClientM Limits
API.limits
  where
    requestPath :: ByteString
requestPath = [Text] -> ByteString
encodeRequestPath [Text
usersPath, Text
selfPath, 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 = ByteString
-> ByteString
-> ByteString
-> (AuthenticatedRequest (AuthProtect "CBAuth")
    -> ClientM [Transfer])
-> CBAuthT ClientM [Transfer]
forall b.
ByteString
-> ByteString
-> ByteString
-> (AuthenticatedRequest (AuthProtect "CBAuth") -> ClientM b)
-> CBAuthT ClientM b
authRequest ByteString
methodGet ByteString
requestPath ByteString
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 :: ByteString
query       = Bool -> Query -> ByteString
renderQuery Bool
True (Query -> ByteString)
-> ([SimpleQueryItem] -> Query) -> [SimpleQueryItem] -> ByteString
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [SimpleQueryItem] -> Query
simpleQueryToQuery ([SimpleQueryItem] -> ByteString)
-> [SimpleQueryItem] -> ByteString
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 :: ByteString
requestPath = [Text] -> ByteString
encodeRequestPath [Text
transferPath Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
"s"] ByteString -> ByteString -> ByteString
forall a. Semigroup a => a -> a -> a
<> ByteString
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) = ByteString
-> ByteString
-> ByteString
-> (AuthenticatedRequest (AuthProtect "CBAuth")
    -> ClientM Transfer)
-> CBAuthT ClientM Transfer
forall b.
ByteString
-> ByteString
-> ByteString
-> (AuthenticatedRequest (AuthProtect "CBAuth") -> ClientM b)
-> CBAuthT ClientM b
authRequest ByteString
methodGet ByteString
requestPath ByteString
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 :: ByteString
requestPath = [Text] -> ByteString
encodeRequestPath [Text
transferPath Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
"s", 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 =
    ByteString
-> ByteString
-> ByteString
-> (AuthenticatedRequest (AuthProtect "CBAuth")
    -> ClientM DepositResponse)
-> CBAuthT ClientM DepositResponse
forall b.
ByteString
-> ByteString
-> ByteString
-> (AuthenticatedRequest (AuthProtect "CBAuth") -> ClientM b)
-> CBAuthT ClientM b
authRequest ByteString
methodPost ByteString
requestPath (DepositRequest -> ByteString
forall b. ToJSON b => b -> ByteString
encodeBody DepositRequest
body) ((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 :: ByteString
requestPath = [Text] -> ByteString
encodeRequestPath [Text
depositsPath, Text
"payment-method"]
    body :: DepositRequest
body        = Double -> Text -> PaymentMethodId -> DepositRequest
DepositRequest Double
amt Text
cur PaymentMethodId
pmi


-- | 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 =
    ByteString
-> ByteString
-> ByteString
-> (AuthenticatedRequest (AuthProtect "CBAuth")
    -> ClientM DepositResponse)
-> CBAuthT ClientM DepositResponse
forall b.
ByteString
-> ByteString
-> ByteString
-> (AuthenticatedRequest (AuthProtect "CBAuth") -> ClientM b)
-> CBAuthT ClientM b
authRequest ByteString
methodPost ByteString
requestPath (CoinbaseDepositRequest -> ByteString
forall b. ToJSON b => b -> ByteString
encodeBody CoinbaseDepositRequest
body) ((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 :: ByteString
requestPath = [Text] -> ByteString
encodeRequestPath [Text
depositsPath, Text
coinbaseAccountPath]
    body :: CoinbaseDepositRequest
body        = Double -> Text -> AccountId -> CoinbaseDepositRequest
CoinbaseDepositRequest Double
amt Text
cur AccountId
act


-- | https://docs.pro.coinbase.com/#generate-a-crypto-deposit-address
cryptoDepositAddress :: AccountId -> CBAuthT ClientM CryptoDepositAddress
cryptoDepositAddress :: AccountId -> CBAuthT ClientM CryptoDepositAddress
cryptoDepositAddress AccountId
act =
    ByteString
-> ByteString
-> ByteString
-> (AuthenticatedRequest (AuthProtect "CBAuth")
    -> ClientM CryptoDepositAddress)
-> CBAuthT ClientM CryptoDepositAddress
forall b.
ByteString
-> ByteString
-> ByteString
-> (AuthenticatedRequest (AuthProtect "CBAuth") -> ClientM b)
-> CBAuthT ClientM b
authRequest ByteString
methodPost ByteString
requestPath ByteString
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 :: ByteString
requestPath = [Text] -> ByteString
encodeRequestPath [Text
coinbaseAccountPath Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
"s", 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 =
    ByteString
-> ByteString
-> ByteString
-> (AuthenticatedRequest (AuthProtect "CBAuth")
    -> ClientM WithdrawalResponse)
-> CBAuthT ClientM WithdrawalResponse
forall b.
ByteString
-> ByteString
-> ByteString
-> (AuthenticatedRequest (AuthProtect "CBAuth") -> ClientM b)
-> CBAuthT ClientM b
authRequest ByteString
methodPost ByteString
requestPath (WithdrawalRequest -> ByteString
forall b. ToJSON b => b -> ByteString
encodeBody WithdrawalRequest
body) ((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 :: ByteString
requestPath = [Text] -> ByteString
encodeRequestPath [Text
withdrawalsPath, Text
"payment-method"]
    body :: WithdrawalRequest
body        = Double -> Text -> PaymentMethodId -> WithdrawalRequest
WithdrawalRequest Double
amt Text
cur PaymentMethodId
pmi


-- | 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 =
    ByteString
-> ByteString
-> ByteString
-> (AuthenticatedRequest (AuthProtect "CBAuth")
    -> ClientM WithdrawalResponse)
-> CBAuthT ClientM WithdrawalResponse
forall b.
ByteString
-> ByteString
-> ByteString
-> (AuthenticatedRequest (AuthProtect "CBAuth") -> ClientM b)
-> CBAuthT ClientM b
authRequest ByteString
methodPost ByteString
requestPath (CoinbaseWithdrawalRequest -> ByteString
forall b. ToJSON b => b -> ByteString
encodeBody CoinbaseWithdrawalRequest
body) ((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 :: ByteString
requestPath = [Text] -> ByteString
encodeRequestPath [Text
withdrawalsPath, Text
coinbaseAccountPath]
    body :: CoinbaseWithdrawalRequest
body        = Double -> Text -> AccountId -> CoinbaseWithdrawalRequest
CoinbaseWithdrawalRequest Double
amt Text
cur AccountId
act


-- | 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 =
    ByteString
-> ByteString
-> ByteString
-> (AuthenticatedRequest (AuthProtect "CBAuth")
    -> ClientM CryptoWithdrawalResponse)
-> CBAuthT ClientM CryptoWithdrawalResponse
forall b.
ByteString
-> ByteString
-> ByteString
-> (AuthenticatedRequest (AuthProtect "CBAuth") -> ClientM b)
-> CBAuthT ClientM b
authRequest ByteString
methodPost ByteString
requestPath (CryptoWithdrawalRequest -> ByteString
forall b. ToJSON b => b -> ByteString
encodeBody CryptoWithdrawalRequest
body) ((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 :: ByteString
requestPath = [Text] -> ByteString
encodeRequestPath [Text
withdrawalsPath, Text
"crypto"]
    body :: CryptoWithdrawalRequest
body        = Double -> Text -> Text -> CryptoWithdrawalRequest
CryptoWithdrawalRequest Double
amt Text
cur Text
addr


-- | https://docs.pro.coinbase.com/#fee-estimate
withdrawalFeeEstimate :: CurrencyType
                      -> CryptoAddress
                      -> CBAuthT ClientM WithdrawalFeeEstimateResponse
withdrawalFeeEstimate :: CurrencyType
-> CryptoAddress -> CBAuthT ClientM WithdrawalFeeEstimateResponse
withdrawalFeeEstimate CurrencyType
cur CryptoAddress
addr =
    ByteString
-> ByteString
-> ByteString
-> (AuthenticatedRequest (AuthProtect "CBAuth")
    -> ClientM WithdrawalFeeEstimateResponse)
-> CBAuthT ClientM WithdrawalFeeEstimateResponse
forall b.
ByteString
-> ByteString
-> ByteString
-> (AuthenticatedRequest (AuthProtect "CBAuth") -> ClientM b)
-> CBAuthT ClientM b
authRequest ByteString
methodGet ByteString
requestPath ByteString
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 :: ByteString
query       = Bool -> Query -> ByteString
renderQuery Bool
True (Query -> ByteString)
-> ([SimpleQueryItem] -> Query) -> [SimpleQueryItem] -> ByteString
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [SimpleQueryItem] -> Query
simpleQueryToQuery ([SimpleQueryItem] -> ByteString)
-> [SimpleQueryItem] -> ByteString
forall a b. (a -> b) -> a -> b
$ [SimpleQueryItem]
curQ [SimpleQueryItem] -> [SimpleQueryItem] -> [SimpleQueryItem]
forall a. Semigroup a => a -> a -> a
<> [SimpleQueryItem]
addrQ
    requestPath :: ByteString
requestPath = [Text] -> ByteString
encodeRequestPath [Text
withdrawalsPath, Text
"fee-estimate"] ByteString -> ByteString -> ByteString
forall a. Semigroup a => a -> a -> a
<> ByteString
query


-- | https://docs.pro.coinbase.com/#stablecoin-conversions
createStablecoinConversion :: CurrencyType -> CurrencyType -> Double -> CBAuthT ClientM StablecoinConversionResponse
createStablecoinConversion :: CurrencyType
-> CurrencyType
-> Double
-> CBAuthT ClientM StablecoinConversionResponse
createStablecoinConversion CurrencyType
fromCur CurrencyType
toCur Double
amt =
    ByteString
-> ByteString
-> ByteString
-> (AuthenticatedRequest (AuthProtect "CBAuth")
    -> ClientM StablecoinConversionResponse)
-> CBAuthT ClientM StablecoinConversionResponse
forall b.
ByteString
-> ByteString
-> ByteString
-> (AuthenticatedRequest (AuthProtect "CBAuth") -> ClientM b)
-> CBAuthT ClientM b
authRequest ByteString
methodPost ByteString
requestPath (StablecoinConversionRequest -> ByteString
forall b. ToJSON b => b -> ByteString
encodeBody StablecoinConversionRequest
body) ((AuthenticatedRequest (AuthProtect "CBAuth")
  -> ClientM StablecoinConversionResponse)
 -> CBAuthT ClientM StablecoinConversionResponse)
-> (AuthenticatedRequest (AuthProtect "CBAuth")
    -> ClientM StablecoinConversionResponse)
-> CBAuthT ClientM StablecoinConversionResponse
forall a b. (a -> b) -> a -> b
$ StablecoinConversionRequest
-> AuthenticatedRequest (AuthProtect "CBAuth")
-> ClientM StablecoinConversionResponse
API.createStablecoinConversion StablecoinConversionRequest
body
  where
    requestPath :: ByteString
requestPath = [Text] -> ByteString
encodeRequestPath [Text
"conversions"]
    body :: StablecoinConversionRequest
body        = CurrencyType
-> CurrencyType -> Double -> StablecoinConversionRequest
StablecoinConversionRequest CurrencyType
fromCur CurrencyType
toCur Double
amt


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


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


-- | https://docs.pro.coinbase.com/#list-profiles
profiles :: Maybe Bool -> CBAuthT ClientM [Profile]
profiles :: Maybe Bool -> CBAuthT ClientM [Profile]
profiles Maybe Bool
active = ByteString
-> ByteString
-> ByteString
-> (AuthenticatedRequest (AuthProtect "CBAuth")
    -> ClientM [Profile])
-> CBAuthT ClientM [Profile]
forall b.
ByteString
-> ByteString
-> ByteString
-> (AuthenticatedRequest (AuthProtect "CBAuth") -> ClientM b)
-> CBAuthT ClientM b
authRequest ByteString
methodGet ByteString
requestPath ByteString
emptyBody ((AuthenticatedRequest (AuthProtect "CBAuth") -> ClientM [Profile])
 -> CBAuthT ClientM [Profile])
-> (AuthenticatedRequest (AuthProtect "CBAuth")
    -> ClientM [Profile])
-> CBAuthT ClientM [Profile]
forall a b. (a -> b) -> a -> b
$ Maybe Bool
-> AuthenticatedRequest (AuthProtect "CBAuth") -> ClientM [Profile]
API.profiles Maybe Bool
active
  where
    activeQ :: [SimpleQueryItem]
activeQ  = Text -> Maybe Bool -> [SimpleQueryItem]
forall a. Show a => Text -> Maybe a -> [SimpleQueryItem]
optionalQuery Text
"active" Maybe Bool
active

    query :: ByteString
query       = Bool -> Query -> ByteString
renderQuery Bool
True (Query -> ByteString)
-> ([SimpleQueryItem] -> Query) -> [SimpleQueryItem] -> ByteString
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [SimpleQueryItem] -> Query
simpleQueryToQuery ([SimpleQueryItem] -> ByteString)
-> [SimpleQueryItem] -> ByteString
forall a b. (a -> b) -> a -> b
$ [SimpleQueryItem]
activeQ
    requestPath :: ByteString
requestPath = [Text] -> ByteString
encodeRequestPath [Text
profilesPath] ByteString -> ByteString -> ByteString
forall a. Semigroup a => a -> a -> a
<> ByteString
query


-- | https://docs.pro.coinbase.com/#get-a-profile
profile :: ProfileId -> CBAuthT ClientM Profile
profile :: Text -> CBAuthT ClientM Profile
profile Text
profId = ByteString
-> ByteString
-> ByteString
-> (AuthenticatedRequest (AuthProtect "CBAuth") -> ClientM Profile)
-> CBAuthT ClientM Profile
forall b.
ByteString
-> ByteString
-> ByteString
-> (AuthenticatedRequest (AuthProtect "CBAuth") -> ClientM b)
-> CBAuthT ClientM b
authRequest ByteString
methodGet ByteString
requestPath ByteString
emptyBody ((AuthenticatedRequest (AuthProtect "CBAuth") -> ClientM Profile)
 -> CBAuthT ClientM Profile)
-> (AuthenticatedRequest (AuthProtect "CBAuth") -> ClientM Profile)
-> CBAuthT ClientM Profile
forall a b. (a -> b) -> a -> b
$ Text
-> AuthenticatedRequest (AuthProtect "CBAuth") -> ClientM Profile
API.profile Text
profId
  where
    requestPath :: ByteString
requestPath = [Text] -> ByteString
encodeRequestPath [Text
profilesPath, Text
profId]


-- | https://docs.pro.coinbase.com/#create-profile-transfer
profileTransfer :: ProfileId
                -> ProfileId
                -> CurrencyType
                -> String
                -> CBAuthT ClientM ()
profileTransfer :: Text -> Text -> CurrencyType -> String -> CBAuthT ClientM ()
profileTransfer Text
fromProf Text
toProf CurrencyType
cur String
amt = 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
. ByteString
-> ByteString
-> ByteString
-> (AuthenticatedRequest (AuthProtect "CBAuth")
    -> ClientM NoContent)
-> CBAuthT ClientM NoContent
forall b.
ByteString
-> ByteString
-> ByteString
-> (AuthenticatedRequest (AuthProtect "CBAuth") -> ClientM b)
-> CBAuthT ClientM b
authRequest ByteString
methodPost ByteString
requestPath (ProfileTransfer -> ByteString
forall b. ToJSON b => b -> ByteString
encodeBody ProfileTransfer
body) ((AuthenticatedRequest (AuthProtect "CBAuth") -> ClientM NoContent)
 -> CBAuthT ClientM ())
-> (AuthenticatedRequest (AuthProtect "CBAuth")
    -> ClientM NoContent)
-> CBAuthT ClientM ()
forall a b. (a -> b) -> a -> b
$ ProfileTransfer
-> AuthenticatedRequest (AuthProtect "CBAuth") -> ClientM NoContent
API.profileTransfer ProfileTransfer
body
  where
    requestPath :: ByteString
requestPath = [Text] -> ByteString
encodeRequestPath [Text
profilesPath, Text
transferPath]
    body :: ProfileTransfer
body        = Text -> Text -> CurrencyType -> String -> ProfileTransfer
ProfileTransfer Text
fromProf Text
toProf CurrencyType
cur String
amt


-- | https://docs.pro.coinbase.com/#create-a-new-report
createReport :: ReportRequest -> CBAuthT ClientM ReportResponse
createReport :: ReportRequest -> CBAuthT ClientM ReportResponse
createReport ReportRequest
req = ByteString
-> ByteString
-> ByteString
-> (AuthenticatedRequest (AuthProtect "CBAuth")
    -> ClientM ReportResponse)
-> CBAuthT ClientM ReportResponse
forall b.
ByteString
-> ByteString
-> ByteString
-> (AuthenticatedRequest (AuthProtect "CBAuth") -> ClientM b)
-> CBAuthT ClientM b
authRequest ByteString
methodPost ByteString
requestPath (ReportRequest -> ByteString
forall b. ToJSON b => b -> ByteString
encodeBody ReportRequest
req) ((AuthenticatedRequest (AuthProtect "CBAuth")
  -> ClientM ReportResponse)
 -> CBAuthT ClientM ReportResponse)
-> (AuthenticatedRequest (AuthProtect "CBAuth")
    -> ClientM ReportResponse)
-> CBAuthT ClientM ReportResponse
forall a b. (a -> b) -> a -> b
$ ReportRequest
-> AuthenticatedRequest (AuthProtect "CBAuth")
-> ClientM ReportResponse
API.createReport ReportRequest
req
  where
    requestPath :: ByteString
requestPath = [Text] -> ByteString
encodeRequestPath [Text
reportsPath]


-- | https://docs.pro.coinbase.com/#get-report-status
getReport :: ReportId -> CBAuthT ClientM ReportResponse
getReport :: ReportId -> CBAuthT ClientM ReportResponse
getReport ReportId
rid = ByteString
-> ByteString
-> ByteString
-> (AuthenticatedRequest (AuthProtect "CBAuth")
    -> ClientM ReportResponse)
-> CBAuthT ClientM ReportResponse
forall b.
ByteString
-> ByteString
-> ByteString
-> (AuthenticatedRequest (AuthProtect "CBAuth") -> ClientM b)
-> CBAuthT ClientM b
authRequest ByteString
methodGet ByteString
requestPath ByteString
emptyBody ((AuthenticatedRequest (AuthProtect "CBAuth")
  -> ClientM ReportResponse)
 -> CBAuthT ClientM ReportResponse)
-> (AuthenticatedRequest (AuthProtect "CBAuth")
    -> ClientM ReportResponse)
-> CBAuthT ClientM ReportResponse
forall a b. (a -> b) -> a -> b
$ ReportId
-> AuthenticatedRequest (AuthProtect "CBAuth")
-> ClientM ReportResponse
API.getReport ReportId
rid
  where
    requestPath :: ByteString
requestPath = [Text] -> ByteString
encodeRequestPath [Text
reportsPath, UUID -> Text
toText (UUID -> Text) -> UUID -> Text
forall a b. (a -> b) -> a -> b
$ ReportId -> UUID
unReportId ReportId
rid]


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