Skip to content

Commit

Permalink
[PCS]: Fix #23 #18
Browse files Browse the repository at this point in the history
  • Loading branch information
lmusarella authored and lmusarella committed Sep 24, 2023
1 parent 76dda09 commit 2e5a57a
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 14 deletions.
10 changes: 8 additions & 2 deletions bot-configuration/bot-configuration.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,13 @@ const GLOBAL_CONFIG = {
* @default 2
* @type {number}
*/
INCREMENT_BET_AMOUNT: 2
INCREMENT_BET_AMOUNT: 2,
/**
* After how many rounds will the suspended rounds be eliminated, because of PancakeSwap can burn/delete some rounds, which will never be completed, remaining in the hanging rounds stack
* @default 5
* @type {number}
*/
NUM_ROUNDS_AFTER_DELETE_PENDING_ROUNDS: 5
}
},
STRATEGY_CONFIGURATION: {
Expand All @@ -99,7 +105,7 @@ const GLOBAL_CONFIG = {
* @default SIGNAL_STRATEGY
* @type {string}
*/
SELECTED_STRATEGY: 'PATTERN_STRATEGY',
SELECTED_STRATEGY: 'QUOTE_STRATEGY',
/**
* Time after execute bet strategy when start a new round.
* @default 265000 in Miliseconds (4.3 Minutes)
Expand Down
13 changes: 10 additions & 3 deletions bot-lib/common/constants/strings.constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,13 @@ const CONSOLE_STRINGS = {
INACTIVITY_USER_MESSAGE: "🥺 Round [{round}] Sorry your friend [{friendAddress}] didn't bet!",
SKIP_MESSAGE: "♻️ Skip: {message}",
SKIP_ROUND_MESSAGE: "♻️ Skip round: {round}",
MARTINGALE_MODE_MESSAGE: "🚨 Bot is running in Martingale Mode! Waiting pending rounds: [{rounds}]",
MARTINGALE_MODE_MESSAGE: "🚨 Bot is running in Martingale Mode! Waiting pending rounds: [{rounds}] - if some rounds remain hanging, they will be eliminated after {numR} rounds.",
BOT_STOPPING_MESSAGE: "🚨 Bot is stopping! Waiting pending rounds: [{rounds}]",
WAITING_STRATEGY_MESSAGE: "⏰ Waiting {minutes} minutes before execute {strategy}",
EVENT_PATTERN_NOT_FOUND: "No pattern found. No event {event} repeated {n} times",
EVENT_NOT_PREDICTABLE: "Previous Rounds's {round} Event not predictable - the absolute difference price {difference} does not reach the threshold: {threshold}",
PATTERN_STATEGY_BET_MESSAGE: "🔮 The previous round {previous} is very likely to end with the following outcome: {res}",
PATTERN_STATEGY_PRICE_MESSAGE: "⚖️ Current price: {currentPrice} is {current} than open price: {openPrice}, price difference: {difference}, it seems that the pattern is respected, {res} event repeated {numberEvent} times!"

PATTERN_STATEGY_PRICE_MESSAGE: "⚖️ Current price: {currentPrice} is {current} than open price: {openPrice}, price difference: {difference}, it seems that the pattern is respected, {res} event repeated {numberEvent} times!",
},
TEMPLATES: {
UTILS: {
Expand All @@ -55,6 +54,14 @@ const CONSOLE_STRINGS = {
SPACE: " ",
EMPTY: ""
},
CALL_TO_ACTION: {
HEADER: "❤️ DONATIONS & SUPPORT",
CALL_TO_ACTION_STAR: "To support me leave a star ⭐ to my GitHub repository",
CALL_TO_ACTION_REPOLINK: "https://github.com/lmusarella/Pancakeswap-Prediction-Bot-2023",
CALL_TO_ACTION_DONATION: "If you want to make a small donation you can make it on my personal wallet",
CALL_TO_ACTION_DONATION_WALLET: "0x0C40e4F3606aE2F41DAc9bB67606f41284755350",
CALL_TO_ACTION_THANK: "Thank you so much! 🙏 Happy continuation!"
},
COPYRIGHT: {
FIRST_LINE: "Copyright (c) 2023 l.musarella",
SECOND_LINE: "Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.",
Expand Down
18 changes: 17 additions & 1 deletion bot-lib/common/print.module.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,21 @@ const printWalletInfo = (balance) => {
printSectionSeparator();
}

const printCallToAction = () => {
console.log(CONSOLE_STRINGS.TEMPLATES.CALL_TO_ACTION.HEADER);
printSubSectionSeparator();
console.log(SPACE, CONSOLE_STRINGS.TEMPLATES.CALL_TO_ACTION.CALL_TO_ACTION_STAR);
printEmptyRow();
console.log(SPACE, [CONSOLE_STRINGS.TEMPLATES.CALL_TO_ACTION.CALL_TO_ACTION_REPOLINK]);
printEmptyRow();
console.log(SPACE, CONSOLE_STRINGS.TEMPLATES.CALL_TO_ACTION.CALL_TO_ACTION_DONATION);
printEmptyRow();
console.log(SPACE, [CONSOLE_STRINGS.TEMPLATES.CALL_TO_ACTION.CALL_TO_ACTION_DONATION_WALLET]);
printEmptyRow();
console.log(SPACE, CONSOLE_STRINGS.TEMPLATES.CALL_TO_ACTION.CALL_TO_ACTION_THANK);
printSectionSeparator();
}

const printStartRoundEvent = (startRoundEvent, pendingRounds) => {
console.log(evalString(CONSOLE_STRINGS.TEMPLATES.START_ROUND_EVENT.HEADER, { round: startRoundEvent.id, time: getConsoleTime() }));
printSubSectionSeparator();
Expand All @@ -128,7 +143,7 @@ const printStartRoundEvent = (startRoundEvent, pendingRounds) => {
const rounds = Array.from(pendingRounds.values()).map(round => round.id);
if (GLOBAL_CONFIG.BET_CONFIGURATION.MARTINGALE_CONFIG.ACTIVE && startRoundEvent.validProfit && startRoundEvent.validBalance) {
console.log(evalString(CONSOLE_STRINGS.INFO_MESSAGE.SKIP_ROUND_MESSAGE, { round: startRoundEvent.id }));
console.log(evalString(CONSOLE_STRINGS.INFO_MESSAGE.MARTINGALE_MODE_MESSAGE, { rounds: rounds }));
console.log(evalString(CONSOLE_STRINGS.INFO_MESSAGE.MARTINGALE_MODE_MESSAGE, { rounds: rounds , numR: GLOBAL_CONFIG.BET_CONFIGURATION.MARTINGALE_CONFIG.NUM_ROUNDS_AFTER_DELETE_PENDING_ROUNDS}));
printSectionSeparator();
} else {
console.log(evalString(CONSOLE_STRINGS.INFO_MESSAGE.BOT_STOPPING_MESSAGE, { rounds: rounds }));
Expand Down Expand Up @@ -237,6 +252,7 @@ module.exports = {
printEndRoundEvent,
printStatistics,
printClaimMessage,
printCallToAction,
printFriendInactivityMessage,
printMostActiveUserMessage,
evalString
Expand Down
13 changes: 12 additions & 1 deletion bot-lib/common/utils.module.js
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,16 @@ const deleteFile = (path) => {
fs.unlink(path, function(){});
}

/**
* Check if a round is burn or cancelled
* @date 4/25/2023 - 3:36:11 PM
*
* @param {String} dir
*/
const checkCancelledRound = (currentRound, stackRound) => {
return currentRound - stackRound >= GLOBAL_CONFIG.BET_CONFIGURATION.MARTINGALE_CONFIG.NUM_ROUNDS_AFTER_DELETE_PENDING_ROUNDS;
}

/**
* Return the file content
* @date 4/25/2023 - 3:36:11 PM
Expand Down Expand Up @@ -373,5 +383,6 @@ module.exports = {
getBetAmount,
setBetAmount,
getStringDate,
deleteFile
deleteFile,
checkCancelledRound
};
3 changes: 2 additions & 1 deletion bot-lib/pcs-bot.module.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const { getRoundData, getMinBetAmount, getCurrentEpoch, setSmartContratConfig }
const { getStatisticFromHistory, saveRoundInHistory, ALL_ROUND_HISTORY_FILENAME, backUpFilesHistory, resetFilesHistory} = require('./history/history.module');
const { getSimulationBalance, updateSimulationBalance, getBNBBalance } = require('./wallet/wallet.module');
const { getBinancePrice } = require('./external-data/binance.module');
const { printWelcomeMessage, printGlobalSettings, printWalletInfo, printSectionSeparator, printStopBotMessage, printInitBotMessage, printStartBotMessage, printCurrencyInfo } = require('./common/print.module');
const { printWelcomeMessage, printGlobalSettings, printWalletInfo, printSectionSeparator, printStopBotMessage, printInitBotMessage, printStartBotMessage, printCurrencyInfo, printCallToAction } = require('./common/print.module');
const { executeStrategyWithSignals, isSignalStrategy } = require('./strategies/signals-strategy.module');
const { isQuoteStrategy, executeStrategyWithQuotes } = require('./strategies/quote-strategy.module');
const { executeBetUpCopyTradingStrategy, executeBetDownCopyTradingStrategy } = require('./strategies/copytrading-strategy.module');
Expand Down Expand Up @@ -89,6 +89,7 @@ const startBotCommand = async () => {
}
const balance = await getPersonalBalance();
printWalletInfo(balance);
printCallToAction();
printStartBotMessage(currentEpoch);
}

Expand Down
12 changes: 6 additions & 6 deletions bot-script/pcs-bot.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const { EVENTS } = require("../bot-lib/common/constants/smart-contract.constants
const { saveRoundInHistory, saveStatisticsInHistory } = require('../bot-lib/history/history.module');
const { getSmartContract, getRoundData } = require('../bot-lib/smart-contracts/pcs-prediction-smart-contract.module');
const { stopBotCommand, startBotCommand, executeBetStrategy, createStartRoundEvent, createEndRoundEvent, executeBetUpStrategy, executeBetDownStrategy, getEndRoundData, handleRoundResult } = require('../bot-lib/pcs-bot.module');
const { updateCryptoUsdPriceFromSmartContract, formatUnit, setCryptoFeeUsdPrice } = require('../bot-lib/common/utils.module');
const { updateCryptoUsdPriceFromSmartContract, formatUnit, setCryptoFeeUsdPrice, checkCancelledRound } = require('../bot-lib/common/utils.module');
const { updateSimulationBalance } = require("../bot-lib/wallet/wallet.module");
const { printStartRoundEvent, printBetRoundEvent, printEndRoundEvent, printStatistics, printClaimMessage, printFriendInactivityMessage } = require("../bot-lib/common/print.module");
const { isCopyTradingStrategy, registerUser, handleUsersActivity, getMostActiveUser } = require("../bot-lib/strategies/copytrading-strategy.module");
Expand All @@ -33,6 +33,7 @@ const init = async () => {

init();


//Listener on "StartRound" event from {@PredictionGameSmartContract}
getSmartContract().on(EVENTS.START_ROUND_EVENT, async (epoch) => {
//Wait EndRoundEvent processed
Expand Down Expand Up @@ -153,11 +154,10 @@ getSmartContract().on(EVENTS.LOCK_ROUND, async (epoch) => {
}

const rounds = Array.from(pendingRoundEventStack.values());

// Check if some round are stuck (deleted or cancelled) and remouved from run time map
rounds.forEach(r => {
if (round - r >= 5) {
pendingRoundEventStack.delete(r);
// Check if some round are stuck (deleted or cancelled) and remouved from runtime map
rounds.forEach(async stackRound => {
if (checkCancelledRound(round, stackRound.id)) {
pendingRoundEventStack.delete(stackRound.id);
}
})
});
Expand Down

0 comments on commit 2e5a57a

Please sign in to comment.