pattern-tech / gateway

Middleware that standardizes DEX API endpoints on different blockchain networks
Apache License 2.0
1 stars 1 forks source link

Create test strategy #23

Closed mehrdadmms closed 1 month ago

mehrdadmms commented 2 months ago

Description

We need to create an arbitrage functionality that exchanges ERG for USD between a CEX (like Coinex) and a DEX (Spectrum). The strategy should find opportunities based on the defined code rules and runs the transactions. We then need to verify transactions to make sure that everything works properly.

Task

Appendix

How to setup a bot

For more information search in youtube

What is arbitrage

Arbitrage trading in the context of cryptocurrency involves taking advantage of price differences between two or more markets. When dealing with a crypto token pair on a Decentralized Exchange (DEX) and a Centralized Exchange (CEX), the strategy generally follows these steps:

Identify Price Discrepancies:
    Monitor the prices of the same cryptocurrency pair (e.g., BTC/ETH) on both the DEX and CEX.
    Look for significant differences in the prices that can cover transaction costs and provide a profit.

Execution of Trades:
    When a price discrepancy is identified, buy the cryptocurrency on the exchange where the price is lower.
    Simultaneously, sell the cryptocurrency on the exchange where the price is higher.

Transaction Costs and Fees:
    Take into account the transaction fees on both the DEX and CEX.
    Include network fees, especially on a DEX where transactions are executed on the blockchain.

Liquidity Considerations:
    Ensure there is enough liquidity on both the DEX and CEX to execute the trades without causing significant slippage.
    Higher liquidity usually means lower slippage and more efficient trades.

Speed and Timing:
    Execute the trades as quickly as possible to minimize the risk of price changes during the transactions.
    Automated trading bots are often used to execute arbitrage trades within seconds.

Regulatory and Security Considerations:
    Be aware of the regulatory environment of both the DEX and CEX, especially concerning large transactions.
    Ensure the security of your funds on both exchanges, as DEXs and CEXs have different security protocols.

Example Scenario

Identify Price Discrepancy:
    On the CEX, ETH/BTC is trading at 0.034 BTC.
    On the DEX, ETH/BTC is trading at 0.033 BTC.

Execute Trade:
    Buy 10 ETH on the DEX at 0.033 BTC/ETH (total cost: 0.33 BTC).
    Sell 10 ETH on the CEX at 0.034 BTC/ETH (total revenue: 0.34 BTC).

Calculate Profit:
    Gross profit: 0.34 BTC - 0.33 BTC = 0.01 BTC.
    Deduct transaction fees and network fees from the gross profit to find the net profit.