add history db

This commit is contained in:
Dung Nguyen 2022-03-03 11:41:53 +07:00
parent 115c3fb013
commit 50315c5e8e
4 changed files with 2139 additions and 64 deletions

20
database.js Normal file
View File

@ -0,0 +1,20 @@
const { createPool } = require('mysql');
const CONFIG = {
DATA_HOST: '128.199.96.244',
DATA_USER: 'root',
DATA_PASS: 'Xinchao@123!',
DATA_DB: 'auto_trade',
DATA_PORT: 3306,
}
const pool = createPool({
host: CONFIG.DATA_HOST,
user: CONFIG.DATA_USER,
password: CONFIG.DATA_PASS,
database: CONFIG.DATA_DB,
port: CONFIG.DATA_PORT,
connectionLimit: 10
});
module.exports = pool;

View File

@ -5,6 +5,8 @@ const cron = require("cron");
const RecaptchaPlugin = require("puppeteer-extra-plugin-recaptcha"); const RecaptchaPlugin = require("puppeteer-extra-plugin-recaptcha");
const TelegramBot = require("node-telegram-bot-api"); const TelegramBot = require("node-telegram-bot-api");
const db = require("./database");
const capchaApi = "74dff1d33afbc505c712408e4bc8c5c2"; const capchaApi = "74dff1d33afbc505c712408e4bc8c5c2";
const TELEGRAM_TOKEN = "5205509778:AAEOFE72whCgwOmgr8O-PY1C2h6KZrbAwX4"; const TELEGRAM_TOKEN = "5205509778:AAEOFE72whCgwOmgr8O-PY1C2h6KZrbAwX4";
const TELEGRAM_CHANNEL = `@bot_bao_lenh`; const TELEGRAM_CHANNEL = `@bot_bao_lenh`;
@ -41,11 +43,10 @@ let dInWeb = null; // Ví tiền theo web
*/ */
const CONFIG = { const CONFIG = {
autoTrade: true, autoTrade: true,
countTradeContinue: 1, // 7 lệnh thông thì đánh ngược lại countTradeContinue: 2, // 7 lệnh thông thì đánh ngược lại
moneyEnterOrder: [5, 10, 20, 40, 80], // Nếu gặp 7 lệnh thông sẽ đánh ngược lại với từng mệnh giá này moneyEnterOrder: [5, 10, 20, 40, 80], // Nếu gặp 7 lệnh thông sẽ đánh ngược lại với từng mệnh giá này
maxHistory: 40, // Lưu lại lịch sử 40 phiên maxHistory: 40, // Lưu lại lịch sử 40 phiên
historys: [], // Lịch sử lệnh historys: [], // Lịch sử lệnh
historyEnterOrder: [], // Lịch sử vào lệnh
enterOrderList: [], // Lệnh đang vào enterOrderList: [], // Lệnh đang vào
}; };
@ -55,7 +56,7 @@ puppeteer
const page = await browser.newPage(); const page = await browser.newPage();
await page.setViewport({ width: 1366, height: 768 }); await page.setViewport({ width: 1366, height: 768 });
await page.setDefaultNavigationTimeout(0); await page.setDefaultNavigationTimeout(0);
await page.goto("https://moonata1.net/login"); await page.goto("https://moonata2.net/login");
await page.type('input[name="email"]', "gavol68807@ishop2k.com", { await page.type('input[name="email"]', "gavol68807@ishop2k.com", {
delay: 100, delay: 100,
}); });
@ -259,8 +260,7 @@ puppeteer
5. /set_money_enter:number1,number2 - Vào tiền khi đủ điều kiện; 5. /set_money_enter:number1,number2 - Vào tiền khi đủ điều kiện;
6. /history - Vào tiền khi đủ điều kiện; 6. /history - Vào tiền khi đủ điều kiện;
7. /check_tk - Check tiền ; 7. /check_tk - Check tiền ;
8. /clear_history - Xoá toàn bộ lịch sử giao dịch; 8. /view_history - Xem toàn bộ lịch sử vào lệnh;`,
9. /view_history - Xem toàn bộ lịch sử vào lệnh;`,
{ parse_mode: "HTML" } { parse_mode: "HTML" }
); );
return; return;
@ -303,10 +303,7 @@ puppeteer
CONFIG.autoTrade = true; CONFIG.autoTrade = true;
TeleGlobal.sendMessage( TeleGlobal.sendMessage(
myTelegramID, myTelegramID,
`Bật auto trade thành công!. `Bật auto trade thành công!`,
Để vào lệnh 1 phiên bất :
BUY: /buy:[number]
SELL: /sell:[number]`,
{ parse_mode: "HTML" } { parse_mode: "HTML" }
); );
return; return;
@ -350,27 +347,29 @@ SELL: /sell:[number]`,
return; return;
} }
if (text.startsWith('/clear_history')) { if (text.startsWith('/view_history')) {
CONFIG.historyEnterOrder = []; db.query(
TeleGlobal.sendMessage(myTelegramID, `Xoá toàn bộ lịch sử vào lệnh thành công`, { `SELECT * FROM histories ORDER BY id desc`,
[], (error, results) => {
if (error) {
console.log(error);
TeleGlobal.sendMessage(myTelegramID, `Truy vấn lịch sử thất bại!`, {
parse_mode: "HTML", parse_mode: "HTML",
}); });
} else {
return;
}
if (text.startsWith('/view_history')) {
let textResult = ''; let textResult = '';
if (!CONFIG.historyEnterOrder.length) {
if (!results.length) {
textResult = 'Chưa có lịch sử giao dịch!'; textResult = 'Chưa có lịch sử giao dịch!';
} else { } else {
CONFIG.historyEnterOrder.forEach((e) => { results.forEach((e) => {
textResult += `${e.time} | ${e.sessionID} | ${e.trend} | ${e.isWin ? 'Thắng' : 'Thua'} ${e.money}$\n`; textResult += `${e.time} | ${e.sessionID} | ${e.trend} | ${e.isWin ? 'Thắng' : 'Thua'} ${e.money}$\n`;
}); });
} }
TeleGlobal.sendMessage(myTelegramID, textResult, { TeleGlobal.sendMessage(myTelegramID, textResult, { parse_mode: "HTML" });
parse_mode: "HTML", }
}); }
)
} }
}); });
}); });
@ -388,7 +387,10 @@ function roleEnterOrder(sessionID, lastResult) {
} }
CONFIG.historys.push({ sessionID, lastResult }); CONFIG.historys.push({ sessionID, lastResult });
// PHIÊN ĐÃ VÀO LỆNH SẼ CHECK - sessionID - 1 = enterOrder.sessionID /**
* PHIÊN ĐÃ VÀO LỆNH SẼ CHECK
* sessionID - 1 = enterOrder.sessionID
*/
function currentEnterOrderFn() { function currentEnterOrderFn() {
const indEnterOrder = CONFIG.enterOrderList.findIndex((e) => e.sessionID === sessionID - 1); const indEnterOrder = CONFIG.enterOrderList.findIndex((e) => e.sessionID === sessionID - 1);
if (indEnterOrder === -1) return undefined; if (indEnterOrder === -1) return undefined;
@ -415,13 +417,15 @@ function roleEnterOrder(sessionID, lastResult) {
); );
d.demoBalance += CONFIG.moneyEnterOrder[currentEnterOrder.ind] * 0.95; d.demoBalance += CONFIG.moneyEnterOrder[currentEnterOrder.ind] * 0.95;
CONFIG.historyEnterOrder.push({ db.query(`INSERT INTO histories (sessionID, trend, time, isWin, money)
sessionID: sessionID - 1, VALUES(?,?,?,?,?)`,
trend: coverLastResult(lastResult), [
time: currentEnterOrder.time, sessionID - 1,
isWin: true, coverLastResult(lastResult),
money: CONFIG.moneyEnterOrder[currentEnterOrder.ind] * 0.95, currentEnterOrder.time,
}); 1,
CONFIG.moneyEnterOrder[currentEnterOrder.ind] * 0.95,
]);
deleteCurrentEnterOrder(); deleteCurrentEnterOrder();
} else { } else {
@ -439,13 +443,15 @@ Bạn sẽ vào lệnh ở phiên tiếp theo(${currentEnterOrder.sessionID})!`,
); );
d.demoBalance -= CONFIG.moneyEnterOrder[currentEnterOrder.ind]; d.demoBalance -= CONFIG.moneyEnterOrder[currentEnterOrder.ind];
CONFIG.historyEnterOrder.push({ db.query(`INSERT INTO histories (sessionID, trend, time, isWin, money)
sessionID: sessionID - 1, VALUES(?,?,?,?,?)`,
trend: coverLastResult(lastResult), [
time: currentEnterOrder.time, sessionID - 1,
isWin: false, coverLastResult(lastResult),
money: CONFIG.moneyEnterOrder[currentEnterOrder.ind], currentEnterOrder.time,
}); 0,
CONFIG.moneyEnterOrder[currentEnterOrder.ind],
]);
currentEnterOrder.ind += 1; currentEnterOrder.ind += 1;
currentEnterOrder.enable = true; currentEnterOrder.enable = true;
@ -462,19 +468,25 @@ Bạn sẽ vào lệnh ở phiên tiếp theo(${currentEnterOrder.sessionID})!`,
} }
// 1. Số lệnh thông = 7 thì đánh lệnh ngược lại // 1. Số lệnh thông = 7 thì đánh lệnh ngược lại
const listContinue = CONFIG.historys.slice(
CONFIG.historys.length - CONFIG.countTradeContinue,
CONFIG.historys.length
);
let isNotBreakdowUp = true; // Xanh let isNotBreakdowUp = true; // Xanh
let isNotBreakdowDown = true; // Đỏ let isNotBreakdowDown = true; // Đỏ
listContinue.reverse().forEach((e) => { let totalEnterOrderContinue = 0;
const historyReverse = CONFIG.historys.reverse();
historyReverse.forEach((e, ind) => {
if (ind < CONFIG.countTradeContinue) {
if (e.lastResult === 0) { if (e.lastResult === 0) {
// Xanh // Xanh
isNotBreakdowDown = false; isNotBreakdowDown = false;
} else { } else {
isNotBreakdowUp = false; isNotBreakdowUp = false;
} }
}
// Đếm tổng lệnh thông
if (e.lastResult === historyReverse[0].lastResult && totalEnterOrderContinue !== -1) {
totalEnterOrderContinue += 1;
} else {
totalEnterOrderContinue = -1;
}
}); });
// TỰ VÀO LỆNH KHI ĐỦ ĐIỀU KIỆN // TỰ VÀO LỆNH KHI ĐỦ ĐIỀU KIỆN
@ -483,7 +495,7 @@ Bạn sẽ vào lệnh ở phiên tiếp theo(${currentEnterOrder.sessionID})!`,
CONFIG.historys.length >= CONFIG.countTradeContinue CONFIG.historys.length >= CONFIG.countTradeContinue
) { ) {
const isEnterOrderd = CONFIG.enterOrderList.map((e) => e.sessionID).includes(sessionID + 1); const isEnterOrderd = CONFIG.enterOrderList.map((e) => e.sessionID).includes(sessionID + 1);
const textAlert = `Hệ thống đang thông ${CONFIG.countTradeContinue} lệnh ${coverLastResult(lastResult)} liên tiếp.`; const textAlert = `Hệ thống đang thông ${totalEnterOrderContinue} lệnh ${coverLastResult(lastResult)} liên tiếp.`;
if (isEnterOrderd) { if (isEnterOrderd) {
TeleGlobal.sendMessage( TeleGlobal.sendMessage(
TELEGRAM_CHANNEL, TELEGRAM_CHANNEL,

2062
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -11,6 +11,7 @@
"license": "ISC", "license": "ISC",
"dependencies": { "dependencies": {
"cron": "^1.8.2", "cron": "^1.8.2",
"mysql": "^2.18.1",
"node-telegram-bot-api": "^0.56.0", "node-telegram-bot-api": "^0.56.0",
"puppeteer": "^13.4.0", "puppeteer": "^13.4.0",
"puppeteer-extra": "^3.2.3", "puppeteer-extra": "^3.2.3",