ARBITRAGE mode

Risk-free and time-saving

The Arbitrage mode in a Selenium bot provides the opportunity for automatic execution of arbitrage deals between various decentralized exchanges. The bot analyzes token prices on different exchanges and executes buy-sell operations to profit from price differences. This allows users to automate the arbitrage process and benefit from cryptocurrency price fluctuations without the need for constant market monitoring

  1. arbitrage: This function will allow the user to perform arbitrage between two different tokens on two different DEXs. The function will take the following arguments:

    tokenA: The first token to swap. tokenB: The second token to swap. dexA: The first DEX to use. dexB: The second DEX to use. amount: The amount of tokenA to swap. slippage: The slippage tolerance. maxGasPrice: The maximum gas price to use.

  2. arbitrageWithGasPrice: This function will allow the user to perform arbitrage between two different tokens on two different DEXs and specify a gas price. The function will take the following arguments:

    tokenA: The first token to swap. tokenB: The second token to swap. dexA: The first DEX to use. dexB: The second DEX to use. amount: The amount of tokenA to swap. slippage: The slippage tolerance. maxGasPrice: The maximum gas price to use. gasPrice: The gas price to use.

  3. arbitrageWithGasLimit: This function will allow the user to perform arbitrage between two different tokens on two different DEXs and specify a gas limit. The function will take the following arguments:

    tokenA: The first token to swap. tokenB: The second token to swap. dexA: The first DEX to use. dexB: The second DEX to use. amount: The amount of tokenA to swap. slippage: The slippage tolerance. maxGasPrice: The maximum gas price to use. gasLimit: The gas limit to use.

  4. arbitrageWithGasPriceAndGasLimit: This function will allow the user to perform arbitrage between two different tokens on two different DEXs and specify a gas price and gas limit. The function will take the following arguments:

    tokenA: The first token to swap. tokenB: The second token to swap. dexA: The first DEX to use. dexB: The second DEX to use. amount: The amount of tokenA to swap. slippage: The slippage tolerance. maxGasPrice: The maximum gas price to use. gasPrice: The gas price to use. gasLimit: The gas limit to use.

async def arbitrage( tokenA: str, tokenB: str, dexA: str, dexB: str, amount: float, slippage: float = 0.5, max_gas_price: int = 100, gas_price: int = None, gas_limit: int = None, ): """ Performs arbitrage between two tokens on two different DEXs.

Args:
    tokenA (str): The first token to swap.
    tokenB (str): The second token to swap.
    dexA (str): The first DEX to use.
    dexB (str): The second DEX to use.
    amount (float): The amount of tokenA to swap.
    slippage (float): The slippage tolerance.
    max_gas_price (int): The maximum gas price to use.
    gas_price (int): The gas price to use.
    gas_limit (int): The gas limit to use.
"""

# Get the contracts for the DEXs
contractA = await get_contract(dexA)
contractB = await get_contract(dexB)

# Get the paths for the swaps
pathA = [tokenA, tokenB]
pathB = [tokenB, tokenA]

# Get the amount out minimums
amount_out_minA = await contractA.functions.getAmountsOut(amount, pathA).call()
amount_out_minA = amount_out_minA[-1] * (1 - slippage / 100)
amount_out_minB = await contractB.functions.getAmountsOut(amount, pathB).call()
amount_out_minB = amount_out_minB[-1] * (1 - slippage / 100)

# Get the gas prices
if gas_price is None:
    gas_price = await get_gas_price(max_gas_price)

# Get the gas limits
if gas_limit is None:
    gas_limit = await get_gas_limit(contractA)

# Perform the arbitrage
if amount_out_minB > amount:
    # Swap tokenA for tokenB on DEXA
    await contractA.functions.swapExactTokensForTokens(
        amount,
        amount_out_minA,
        pathA,
        msg.sender,
        (int(time.time()) + 600),
    ).call(gas_price=gas_price, gas=gas_limit)

    # Swap tokenB for tokenA on DEXB
    await contractB.functions.swapExactTokensForTokens(
        amount_out_minA,
        amount,
        pathB,
        msg.sender,
        (int(time.time()) + 600),
    ).call(gas_price=gas_price, gas=gas_limit)
else:
    # Swap tokenA for tokenB on DEXB
    await contractB.functions.swapExactTokensForTokens(
        amount,
        amount_out_minB,
        pathB,
        msg.sender,
        (int(time.time()) + 600),
    ).call(gas_price=gas_price, gas=gas_limit)

    # Swap tokenB for tokenA on DEXA
    await contractA.functions.swapExactTokensForTokens(
        amount_out_minB,
        amount,
        pathA,
        msg.sender,
        (int(time.time()) + 600),
    ).call(gas_price=gas_price, gas=gas_limit)

Last updated