-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added support for stablecoin conversions.
- Loading branch information
Showing
4 changed files
with
85 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
{-# LANGUAGE OverloadedStrings #-} | ||
{-# LANGUAGE TemplateHaskell #-} | ||
|
||
module CoinbasePro.Authenticated.Conversion | ||
( ConversionId | ||
, StablecoinConversionRequest (..) | ||
, StablecoinConversionResponse (..) | ||
) where | ||
|
||
import Data.Aeson (FromJSON, parseJSON, | ||
withObject, (.:)) | ||
import Data.Aeson.Casing (snakeCase) | ||
import Data.Aeson.TH (defaultOptions, deriveJSON, | ||
fieldLabelModifier, | ||
unwrapUnaryRecords) | ||
import Data.UUID (UUID, toString) | ||
|
||
import CoinbasePro.Authenticated.Accounts (AccountId) | ||
import CoinbasePro.Types (CurrencyType) | ||
|
||
|
||
data StablecoinConversionRequest = StablecoinConversionRequest | ||
{ reqFrom :: CurrencyType | ||
, reqTo :: CurrencyType | ||
, reqAmount :: Double | ||
} deriving Show | ||
|
||
|
||
deriveJSON defaultOptions | ||
{ fieldLabelModifier = snakeCase . drop 3 | ||
} ''StablecoinConversionRequest | ||
|
||
|
||
newtype ConversionId = ConversionId UUID | ||
|
||
|
||
instance Show ConversionId where | ||
show (ConversionId u) = toString u | ||
|
||
|
||
deriveJSON defaultOptions | ||
{ fieldLabelModifier = snakeCase | ||
, unwrapUnaryRecords = True | ||
} ''ConversionId | ||
|
||
|
||
data StablecoinConversionResponse = StablecoinConversionResponse | ||
{ resId :: ConversionId | ||
, resAmount :: Double | ||
, resFromAccountId :: AccountId | ||
, resToAccountId :: AccountId | ||
, resFrom :: CurrencyType | ||
, restTo :: CurrencyType | ||
} deriving Show | ||
|
||
|
||
instance FromJSON StablecoinConversionResponse where | ||
parseJSON = withObject "stablecoin conversion response" $ \o -> StablecoinConversionResponse | ||
<$> o .: "id" | ||
<*> (read <$> o .: "amount") | ||
<*> o .: "from_account_id" | ||
<*> o .: "to_account_id" | ||
<*> o .: "from" | ||
<*> o .: "to" |