Skip to content

Commit a5b04da

Browse files
authored
Merge pull request #86 from geniusyield/85-add-taptools-prices-endpoint
feat(#85): add taptools `/prices` route
2 parents 68d6218 + b6ab4d8 commit a5b04da

File tree

6 files changed

+57
-12
lines changed

6 files changed

+57
-12
lines changed

.github/workflows/haskell.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ jobs:
5757
uses: haskell-actions/setup@v2
5858
with:
5959
ghc-version: '9.6.5'
60-
cabal-version: '3.10.1.0'
60+
cabal-version: '3.12.1.0'
6161
enable-stack: true
6262
stack-version: '2.9'
6363
- name: Setup cache

Dockerfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ RUN gpg --batch --keyserver keyserver.ubuntu.com --recv-keys 7D1E8AFD1D4A16D71FA
8181
# ghcup:
8282
ENV BOOTSTRAP_HASKELL_NONINTERACTIVE=1
8383
ENV BOOTSTRAP_HASKELL_GHC_VERSION=9.6.5
84-
ENV BOOTSTRAP_HASKELL_CABAL_VERSION=3.10.2.0
84+
ENV BOOTSTRAP_HASKELL_CABAL_VERSION=3.12.1.0
8585
RUN bash -c "curl --proto '=https' --tlsv1.2 -sSf https://get-ghcup.haskell.org | sh"
8686
ENV PATH=${PATH}:/root/.local/bin
8787
ENV PATH=${PATH}:/root/.ghcup/bin

geniusyield-server-lib/CHANGELOG.md

+5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
# Revision history for geniusyield-server-lib
22

3+
## 0.11.1 -- 2024-10-30
4+
5+
* Adds support of [`prices`](https://openapi.taptools.io/#tag/Market-Tokens/paths/~1token~1prices/post) TapTools endpoint.
6+
* In case project is being built from an environment which lacks access to corresponding `.git` directory, "UNKNOWN_REVISION" is used for `revision` field when querying for settings of the server.
7+
38
## 0.11.0 -- 2024-08-30
49

510
* Update to Atlas v0.6.0.

geniusyield-server-lib/geniusyield-server-lib.cabal

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
cabal-version: 3.6
1+
cabal-version: 3.12
22
name: geniusyield-server-lib
3-
version: 0.11.0
3+
version: 0.11.1
44
synopsis: GeniusYield server library
55
description: Library for GeniusYield server.
66
license: Apache-2.0
@@ -85,6 +85,7 @@ library
8585
, binary
8686
, bytestring
8787
, cardano-api
88+
, containers
8889
, deriving-aeson
8990
, envy
9091
, fast-logger

geniusyield-server-lib/src/GeniusYield/Server/Constants.hs

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,4 @@ import RIO
99

1010
-- | The git hash of the current commit.
1111
gitHash String
12-
gitHash = $$tGitInfoCwd & giHash
12+
gitHash = either (const "UNKNOWN_REVISION") giHash $$tGitInfoCwdTry

geniusyield-server-lib/src/GeniusYield/Server/Dex/HistoricalPrices/TapTools/Client.hs

+46-7
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,25 @@ module GeniusYield.Server.Dex.HistoricalPrices.TapTools.Client (
66
TapToolsOHLCVAPI,
77
tapToolsClientEnv,
88
tapToolsOHLCV,
9+
tapToolsPrices,
10+
PricesResponse,
911
TapToolsException,
1012
handleTapToolsError,
1113
) where
1214

1315
import Control.Lens ((?~))
1416
import Data.Aeson (ToJSON (..))
17+
import Data.Aeson qualified as Aeson
18+
import Data.Aeson.Types qualified as Aeson
19+
import Data.Map.Strict qualified as Map
1520
import Data.Swagger qualified as Swagger
1621
import Data.Time.Clock.POSIX
1722
import Deriving.Aeson
1823
import GHC.TypeLits (Symbol, symbolVal)
1924
import GeniusYield.Server.Ctx (TapToolsApiKey, TapToolsEnv (tteApiKey, tteClientEnv))
2025
import GeniusYield.Server.Utils (commonEnumParamSchemaRecipe, hideServantClientErrorHeader)
2126
import GeniusYield.Swagger.Utils
22-
import GeniusYield.Types (GYAssetClass)
27+
import GeniusYield.Types (GYAssetClass, makeAssetClass)
2328
import Maestro.Types.Common (LowerFirst)
2429
import Network.HTTP.Client (newManager)
2530
import Network.HTTP.Client.TLS (tlsManagerSettings)
@@ -47,6 +52,25 @@ instance ToHttpApiData TapToolsUnit where
4752
where
4853
removeDot = Text.filter (/= '.')
4954

55+
instance Aeson.ToJSON TapToolsUnit where
56+
toJSON = Aeson.toJSON . toUrlPiece
57+
58+
instance Aeson.ToJSONKey TapToolsUnit where
59+
toJSONKey = Aeson.toJSONKeyText toUrlPiece
60+
61+
instance FromHttpApiData TapToolsUnit where
62+
parseUrlPiece t =
63+
let (pid, tn) = Text.splitAt 56 t
64+
in bimap Text.pack TapToolsUnit $ makeAssetClass pid tn
65+
66+
instance Aeson.FromJSON TapToolsUnit where
67+
parseJSON = Aeson.withText "TapToolsUnit" $ \t case parseUrlPiece t of
68+
Left e fail $ show e
69+
Right ttu pure ttu
70+
71+
instance Aeson.FromJSONKey TapToolsUnit where
72+
fromJSONKey = Aeson.FromJSONKeyTextParser (either (fail . show) pure . parseUrlPiece)
73+
5074
data TapToolsInterval = TTI3m | TTI5m | TTI15m | TTI30m | TTI1h | TTI2h | TTI4h | TTI12h | TTI1d | TTI3d | TTI1w | TTI1M
5175
deriving stock (Eq, Ord, Enum, Bounded, Data, Typeable, Generic)
5276
deriving (FromJSON, ToJSON) via CustomJSON '[ConstructorTagModifier '[StripPrefix "TTI"]] TapToolsInterval
@@ -111,22 +135,34 @@ instance Swagger.ToSchema TapToolsOHLCV where
111135
& addSwaggerDescription "Get a specific token's trended (open, high, low, close, volume) price data."
112136
& addSwaggerExample (toJSON $ TapToolsOHLCV {tapToolsOHLCVTime = 1_715_007_300, tapToolsOHLCVOpen = open, tapToolsOHLCVHigh = open, tapToolsOHLCVLow = open, tapToolsOHLCVClose = open, tapToolsOHLCVVolume = 120})
113137

138+
type PricesResponse = Map.Map TapToolsUnit Double
139+
114140
type TapToolsApiKeyHeaderName Symbol
115141
type TapToolsApiKeyHeaderName = "x-api-key"
116142

117143
type TapToolsAPI =
118-
Header' '[Required] TapToolsApiKeyHeaderName TapToolsApiKey :> TapToolsOHLCVAPI
144+
Header' '[Required] TapToolsApiKeyHeaderName TapToolsApiKey
145+
:> "token"
146+
:> (TapToolsOHLCVAPI :<|> TapToolsPricesAPI)
119147

120148
type TapToolsOHLCVAPI =
121-
"token"
122-
:> "ohlcv"
149+
"ohlcv"
123150
:> QueryParam "unit" TapToolsUnit
124151
:> QueryParam' '[Required, Strict] "interval" TapToolsInterval
125152
:> QueryParam "numIntervals" Natural
126153
:> Get '[JSON] [TapToolsOHLCV]
127154

128-
_tapToolsOHLCV TapToolsApiKey Maybe TapToolsUnit TapToolsInterval Maybe Natural ClientM [TapToolsOHLCV]
129-
_tapToolsOHLCV = client (Proxy @TapToolsAPI)
155+
type TapToolsPricesAPI = "prices" :> ReqBody '[JSON] [TapToolsUnit] :> Post '[JSON] PricesResponse
156+
157+
data TapToolsClient = TapToolsClient
158+
{ tapToolsOHLCVClient Maybe TapToolsUnit TapToolsInterval Maybe Natural ClientM [TapToolsOHLCV],
159+
tapToolsPricesClient [TapToolsUnit] ClientM PricesResponse
160+
}
161+
162+
mkTapToolsClient TapToolsApiKey TapToolsClient
163+
mkTapToolsClient apiKey =
164+
let tapToolsOHLCVClient :<|> tapToolsPricesClient = client (Proxy @TapToolsAPI) apiKey
165+
in TapToolsClient {..}
130166

131167
tapToolsBaseUrl String
132168
tapToolsBaseUrl = "https://openapi.taptools.io/api/v1"
@@ -151,4 +187,7 @@ handleTapToolsError ∷ Text → Either ClientError a → IO a
151187
handleTapToolsError locationInfo = either (throwIO . TapToolsApiError locationInfo . hideServantClientErrorHeader (fromString $ symbolVal (Proxy @TapToolsApiKeyHeaderName))) pure
152188

153189
tapToolsOHLCV TapToolsEnv Maybe TapToolsUnit TapToolsInterval Maybe Natural IO [TapToolsOHLCV]
154-
tapToolsOHLCV env@(tteApiKey apiKey) ttu tti mttni = _tapToolsOHLCV apiKey ttu tti mttni & runTapToolsClient env >>= handleTapToolsError "tapToolsOHLCV"
190+
tapToolsOHLCV env@(tteApiKey apiKey) ttu tti mttni = mkTapToolsClient apiKey & tapToolsOHLCVClient & (\f f ttu tti mttni) & runTapToolsClient env >>= handleTapToolsError "tapToolsOHLCV"
191+
192+
tapToolsPrices TapToolsEnv [TapToolsUnit] IO PricesResponse
193+
tapToolsPrices env@(tteApiKey apiKey) ttus = mkTapToolsClient apiKey & tapToolsPricesClient & (\f f ttus) & runTapToolsClient env >>= handleTapToolsError "tapToolsPrices"

0 commit comments

Comments
 (0)