NEED checkForProfit on Mempool for Sell
vnvdev opened this issue · 3 comments
async function checkForProfit(token) {
var sellAttempts = 0;
token.contract.on("Transfer", async (from, to, value, event) => {
const takeLoss = (parseFloat(token.investmentAmount) * (token.stopLossMultiplier - token.tokenSellTax / 100)).toFixed(18).toString();
const takeProfit = (parseFloat(token.investmentAmount) * (token.profitMultiplier + token.tokenSellTax / 100)).toFixed(18).toString();
const tokenName = await token.contract.name();
let bal = await token.contract.balanceOf(addresses.recipient);
const amount = await pancakeRouter.getAmountsOut(bal, token.sellPath);
const profitDesired = ethers.utils.parseUnits(takeProfit);
const stopLoss = ethers.utils.parseUnits(takeLoss);
let currentValue;
if (token.sellPath.length == 3) {
currentValue = amount[2];
} else {
currentValue = amount[1];
}
console.log('--- ', tokenName, '--- Current Value in BNB:', ethers.utils.formatUnits(currentValue), '--- Profit At:', ethers.utils.formatUnits(profitDesired), '--- Stop Loss At:', ethers.utils.formatUnits(stopLoss), '\n');
if (currentValue.gte(profitDesired)) {
if (buyCount <= numberOfTokensToBuy && !token.didSell && token.didBuy && sellAttempts == 0) {
sellAttempts++;
console.log("Selling", tokenName, "now profit target reached", "\n");
sell(token, true);
token.contract.removeAllListeners();
}
}
if (currentValue.lte(stopLoss)) {
if (buyCount <= numberOfTokensToBuy && !token.didSell && token.didBuy && sellAttempts == 0) {
sellAttempts++;
console.log("Selling", tokenName, "now stoploss reached", "\n");
sell(token, false);
token.contract.removeAllListeners();
}
}
});
}
This is not a very good idea unless you have your own bsc dedicated full node with unlimited requests.
This is not a very good idea unless you have your own bsc dedicated full node with unlimited requests.
Moralis have free full node unlimited request
You only get 10,000,000 free requests a month. BSC does millions of transactions a day. To scan mempool constantly for hours would eat that up very quickly and no real benefit to do that.