Skip to content

Commit 62a776a

Browse files
authored
Merge pull request #85 from geniusyield/visibility
feat: make some internal libraries public & utilise `/prices` taptools endpoint
2 parents a026d8c + 3420fbf commit 62a776a

File tree

14 files changed

+121
-127
lines changed

14 files changed

+121
-127
lines changed

README.md

+1-2
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ Note that two prices providers are supported: *Maestro* and *Taptools*. It is
136136

137137
* `ur_coll` (optional) is the UTxO to be reserved as collateral. Though specifying `ur_coll` is optional but it is advised to set it as then this UTxO would be reserved (i.e., would not be spent) and thus be always available to serve as collateral. It is preferred for `ur_coll` to be pure 5 ADA only UTxO (i.e., no other tokens besides ADA).
138138
* `mbc_delay` - Bot in single iteration tries to determine which orders need to be placed and which are needed to be cancelled. Once determined, it tries building the transactions and proceeds with submitting them, completing this single iteration. `mbc_delay` determines time in microseconds that bot must wait before proceeding with next iteration.
139-
* `mbc_price_config` gives the configuration on how to get market price using [Maestro](https://docs.gomaestro.org/Cardano/DefiMarketAPI/mkt-dex-ohlc) or [Taptools](https://openapi.taptools.io/#tag/Market-Tokens/paths/~1token~1ohlcv/get) endpoints, for a token.
139+
* `mbc_price_config` gives the configuration on how to get market price using [Maestro](https://docs.gomaestro.org/Cardano/DefiMarketAPI/mkt-dex-ohlc) or [Taptools](https://openapi.taptools.io/#tag/Market-Tokens/paths/~1token~1prices/post) endpoints, for a token.
140140
* `pc_price_common_cfg` contains the configuration parameters common to both prices providers.
141141
* `pcc_network_id` determines Cardano network which is mentioned for in API calls. It should always be kept `mainnet` as of now.
142142
* `pcc_price_diff_threshold1` if the *relative standard deviation*[^relstddev] among the prices providers is above this parameter, automatic cancelation of open orders is triggered (without raising logs' severity to "warning").
@@ -158,7 +158,6 @@ Note that two prices providers are supported: *Maestro* and *Taptools*. It is
158158

159159
* Taptools:
160160
* `ttc_api_key` is the Taptools API key.
161-
* `ttc_resolution` is the resolution for the mentioned Taptools endpoint. Possible values of resolution can be seen [here](https://openapi.taptools.io/#tag/Market-Tokens/paths/~1token~1ohlcv/get).
162161
* `ttc_pair_override` plays the same role as `mc_pair_override` described above, but for Taptools. Note that asset class is set with `ttpo_asset` and its precison (number of decimals) with `ttpo_precision`.
163162

164163
* `mbc_strategy_config` determines parameters for strategy:

geniusyield-market-maker/CHANGELOG.md

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

3+
## 0.6.0 -- 2024-06-24
4+
5+
* Utilise [`/token/prices`](https://openapi.taptools.io/#tag/Market-Tokens/paths/~1token~1prices/post) api endpoint instead of [`/token/ohlcv`](https://openapi.taptools.io/#tag/Market-Tokens/paths/~1token~1ohlcv/get) for TapTools price provider.
6+
* Internal code refactoring to facilitate importing this library.
7+
38
## 0.5.0 -- 2024-05-14
49

510
* Added support for having Taptools as a second prices provider.

geniusyield-market-maker/geniusyield-market-maker.cabal

+6-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
cabal-version: 3.4
22
name: geniusyield-market-maker
3-
version: 0.5.0
3+
version: 0.6.0
44
build-type: Simple
55
extra-doc-files: CHANGELOG.md
66
synopsis:
@@ -102,24 +102,26 @@ library datasource-providers
102102
import: common-lang
103103
import: common-deps
104104
import: common-ghc-opts
105-
hs-source-dirs: ../impl/datasource-providers
105+
hs-source-dirs: impl/datasource-providers
106106
build-depends:
107107
, geniusyield-dex-api
108108
, geniusyield-orderbot-framework:common
109109

110110
exposed-modules: GeniusYield.OrderBot.DataSource.Providers
111+
visibility: public
111112

112113
library orderbook-annset
113114
import: common-lang
114115
import: common-deps
115116
import: common-ghc-opts
116-
hs-source-dirs: ../impl/orderbook-annset
117+
hs-source-dirs: impl/orderbook-annset
117118
build-depends:
118119
, geniusyield-annset
119120
, geniusyield-dex-api
120121
, geniusyield-orderbot-framework:{common, datasource}
121122

122123
exposed-modules: GeniusYield.OrderBot.OrderBook.AnnSet
124+
visibility: public
123125

124126
library geniusyield-market-maker-lib
125127
import: common-lang
@@ -150,6 +152,7 @@ library geniusyield-market-maker-lib
150152
, servant-client-core
151153
mixins:
152154
geniusyield-market-maker:orderbook-annset requires (GeniusYield.OrderBot.DataSource as GeniusYield.OrderBot.DataSource.Providers)
155+
visibility: public
153156

154157
-- Build targets
155158

geniusyield-market-maker/src/GeniusYield/MarketMaker/MakerBot.hs

+17-19
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ data MBFret = MBReady | MBSpooked1
4040
}
4141
| MBSpooked2
4242
{ mbs2Relax !Int }
43-
43+
4444

4545
-----------------------------------------------------------------------
4646
---------------------------- ACTIONS ----------------------------------
@@ -62,7 +62,7 @@ cancelAllOrders' MakerBot {mbUser} netId providers di = do
6262
else do
6363
let (batch, rest) = splitAt 6 partialOrderInfos
6464
userAddr = addrUser netId mbUser
65-
txBody
65+
txBody
6666
runGYTxMonadNode netId providers [userAddr] userAddr (uColl mbUser)
6767
$ runReaderT (cancelMultiplePartialOrders' (dexPORefs di) batch) di
6868
let signedTx =
@@ -90,7 +90,7 @@ buildAndSubmitActions user@User {uColl, uStakeCred} providers netId ua di = flip
9090

9191
forM_ placeActions $ \pa@PlaceOrderAction {..} do
9292
logInfo $ "Building for place action: " <> show pa
93-
txBody
93+
txBody
9494
runGYTxMonadNode netId providers [userAddr] userAddr uColl
9595
$ flip runReaderT di
9696
$ placePartialOrder
@@ -173,62 +173,60 @@ mbStateMachine runStrategy mb@MakerBot {mbUser, mbDelay, mbToken} netId provider
173173

174174
MBSpooked1 {..} do
175175
if mbs1Relax >= pccAfterExitRelaxAim1 cfg then do
176-
lift $ gyLogInfo providers logNS $ "[MBSpooked1] Resuming strategy"
176+
lift $ gyLogInfo providers logNS "[MBSpooked1] Resuming strategy"
177177
put MBReady
178178
else if mbs1Worse >= pccAfterExitWorseMax1 cfg
179179
then do
180-
lift $ gyLogWarning providers logNS $ "[MBSpooked1] Price mismatch among providers lasting a long time!"
180+
lift $ gyLogWarning providers logNS "[MBSpooked1] Price mismatch among providers lasting a long time!"
181181
put MBSpooked2 { mbs2Relax = 0 }
182182
else do
183183
pe lift $ priceEstimate' pp mbToken
184184

185185
case pe of
186186
PriceMismatch1 do
187-
lift $ gyLogInfo providers logNS $ "[MBSpooked1] Price mismatch persists"
187+
lift $ gyLogInfo providers logNS "[MBSpooked1] Price mismatch persists"
188188
put MBSpooked1 { mbs1Relax = 0, mbs1Worse = mbs1Worse + 1 }
189189

190190
PriceMismatch2 do
191-
lift $ gyLogWarning providers logNS $ "[MBSpooked1] Outrageous price mismatch among providers!"
191+
lift $ gyLogWarning providers logNS "[MBSpooked1] Outrageous price mismatch among providers!"
192192
put MBSpooked2 { mbs2Relax = 0 }
193193

194194
PriceUnavailable do
195-
lift $ gyLogWarning providers logNS $ "[MBSpooked1] All Prices Providers unavailable!"
195+
lift $ gyLogWarning providers logNS "[MBSpooked1] All Prices Providers unavailable!"
196196
put MBSpooked2 { mbs2Relax = 0 }
197197

198-
PriceSourceFail es pps _ do
199-
lift $ logPricesProviderFail providers es pps
198+
PriceSourceFail es pps _ lift $ logPricesProviderFail providers es pps
200199

201200
PriceAverage _ do
202-
lift $ gyLogInfo providers logNS $ "[MBSpooked1] Apparent recovery of Prices Providers; waiting for observation period to elapse."
201+
lift $ gyLogInfo providers logNS "[MBSpooked1] Apparent recovery of Prices Providers; waiting for observation period to elapse."
203202
put MBSpooked1 { mbs1Relax = mbs1Relax + 1, mbs1Worse = mbs1Worse }
204203

205204
lift $ threadDelay respiteDelay
206205

207206
MBSpooked2 {..} do
208207
if mbs2Relax >= pccAfterExitRelaxAim2 cfg then do
209-
lift $ gyLogInfo providers logNS $ "[MBSpooked2] Resuming strategy"
208+
lift $ gyLogInfo providers logNS "[MBSpooked2] Resuming strategy"
210209
put MBReady
211210
else do
212211
pe lift $ priceEstimate' pp mbToken
213212

214213
case pe of
215214
PriceMismatch1 do
216-
lift $ gyLogWarning providers logNS $ "[MBSpooked2] Price mismatch persists"
215+
lift $ gyLogWarning providers logNS "[MBSpooked2] Price mismatch persists"
217216
put MBSpooked2 { mbs2Relax = 0 }
218217

219218
PriceMismatch2 do
220-
lift $ gyLogWarning providers logNS $ "[MBSpooked2] Outrageous price mismatch persists"
219+
lift $ gyLogWarning providers logNS "[MBSpooked2] Outrageous price mismatch persists"
221220
put MBSpooked2 { mbs2Relax = 0 }
222221

223222
PriceUnavailable do
224-
lift $ gyLogWarning providers logNS $ "[MBSpooked2] All Prices Providers unavailable"
223+
lift $ gyLogWarning providers logNS "[MBSpooked2] All Prices Providers unavailable"
225224
put MBSpooked2 { mbs2Relax = 0 }
226225

227-
PriceSourceFail es pps _ do
228-
lift $ logPricesProviderFail providers es pps
226+
PriceSourceFail es pps _ lift $ logPricesProviderFail providers es pps
229227

230228
PriceAverage _ do
231-
lift $ gyLogInfo providers logNS $ "[MBSpooked2] Apparent recovery of Prices Providers; waiting for observation period to elapse."
229+
lift $ gyLogInfo providers logNS "[MBSpooked2] Apparent recovery of Prices Providers; waiting for observation period to elapse."
232230
put MBSpooked2 { mbs2Relax = mbs2Relax + 1 }
233231

234232
lift $ threadDelay respiteDelay
@@ -243,7 +241,7 @@ evolveStrategy
243241
StateT MBFret IO ()
244242
evolveStrategy runStrategy mb netId providers pp di =
245243
forever $ mbStateMachine runStrategy mb netId providers pp di
246-
244+
247245
executeStrategy
248246
Strategy
249247
MakerBot

geniusyield-market-maker/src/GeniusYield/MarketMaker/MakerBotConfig.hs

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ data MakerBotConfig = MakerBotConfig
2323
mbcPriceConfig !PriceConfig
2424
}
2525
deriving stock (Show, Generic)
26-
deriving (FromJSON) via CustomJSON '[FieldLabelModifier '[CamelToSnake]] MakerBotConfig
26+
deriving (FromJSON, ToJSON) via CustomJSON '[FieldLabelModifier '[CamelToSnake]] MakerBotConfig
2727

2828
instance FromEnv MakerBotConfig where
2929
fromEnv _ =

0 commit comments

Comments
 (0)