Skip to content

Commit

Permalink
Merge pull request #85 from geniusyield/visibility
Browse files Browse the repository at this point in the history
feat: make some internal libraries public & utilise `/prices` taptools endpoint
  • Loading branch information
brunjlar authored Jun 26, 2024
2 parents a026d8c + 3420fbf commit 62a776a
Show file tree
Hide file tree
Showing 14 changed files with 121 additions and 127 deletions.
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ Note that two prices providers are supported: *Maestro* and *Taptools*. It is

* `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).
* `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.
* `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.
* `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.
* `pc_price_common_cfg` contains the configuration parameters common to both prices providers.
* `pcc_network_id` determines Cardano network which is mentioned for in API calls. It should always be kept `mainnet` as of now.
* `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").
Expand All @@ -158,7 +158,6 @@ Note that two prices providers are supported: *Maestro* and *Taptools*. It is

* Taptools:
* `ttc_api_key` is the Taptools API key.
* `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).
* `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`.

* `mbc_strategy_config` determines parameters for strategy:
Expand Down
5 changes: 5 additions & 0 deletions geniusyield-market-maker/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Revision history for geniusyield-market-maker

## 0.6.0 -- 2024-06-24

* 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.
* Internal code refactoring to facilitate importing this library.

## 0.5.0 -- 2024-05-14

* Added support for having Taptools as a second prices provider.
Expand Down
9 changes: 6 additions & 3 deletions geniusyield-market-maker/geniusyield-market-maker.cabal
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
cabal-version: 3.4
name: geniusyield-market-maker
version: 0.5.0
version: 0.6.0
build-type: Simple
extra-doc-files: CHANGELOG.md
synopsis:
Expand Down Expand Up @@ -102,24 +102,26 @@ library datasource-providers
import: common-lang
import: common-deps
import: common-ghc-opts
hs-source-dirs: ../impl/datasource-providers
hs-source-dirs: impl/datasource-providers
build-depends:
, geniusyield-dex-api
, geniusyield-orderbot-framework:common

exposed-modules: GeniusYield.OrderBot.DataSource.Providers
visibility: public

library orderbook-annset
import: common-lang
import: common-deps
import: common-ghc-opts
hs-source-dirs: ../impl/orderbook-annset
hs-source-dirs: impl/orderbook-annset
build-depends:
, geniusyield-annset
, geniusyield-dex-api
, geniusyield-orderbot-framework:{common, datasource}

exposed-modules: GeniusYield.OrderBot.OrderBook.AnnSet
visibility: public

library geniusyield-market-maker-lib
import: common-lang
Expand Down Expand Up @@ -150,6 +152,7 @@ library geniusyield-market-maker-lib
, servant-client-core
mixins:
geniusyield-market-maker:orderbook-annset requires (GeniusYield.OrderBot.DataSource as GeniusYield.OrderBot.DataSource.Providers)
visibility: public

-- Build targets

Expand Down
36 changes: 17 additions & 19 deletions geniusyield-market-maker/src/GeniusYield/MarketMaker/MakerBot.hs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ data MBFret = MBReady | MBSpooked1
}
| MBSpooked2
{ mbs2Relax !Int }


-----------------------------------------------------------------------
---------------------------- ACTIONS ----------------------------------
Expand All @@ -62,7 +62,7 @@ cancelAllOrders' MakerBot {mbUser} netId providers di = do
else do
let (batch, rest) = splitAt 6 partialOrderInfos
userAddr = addrUser netId mbUser
txBody
txBody
runGYTxMonadNode netId providers [userAddr] userAddr (uColl mbUser)
$ runReaderT (cancelMultiplePartialOrders' (dexPORefs di) batch) di
let signedTx =
Expand Down Expand Up @@ -90,7 +90,7 @@ buildAndSubmitActions user@User {uColl, uStakeCred} providers netId ua di = flip

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

MBSpooked1 {..} do
if mbs1Relax >= pccAfterExitRelaxAim1 cfg then do
lift $ gyLogInfo providers logNS $ "[MBSpooked1] Resuming strategy"
lift $ gyLogInfo providers logNS "[MBSpooked1] Resuming strategy"
put MBReady
else if mbs1Worse >= pccAfterExitWorseMax1 cfg
then do
lift $ gyLogWarning providers logNS $ "[MBSpooked1] Price mismatch among providers lasting a long time!"
lift $ gyLogWarning providers logNS "[MBSpooked1] Price mismatch among providers lasting a long time!"
put MBSpooked2 { mbs2Relax = 0 }
else do
pe lift $ priceEstimate' pp mbToken

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

PriceMismatch2 do
lift $ gyLogWarning providers logNS $ "[MBSpooked1] Outrageous price mismatch among providers!"
lift $ gyLogWarning providers logNS "[MBSpooked1] Outrageous price mismatch among providers!"
put MBSpooked2 { mbs2Relax = 0 }

PriceUnavailable do
lift $ gyLogWarning providers logNS $ "[MBSpooked1] All Prices Providers unavailable!"
lift $ gyLogWarning providers logNS "[MBSpooked1] All Prices Providers unavailable!"
put MBSpooked2 { mbs2Relax = 0 }

PriceSourceFail es pps _ do
lift $ logPricesProviderFail providers es pps
PriceSourceFail es pps _ lift $ logPricesProviderFail providers es pps

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

lift $ threadDelay respiteDelay

MBSpooked2 {..} do
if mbs2Relax >= pccAfterExitRelaxAim2 cfg then do
lift $ gyLogInfo providers logNS $ "[MBSpooked2] Resuming strategy"
lift $ gyLogInfo providers logNS "[MBSpooked2] Resuming strategy"
put MBReady
else do
pe lift $ priceEstimate' pp mbToken

case pe of
PriceMismatch1 do
lift $ gyLogWarning providers logNS $ "[MBSpooked2] Price mismatch persists"
lift $ gyLogWarning providers logNS "[MBSpooked2] Price mismatch persists"
put MBSpooked2 { mbs2Relax = 0 }

PriceMismatch2 do
lift $ gyLogWarning providers logNS $ "[MBSpooked2] Outrageous price mismatch persists"
lift $ gyLogWarning providers logNS "[MBSpooked2] Outrageous price mismatch persists"
put MBSpooked2 { mbs2Relax = 0 }

PriceUnavailable do
lift $ gyLogWarning providers logNS $ "[MBSpooked2] All Prices Providers unavailable"
lift $ gyLogWarning providers logNS "[MBSpooked2] All Prices Providers unavailable"
put MBSpooked2 { mbs2Relax = 0 }

PriceSourceFail es pps _ do
lift $ logPricesProviderFail providers es pps
PriceSourceFail es pps _ lift $ logPricesProviderFail providers es pps

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

lift $ threadDelay respiteDelay
Expand All @@ -243,7 +241,7 @@ evolveStrategy
StateT MBFret IO ()
evolveStrategy runStrategy mb netId providers pp di =
forever $ mbStateMachine runStrategy mb netId providers pp di

executeStrategy
Strategy
MakerBot
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ data MakerBotConfig = MakerBotConfig
mbcPriceConfig !PriceConfig
}
deriving stock (Show, Generic)
deriving (FromJSON) via CustomJSON '[FieldLabelModifier '[CamelToSnake]] MakerBotConfig
deriving (FromJSON, ToJSON) via CustomJSON '[FieldLabelModifier '[CamelToSnake]] MakerBotConfig

instance FromEnv MakerBotConfig where
fromEnv _ =
Expand Down
Loading

0 comments on commit 62a776a

Please sign in to comment.