This guide shows you how to show how to install and run the new
amm_arb strategy. The
amm_arb strategy, which we describe in this blog post, lets you arbitrage price differences between AMM protocols like Balancer and order book exchanges.
You'll learn how to:
Let's get started!
Note: If you have already installed Hummingbot v0.33 or higher using Docker or from source, you can skip this step.
amm_arb requires Hummingbot Gateway, a separate repository, you have to install Hummingbot either using Docker or from source to run it. This strategy will not work if you install Hummingbot with the Windows or macOS installers.
First, let's install the Docker version of Hummingbot. We have guides for each OS:
If installation is successful, you should see the Hummingbot client interface:
Next, we need to add our credentials to the Hummingbot client so that it can trade on both the AMM protocol and an order book exchange.
We'll also configure Hummingbot to work with Hummingbot Gateway, a separate module that facilitates communication with blockchain protocols. Since Gateway is a separate web server that resides in the same local machine as Hummingbot, we need to make sure that all communications between the two are securely encrypted.
If you are using Hummingbot for the first time on this machine, the system will prompt you to create a password. This password will be used to encrypt sensitive configuration settings e.g. API keys, secret keys and wallet private keys.
amm_arb arbitrages price differences between an AMM protocol and a centralized exchange, you have to enter in your credentials for both before you can start trading. Let's enter the exchange API keys first.
Hummingbot requires trade enabled API keys to access your exchange account. For exchange-specific information on how to find your API keys, please see the See all connectors page in the Hummingbot docs.
Enter the command
connect to see what exchanges are available. Afterwards, enter
connect [exchange] to connect your exchange account to Hummingbot by adding API keys, where
[exchange]is one of the exchanges supported by Hummingbot.
>>> connect binance Enter your Binance API key >>> **************************** Enter your Binance API secret >>> **************************** You are now connected to binance.
See See all connectors for a list of available exchanges.
Next, we will add our Ethereum wallet and connect to an Ethereum node, which are needed to submit transactions on the Ethereum blockchain.
Note: If you are running
amm_arbon an non-Ethereum protocol, the instructions below may not apply.
Enter the command
connect ethereum and add the private key associated with your Ethereum wallet. Hummingbot stores both your private key and exchange API keys in encrypted form.
>>> connect ethereum Enter your wallet private key >>> **************************** Wallet 0x...xxxx connected to hummingbot.
config ethereum_rpc_url and enter the URL of your Infura node.
>>> config ethereum_rpc_url Which Ethereum node would you like your client to connect to? >>> https://mainnet.infura.io/v3/XXXX
Note that we'll need this URL again later when we set up Hummingbot Gateway.
Note: To see how to set up your own Ethereum node or other providers besides Infura, please see Advanced Configuration - Ethereum Nodes.
ETH Gas Station is a free site that tracks real-time Ethereum gas prices. Since Ethereum gas prices are highly volatile, we recommend adding an API key so that the client can incorporate live gas prices when a running a bot.
To get a free API key for ETH Gas Station, visit DefiPulse Data and create an account. Afterwards, save the API key for use in Hummingbot:
Next, run the following commands to input your ETH Gas Station API key and tell Hummingbot to use it for gas price lookups:
>>> config ethgasstation_gas_enabled Do you want to enable Ethereum gas station price lookup? >>> Yes >>> config ethgasstation_api_key Enter API key for defipulse.com gas station API >>> ************** >>> config ethgasstation_gas_level Enter gas level you want to use for Ethereum transactions (fast, fastest, safeLow, average) >>> fast (or another option)
Note: You can also manually set the gas price by running
Finally, we will generate an SSL certificate that secures communications between the Hummingbot client and Hummingbot Gateway.
generate_certs to create the SSL cert:
>>> generate_certs Enter passphrase to generate Gateway SSL certification >>> [your secret passphrase] Gateway SSL certification files are created in /Users/[USERNAME]/hummingbot/certs
Write down your passphrase and the certification path, since we'll need it shortly.
Getting the Certs Path: If you need to fetch the certification path later on, go to the directory where your Hummingbot files are stored. If you accepted the default options when installing the Docker version of Hummingbot, there will be a
/hummingbot_filesdirectory on your machine. Go to it and run
cd certsto enter the
certsfolder. Then, you can run
pwdfrom inside the
certsdirectory to get the absolute path.
From Terminal or Bash, run the following commands to download and execute the installation script:
# Download Hummingbot Gateway install curl https://raw.githubusercontent.com/CoinAlpha/hummingbot/development/installation/docker-commands/create-gateway.sh -o create-gateway.sh curl https://raw.githubusercontent.com/CoinAlpha/hummingbot/development/installation/docker-commands/update-gateway.sh -o update-gateway.sh # Enable script permissions chmod a+x create-gateway.sh # Create a gateway instance ./create-gateway.sh
The script asks you some questions to complete the installation process:
=============== CREATE A NEW GATEWAY INSTANCE =============== ℹ️ Press [ENTER] for default values:
For the first 3 questions, you can press ENTER to accept the default values:
Enter Gateway version you want to use [latest/development] (default = "latest") >>> Enter a name for your new Gateway instance (default = "gateway-instance") >>> Enter Balancer network you want to use [mainnet/kovan] (default = "mainnet") >>>
Enter the absolute path to the
certs folder that you wrote down in Step 2:
Enter the full location path where your Hummingbot cert files are located >>> /Users/[USERNAME]/hummingbot/certs
Enter your Infura node URL that you added in Step 2:
Enter the Ethereum RPC URL set in your Hummingbot instance >>> https://mainnet.infura.io/v3/XXXX
Enter the passphrase that you used to generate the SSL certificate in Step 2:
Enter your Gateway cert passphrase configured in Hummingbot >>> [your secret passphrase]
Afterwards, review the information and enter Yes to complete the Gateway configuration:
Changing Ports: By default, Gateway will install on port
5000that Hummingbot uses to connect to . If port 5000 is not available, Gateway will increment the port number and use port
5001. If the port is 5001, run
config gateway_api_portin Hummingbot to set the correct port.
Now, we can finally configure an
amm_arb bot that arbitrages between AMM protocols and order book exchanges!
create command to build a strategy configuration file:
What is your market making strategy? >>> amm_arb Enter your first connector (exchange/AMM)? >>> balancer Enter the token trading pair you would like to trade on balancer (e.g. WETH-DAI) >>> WETH-DAI Enter your second connector (exchange/AMM)? >>> binance Enter the token trading pair you would like to trade on binance (e.g. ZRX-ETH) >>> ETH-USDT What is the amount of WETH per order? >>> [order_amount] What is the minimum profitability for you to make a trade (Enter 1 to indicate 1%)? >>> 1 # Buffer added to the price to account for price movement before trade execution How much buffer do you want to add to the price to account for slippage for orders on the first market (Enter 1 for 1%)? >>> 0.1 How much buffer do you want to add to the price to account for slippage for orders on the second market (Enter 1 for 1%)? >>> 0.1 # If true the bot submits both arbitrage taker orders (buy and sell) simultaneously. # If false, the bot will wait for first exchange order filled before submitting the other order. Do you want to submit both arb order concurrently (Yes/No)? >>> Yes
For details on each parameter above, see Strategies - AMM Arb.
Adding Ethereum tokens: To add token addresses to the the list of Ethereum tokens maintained by Hummingbot, edit the following file in the Hummingbot directory (if you installed from source):
/hummingbot/hummingbot/wallet/ethereum/erc20_tokens.json. We intend to simplify this process in future versions of Hummingbot.
start to run the bot.
The perform will perform checks to ensure that it can connect to both the protocol and the exchange. Afterwards, the bot will automatically call the
approve function on any tokens that need approval.
Then, the bot will continually scan for arbitrage opportunities and execute trades to capture them.
status to see the current profitability of each arbitrage leg.
history to see what trades your bot has made in the current session.
Checking Transaction Status: To check the status of submitted transactions, go to Etherscan to check if any pending transaction gets stuck for too long (> 5 min). If any transactions are stuck, consider changing the
config ethgasstation_gas_levelto fast or fastest.