Skip to content

Commit

Permalink
Merge pull request #45 from maestro-org/update-dex-prices-endpoint
Browse files Browse the repository at this point in the history
Added GeniusYield as option to get market price from
  • Loading branch information
Vardominator authored Jan 2, 2024
2 parents 7f4faa2 + b055782 commit bafa41f
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 51 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# Revision history for `maestro-sdk`

## [1.5.0](https://github.com/maestro-org/haskell-sdk/compare/v1.4.0..v1.5.0) -- 2024-01-02

* Added support GeniusYield DEX to market defi endpoints in [#45](https://github.com/maestro-org/haskell-sdk/pull/45).

## [1.4.0](https://github.com/maestro-org/haskell-sdk/compare/v1.3.0..v1.4.0) -- 2023-12-12

* Added support of OHCL and pair endpoints in [#44](https://github.com/maestro-org/haskell-sdk/pull/44).

## [1.3.0](https://github.com/maestro-org/haskell-sdk/compare/v1.2.0..v1.3.0) -- 2023-11-27

* Removed deprecated `/datum` endpoint in favour of `/datums`, [#42](https://github.com/maestro-org/haskell-sdk/pull/42).
Expand Down
2 changes: 1 addition & 1 deletion maestro-sdk.cabal
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
cabal-version: 3.0
name: maestro-sdk
version: 1.3.0
version: 1.5.0
synopsis: Maestro Blockchain Indexer SDK
description: Maestro provides blockchain indexers, APIs and event management systems for the Cardano blockchain.
license: Apache-2.0
Expand Down
98 changes: 48 additions & 50 deletions src/Maestro/Types/V1/DefiMarkets.hs
Original file line number Diff line number Diff line change
@@ -1,35 +1,30 @@
-- | Module to define types for /"DeFi Markets"/ category of endpoints defined at [docs.gomaestro.org](https://docs.gomaestro.org/category/defi-market-api).

module Maestro.Types.V1.DefiMarkets (
Dex(..),
PairOfDexTokens,
Resolution (..),
DexPairResponse(..),
DexPairInfo (..),
OHLCCandleInfo (..)
) where
Dex (..),
PairOfDexTokens,
Resolution (..),
DexPairResponse (..),
DexPairInfo (..),
OHLCCandleInfo (..),
) where

import qualified Data.Text as T
import Deriving.Aeson
import Maestro.Types.V1.Common
import qualified Data.Aeson as Aeson
import Servant.API
import Deriving.Aeson
import Maestro.Types.V1.Common
import Servant.API

-- | Denotes which dex to use
data Dex = Minswap
data Dex = Minswap | GeniusYield
deriving stock (Eq, Ord, Generic)
deriving (FromJSON, ToJSON) via CustomJSON '[ConstructorTagModifier '[CamelToKebab]] Dex

instance Show Dex where
show Minswap = "minswap"
show Minswap = "minswap"
show GeniusYield = "genius-yield"

instance ToHttpApiData Dex where
toQueryParam = T.pack . show

-- | Because there is only one dex at the moment, the derivation returns "[]". This can be removed once support for a new dex is added.
instance FromJSON Dex where
parseJSON (Aeson.String "minswap") = return Minswap
parseJSON _ = fail "Expecting oneof [minswap]"

-- | Token Pair that is queried
type PairOfDexTokens = "Token pair to look for. Format: XXX-YYY"

Expand All @@ -39,52 +34,55 @@ data Resolution = Res1m | Res5m | Res15m | Res30m | Res1h | Res4h | Res1d | Res1
deriving (FromJSON, ToJSON) via CustomJSON '[ConstructorTagModifier '[StripPrefix "Res"]] Resolution

instance Show Resolution where
show Res1m = "1m"
show Res5m = "5m"
show Res1m = "1m"
show Res5m = "5m"
show Res15m = "15m"
show Res30m = "30m"
show Res1h = "1h"
show Res4h = "4h"
show Res1d = "1d"
show Res1w = "1w"
show Res1h = "1h"
show Res4h = "4h"
show Res1d = "1d"
show Res1w = "1w"
show Res1mo = "1mo"

instance ToHttpApiData Resolution where
toQueryParam = T.pack . show

data DexPairInfo = DexPairInfo
{ dexPairInfoCoinAAssetName :: TokenName
, dexPairInfoCoinAPolicy :: PolicyId
, dexPairInfoCoinBAssetName :: TokenName
, dexPairInfoCoinBPolicy :: PolicyId
, dexPairInfoPair :: String
}
{ dexPairInfoCoinAAssetName :: !TokenName
, dexPairInfoCoinAPolicy :: !PolicyId
, dexPairInfoCoinBAssetName :: !TokenName
, dexPairInfoCoinBPolicy :: !PolicyId
, dexPairInfoPair :: !T.Text
}
deriving stock (Show, Eq, Ord, Generic)
deriving (FromJSON)
via CustomJSON '[FieldLabelModifier '[StripPrefix "dexPairInfo", CamelToSnake]] DexPairInfo
deriving
(FromJSON)
via CustomJSON '[FieldLabelModifier '[StripPrefix "dexPairInfo", CamelToSnake]] DexPairInfo

data DexPairResponse = DexPairResponse
{ dexPairResponseDex :: Dex
, dexPairResponsePairs :: [DexPairInfo]
{ dexPairResponseDex :: !Dex
, dexPairResponsePairs :: ![DexPairInfo]
}
deriving stock (Show, Eq, Ord, Generic)
deriving (FromJSON)
via CustomJSON '[FieldLabelModifier '[StripPrefix "dexPairResponse", LowerFirst]] DexPairResponse
deriving
(FromJSON)
via CustomJSON '[FieldLabelModifier '[StripPrefix "dexPairResponse", LowerFirst]] DexPairResponse

-- | Candle data according to the [OHLC format](https://en.wikipedia.org/wiki/Open-high-low-close_chart)
data OHLCCandleInfo = OHLCCandleInfo
{ ohlcCandleInfoCoinAClose :: Double
, ohlcCandleInfoCoinAHigh :: Double
, ohlcCandleInfoCoinALow :: Double
, ohlcCandleInfoCoinAOpen :: Double
, ohlcCandleInfoCoinAVolume :: Double
, ohlcCandleInfoCoinBClose :: Double
, ohlcCandleInfoCoinBHigh :: Double
, ohlcCandleInfoCoinBLow :: Double
, ohlcCandleInfoCoinBOpen :: Double
, ohlcCandleInfoCoinBVolume :: Double
, ohlcCandleInfoCount :: Integer
{ ohlcCandleInfoCoinAClose :: !Double
, ohlcCandleInfoCoinAHigh :: !Double
, ohlcCandleInfoCoinALow :: !Double
, ohlcCandleInfoCoinAOpen :: !Double
, ohlcCandleInfoCoinAVolume :: !Double
, ohlcCandleInfoCoinBClose :: !Double
, ohlcCandleInfoCoinBHigh :: !Double
, ohlcCandleInfoCoinBLow :: !Double
, ohlcCandleInfoCoinBOpen :: !Double
, ohlcCandleInfoCoinBVolume :: !Double
, ohlcCandleInfoCount :: !Integer
}
deriving stock (Show, Eq, Ord, Generic)
deriving (FromJSON)
via CustomJSON '[FieldLabelModifier '[StripPrefix "ohlcCandleInfo", CamelToSnake]] OHLCCandleInfo
deriving
(FromJSON)
via CustomJSON '[FieldLabelModifier '[StripPrefix "ohlcCandleInfo", CamelToSnake]] OHLCCandleInfo

0 comments on commit bafa41f

Please sign in to comment.