<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Perpetual Protocol (✨🔴_🔴✨)</title>
    <description>The latest articles on DEV Community by Perpetual Protocol (✨🔴_🔴✨) (@perpprotocol).</description>
    <link>https://dev.to/perpprotocol</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F870410%2F5bda1e2d-4b30-4f0c-97fe-248750e6e321.jpg</url>
      <title>DEV Community: Perpetual Protocol (✨🔴_🔴✨)</title>
      <link>https://dev.to/perpprotocol</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/perpprotocol"/>
    <language>en</language>
    <item>
      <title>Arbitraging Between DEXes and CEXes for Profits &amp; Fun</title>
      <dc:creator>Perpetual Protocol (✨🔴_🔴✨)</dc:creator>
      <pubDate>Thu, 09 Jun 2022 10:14:24 +0000</pubDate>
      <link>https://dev.to/perpprotocol/arbitraging-between-dexes-and-cexes-for-profits-fun-39nh</link>
      <guid>https://dev.to/perpprotocol/arbitraging-between-dexes-and-cexes-for-profits-fun-39nh</guid>
      <description>&lt;p&gt;&lt;a href="https://github.com/perpetual-protocol/perp-curie-arbitrageur"&gt;Perp-curie-arbitrageur&lt;/a&gt; is an open-sourced template that automatically executes your arbitrage strategy between &lt;a href="https://app.perp.com/?utm_source=perp_devto&amp;amp;utm_medium=blog_post"&gt;Perpetual Protocol v2&lt;/a&gt; "Curie" and FTX.&lt;/p&gt;

&lt;p&gt;In this blog post, we'll cover what Perpetual Protocol v2 is, the risks and rewards of running this bot, how you can run it on your computer and on AWS, and further modification suggestions.&lt;/p&gt;

&lt;h1&gt;
  
  
  Perpetual Protocol 101
&lt;/h1&gt;

&lt;p&gt;Perpetual Protocol, or Perp v2 "Curie" specifically, is a decentralized derivative exchange (DEX) on &lt;a href="https://www.optimism.io/"&gt;Optimism&lt;/a&gt; where traders can use USDC (a USD-backed stablecoin) to speculate on cryptocurrency's price movement with up to 10x leverage. You can open a long position if you believe one asset's price will go up or open short positions if you expect it will go down. At the time of writing, the DEX supports 17 markets, including BTC, ETH, ATOM, BNB, and more!&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--3QB66v0a--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/8seh97ph5bb2sdxvozp3.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--3QB66v0a--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/8seh97ph5bb2sdxvozp3.png" alt="Image description" width="880" height="518"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You can learn how it works in detail by watching this &lt;a href="https://www.youtube.com/watch?v=pBoKtkoNZEY"&gt;10-minute video&lt;/a&gt; or reading &lt;a href="https://cryptotesters.com/blog/perp-protocol"&gt;this article&lt;/a&gt;.&lt;/p&gt;

&lt;h1&gt;
  
  
  Risks and Rewards of Running Perp-curie-arbitrageur
&lt;/h1&gt;

&lt;p&gt;The way perp-curie-arbitrageur works is that, whenever there is a price difference between &lt;a href="https://app.perp.com/?utm_source=perp_devto&amp;amp;utm_medium=blog_post"&gt;Perp v2&lt;/a&gt; (a derivative DEX) and &lt;a href="https://ftx.com"&gt;FTX&lt;/a&gt; (a CEX), the bot will buy on the cheaper side and sell on the more expensive side. Out of the box, this template allows you to set the desired price difference for the bot to take action. Additionally, you can specify the markets for the bot to run the arbitrage strategy.&lt;/p&gt;

&lt;p&gt;Of course, we can't just look at the rewards. How about the risks associated with running this bot?&lt;/p&gt;

&lt;p&gt;The main risk is liquidation, which can happen when you use too much leverage to trade on either Perp v2 or FTX. Luckily, the bot lets you set the margin ratio you're comfortable with, which is the reciprocal of leverage, and it will start to reduce the position sizes whenever the margin ratio is reached.&lt;/p&gt;

&lt;h1&gt;
  
  
  Setting the Stage
&lt;/h1&gt;

&lt;blockquote&gt;
&lt;p&gt;If you consider yourself an experienced programmer, you should have no problem setting up the bot by the readme in the &lt;a href="https://github.com/perpetual-protocol/perp-maker/"&gt;perp-curie-arbitrageur&lt;/a&gt; repo.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;In the previous sections, we learned what Perp v2 is and the risks and rewards of running an arbitraging bot on the platform. This section will go through the steps to set up a bot on your computer. You can join our Discord server where we have a &lt;a href="https://discord.com/invite/M7y2VFqwCb"&gt;#coding-chat&lt;/a&gt; channel for questions you encounter when building on top of Perp v2.&lt;/p&gt;

&lt;p&gt;First, you need to download and &lt;a href="https://nodejs.org/en/download/"&gt;install Node.JS&lt;/a&gt; on your computer, which comes along with the Node Package Manager (npm) that we need.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s---MVeQhb_--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/amxtp1h5l8ypt2oogjno.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s---MVeQhb_--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/amxtp1h5l8ypt2oogjno.png" alt="Image description" width="768" height="596"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Once installed, you can type the following commands in your terminal (Terminal for macOS or Command Prompt for Windows) to check both software versions on your computer.&lt;br&gt;
&lt;code&gt;node -v&lt;br&gt;
npm -v&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;You should see similar responses on your screen, like the screenshot below. There might be some differences between your version and mine, but you'll be fine if the npm version is at least seven and Node.js is at least 16.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--JEEgck86--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/lb9ico9gf7jfo74pmh77.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--JEEgck86--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/lb9ico9gf7jfo74pmh77.png" alt="Image description" width="880" height="500"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;For Windows users, if you see an error message of "'node' is not recognized as an internal or external command," you need to modify your Environment Variables. You can search "Environment Variables" on your PC and add the location where you installed Node.js in the PATH. My installed location is at "C:\Program Files\nodejs\".&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--A8YZ_CNt--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/l6jq4zwckb00nlzw3kst.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--A8YZ_CNt--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/l6jq4zwckb00nlzw3kst.png" alt="Image description" width="880" height="839"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Then you need to install Git on your computer. You can visit &lt;a href="https://git-scm.com/book/en/v2/Getting-Started-Installing-Git"&gt;this site&lt;/a&gt; to see the install guide for each OS. For those who want to learn more about Git, you can watch &lt;a href="https://www.youtube.com/watch?v=hwP7WQkmECE"&gt;this 100 second video&lt;/a&gt; to know more about it. Once installed, type the following command in your terminal to verify it's working:&lt;br&gt;
&lt;code&gt;git - version&lt;/code&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Again, for Windows users, if you run into an error that starts with "git is not recognized as an internal or external command…", you need to edit your Environment Variables as we previously did for Node.js.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Now, we will clone the perp-curie-arbitrageur repo and build it locally. You can do so with the following commands in your terminal:&lt;br&gt;
&lt;code&gt;git clone https://github.com/perpetual-protocol/perp-curie-arbitrageur.git&lt;br&gt;
cd perp-curie-arbitrageur&lt;br&gt;
npm install&lt;br&gt;
npm run build&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;If everything goes well, you should be able to see comparable responses like the ones below:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--HYc43rvc--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/rwed5j1348wzq0skbx5g.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--HYc43rvc--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/rwed5j1348wzq0skbx5g.png" alt="Image description" width="880" height="272"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The last thing in this section is that you need to download a cryptocurrency wallet. We recommend &lt;a href="https://chrome.google.com/webstore/detail/metamask/nkbihfbeogaeaoehlefnkodbefgpgknn"&gt;MetaMask&lt;/a&gt; as it's the world's most popular browser wallet. During onboarding, you'll be asked to save 12 recovery phrases. You should &lt;strong&gt;never&lt;/strong&gt; share these with anyone under any circumstances, &lt;strong&gt;especially those who claim to be part of a customer service team&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--K-abAZOI--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/a9gd32mapn247xf89oxk.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--K-abAZOI--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/a9gd32mapn247xf89oxk.png" alt="Image description" width="880" height="520"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  Get the Tokens you Need
&lt;/h1&gt;

&lt;p&gt;There are two tokens we need in order to run perp-curie-arbitrageur. They are ETH and USDC. &lt;strong&gt;Please be aware that, since there is no test account on FTX, we'll be using real ETH and USDC in the following.&lt;/strong&gt; It's better to start with a small amount to get comfortable with it and then increase from there.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;For ETH:&lt;/li&gt;
&lt;li&gt;If you only use CEXes like Binance or FTX, you can use &lt;a href="https://www.layerswap.io/"&gt;LayerSwap&lt;/a&gt; to transfer some of your ETH to Optimism. If you have ETH on chains like Ethereum or BNB Chain, you can use &lt;a href="https://transferto.xyz/swap"&gt;TransferTo.xyz&lt;/a&gt; to bridge your ETH to Optimism. ETH is used to pay the gas fees for your transactions and each transaction on Perp v2 costs around 0.001 ETH, so even 0.1 ETH can be used for a long time.&lt;/li&gt;
&lt;li&gt;For USDC:&lt;/li&gt;
&lt;li&gt;Similar to ETH, you can use either &lt;a href="https://www.layerswap.io/"&gt;LayerSwap&lt;/a&gt; or &lt;a href="https://transferto.xyz/swap"&gt;TransferTo&lt;/a&gt; depending on how much you want to transfer and from where. And as mentioned above, USDC is used as the collateral for your positions.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Also, because by default, MetaMask doesn't include Optimism in the network list, you need to go to &lt;a href="https://chainlist.org/"&gt;Chainlist&lt;/a&gt; to add Optimism to your MetaMask to see your ETH and USDC balance in your wallet.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--0muRiJDd--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/qwvuoyxdvf90c9ey5nxo.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--0muRiJDd--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/qwvuoyxdvf90c9ey5nxo.png" alt="Image description" width="880" height="493"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  Configure the Bot: Local Variables and Strategy
&lt;/h1&gt;

&lt;p&gt;At this point, we're just a few adjustments away from running the bot locally.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1. Rename the .env.example file to .env and modify it&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;You need to rename the .env.example file in the root folder of perp-curie-arbitrageur to .env and add a web3 endpoint, your wallet's private key, and everything related to FTX to it. Here is what your .env file looks like once it's done:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--ZkqsB218--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/xac9grvp5a97dpxur8oc.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--ZkqsB218--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/xac9grvp5a97dpxur8oc.png" alt="Image description" width="880" height="251"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;For a web3 endpoint for Optimism, you can obtain it by creating a free account on &lt;a href="https://infura.io/"&gt;Infura&lt;/a&gt; or &lt;a href="https://www.alchemy.com/"&gt;Alchemy&lt;/a&gt;. If you wonder what a web3 endpoint is, it's where this bot submits your transaction. The endpoint provider, e.g. Infura, will broadcast your transaction to blockchain miners/validators upon reception, who will later validate your transaction and add it to the blockchain's latest block.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--7k7Jgmd4--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/jizrguh8gvtq70i6qwin.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--7k7Jgmd4--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/jizrguh8gvtq70i6qwin.png" alt="Image description" width="880" height="515"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;As for the private key, you can export it from your MetaMask by clicking the more button (besides your wallet address), clicking "Account details," then "Export Private Key." Similar to recovery phrases, you should never share your private key. It's recommended that you use a new MetaMask account rather than the one that you've been using for trades.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--wyn-WcgV--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/bzmr681mqs5pvg94rx6l.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--wyn-WcgV--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/bzmr681mqs5pvg94rx6l.png" alt="Image description" width="535" height="907"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;As for FTX's API key and secret, you can generate them by going to the API page of your subaccount and clicking "Create API Key". The permission should be "Trading" only.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--ZzAAieKJ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/trgco9teaq44u2xwg12t.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--ZzAAieKJ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/trgco9teaq44u2xwg12t.png" alt="Image description" width="880" height="490"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2. Modify config.json file&lt;/strong&gt;&lt;br&gt;
Next up, we need to modify the parameters in the config.json file, which sits in the configs subfolder of the src folder, to create our strategy.&lt;/p&gt;

&lt;p&gt;Here are the parameters that you need to determine and the respective description in the config file:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;PRICE_CHECK_INTERVAL_SEC: &lt;/li&gt;
&lt;li&gt;The frequency to check the price in seconds.&lt;/li&gt;
&lt;li&gt;BALANCE_CHECK_INTERVAL_SEC:&lt;/li&gt;
&lt;li&gt;The frequency to check your balance on FTX and your address.&lt;/li&gt;
&lt;li&gt;ARBITRAGE_MAX_GAS_FEE_ETH:&lt;/li&gt;
&lt;li&gt;BALANCE_MAX_GAS_FEE_ETH:&lt;/li&gt;
&lt;li&gt;The maximum amount of gas fees in ETH that you're willing to pay to do arbitrage. One thing worth pointing out is that Optimism uses the first-come, first-served approach to process transactions, meaning that increasing the ARBITRAGE_MAX_GAS_FEE_ETH will not confirm your transaction any faster.&lt;/li&gt;
&lt;li&gt;PERP_MIN_MARGIN_RATIO:&lt;/li&gt;
&lt;li&gt;FTX_MIN_MARGIN_RATIO: &lt;/li&gt;
&lt;li&gt;As we mentioned above, the margin ratio is the metric to show how many leverages you use. The lower this metric, the easier for your position to get liquidated. If you set them as 0.2, then the max leverage is 5x. Recommended to start from 1 to be safe.&lt;/li&gt;
&lt;li&gt;PERP_EMERGENCY_MARGIN_RATIO:&lt;/li&gt;
&lt;li&gt;FTX_EMERGENCY_MARGIN_RATIO:&lt;/li&gt;
&lt;li&gt;The margin ratio threshold when the positions on both platforms will start to be reduced. For instance, if you set them as 0.1 here, that means your positions will begin to be closed when your leverage reaches 10x. Recommended to begin with a number that is closer to 1 to start with.&lt;/li&gt;
&lt;li&gt;EMERGENCY_REDUCE_AMOUNT: 9000,&lt;/li&gt;
&lt;li&gt;The USD value of the position that the bot should start to close when the emergency margin ratio is reached.&lt;/li&gt;
&lt;li&gt;EMERGENCY_REDUCE_SLEEP_SEC:&lt;/li&gt;
&lt;li&gt;The interval between each emergency reduction should be.&lt;/li&gt;
&lt;li&gt;EMERGENCY_REDUCE_CHECK_INTERVAL_SEC: &lt;/li&gt;
&lt;li&gt;The frequency that emergency checks should be conducted.&lt;/li&gt;
&lt;li&gt;IS_ENABLED: &lt;/li&gt;
&lt;li&gt;Set to true to enable this market.&lt;/li&gt;
&lt;li&gt;FTX_MARKET_NAME:&lt;/li&gt;
&lt;li&gt;The name of the market on FTX. Usually, if it's a perpetual market, then it'll follow a naming convention of ticker-perp. For instance, BTC's perpetual market is known as BTC-PERP on FTX.&lt;/li&gt;
&lt;li&gt;ORDER_AMOUNT: &lt;/li&gt;
&lt;li&gt;Order amount in USDC for each trade. Remember to top up your account before running the bot.&lt;/li&gt;
&lt;li&gt;SHORT_TRIGGER_SPREAD:&lt;/li&gt;
&lt;li&gt;LONG_TRIGGER_SPREAD:&lt;/li&gt;
&lt;li&gt;The price difference threshold between both platforms at which the bot should start executing your strategy.&lt;/li&gt;
&lt;li&gt;IS_EMERGENCY_REDUCE_MODE_ENABLED:&lt;/li&gt;
&lt;li&gt;Whether (or not) the bot should reduce positions when the leverage is too high.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;We use vBTC (BTC market) and vPERP (PERP market) as the target markets in the config file by default. However, the bot can support up to 5 markets simultaneously. You can check the list of markets on Perp v2 from &lt;a href="https://app.perp.com/?utm_source=perp_devto&amp;amp;utm_medium=blog_post"&gt;the UI&lt;/a&gt; or &lt;a href="https://metadata.perp.exchange/v2/optimism.json"&gt;this JSON file&lt;/a&gt;.&lt;/p&gt;

&lt;h1&gt;
  
  
  Run Locally
&lt;/h1&gt;

&lt;p&gt;There is one extra step for Windows users - you need to add additional two lines below above the initLog() in the index.ts file otherwise it can't read the parameters in your .env file.&lt;br&gt;
&lt;code&gt;import dotenv from "dotenv";&lt;br&gt;
dotenv.config();&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;If there is any error saying dotenv isn't installed, you can run the command below in your terminal to &lt;a href="https://www.npmjs.com/package/dotenv"&gt;install dotenv&lt;/a&gt;.&lt;br&gt;
&lt;code&gt;npm install dotenv - save&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Now, we're all set! For macOS users, type the command below to run the bot locally:&lt;br&gt;
&lt;code&gt;env $(cat .env | grep -v '#' | xargs) npm run start&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;For Windows users, type the command below in your terminal:&lt;br&gt;
&lt;code&gt;npm start&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;If it runs successfully on your machine, you should be able to see similar responses on your terminal:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--EIpRDmO8--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/r8gu1rmvvvb31sp5vhmt.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--EIpRDmO8--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/r8gu1rmvvvb31sp5vhmt.png" alt="Image description" width="880" height="485"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  Run on AWS Lambda
&lt;/h1&gt;

&lt;blockquote&gt;
&lt;p&gt;If you're not familiar with AWS Lambda, you can watch &lt;a href="https://www.youtube.com/watch?v=W_VV2Fx32_Y&amp;amp;ab_channel=Fireship"&gt;this video&lt;/a&gt; to learn more about it (or serverless in general) in 100 seconds. But in general, the main selling point of AWS' Lambda is that, instead of renting a dedicated server on AWS to run your program 24/7. You only pay the times when your application runs on a shared server, which is more suitable for our use case as the bot only runs from time to time based on your settings.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;As a starter for this section, you need to register an account on AWS and install AWS CLI on your machine. Check the installation instructions for each OS here.&lt;/p&gt;

&lt;p&gt;Once AWS CLI is installed, you need to &lt;a href="https://docs.aws.amazon.com/cli/latest/userguide/getting-started-quickstart.html"&gt;configure your AWS profile&lt;/a&gt; by running the following command in your Terminal (macOS) or Command Prompt (Windows):&lt;br&gt;
&lt;code&gt;aws configure&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Then you need to type your access key and secret. You can create them from the &lt;a href="https://us-east-1.console.aws.amazon.com/iamv2/home?region=us-east-1"&gt;Identity and Access Management page&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--jySAsGzo--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/dhx7l56v42o5x2ke9bl5.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--jySAsGzo--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/dhx7l56v42o5x2ke9bl5.png" alt="Image description" width="880" height="214"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--V5hB2R0y--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/dktxz9wenxik2g862rdf.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--V5hB2R0y--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/dktxz9wenxik2g862rdf.png" alt="Image description" width="880" height="493"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Depending on your settings, sometimes you need to create a new user on AWS to generate a key. To do so, you need to click Users on the Identity and Access Management page and then create a new user with permission to manage Lambda.&lt;/p&gt;

&lt;p&gt;Following this, you need to type the AWS region you use in the .env file in your perp-maker folder. For instance, add AWS_REGION=ap-southest-1 to the file if you choose a server located in Singapore.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--XS_L2qLk--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/2bw3c4647z166m5iw2ht.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--XS_L2qLk--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/2bw3c4647z166m5iw2ht.png" alt="Image description" width="880" height="490"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Also, for Windows users who have run the bot locally in the previous sections, you need to remove the two lines that you added in the index.ts file.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;import dotenv from "dotenv";&lt;br&gt;
dotenv.config();&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;By now we're all set! Enter the following commands in your terminal to deploy the bot to AWS:&lt;br&gt;
&lt;code&gt;npm run build&lt;br&gt;
npm run sls:deploy&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;You should be able to see the following responses if everything goes well:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--LfcyYef2--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/oo5icrlntr79e9yevt1p.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--LfcyYef2--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/oo5icrlntr79e9yevt1p.png" alt="Image description" width="880" height="349"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Once your bot is running, you can see the real-time logs by going to the perp-arbitrageur-production-main Lambda function on AWS and clicking the "View logs in CloudWatch" under the Monitor tab. You can be able to see similar logs as you saw when the bot ran on your computer.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--cD40oSTR--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/pw21w8c2790u1lk4fnmy.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--cD40oSTR--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/pw21w8c2790u1lk4fnmy.png" alt="Image description" width="880" height="512"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Congratulations! Your bot is now automatically arbitraging the price difference between Perp v2 and FTX!&lt;/p&gt;

&lt;h1&gt;
  
  
  Further modification suggestions
&lt;/h1&gt;

&lt;p&gt;As mentioned at the beginning of this article, this bot is just a template for arbitraging between Perp v2 and FTX. Given the nature of an open-sourced software, anyone can add functionalities to this bot. Below are some directions that you can explore:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Support more DEXes and CEXes&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;You can modify the bot to support CEXs like Binance or Huobi to discover more arbitraging opportunities. It also applies to derivative DEXs as there are numerous of them on the market.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Better position wind down process&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;Currently, the bot will close positions from both exchanges when the margin ratio reaches the limit you set. A better approach to wind down positions would be closing both sides when the prices on both exchanges are the same and do it gradually to reduce price impact aka slippage per trade.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Error or success report &lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;Right now the bot only does its jobs quietly and you can only check CloudWatch to know its status. One way to improve this is to add a script to send out a Telegram or Discord message when certain criteria are met. For instance, you can write a script to send out Telegram messages when a trade is successful.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;That's the end of our tutorial on how to run &lt;a href="https://github.com/perpetual-protocol/perp-curie-arbitrageur"&gt;perp-curie-arbitrageur&lt;/a&gt;!&lt;/p&gt;

&lt;p&gt;Besides this tutorial, recently we also have released &lt;a href="https://dev.to/perpprotocol/running-perp-maker-for-profits-and-fun-part-1-5597"&gt;tutorials&lt;/a&gt; on how to run &lt;a href="https://github.com/perpetual-protocol/perp-maker"&gt;perp-maker&lt;/a&gt;! Feel free to check it out.&lt;br&gt;
One last thing - we have a &lt;a href="https://discord.com/invite/M7y2VFqwCb"&gt;#coding-chat channel&lt;/a&gt; on our Discord for questions you encounter when building on top of Perp v2. Feel free to join and say hi.&lt;/p&gt;

&lt;h1&gt;
  
  
  Helpful Resources
&lt;/h1&gt;

&lt;ul&gt;
&lt;li&gt;A third-party site to track your fees and APR: &lt;a href="https://www.seedle.finance"&gt;https://www.seedle.finance/&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Maker simulator for Perp v2: &lt;a href="https://defi-lab.xyz/perpetualsimulator"&gt;https://defi-lab.xyz/perpetualsimulator&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;API for Perp v2: &lt;a href="https://thegraph.com/hosted-service/subgraph/perpetual-protocol/perpetual-v2-optimism?query=Get%20Trader"&gt;https://thegraph.com/hosted-service/subgraph/perpetual-protocol/perpetual-v2-optimism?query=Get%20Trader&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Contract addresses on Perp v2: &lt;a href="https://metadata.perp.exchange/v2/optimism.json"&gt;https://metadata.perp.exchange/v2/optimism.json&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Perp v2 documentation: &lt;a href="https://v2docs.perp.fi/"&gt;https://v2docs.perp.fi/&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>beginners</category>
      <category>tutorial</category>
      <category>web3</category>
      <category>aws</category>
    </item>
    <item>
      <title>Running Perp-maker for Profits &amp; Fun: Part 2</title>
      <dc:creator>Perpetual Protocol (✨🔴_🔴✨)</dc:creator>
      <pubDate>Wed, 08 Jun 2022 13:46:15 +0000</pubDate>
      <link>https://dev.to/perpprotocol/running-perp-maker-for-profits-and-fun-part-2-12jj</link>
      <guid>https://dev.to/perpprotocol/running-perp-maker-for-profits-and-fun-part-2-12jj</guid>
      <description>&lt;p&gt;This is the second article in our two-part series on how to run perp-maker, a market-making template for &lt;a href="https://perp.com/?utm_source=perp_devto&amp;amp;utm_medium=blog_post"&gt;Perpetual Protocol v2&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;In &lt;a href="https://dev.to/perpprotocol/running-perp-maker-for-profits-and-fun-part-1-5597"&gt;part one&lt;/a&gt;, we covered the basics of Perpetual Protocol, the risks and rewards of running the bot, and how to run it locally. It's recommended to go through &lt;a href="https://dev.to/perpprotocol/running-perp-maker-for-profits-and-fun-part-1-5597"&gt;part one&lt;/a&gt; before reading part two.&lt;/p&gt;

&lt;p&gt;In the following, we'll guide you through how to run the bot on AWS Lambda with npm, preparation to go mainnet, as well as further modification suggestions. If you're an experienced engineer, you should have no problem setting up the bot via the readme on &lt;a href="https://github.com/perpetual-protocol/perp-maker"&gt;our repo&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Let's get started!&lt;/p&gt;

&lt;h1&gt;
  
  
  Run on AWS Lambda with npm
&lt;/h1&gt;

&lt;p&gt;If you've gone through the steps in part one, you should be able to run perp-maker locally. Now, let's try to deploy it to AWS Lambda.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;If you're not familiar with it, the main selling point of AWS Lambda is that, instead of renting a dedicated server on AWS to run your program 24/7. You only pay the times when your application runs on a shared server, which is more suitable for our use case as the bot only runs from time to time based on your settings. You can watch &lt;a href="https://www.youtube.com/watch?v=W_VV2Fx32_Y&amp;amp;ab_channel=Fireship"&gt;this video to learn more about AWS Lambda (or serverless in general) in 100 seconds&lt;/a&gt;.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;As the first step, you need to register an account on AWS and install AWS CLI on your machine. Check the installation instructions for each OS &lt;a href="https://docs.aws.amazon.com/cli/latest/userguide/getting-started-install.html"&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Once AWS CLI is installed, you need to &lt;a href="https://docs.aws.amazon.com/cli/latest/userguide/getting-started-quickstart.html"&gt;configure your AWS profile&lt;/a&gt; by running the following command in your Terminal (macOS) or Command Prompt (Windows):&lt;/p&gt;

&lt;p&gt;&lt;code&gt;aws configure&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Then you need to type your access key and secret. You can create them from the &lt;a href="https://us-east-1.console.aws.amazon.com/iamv2/home?region=us-east-1"&gt;Identity and Access Management page&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--MYs5CVDb--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/1kiiprjbmve25axidy8q.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--MYs5CVDb--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/1kiiprjbmve25axidy8q.png" alt="Image description" width="800" height="194"&gt;&lt;/a&gt;&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Lmmap0Ce--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ju7a0mp4m84qei8hammc.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Lmmap0Ce--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ju7a0mp4m84qei8hammc.png" alt="Image description" width="800" height="448"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Depending on your settings, sometimes you need to create a new user on AWS to generate a key. To do so, you need to click Users on the Identity and Access Management page and then create a new user with permission to manage Lambda.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;Following this, you need to type the AWS region you use in the .env file in your perp-maker folder.&lt;/strong&gt; For instance, add AWS_REGION=ap-southest-1 to the file if you choose a server located in Singapore.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--2eGtjhuJ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/l0f0b6jfl7a1aw8s4w2p.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--2eGtjhuJ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/l0f0b6jfl7a1aw8s4w2p.png" alt="Image description" width="800" height="445"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;For other variables in the .env file, please check part 1 of this series or &lt;a href="https://github.com/perpetual-protocol/perp-maker"&gt;perp-maker repo&lt;/a&gt; to learn more.&lt;br&gt;
Additionally, for Windows users who have run it locally per &lt;a href="https://dev.to/perpprotocol/running-perp-maker-for-profits-and-fun-part-1-5597"&gt;part one&lt;/a&gt;'s instructions, you need to remove the two lines you added in the index.ts file.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;import dotenv from "dotenv";&lt;br&gt;
dotenv.config();&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;By now we're all set! Enter the following commands in your terminal to deploy the bot to AWS:&lt;br&gt;
&lt;code&gt;npm run build&lt;br&gt;
npm run sls:deploy&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;You should be able to see the following responses if everything goes well:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--EcdhnmDQ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/eh0cdkre66icmk4j51q0.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--EcdhnmDQ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/eh0cdkre66icmk4j51q0.png" alt="Image description" width="800" height="361"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Once your bot is running, you can see the real-time logs by going to the perp-maker-main Lambda function on AWS and clicking the "View logs in CloudWatch" under the Monitor tab.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--cmbc5Ap9--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/hv1gqjshujp3ssk5s0mp.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--cmbc5Ap9--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/hv1gqjshujp3ssk5s0mp.png" alt="Image description" width="800" height="462"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Another way to validate if the template runs successfully is to check the target markets in the pool section on the UI. For testnet (Optimism Kovan), please visit &lt;a href="https://testnet.perp.exchange/"&gt;testnet.perp.exchange&lt;/a&gt;; As for mainnet (Optimism), visit &lt;a href="https://perp.com/?utm_source=perp_devto&amp;amp;utm_medium=blog_post"&gt;app.perp.com&lt;/a&gt;.&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--YwybkIVb--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/xk8809gst565r8s1l2ff.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--YwybkIVb--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/xk8809gst565r8s1l2ff.png" alt="Image description" width="800" height="446"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  Prepare for Mainnet
&lt;/h1&gt;

&lt;p&gt;Ready for mainnet? Here's a checklist:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;You need to get some USDC on Optimism. You can use &lt;a href="https://transferto.xyz/swap"&gt;TransferTo.xyz&lt;/a&gt; to bridge your USDC from another chain to Optimism. If you only have USDC on a centralized exchange like Binance or FTX and you only want to test a small amount out, you can use &lt;a href="https://www.layerswap.io/"&gt;LayerSwap&lt;/a&gt; to transfer directly to Optimism; as for greater amounts like over 5,000 USDC, you can withdraw to BNB Chain or Avalanche's C-chain and then use TransferTo to go to Optimism (requires a small amount of BNB or AVAX to pay for gas).&lt;/li&gt;
&lt;li&gt;You need to get ETH on Optimism to pay for the gas fees. Much like USDC, you can use &lt;a href="https://transferto.xyz/swap"&gt;TransferTo&lt;/a&gt; or &lt;a href="https://www.layerswap.io/"&gt;LayerSwap&lt;/a&gt; (for CEX) depending on how much USDC or ETH you want to transfer. In general, each transaction on Perp v2 costs around 0.0001 ETH, so even 0.1 ETH can be used for a long time.&lt;/li&gt;
&lt;li&gt;You need to change the endpoint in the .env file to the mainnet one.&lt;/li&gt;
&lt;li&gt;You need to uncomment the two lines for process.env in the index.ts file that we added in &lt;a href="https://dev.to/perpprotocol/running-perp-maker-for-profits-and-fun-part-1-5597"&gt;part one&lt;/a&gt; (// process.env["STAGE"] = "production" and // process.env["NETWORK"] = "optimism").&lt;/li&gt;
&lt;/ul&gt;

&lt;h1&gt;
  
  
  Further Modification Suggestions
&lt;/h1&gt;

&lt;p&gt;As mentioned at the beginning of this article, this bot is just a template to market-make on Perp v2. Given the nature of an open-sourced software, anyone can add functionalities to this bot. Here are some directions that you can explore:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Provide single-sided liquidity&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;Currently, the bot only supports a fixed range above and below the market price. Another way to market-make on Perp v2 is to only provide liquidity for a single side, i.e., only above or below the current market price. One major benefit of providing single-sided liquidity is that when the price moves in the range and then subsequently moves out of the range, the maker can collect fees without any impermanent loss. You can already provide single-sided liquidity on &lt;a href="https://app.perp.com/?utm_source=perp_devto&amp;amp;utm_medium=blog_post"&gt;the UI&lt;/a&gt; with the simple mode, or "Easy LP" as we call it.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Close the newly created position gradually&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;With the current design, the bot will adjust your liquidity when the price is out of the LIQUIDITY_ADJUST_THRESHOLD. When doing that, it'll realize the impermanent loss by closing 100% of your taker position. This approach should be fine for small positions. However, if your position size is quite large, it's better to close your position gradually to reduce the slippage incurred in each trade.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Utilize the multi-collateral feature&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;One of the selling points of Perp v2 is &lt;a href="https://blog.perp.fi/introducing-multi-collateral-on-perpetual-protocol-fe1f4fa6fb90"&gt;multi-collateral support&lt;/a&gt;, meaning that users can deposit ETH, USDC, FRAX, (and more in the future) as the collateral for their positions. The current template only supports USDC as the collateral. One major benefit of using ETH as the collateral is that your collateral value will increase as the price of ETH increases, which is handy if you're providing liquidity to the ETH market as you're acting as the short side during the bull market. In other words, in net USD terms, you're collecting transaction fees without liquidation risk.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;That's the end of our two-part series on how to run &lt;a href="https://github.com/perpetual-protocol/perp-maker"&gt;perp-maker&lt;/a&gt;!&lt;/p&gt;

&lt;p&gt;We'll release another tutorial on how to run &lt;a href="https://github.com/perpetual-protocol/perp-curie-arbitrageur"&gt;perp-curie-arbitrageur&lt;/a&gt; very soon! In the meantime, feel free to join our Discord where we have a &lt;a href="https://discord.com/invite/M7y2VFqwCb"&gt;#coding-chat channel&lt;/a&gt; for questions you encounter when building on top of Perp v2.&lt;/p&gt;

&lt;h1&gt;
  
  
  Helpful Resources
&lt;/h1&gt;

&lt;ul&gt;
&lt;li&gt;A third-party site to track your fees and APR: &lt;a href="https://www.seedle.finance/"&gt;https://www.seedle.finance/&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Maker simulator for Perp v2: &lt;a href="https://defi-lab.xyz/perpetualsimulator"&gt;https://defi-lab.xyz/perpetualsimulator&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;API for Perp v2: &lt;a href="https://thegraph.com/hosted-service/subgraph/perpetual-protocol/perpetual-v2-optimism?query=Get%20Trader"&gt;https://thegraph.com/hosted-service/subgraph/perpetual-protocol/perpetual-v2-optimism?query=Get%20Trader&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Contract addresses on Perp v2: &lt;a href="https://metadata.perp.exchange/v2/optimism.json"&gt;https://metadata.perp.exchange/v2/optimism.json&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Perp v2 documentation: &lt;a href="https://v2docs.perp.fi/"&gt;https://v2docs.perp.fi/&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>web3</category>
      <category>typescript</category>
      <category>tutorial</category>
      <category>aws</category>
    </item>
    <item>
      <title>Running Perp-maker for Profits &amp; Fun: Part 1</title>
      <dc:creator>Perpetual Protocol (✨🔴_🔴✨)</dc:creator>
      <pubDate>Fri, 03 Jun 2022 13:41:35 +0000</pubDate>
      <link>https://dev.to/perpprotocol/running-perp-maker-for-profits-and-fun-part-1-5597</link>
      <guid>https://dev.to/perpprotocol/running-perp-maker-for-profits-and-fun-part-1-5597</guid>
      <description>&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--GNfgZjd7--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/tbiuowyuaofzev3n53wv.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--GNfgZjd7--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/tbiuowyuaofzev3n53wv.png" alt="Image description" width="880" height="467"&gt;&lt;/a&gt;&lt;br&gt;
&lt;a href="https://github.com/perpetual-protocol/perp-maker"&gt;Perp-maker&lt;/a&gt; is an open-source market-making template for &lt;a href="https://app.perp.com/?utm_source=devto&amp;amp;utm_medium=blog_post"&gt;Perpetual Protocol v2&lt;/a&gt;, the most popular dApp on &lt;a href="https://optimism.io/"&gt;Optimism&lt;/a&gt; (a layer-2 scaling solution for Ethereum). Anyone can use or modify the template to facilitate trades on the protocol and earn fees. &lt;/p&gt;

&lt;p&gt;In this tutorial, we’ll go over what Perpetual Protocol is, the risks and rewards associated with running the bot, and how to run it locally. Due to the length of this article, we’ll cover how to run the bot on AWS and further modification suggestions in part 2. Stay tuned!&lt;/p&gt;
&lt;h2&gt;
  
  
  Perpetual Protocol 101
&lt;/h2&gt;

&lt;p&gt;First thing first, what is Perpetual Protocol?&lt;/p&gt;

&lt;p&gt;Perpetual Protocol is a decentralized derivative exchange (DEX) where traders can use USDC (a USD-pegged stablecoin) to speculate on cryptocurrency’s price movement with up to 10x leverage. At the time of writing, the DEX supports 17 markets, including BTC, ETH, ATOM, BNB, and more! You can learn how it works in detail by watching this &lt;a href="https://www.youtube.com/watch?v=pBoKtkoNZEY"&gt;10-minute video&lt;/a&gt; or reading &lt;a href="https://cryptotesters.com/blog/perp-protocol"&gt;this article&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--SMIg3vrW--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/8mtnqgtmd8fj3dko0wt4.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--SMIg3vrW--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/8mtnqgtmd8fj3dko0wt4.png" alt="Image description" width="880" height="517"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;But what does “market-making” mean?&lt;br&gt;
Whenever a trade happens, there will always be two sides involved - a taker and a maker. &lt;strong&gt;The takers initiate a trade, and the makers provide the inventory to let the taker take.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Here is a real-life example. When buying a fish from a vendor, you’re the taker of this trade as you’re the one that takes what the vendor supplies. As for the vendor, he is the maker of this trade as he prepares the inventory (fish in this example) that makes this trade possible. &lt;/p&gt;

&lt;p&gt;Similarly, &lt;strong&gt;being a market-maker, or “maker,” on Perp v2 means you &lt;a href="https://blog.perp.fi/how-to-provide-liquidity-on-perp-v2-9064ed085d7f"&gt;provide the liquidity&lt;/a&gt; (the assets) that traders can take, making the market viable. In return, you receive 80% of the transaction fees paid by the trader.&lt;/strong&gt; For instance, if a trader opens a long position and this trade happens in the price range you set, you act as the other side of the trade - i.e., opening a short position as a result, and vice versa. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Makers on Perp v2 can choose the price range to which they provide liquidity.&lt;/strong&gt; For instance, in the screenshot below, this user wants to provide liquidity to the BTC market with a price range of $9,991.99 to $60,081. &lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--8jCFeN7B--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/qj5oep0xh8bzwxq8bmsr.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--8jCFeN7B--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/qj5oep0xh8bzwxq8bmsr.png" alt="Image description" width="880" height="519"&gt;&lt;/a&gt;&lt;br&gt;
Whenever a trade happens in that range, this user collects 80% of the transaction fees proportionately. One thing worth pointing out is that USDC is the only asset you need to deposit to start market-making on Perp v2. Once you deposit some USDC, the system will mint the virtual tokens (0.1 vBTC and 4316.31 vUSD in the screenshot) you need to trade or market-make with. &lt;/p&gt;
&lt;h2&gt;
  
  
  Risks and Rewards of Running Perp-maker
&lt;/h2&gt;

&lt;p&gt;With perp-maker, anyone can automate their market-making strategy on Perp v2 to earn transaction fees and liquidity mining rewards (more on this later).&lt;/p&gt;

&lt;p&gt;Out of the box, &lt;strong&gt;perp-maker lets you choose which market you want to provide liquidity to and within what price range.&lt;/strong&gt; As a reminder, if the market price moves out of the range you set, you will not collect any transaction fees until it moves back in the range. &lt;strong&gt;Perp-maker can automatically adjust your liquidity and realize the impermanent loss when the market price reaches the price level you set.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;But what is impermanent loss?&lt;br&gt;
&lt;strong&gt;On Perp v2, makers act as the other side of each trade. If a trader makes a profit, a maker loses money. This loss is impermanent as it will become 0 when the market price returns to the initial price.&lt;/strong&gt; Even if the market price moves away from the initial price, you can collect fees if the market price stays in the price range.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--qCsQH0eI--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/71lo6olyag8yyrz7r4k5.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--qCsQH0eI--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/71lo6olyag8yyrz7r4k5.png" alt="Image description" width="880" height="467"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;As a rule of thumb, the wider the price range you set, the less impermanent loss you suffer; however, the less transaction fees you can collect. And the more transaction fees generated on a market, the better for you as a maker. You can use the Perpetual Simulator to simulate different price ranges in any given market to gauge the profitability of your strategy.&lt;/p&gt;

&lt;p&gt;Additionally, the developers behind the protocol provide its token, known as $PERP, as an extra reward to encourage more people to be makers. This reward is distributed weekly proportional to the transactions fees you collect for that market in that week. This weekly reward is known as liquidity mining rewards.&lt;/p&gt;

&lt;p&gt;To recap - if the transaction fees plus liquidity mining rewards outweigh the impermanent loss, it’s a profitable strategy. If not, it can still be a profitable strategy in a more extended timeframe as it takes time for the value of the fees and liquidity mining rewards to catch up with the impermanent loss.&lt;/p&gt;
&lt;h2&gt;
  
  
  Setting the Stage
&lt;/h2&gt;

&lt;blockquote&gt;
&lt;p&gt;If you consider yourself an experienced programmer, you should have no problem setting up the bot using the readme in the &lt;a href="https://github.com/perpetual-protocol/perp-maker"&gt;perp-maker repo&lt;/a&gt;. &lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;In the previous sections, we learned how Perp v2 works and the risks and rewards of being a maker on the platform. This section will go through the steps to set up a perp-maker on your computer. You can join our Discord server where we have a &lt;a href="https://discord.com/invite/M7y2VFqwCb"&gt;#coding-chat channel&lt;/a&gt; for questions you encounter when building on top of Perp v2.&lt;/p&gt;

&lt;p&gt;First, you need to download and install Node.JS on your computer, which comes along with the Node Package Manager (npm) that we need. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--zTEoEynL--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/jxg5xtgeufx36efhk64h.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--zTEoEynL--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/jxg5xtgeufx36efhk64h.png" alt="Image description" width="768" height="596"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Once installed, you can type the following commands in your terminal (Terminal for macOS or Command Prompt for Windows) to check both software versions on your computer.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;node -v&lt;br&gt;
npm -v&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;You should see similar responses on your screen, like the screenshot below. There might be some differences between your version and mine, but you’ll be fine if the npm version is at least seven and Node.js is at least 16.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--1yf41IAG--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/1uht1lj89j4g4731wxin.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--1yf41IAG--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/1uht1lj89j4g4731wxin.png" alt="Image description" width="880" height="500"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;For Windows users, if you see an error message of “‘node’ is not recognized as an internal or external command,” you need to modify your Environment Variables. You can search “Environment Variables” on your PC and add the location where you installed Node.js in the PATH. My installed location is at “C:\Program Files\nodejs\”. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--HvRD62_p--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ura7g6ctkn4bstjr47x3.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--HvRD62_p--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ura7g6ctkn4bstjr47x3.png" alt="Image description" width="880" height="839"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Then you need to install Git on your computer. You can visit this site to see the install guide for each OS. For those who want to learn more about Git, you can watch this 100 second video to know more about it. Once installed, type the following command in your terminal to verify it’s working:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;git --version&lt;br&gt;
&lt;/code&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Again, for Windows users, if you run into an error that starts with “git is not recognized as an internal or external command…”, you need to edit your Environment Variables as we previously did for Node.js.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Now, we will clone the perp-maker repo and build it locally. You can do it with the following commands in your terminal:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git clone https://github.com/perpetual-protocol/perp-maker.git
cd perp-maker
npm i
npm run build
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If everything works properly, you should see something on your terminal that’s similar to what’s displayed below:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--1v7esAmN--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/u1nclobdh6wdx3yzviz3.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--1v7esAmN--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/u1nclobdh6wdx3yzviz3.png" alt="Image description" width="880" height="318"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The last thing in this section is that you need to download a cryptocurrency wallet. We recommend &lt;a href="https://chrome.google.com/webstore/detail/metamask/nkbihfbeogaeaoehlefnkodbefgpgknn"&gt;MetaMask&lt;/a&gt; as it’s the world’s most popular browser wallet. During onboarding, you’ll be asked to save 12 recovery phrases. You should &lt;strong&gt;never&lt;/strong&gt; share these with anyone under any circumstances. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--hCd5n9C8--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/l33f5ut7bun1gqsmg9ps.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--hCd5n9C8--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/l33f5ut7bun1gqsmg9ps.png" alt="Image description" width="880" height="520"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Configure the Bot: Local Variables and Strategy
&lt;/h2&gt;

&lt;p&gt;At this point, we’re just a few adjustments away from running the bot locally. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1. Modify .env file&lt;/strong&gt;&lt;br&gt;
You need to add a web3 endpoint and your wallet’s private key to the .env file in your perp-maker folder. Here is what it looks like once it’s done:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--VARSsZmr--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/tpl5jkaqsw51edeyg7c2.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--VARSsZmr--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/tpl5jkaqsw51edeyg7c2.png" alt="Image description" width="880" height="559"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;For a web3 endpoint, you can obtain it by creating a free account on &lt;a href="https://infura.io/"&gt;Infura&lt;/a&gt; or &lt;a href="https://www.alchemy.com/"&gt;Alchemy&lt;/a&gt;. For testing purposes, you should get an endpoint for “Optimism Kovan”, not “Optimism Mainnet” or “Kovan”. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--FHPdUc1r--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/i8vuf9o39rbz1lykh6od.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--FHPdUc1r--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/i8vuf9o39rbz1lykh6od.png" alt="Image description" width="880" height="515"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;If you're wondering what a web3 endpoint is, it’s where this bot submits your transaction. The endpoint provider e.g. Infura will broadcast your transaction to blockchain miners/validators upon reception, who will later validate your transaction and add it to the blockchain's latest block.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;As for the private key, you can export it from your MetaMask by clicking the more button (besides your wallet address), clicking “Account details,” then “Export Private Key.” Similar to recovery phrases, you should never share your private key. It’s recommended that you use a new MetaMask account rather than the one that you’ve been using for trades.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--tHQqp4c8--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/1fivmfdtk8bfh5238qen.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--tHQqp4c8--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/1fivmfdtk8bfh5238qen.png" alt="Image description" width="535" height="907"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2. Modify config.json file&lt;/strong&gt;&lt;br&gt;
Next up, we need to modify the parameters in the config.json file, which sits in the configs subfolder of the src folder, to create our strategy.&lt;/p&gt;

&lt;p&gt;Here are the parameters that you need to determine and the respective description in the config file:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;PRICE_CHECK_INTERVAL_SEC: 
The frequency to check the price in seconds.
ADJUST_MAX_GAS_PRICE_GWEI: 
The maximum gas fee in Gwei which the bot will adjust liquidity. If the gas price exceeds this number, the liquidity won't be adjusted. Currently, the gas price on Optimism is fixed at 0.001 Gwei.
IS_ENABLED: 
Set to `true` to enable this market.
LIQUIDITY_AMOUNT: 
How much vUSD (after leverage) to provide as liquidity. Perp v2 supports up to 10x leverage, meaning that you can use up to 10x of your deposited USDC to provide liquidity.  
LIQUIDITY_RANGE_OFFSET: 
The offset to upper price and lower price of the liquidity range. For example, if it’s set to 0.05, it will provide liquidity from (current price / 1.05) to (current price * 1.05).
LIQUIDITY_ADJUST_THRESHOLD:
The threshold that the bot will remove your existing liquidity, realize the impermanent loss, and place a new price range. For example, if it’s set to 0.01, the bot will remove your existing liquidity when the current price goes out of the range below (initial price/ 1.01) or above (the initial price* 1.01), and subsequently provides liquidity with a new price range based on LIQUIDITY_RANGE_OFFSET and the current price.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We use vBTC (BTC market) and vPERP (PERP market) as the target markets in the config file by default. You can check the list of markets on Perp v2 from &lt;a href="https://app.perp.com/?utm_source=devto&amp;amp;utm_medium=blog_post"&gt;the UI&lt;/a&gt; or this JSON file.&lt;/p&gt;

&lt;h2&gt;
  
  
  Run Locally on Optimism Kovan (Testnet)
&lt;/h2&gt;

&lt;p&gt;You need to get some test tokens before running the bot on Optimism testnet. Head to &lt;a href="https://kovan.optifaucet.com/"&gt;Optifaucet&lt;/a&gt;, type in your wallet address (which starts with 0x) and send out the request. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--iYrPwFLh--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/aabxax1i9bd6bng3cfjs.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--iYrPwFLh--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/aabxax1i9bd6bng3cfjs.png" alt="Image description" width="880" height="513"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;If you run out of the test ETH to pay for transactions, you can go to Paradigm’s &lt;a href="https://faucet.paradigm.xyz/"&gt;faucet&lt;/a&gt; to request more test ETH and then bridge them to Optimism Kovan via &lt;a href="https://app.optimism.io/bridge"&gt;Optimism Bridge&lt;/a&gt;.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;We’re almost ready! The bot by default is set to run on Optimism. To run on Optimism Kovan, you need to add an endpoint for the testnet (as demonstrated above) and comments (add two “slashes” before the codes) the two lines below in the index.ts file which is located in the src folder.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// process.env["STAGE"] = "production"
// process.env["NETWORK"] = "optimism"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;For Windows users, you need to add additional two lines below above the initLog() in the index.ts file.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import dotenv from "dotenv";
dotenv.config();
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If there is any error saying dotenv isn’t installed, you can run the command below in your terminal to install dotenv.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;npm install dotenv --save&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Now, we’re all set! For macOS users, type the command below to run the bot locally:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;env $(cat .env | grep -v '#' | xargs) npm run start&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;For Windows users, type the command below in your terminal to do it:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;npm start&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;If it runs successfully, you should be able to see similar responses on your terminal:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--manVM1-n--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/11f60ana69mi7wceqdug.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--manVM1-n--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/11f60ana69mi7wceqdug.png" alt="Image description" width="880" height="239"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Another way to validate if the template runs successfully is to check the target markets in the pool section on the UI. For testnet (Optimism Kovan), please visit &lt;a href="https://testnet.perp.exchange/"&gt;testnet.perp.exchange&lt;/a&gt;; As for mainnet (Optimism), visit &lt;a href="https://app.perp.com/?utm_source=devto&amp;amp;utm_medium=blog_post"&gt;app.perp.com&lt;/a&gt;. &lt;/p&gt;

&lt;p&gt;Alright! That’s all we have for today. Hope you have fun, or at least learned something in our journey. Stay tuned for part two! In the meantime, feel free to join our Discord server where we have a &lt;a href="https://discord.com/invite/M7y2VFqwCb"&gt;#coding-chat channel&lt;/a&gt; dedicated to technical questions.&lt;/p&gt;

&lt;h2&gt;
  
  
  Helpful Resources
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;A third-party site to track your fees and APR: &lt;a href="https://www.seedle.finance/"&gt;https://www.seedle.finance/&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Maker simulator for Perp v2: &lt;a href="https://defi-lab.xyz/perpetualsimulator"&gt;https://defi-lab.xyz/perpetualsimulator&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;API for Perp v2: &lt;a href="https://thegraph.com/hosted-service/subgraph/perpetual-protocol/perpetual-v2-optimism?query=Get%20Trader"&gt;https://thegraph.com/hosted-service/subgraph/perpetual-protocol/perpetual-v2-optimism?query=Get%20Trader&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Contract addresses on Perp v2: &lt;a href="https://metadata.perp.exchange/v2/optimism.json"&gt;https://metadata.perp.exchange/v2/optimism.json&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Perp v2 documentation: &lt;a href="https://v2docs.perp.fi/"&gt;https://v2docs.perp.fi/&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>web3</category>
      <category>typescript</category>
      <category>javascript</category>
      <category>aws</category>
    </item>
  </channel>
</rss>
