{-# LANGUAGE DataKinds #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE TypeOperators #-}
module CoinbasePro.Request
( RequestPath
, Body
, CBGet
, CBRequest
, run
, run_
, runWithManager
, runSandbox
, runSandbox_
, runSandboxWithManager
) where
import Control.Exception (throw)
import Control.Monad (void)
import Network.HTTP.Client (Manager, newManager)
import Network.HTTP.Client.TLS (tlsManagerSettings)
import Servant.API ((:>), Get, JSON)
import Servant.Client
import CoinbasePro.Headers (UserAgent, UserAgentHeader)
type CBGet a = UserAgentHeader :> Get '[JSON] a
type CBRequest a = UserAgent -> ClientM a
type RequestPath = String
type Body = String
run :: ClientM a -> IO a
run f = flip runWithManager f =<< newManager tlsManagerSettings
run_ :: ClientM a -> IO ()
run_ = void . run
runWithManager :: Manager -> ClientM a -> IO a
runWithManager mgr f = either throw return =<<
runClientM f (mkClientEnv mgr (BaseUrl Https production 443 mempty))
where
production = "api.pro.coinbase.com"
runSandbox :: ClientM a -> IO a
runSandbox f = flip runSandboxWithManager f =<< newManager tlsManagerSettings
runSandbox_ :: ClientM a -> IO ()
runSandbox_ = void . runSandbox
runSandboxWithManager :: Manager -> ClientM a -> IO a
runSandboxWithManager mgr f = either throw return =<<
runClientM f (mkClientEnv mgr (BaseUrl Https sandbox 443 mempty))
where
sandbox = "api-public.sandbox.pro.coinbase.com"