Detailed Perp arbitrage robot: help you execute automated trading strategies
星球君的朋友们
2021-03-03 08:04
本文约2796字,阅读全文需要约11分钟
Perp-Arbitrageur is an arbitrage bot that can run on the AWS Lambda cloud (in the free tier) or locally on your computer.

Editor's Note: This article comes fromPerpetual Protocol (ID: Perpetual_China), reprinted by Odaily with authorization.

, reprinted by Odaily with authorization.

In this article, you'll learn more about our just-launched Perp Arbitrageur Bot, and start trading like a pro!

NOTE: This bot is for educational purposes only. Derivatives trading is extremely risky and can cause you to lose up to 100% of your capital. Perpetual contract transactions may be subject to different regulations in different regions. Be sure to understand local laws before trading.

GitHub:https://github.com/perpetual-protocol/perp-arbitrageur

Perp-Arbitrageur

secondary title

Since the perpetual protocol runs on the xDai sidechain, you don't need to pay gas fees on Ethereum when using this bot! (The gas fee on xDai is very low)

secondary title

Trading straregy

The default strategy is simply to "sell high & buy low" on the same perpetual contract between two different exchanges to make a profit. You can visit docs.perp.fi to learn more about perp contracts.

More specifically, it is "buy low on exchange A & sell high on exchange B". We earn the spread by trading on both exchanges, and more importantly, hedge the market risk. In this way, no matter whether the price in the market rises or falls, PnL will not be affected.

Scenario #1 - Market Price Up

image description

Blue line: ETH-PERP price of FTX, yellow line: ETH-PERP price of perpetual contract

According to the picture above, the bot will open a position when the spread is greater than the trigger level. When the spread is small, the bot will open a position in the opposite direction to effectively close the position.

Scenario 2 - Market Price Down

image description

Blue line: ETH-PERP price of FTX, yellow line: ETH-PERP price of perpetual contract

As shown in the figure above, when the price difference is greater than the level we set, the bot will open a trade, and when the price difference is lower than the trigger point we set for effective liquidation, the bot will reverse the position to effectively close warehouse.

In both cases, PnL is practically unaffected whether the market goes up or down because we are looking at the spread, not the market price. In this way, you don't have to worry about wild price fluctuations, but can use the price difference between the two exchanges to complete arbitrage.

secondary title

Account Settings & Parameter Definition

You just need to add the following before starting the bot:

account settings

In the ".env.production" file,

1. Wallet private key: It must be the private key of the Ethereum wallet, in which the funds you intend to trade on the perpetual agreement are deposited. The private key must start with "0x" (zero-ex).

Note: The asset used on the perpetual agreement is USDC. You must move USDC to xDai before trading. You can do it with perp.exchange.

2. FTX API Key & Secret: You can create an FTX API key on FTX's profile page. You can choose to create a FTX sub-account to use with the bot.

parameter settings

In the "configs.ts" file, you may need to change these parameters according to your trading knowledge and your own risk tolerance. We will briefly explain some parameters here.

  • Balance & Margin Check

  • XDAI_BALANCE_THRESHOLD: Gas on xDai is paid in xDAI. See "Deposits" section.

  • USDC_BALANCE_THRESHOLD: minimum USDC balance in wallet

  • FTX_USD_BALANCE_THRESHOLD: minimum USD balance on FTX

These events will be displayed in the log if the condition is triggered.

market parameters

market parameters

  • There are many parameters under "ammConfigMap",

  • BTC-USDC//This is the market you want to trade in PERP.

  • ENABLED: false //This is a switch, "true" enables it, "false" disables it.

  • ASSET_CAP: Big(1000)//The amount limit after leverage

  • PERPFI_LEVERAGE: Big(3)//The leverage of the robot to trade when opening a position, it will maintain this leverage level on the PEPR exchange (if the balance is sufficient).

  • PERPFI_SHORT_ENTRY_TRIGGER: Big(0.5).div(100),

  • PERPFI_MIN_TRADE_NOTIONAL: Big(10)//The minimum notional amount traded on the PERP exchange.

  • PERPFI_LONG_ENTRY_TRIGGER: Big(-0.5).div(100), the number is the spread ratio: (PERP-FTX)/FTX. In other words, for example, when the spread ratio is greater than 0.5, the robot will open a short position on PERP. At the same time, it will open a long position on FTX.ADJUST_MARGIN_RATIO_THRESHOLD: Big(10).div(100) // As an example here, the bot will be at > 5.5 or

  • Adjust leverage when <4.5.

  • FTX_MARKET_ID: "BTC-PERP"// Market ticker for FTX.

deposit and operation

deposit assets

  • deposit assets

  • Deposit USDC to perp.exchange for trading

Deposit USDC or other applicable stablecoins on FTX

  • Deposit to GAS

  • Deposit xDAI in your wallet to pay the gas fee on the xDai chain. The xDai chain and Ethereum use the same address, so the same address can own Ethereum tokens and xDai tokens on both chains at the same time.

  • xDai Metamask installation setup (https://www.xdaichain.com/for-users/wallets/metamask/metamask-setup)

  • Use xDai Bridge to convert Dai to xDAI (https://dai-bridge.poa.network/)

If you need some xDAI as GAS to complete the transaction, you can use the faucet to get some (https://blockscout.com/poa/xdai/faucet)

Now, your bot can help you trade on the xDai chain.

Note: As more trades are executed, the balance difference between the two exchange accounts may become larger. Therefore, you may need to rebalance occasionally.

Practical

When you understand the concepts, setting parameters, and how to deposit assets in your wallet and account, it's time to get started! For more information, please refer to our GitHub repsitory (click the original text to get it).

星球君的朋友们
作者文库