A Step-by-Step Guide to Building your own Market Maker Bot with docker on Genius Yield

Aggelos K
6 min readJan 27, 2024

--

Contents

  • Introduction: What a Market Maker bot does?
  • Prerequisites
  • Create the Maestro API Key
  • Create a Cardano Mainnet Payment Signing key
  • Create a suitable UTXO for collateral
  • Market Maker Bot Installation
  • Bot running
  • Additional Links

Introduction: What a Market Maker bot does?

A Market Maker bot is a type of trading bot that continuously buys and sells cryptocurrencies on a digital exchange. Its primary function is to provide liquidity to the market, meaning it helps make it easier for other traders to buy or sell without causing significant price movements. The bot does this by maintaining a constant presence in the order book, placing buy orders at slightly below the market price and sell orders slightly above. This strategy can potentially earn profits from the spread — the difference between the buying and selling prices.

Prerequisites:

Recommended System Requirements:

  • Memory: 1GB
  • CPU: 1vCPU (2.25 GHz CPU Base Frequency)
  • Reliable and blazingly fast internet connection
  • Install Git
sudo apt update
sudo apt install git
git --version

Installing docker depends on your operation system. I would recommend you follow the official installation guide based on your system. Follow the guidance from the link here: https://docs.docker.com/engine/install/

Installation:

  • Guide through the process of cloning the repository and installing any dependencies.

There are two possible ways where you can run your MMB, either using Docker compose or building from source. In both ways there is the need of some common environmental variables that have to be specified for your local configuration, and these are:

  • MAESTRO_API_KEY: : The MAINNET API key to be used for accessing the Maestro services.
  • PAYMENT_SIGNING_KEY: The payment signing key to be used.
  • COLLATERAL_UTXO: A suitable UTxO with 5 ADA to be used as collateral UTxO.

I’ll guide you how you can create all of them one by one.

Create the Maestro API Key

  • Sign up and Login here, Maestro Dashboard
  • Click New Project and your project name and network:

Saving the project will generate you an API key, which you have to copy for later usage for the variable MAESTRO_API_KEY.

Create a Cardano Mainnet Payment Signing key

There are many ways to do this.

  • GY team has provided a simple to use docker image which you can run locally on your terminal or your server:
docker run -it --rm ghcr.io/geniusyield/signing-key-generator:latest

this will generate you something like that:

Payment Signing Key and Wallet Address

Where you will need to use later, all this part, which is written under the PAYMENT SIGNING KEY:

{
"type": "PaymentSigningKeyShelley_ed25519",
"description": "Payment Signing Key",
"cborHex": "5820c84d3e2b662ca761863e3c3e58f63199de16d1056483b84cc53eb8e819c8575c"
}
  • Another possible way to create a Payment Signing key, is with the usage of cardano-cli. You can follow the part 3. of this guide, in case you run your own cardano node instance, which means to do these commands:
./cardano-cli address key-gen \
--verification-key-file bot.vkey \
--signing-key-file bot.skey

./cardano-cli address build \
--payment-verification-key-file bot.vkey \
--mainnet \
--out-file bot.addr

cat bot.skey

where the last command will print you the bot signing key that you have created, similarly with the output of the docker image above. You can use whatever it suits you the most.

Create a suitable UTXO for collateral

In the above picture are generated the mainnet address the signing & verification key. You need to send at least 5ADA in this address to be used as collateral, by setting the COLLATERAL_UTXO environmental variable.

If you run your own cardano node instance (recommended)

Similarly, you need to use the cardano-cli to query the address and confirm the TxHash and TxIn:

./cardano-cli query utxo --address $(cat bot.addr) --mainnet --socket-path  /root/node/sockets/node.socket

where in result of this you will see something like this:

TxHash                                                               TxIx     Amount
--------------------------------------------------------------------------------------
fbfa56e74a0ed92e53c6ed94dc290610d918760e25a700c5a96aee4c62562286 0 5000000 lovelace + TxOutDatumNone

In short COLLATERAL_UTXO=TxHash#TxIx or in that case is equal to fbfa56e74a0ed92e53c6ed94dc290610d918760e25a700c5a96aee4c62562286#0

Market Maker Bot Installation

Let’s begin the installation process of the Market Maker Bot repository with Docker:

# Clone the repository:
git clone git@github.com:geniusyield/market-maker.git MMB
cd MMB
# TODO: YOUR OWN VALUES BELOW AS EXPLAINED ABOVE
export MAESTRO_API_KEY=aBcDefghijoXj3v0LB3txySofSPrP3Vf2
export PAYMENT_SIGNING_KEY='{
"type": "PaymentSigningKeyShelley_ed25519",
"description": "Payment Signing Key",
"cborHex": "5820c84d3e2b662ca761863e3c3e58f63199de16d1056483b84cc53eb8e819c8575c"
}'
export COLLATERAL_UTXO=fbfa56e74a0ed92e53c6ed94dc290610d918760e25a700c5a96aee4c62562286#0

As you can see below, for configuring the Market Maker Bot, the most important variables to consider in the docker-compose.yaml file are:

  1. MAESTRO_API_KEY: This is the API key for accessing Maestro services. It's crucial for the bot to interact with the blockchain.
  2. PAYMENT_SIGNING_KEY: The key used for signing transactions. This ensures the security and authenticity of the transactions made by the bot.
  3. COLLATERAL_UTXO: An optional, but recommended Unspent Transaction Output (UTxO) reserved as collateral to support the bot's operations.
  4. mbc_strategy_config: This section defines the bot's trading strategy, including spread (sc_spread), token volume thresholds (sc_token_volume), and price checking (sc_price_check_product, sc_cancel_threshold_product).
  5. mbc_price_config: Configuration for fetching market prices, including API key (pc_api_key), network ID, and selected DEX.
  6. mbc_user: Details about the bot's wallet, including the path to the signing key and the stake address.

These variables are essential for the initial setup and operation of the bot, defining how it interacts with the blockchain, its trading behavior, and financial parameters. For detailed instructions, refer to the Market Maker Bot README.

version: '3.8'
services:
mm:
image: ghcr.io/geniusyield/market-maker:latest
container_name: mm
environment:
# Supported modes: MM for market making and CANCEL for canceling ALL the orders.
MODE: ${MODE:-MM}
PAYMENT_SIGNING_KEY: ${PAYMENT_SIGNING_KEY}
PROVIDER_CONFIG: |
{
"coreProvider": {
"maestroToken": "${MAESTRO_API_KEY}"
},
"networkId": "${NETWORK:-mainnet}",
"logging": [
{
"type": {
"tag": "stderr"
},
"severity": "Debug",
"verbosity": "V2"
}
]
}
MARKET_MAKER_CONFIG: |
{
"mbc_user": {
"ur_s_key_path": "/root/payment-signing-key.skey",
"ur_coll": "${COLLATERAL_UTXO}"
},
"mbc_fp_nft_policy": "compiled-scripts/minting-policy",
"mbc_fp_order_validator": "compiled-scripts/partial-order",
"mbc_po_config_addr": "addr1w9zr09hgj7z6vz3d7wnxw0u4x30arsp5k8avlcm84utptls8uqd0z",
"mbc_po_refs": {
"por_ref_nft": "fae686ea8f21d567841d703dea4d4221c2af071a6f2b433ff07c0af2.4aff78908ef2dce98bfe435fb3fd2529747b1c4564dff5adebedf4e46d0fc63d",
"por_val_ref": "062f97b0e64130bc18b4a227299a62d6d59a4ea852a4c90db3de2204a2cd19ea#2",
"por_mint_ref": "062f97b0e64130bc18b4a227299a62d6d59a4ea852a4c90db3de2204a2cd19ea#1"
},
"mbc_delay": 120000000,
"mbc_price_config": {
"pc_api_key": "${MAESTRO_API_KEY}",
"pc_resolution": "15m",
"pc_network_id": "${NETWORK:-mainnet}",
"pc_dex": "genius-yield"
},
"mbc_strategy_config": {
"sc_spread": {
"numerator": 1,
"denominator": 100
},
"sc_token_volume": {
"tv_sell_min_vol": 1000000000,
"tv_buy_min_vol": 2000000000,
"tv_sell_budget": 3500000000,
"tv_buy_budget": 6600000000,
"tv_sell_vol_threshold": 10000000000,
"tv_buy_vol_threshold": 20000000000
},
"sc_price_check_product": 9,
"sc_cancel_threshold_product": 4
},
"mbc_token": {
"ac": "dda5fdb1002f7389b33e036b6afee82a8189becb6cba852e8b79b4fb.0014df1047454e53",
"precision": 6
}
}
restart: always

It’s important to note that the initial configuration of the Market Maker Bot, as described above, can and should be adjusted according to the specific strategy and requirements of each trader. The settings provided in the docker-compose.yaml file, like trading strategy parameters and financial thresholds, are not one-size-fits-all and can be fine-tuned to match the trader's objectives, risk tolerance, and market conditions. This customization is crucial for optimizing the bot's performance and achieving desired trading outcomes.

Running the Bot:

If all the variables are set appropriately, then pull the images and run the bot:

# Update the docker images:
docker compose pull
# Start the MM bot with your config:
docker compose up

Additional Resources:

--

--

Aggelos K
Aggelos K

Written by Aggelos K

Software Engineer, Physicist, Blockchain and writing about Blockchain - Software Development - Crypto

No responses yet