fix bot
This commit is contained in:
parent
a2ce011132
commit
7d12cd7773
8
.idea/.gitignore
generated
vendored
Normal file
8
.idea/.gitignore
generated
vendored
Normal file
@ -0,0 +1,8 @@
|
||||
# Default ignored files
|
||||
/shelf/
|
||||
/workspace.xml
|
||||
# Editor-based HTTP Client requests
|
||||
/httpRequests/
|
||||
# Datasource local storage ignored files
|
||||
/dataSources/
|
||||
/dataSources.local.xml
|
9
.idea/botTrade.iml
generated
Normal file
9
.idea/botTrade.iml
generated
Normal file
@ -0,0 +1,9 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module type="JAVA_MODULE" version="4">
|
||||
<component name="NewModuleRootManager" inherit-compiler-output="true">
|
||||
<exclude-output />
|
||||
<content url="file://$MODULE_DIR$" />
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
</component>
|
||||
</module>
|
8
.idea/modules.xml
generated
Normal file
8
.idea/modules.xml
generated
Normal file
@ -0,0 +1,8 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectModuleManager">
|
||||
<modules>
|
||||
<module fileurl="file://$PROJECT_DIR$/.idea/botTrade.iml" filepath="$PROJECT_DIR$/.idea/botTrade.iml" />
|
||||
</modules>
|
||||
</component>
|
||||
</project>
|
6
.idea/vcs.xml
generated
Normal file
6
.idea/vcs.xml
generated
Normal file
@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="VcsDirectoryMappings">
|
||||
<mapping directory="" vcs="Git" />
|
||||
</component>
|
||||
</project>
|
608
index.js
608
index.js
@ -1,6 +1,5 @@
|
||||
// Fix telegram
|
||||
process.env.NTBA_FIX_319 = 1;
|
||||
|
||||
const puppeteer = require("puppeteer-extra");
|
||||
const cron = require("cron");
|
||||
const RecaptchaPlugin = require("puppeteer-extra-plugin-recaptcha");
|
||||
@ -23,234 +22,37 @@ puppeteer.use(
|
||||
})
|
||||
);
|
||||
|
||||
function coverLastResult(resultArg) {
|
||||
if (typeof resultArg === "undefined") return "⚪️";
|
||||
if (typeof resultArg === "number") {
|
||||
switch (resultArg) {
|
||||
case 0:
|
||||
return "🟢";
|
||||
case 1:
|
||||
return "🔴";
|
||||
|
||||
default:
|
||||
return "🏳️";
|
||||
}
|
||||
} else {
|
||||
// In từ lịch sử
|
||||
if (typeof resultArg !== "undefined") {
|
||||
switch (resultArg.lastResult) {
|
||||
case 0:
|
||||
return "🟢";
|
||||
case 1:
|
||||
return "🔴";
|
||||
|
||||
default:
|
||||
return "🏳️";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var lastResult = null; // 0: Xanh 1: Đỏ
|
||||
var idLastSession = null; // ID phiên cuối cùng tương ứng kết quả ở trên
|
||||
var d = null;
|
||||
|
||||
var historyEnterOrder = []; // Lịch sử vào lệnh
|
||||
var lastEnterTheOrder = {
|
||||
/**
|
||||
* 0: Xanh
|
||||
* 1: Đỏ
|
||||
* 2: Hoà
|
||||
*/
|
||||
let lastResult = null;
|
||||
/**
|
||||
* Phiên hiện tại
|
||||
* Nếu -1 tức là đang trong phiên chờ
|
||||
*/
|
||||
let currentSessionID = null;
|
||||
let d = null; // Ví tiền user
|
||||
let enterOrder = {
|
||||
enable: false,
|
||||
money: 0,
|
||||
trend: "", // Up | Down
|
||||
sessionID: 0, // Phiên giao dịch
|
||||
isWin: false,
|
||||
time: "", // Thời gian vào lệnh
|
||||
isGoOrder: false,
|
||||
ind: 0, // Số lần vào lệnh. Sẽ vào lệnh theo CONFIG -> nếu vượt quá số lần vào lệnh sẽ dừng lại.
|
||||
};
|
||||
ind: -1, // Lần vào lệnh thua
|
||||
trend: -1, // Lệnh vào
|
||||
sessionID: -1, // Phiên vào lệnh
|
||||
time: '', // Tgian vào lệnh
|
||||
}
|
||||
|
||||
/**
|
||||
* Tất cả config ở đây
|
||||
*/
|
||||
const CONFIG = {
|
||||
autoTrade: false,
|
||||
autoTrade: true,
|
||||
countTradeContinue: 7, // 7 lệnh thông thì đánh ngược lại
|
||||
moneyEnterOrder: [5, 10, 20, 40], // 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
|
||||
historys: [], // Lưu lại lịch sử
|
||||
};
|
||||
|
||||
function roleEnterOrder(sessionID, lastResult) {
|
||||
// Xử lý lịch sử
|
||||
if (CONFIG.historys.length >= CONFIG.maxHistory) {
|
||||
CONFIG.historys.shift();
|
||||
}
|
||||
CONFIG.historys.push({ sessionID, lastResult });
|
||||
|
||||
// 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 * 2,
|
||||
CONFIG.historys.length
|
||||
);
|
||||
let isNotBreakdowUp = true; // Xanh
|
||||
let isNotBreakdowDown = true; // Đỏ
|
||||
listContinue.reverse().forEach((e, ind) => {
|
||||
if (ind % 2 === 0) {
|
||||
// Xét các phiên chẵn
|
||||
if (e.lastResult === 0) {
|
||||
// Xanh
|
||||
isNotBreakdowDown = false;
|
||||
} else {
|
||||
isNotBreakdowUp = false;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
if (
|
||||
(isNotBreakdowUp || isNotBreakdowDown) &&
|
||||
CONFIG.historys.length >= CONFIG.countTradeContinue * 2
|
||||
) {
|
||||
if (CONFIG.autoTrade) {
|
||||
TeleGlobal.sendMessage(
|
||||
TELEGRAM_CHANNEL,
|
||||
`Hệ thống sẽ tự động vào lệnh cho phiên tiếp theo`,
|
||||
{ parse_mode: "HTML" }
|
||||
);
|
||||
|
||||
lastEnterTheOrder.enable = true;
|
||||
lastEnterTheOrder.sessionID = idLastSession + 1;
|
||||
|
||||
if (isNotBreakdowUp) {
|
||||
lastEnterTheOrder.trend = "sell";
|
||||
}
|
||||
if (isNotBreakdowDown) {
|
||||
lastEnterTheOrder.trend = "buy";
|
||||
}
|
||||
} else {
|
||||
TeleGlobal.sendMessage(
|
||||
TELEGRAM_CHANNEL,
|
||||
`Hệ thống đang thông ${
|
||||
CONFIG.countTradeContinue
|
||||
} lệnh ${coverLastResult(
|
||||
lastResult
|
||||
)} liên tiếp. Mời bạn vào lệnh phiên sau!`,
|
||||
{ parse_mode: "HTML" }
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// check xem có phiên nào đang vào lệnh không
|
||||
function checkSessionEnterOrder(sessionIDEnd, lastResultSessionEnd) {
|
||||
if (sessionIDEnd === lastEnterTheOrder.sessionID + 1 && lastEnterTheOrder.isGoOrder && CONFIG.moneyEnterOrder[lastEnterTheOrder.ind]) {
|
||||
// Nếu đang bật auto vào lệnh thì mới kiểm tra
|
||||
const coverResult = (() => {
|
||||
switch (lastResultSessionEnd) {
|
||||
case 0: // Xanh
|
||||
return "buy";
|
||||
case 1: // Đỏ
|
||||
return "sell";
|
||||
default:
|
||||
return undefined;
|
||||
}
|
||||
})();
|
||||
|
||||
if (coverResult) {
|
||||
if (lastEnterTheOrder.trend === coverResult) {
|
||||
TeleGlobal.sendMessage(
|
||||
TELEGRAM_CHANNEL,
|
||||
`Bạn vừa thắng lệnh phiên ${lastEnterTheOrder.sessionID} với lệnh ${lastEnterTheOrder.trend}.
|
||||
⏰: ${lastEnterTheOrder.time}
|
||||
💰 Lãi: ${CONFIG.moneyEnterOrder[lastEnterTheOrder.ind] * 0.95}$
|
||||
💰 Tổng: ${d.demoBalance + CONFIG.moneyEnterOrder[lastEnterTheOrder.ind] * 0.95}`,
|
||||
{ parse_mode: "HTML" }
|
||||
);
|
||||
d.demoBalance += CONFIG.moneyEnterOrder[lastEnterTheOrder.ind] * 0.95;
|
||||
// Update history
|
||||
const indHistoryOrder = historyEnterOrder.findIndex((e) => e.sessionID === lastEnterTheOrder.sessionID);
|
||||
if (indHistoryOrder > -1) {
|
||||
historyEnterOrder[indHistoryOrder].isWin = true;
|
||||
}
|
||||
|
||||
// Nếu phiên vừa rồi đánh trúng
|
||||
lastEnterTheOrder = {
|
||||
enable: false,
|
||||
money: 0,
|
||||
trend: "", // Up | Down
|
||||
sessionID: 0, // Phiên giao dịch
|
||||
time: "", // Thời gian vào lệnh
|
||||
isGoOrder: false,
|
||||
ind: 0, // Số lần vào lệnh. Sẽ vào lệnh theo CONFIG -> nếu vượt quá số lần vào lệnh sẽ dừng lại.
|
||||
};
|
||||
} else {
|
||||
TeleGlobal.sendMessage(
|
||||
TELEGRAM_CHANNEL,
|
||||
`Bạn vừa thua lệnh phiên ${lastEnterTheOrder.sessionID} với lệnh ${lastEnterTheOrder.trend}.
|
||||
⏰: ${lastEnterTheOrder.time}
|
||||
💰 Thua: ${CONFIG.moneyEnterOrder[lastEnterTheOrder.ind]}$
|
||||
💰 Tổng: ${d.demoBalance - CONFIG.moneyEnterOrder[lastEnterTheOrder.ind]}$
|
||||
Bạn sẽ vào lệnh ở phiên tiếp theo(${lastEnterTheOrder.sessionID + 1})!`,
|
||||
{ parse_mode: "HTML" }
|
||||
);
|
||||
d.demoBalance -= CONFIG.moneyEnterOrder[lastEnterTheOrder.ind];
|
||||
// Thua ở đâu gấp đôi ở đó
|
||||
lastEnterTheOrder.enable = true;
|
||||
lastEnterTheOrder.money = 0;
|
||||
lastEnterTheOrder.isGoOrder = false;
|
||||
lastEnterTheOrder.ind += 1;
|
||||
lastEnterTheOrder.sessionID += 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function drawHistory() {
|
||||
return `
|
||||
${coverLastResult(CONFIG.historys[0])} ${coverLastResult(
|
||||
CONFIG.historys[4]
|
||||
)} ${coverLastResult(CONFIG.historys[8])} ${coverLastResult(
|
||||
CONFIG.historys[12]
|
||||
)} ${coverLastResult(CONFIG.historys[16])} ${coverLastResult(
|
||||
CONFIG.historys[20]
|
||||
)} ${coverLastResult(CONFIG.historys[24])} ${coverLastResult(
|
||||
CONFIG.historys[28]
|
||||
)} ${coverLastResult(CONFIG.historys[32])} ${coverLastResult(
|
||||
CONFIG.historys[36]
|
||||
)}
|
||||
${coverLastResult(CONFIG.historys[1])} ${coverLastResult(
|
||||
CONFIG.historys[5]
|
||||
)} ${coverLastResult(CONFIG.historys[9])} ${coverLastResult(
|
||||
CONFIG.historys[13]
|
||||
)} ${coverLastResult(CONFIG.historys[17])} ${coverLastResult(
|
||||
CONFIG.historys[21]
|
||||
)} ${coverLastResult(CONFIG.historys[25])} ${coverLastResult(
|
||||
CONFIG.historys[29]
|
||||
)} ${coverLastResult(CONFIG.historys[33])} ${coverLastResult(
|
||||
CONFIG.historys[37]
|
||||
)}
|
||||
${coverLastResult(CONFIG.historys[2])} ${coverLastResult(
|
||||
CONFIG.historys[6]
|
||||
)} ${coverLastResult(CONFIG.historys[10])} ${coverLastResult(
|
||||
CONFIG.historys[14]
|
||||
)} ${coverLastResult(CONFIG.historys[18])} ${coverLastResult(
|
||||
CONFIG.historys[22]
|
||||
)} ${coverLastResult(CONFIG.historys[26])} ${coverLastResult(
|
||||
CONFIG.historys[30]
|
||||
)} ${coverLastResult(CONFIG.historys[34])} ${coverLastResult(
|
||||
CONFIG.historys[38]
|
||||
)}
|
||||
${coverLastResult(CONFIG.historys[3])} ${coverLastResult(
|
||||
CONFIG.historys[7]
|
||||
)} ${coverLastResult(CONFIG.historys[11])} ${coverLastResult(
|
||||
CONFIG.historys[15]
|
||||
)} ${coverLastResult(CONFIG.historys[19])} ${coverLastResult(
|
||||
CONFIG.historys[23]
|
||||
)} ${coverLastResult(CONFIG.historys[27])} ${coverLastResult(
|
||||
CONFIG.historys[31]
|
||||
)} ${coverLastResult(CONFIG.historys[35])} ${coverLastResult(
|
||||
CONFIG.historys[39]
|
||||
)}
|
||||
`;
|
||||
}
|
||||
|
||||
puppeteer
|
||||
.launch({ headless: true, args: ["--no-sandbox"] })
|
||||
.then(async (browser) => {
|
||||
@ -280,47 +82,40 @@ puppeteer
|
||||
await cdp.send("Network.enable");
|
||||
await cdp.send("Page.enable");
|
||||
let id = 1;
|
||||
count = 0;
|
||||
let countStaticData = 0;
|
||||
let t;
|
||||
let count;
|
||||
|
||||
const printResponse = async function (cdp, response) {
|
||||
if (!response.response) {
|
||||
return;
|
||||
}
|
||||
let data = response.response.payloadData;
|
||||
if (data.includes("BO_CHART_INDICATORS")) {
|
||||
const moneyOrder = CONFIG.moneyEnterOrder[lastEnterTheOrder.ind]; // Tiền vào lệnh
|
||||
if (
|
||||
lastEnterTheOrder.enable &&
|
||||
idLastSession + 1 === lastEnterTheOrder.sessionID &&
|
||||
moneyOrder
|
||||
) {
|
||||
// Tự động vào lệnh theo chỉ thị
|
||||
const enterOrdered = await enterOrderFn(
|
||||
lastEnterTheOrder.trend,
|
||||
moneyOrder,
|
||||
TELEGRAM_CHANNEL
|
||||
|
||||
if (data.includes("BO_PRICE")) {
|
||||
const isDisableBtn = await page.evaluate(() => {
|
||||
const btnCheck = document.querySelector(
|
||||
"#betAmount > div:nth-child(5) > div > div:nth-child(1) > button"
|
||||
);
|
||||
if (enterOrdered) {
|
||||
// Nếu vào lệnh thành công
|
||||
lastEnterTheOrder.money = moneyOrder;
|
||||
lastEnterTheOrder.trend = lastEnterTheOrder.trend;
|
||||
lastEnterTheOrder.sessionID = idLastSession + 1;
|
||||
lastEnterTheOrder.time = new Date().toLocaleString();
|
||||
lastEnterTheOrder.isWin = false;
|
||||
lastEnterTheOrder.enable = false;
|
||||
lastEnterTheOrder.isGoOrder = true;
|
||||
historyEnterOrder.push(lastEnterTheOrder);
|
||||
}
|
||||
return btnCheck && !btnCheck.hasAttribute("disabled");
|
||||
});
|
||||
currentSessionID = isDisableBtn ? JSON.parse(data.substr(2, data.length))[1].session : -1;
|
||||
// if (currentSessionID !== -1) console.log(currentSessionID);
|
||||
|
||||
const isEnterOrder = enterOrder.sessionID === currentSessionID && enterOrder.enable && isDisableBtn;
|
||||
|
||||
if (isEnterOrder) {
|
||||
enterOrder.enable = false;
|
||||
enterOrder.time = new Date().toLocaleString('vi-VN');
|
||||
const moneyEnterOrder = CONFIG.moneyEnterOrder[enterOrder.ind];
|
||||
await enterOrderFn(enterOrder.trend === 0 ? 'buy' : 'sell', moneyEnterOrder, TELEGRAM_CHANNEL);
|
||||
}
|
||||
}
|
||||
|
||||
if (
|
||||
data.includes("SOCKET_BO_LAST_RESULT") &&
|
||||
data.includes("finalSide")
|
||||
) {
|
||||
let str = response.response.payloadData;
|
||||
const dataParse = JSON.parse(str.substr(2, str.length))[1][0];
|
||||
const dataParse = JSON.parse(data.substr(2, data.length))[1][0];
|
||||
if (id !== dataParse.id) {
|
||||
count = 0;
|
||||
id = dataParse.id;
|
||||
@ -336,10 +131,16 @@ puppeteer
|
||||
} else if (finalSide === "NORMAL") {
|
||||
lastResult = 2;
|
||||
}
|
||||
idLastSession = dataParse.session;
|
||||
// Xử lý các trường hợp
|
||||
roleEnterOrder(dataParse.session, lastResult);
|
||||
checkSessionEnterOrder(dataParse.session, lastResult);
|
||||
|
||||
if (currentSessionID !== -1) {
|
||||
// Không tính nến chờ
|
||||
roleEnterOrder(dataParse.session, lastResult);
|
||||
// TeleGlobal.sendMessage(
|
||||
// TELEGRAM_CHANNEL,
|
||||
// `Kết thúc phiên ${dataParse.session} với kết quả ${coverLastResult(lastResult)}`,
|
||||
// { parse_mode: "HTML" }
|
||||
// );
|
||||
}
|
||||
}
|
||||
}
|
||||
if (data === "3") {
|
||||
@ -364,86 +165,110 @@ puppeteer
|
||||
const request = response.request();
|
||||
if (request.url().includes('binaryoption/spot-balance')){
|
||||
const res = await response.json();
|
||||
if (res.ok) {
|
||||
if (res.ok && !d) {
|
||||
d = res.d;
|
||||
}
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
function isEnterOrderFn() {
|
||||
return page.evaluate(() => {
|
||||
let result = false;
|
||||
page.evaluate(() => {
|
||||
const btnCheck = document.querySelector(
|
||||
"#betAmount > div:nth-child(5) > div > div:nth-child(1) > button"
|
||||
);
|
||||
if (btnCheck) {
|
||||
const isDisableBtn = btnCheck.hasAttribute("disabled");
|
||||
return !isDisableBtn;
|
||||
result = !isDisableBtn;
|
||||
}
|
||||
return false;
|
||||
result = false;
|
||||
});
|
||||
return result;
|
||||
}
|
||||
// Vào lệnh: type - buy/sell
|
||||
async function enterOrderFn(type, countMoney, myTelegramID) {
|
||||
const isEnterOrder = await isEnterOrderFn();
|
||||
if (isEnterOrder) {
|
||||
await page.type(`input#InputNumber`, String(countMoney), {
|
||||
delay: 100,
|
||||
});
|
||||
const isEnterOrderSuccess = await page.evaluate((typeArg) => {
|
||||
let result = false;
|
||||
// Nút vào lệnh
|
||||
if (typeArg === "buy") {
|
||||
const btnBuy = document.querySelector(
|
||||
"#betAmount > div:nth-child(5) > div > div:nth-child(1) > button"
|
||||
);
|
||||
if (btnBuy) {
|
||||
btnBuy.click();
|
||||
result = true;
|
||||
}
|
||||
}
|
||||
if (typeArg === "sell") {
|
||||
const btnSell = document.querySelector(
|
||||
"#betAmount > div:nth-child(5) > div > div:nth-child(3) > button"
|
||||
);
|
||||
if (btnSell) {
|
||||
btnSell.click();
|
||||
result = true;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}, type);
|
||||
if (isEnterOrderSuccess) {
|
||||
TeleGlobal.sendMessage(
|
||||
myTelegramID,
|
||||
`👌 Đặt lệnh ${type} | ${countMoney}$ | ${idLastSession + 1} thành công!`,
|
||||
{ parse_mode: "HTML" }
|
||||
);
|
||||
} else {
|
||||
TeleGlobal.sendMessage(
|
||||
myTelegramID,
|
||||
`⚠️ Có lỗi trong quá trình đặt lệnh!`,
|
||||
{ parse_mode: "HTML" }
|
||||
await page.type(`input#InputNumber`, String(countMoney), {
|
||||
delay: 100,
|
||||
});
|
||||
const isEnterOrderSuccess = await page.evaluate((typeArg) => {
|
||||
let result = false;
|
||||
// Nút vào lệnh
|
||||
if (typeArg === "buy") {
|
||||
const btnBuy = document.querySelector(
|
||||
"#betAmount > div:nth-child(5) > div > div:nth-child(1) > button"
|
||||
);
|
||||
if (btnBuy) {
|
||||
btnBuy.click();
|
||||
result = true;
|
||||
}
|
||||
}
|
||||
|
||||
await page.reload({ waitUntil: ["networkidle0"] });
|
||||
if (typeArg === "sell") {
|
||||
const btnSell = document.querySelector(
|
||||
"#betAmount > div:nth-child(5) > div > div:nth-child(3) > button"
|
||||
);
|
||||
if (btnSell) {
|
||||
btnSell.click();
|
||||
result = true;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}, type);
|
||||
if (isEnterOrderSuccess) {
|
||||
TeleGlobal.sendMessage(
|
||||
myTelegramID,
|
||||
`👌 Đặt lệnh ${type} | ${countMoney}$ thành công!`,
|
||||
{ parse_mode: "HTML" }
|
||||
);
|
||||
} else {
|
||||
TeleGlobal.sendMessage(
|
||||
myTelegramID,
|
||||
`⚠️ Có lỗi trong quá trình đặt lệnh!`,
|
||||
{ parse_mode: "HTML" }
|
||||
);
|
||||
}
|
||||
return isEnterOrder;
|
||||
}
|
||||
|
||||
// Auto vào lệnh
|
||||
TeleGlobal.on("message", async ({ text, from }) => {
|
||||
const myTelegramID = from.id;
|
||||
|
||||
if (text.toLowerCase() === 't') {
|
||||
enterOrder.enable = true;
|
||||
enterOrder.ind = 0;
|
||||
/**
|
||||
*
|
||||
* Nếu currentSessionID = -1 -> đang trong phiên chờ -> đánh phiên tiếp theo
|
||||
* Nếu đang trong phiên thật thì bỏ qua phiên chờ
|
||||
*/
|
||||
enterOrder.sessionID = currentSessionID + (currentSessionID === -1 ? 1 : 2);
|
||||
enterOrder.trend = 0; // Xanh
|
||||
TeleGlobal.sendMessage(
|
||||
myTelegramID,
|
||||
`Bạn đang vào chế độ test. Bạn sẽ vào lệnh buy ở phiên ${enterOrder.sessionID}!`,
|
||||
{ parse_mode: "HTML" }
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
if (text.toLowerCase() === "kq") {
|
||||
TeleGlobal.sendMessage(
|
||||
myTelegramID,
|
||||
JSON.stringify({ enterOrder }, null, 2),
|
||||
{ parse_mode: "HTML" }
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
if (text === "/start") {
|
||||
TeleGlobal.sendMessage(
|
||||
myTelegramID,
|
||||
`1. /config - lấy cấu hình hiện tại;
|
||||
2. /enable_auto_trade - Bật auto trade;
|
||||
3. /disable_auto_trade - Tắt auto trade;
|
||||
4. /set_count_trade:[number] - Gặp số lượng lệnh thông như này thì đánh ngược lại
|
||||
5. /set_money_enter:[5,10,20,40] - Vào tiền khi đủ điều kiện
|
||||
6. /history - Vào tiền khi đủ điều kiện
|
||||
7. /check_tk - Vào tiền khi đủ điều kiện
|
||||
4. /set_count_trade:[number] - Gặp số lượng lệnh thông như này thì đánh ngược lại;
|
||||
5. /set_money_enter:[5,10,20,40] - 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 ví;
|
||||
8. /analytic - Thống kê theo ngày;`,
|
||||
{ parse_mode: "HTML" }
|
||||
);
|
||||
@ -462,6 +287,15 @@ puppeteer
|
||||
}
|
||||
|
||||
if (text === "/check_tk") {
|
||||
if (!d) {
|
||||
TeleGlobal.sendMessage(
|
||||
myTelegramID,
|
||||
`Chưa lấy được thông tin ví`,
|
||||
{ parse_mode: "HTML" }
|
||||
);
|
||||
|
||||
return;
|
||||
}
|
||||
TeleGlobal.sendMessage(
|
||||
myTelegramID,
|
||||
`
|
||||
@ -507,28 +341,6 @@ SELL: /sell:[number]`,
|
||||
return;
|
||||
}
|
||||
|
||||
if (text.toLowerCase() === "test") {
|
||||
lastEnterTheOrder.enable = true;
|
||||
lastEnterTheOrder.sessionID = idLastSession + 1;
|
||||
lastEnterTheOrder.trend = "sell";
|
||||
|
||||
TeleGlobal.sendMessage(
|
||||
myTelegramID,
|
||||
`Bật chế độ test. Bạn sẽ vào lệnh mua ở phiên sau!`,
|
||||
{ parse_mode: "HTML" }
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
if (text.toLowerCase() === "kq") {
|
||||
TeleGlobal.sendMessage(
|
||||
myTelegramID,
|
||||
JSON.stringify({ lastEnterTheOrder, idLastSession }, null, 2),
|
||||
{ parse_mode: "HTML" }
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
// Nếu đang trong phiên chờ thì không mua bán gì
|
||||
if (text.startsWith("/buy:")) {
|
||||
const totalBuy = Number(text.replace("/buy:", ""));
|
||||
@ -542,4 +354,154 @@ SELL: /sell:[number]`,
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
/**
|
||||
* Hàm này xử lý sau mỗi phiên có kết quả
|
||||
* @param sessionID
|
||||
* @param lastResult
|
||||
*/
|
||||
function roleEnterOrder(sessionID, lastResult) {
|
||||
// Xử lý lịch sử
|
||||
if (CONFIG.historys.length >= CONFIG.maxHistory) {
|
||||
CONFIG.historys.shift();
|
||||
}
|
||||
CONFIG.historys.push({ sessionID, lastResult });
|
||||
|
||||
// 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 isNotBreakdowDown = true; // Đỏ
|
||||
listContinue.reverse().forEach((e) => {
|
||||
if (e.lastResult === 0) {
|
||||
// Xanh
|
||||
isNotBreakdowDown = false;
|
||||
} else {
|
||||
isNotBreakdowUp = false;
|
||||
}
|
||||
});
|
||||
|
||||
// TỰ VÀO LỆNH KHI ĐỦ ĐIỀU KIỆN
|
||||
if (
|
||||
(isNotBreakdowUp || isNotBreakdowDown) &&
|
||||
CONFIG.historys.length >= CONFIG.countTradeContinue
|
||||
) {
|
||||
const textAlert = `Hệ thống đang thông ${CONFIG.countTradeContinue} lệnh ${coverLastResult(lastResult)} liên tiếp.`;
|
||||
if (CONFIG.autoTrade) {
|
||||
enterOrder.enable = true;
|
||||
enterOrder.ind = 0;
|
||||
/**
|
||||
* Phiên trong hàm này là kết quả phiên chờ -> khi vào lệnh sẽ vào phiên tiếp theo
|
||||
*/
|
||||
enterOrder.sessionID = sessionID + 1;
|
||||
if (isNotBreakdowUp) {
|
||||
// Sell - Đỏ
|
||||
enterOrder.trend = 1;
|
||||
}
|
||||
if (isNotBreakdowDown) {
|
||||
// Buy - Xanh
|
||||
enterOrder.trend = 0;
|
||||
}
|
||||
|
||||
TeleGlobal.sendMessage(
|
||||
myTelegramID,
|
||||
`${textAlert} Hệ thống đã tự vào lệnh ${coverLastResult(enterOrder.trend)} cho phiên sau(${enterOrder.sessionID})!`,
|
||||
{ parse_mode: "HTML" }
|
||||
);
|
||||
} else {
|
||||
TeleGlobal.sendMessage(
|
||||
TELEGRAM_CHANNEL,
|
||||
`${textAlert} Mời bạn vào lệnh phiên sau!`,
|
||||
{ parse_mode: "HTML" }
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// PHIÊN ĐÃ VÀO LỆNH SẼ CHECK - sessionID - 1 = enterOrder.sessionID
|
||||
if (enterOrder.sessionID === sessionID - 1) {
|
||||
if (enterOrder.trend === lastResult) {
|
||||
// WIN session
|
||||
TeleGlobal.sendMessage(
|
||||
TELEGRAM_CHANNEL,
|
||||
`Bạn vừa thắng lệnh phiên ${sessionID - 1} với lệnh ${coverLastResult(lastResult)}.
|
||||
⏰ Vào lệnh: ${enterOrder.time}
|
||||
💰 Lãi: ${CONFIG.moneyEnterOrder[enterOrder.ind] * 0.95}$
|
||||
💰 Tổng: ${d.demoBalance + CONFIG.moneyEnterOrder[enterOrder.ind] * 0.95}`,
|
||||
{ parse_mode: "HTML" }
|
||||
);
|
||||
d.demoBalance += CONFIG.moneyEnterOrder[enterOrder.ind] * 0.95;
|
||||
|
||||
// Reset
|
||||
enterOrder = {
|
||||
enable: false,
|
||||
ind: -1, // Lần vào lệnh thua
|
||||
trend: -1, // Lệnh vào
|
||||
sessionID: -1, // Phiên vào lệnh
|
||||
time: '', // Tgian vào lệnh
|
||||
}
|
||||
} else {
|
||||
if (enterOrder.ind < CONFIG.moneyEnterOrder.length) {
|
||||
// Nếu vẫn còn vốn xoay vòng thì đánh tiếp
|
||||
enterOrder.sessionID += 2;
|
||||
enterOrder.ind += 1;
|
||||
TeleGlobal.sendMessage(
|
||||
TELEGRAM_CHANNEL,
|
||||
`Bạn vừa thua lệnh phiên ${sessionID - 1} với lệnh ${coverLastResult(lastResult)}.
|
||||
⏰ Vào lệnh: ${enterOrder.time}
|
||||
💰 Thua: ${CONFIG.moneyEnterOrder[enterOrder.ind]}$
|
||||
💰 Tổng: ${d.demoBalance - CONFIG.moneyEnterOrder[enterOrder.ind]}$
|
||||
Bạn sẽ vào lệnh ở phiên tiếp theo(${enterOrder.sessionID})!`,
|
||||
{ parse_mode: "HTML" }
|
||||
);
|
||||
d.demoBalance -= CONFIG.moneyEnterOrder[enterOrder.ind];
|
||||
} else {
|
||||
// Reset
|
||||
enterOrder = {
|
||||
enable: false,
|
||||
ind: -1, // Lần vào lệnh thua
|
||||
trend: -1, // Lệnh vào
|
||||
sessionID: -1, // Phiên vào lệnh
|
||||
time: '', // Tgian vào lệnh
|
||||
}
|
||||
TeleGlobal.sendMessage(
|
||||
TELEGRAM_CHANNEL,
|
||||
`Bạn đã thua hết số vốn cài đặt. Hệ thống sẽ không tự động đánh nữa!`,
|
||||
{ parse_mode: "HTML" }
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function drawHistory() {
|
||||
return `
|
||||
${coverLastResult(CONFIG.historys[0])} ${coverLastResult(CONFIG.historys[4])} ${coverLastResult(CONFIG.historys[8])} ${coverLastResult(CONFIG.historys[12])} ${coverLastResult(CONFIG.historys[16])} ${coverLastResult(CONFIG.historys[20])} ${coverLastResult(CONFIG.historys[24])} ${coverLastResult(CONFIG.historys[28])} ${coverLastResult(CONFIG.historys[32])} ${coverLastResult(CONFIG.historys[36])}
|
||||
${coverLastResult(CONFIG.historys[1])} ${coverLastResult(CONFIG.historys[5])} ${coverLastResult(CONFIG.historys[9])} ${coverLastResult(CONFIG.historys[13])} ${coverLastResult(CONFIG.historys[17])} ${coverLastResult(CONFIG.historys[21])} ${coverLastResult(CONFIG.historys[25])} ${coverLastResult(CONFIG.historys[29])} ${coverLastResult(CONFIG.historys[33])} ${coverLastResult(CONFIG.historys[37])}
|
||||
${coverLastResult(CONFIG.historys[2])} ${coverLastResult(CONFIG.historys[6])} ${coverLastResult(CONFIG.historys[10])} ${coverLastResult(CONFIG.historys[14])} ${coverLastResult(CONFIG.historys[18])} ${coverLastResult(CONFIG.historys[22])} ${coverLastResult(CONFIG.historys[26])} ${coverLastResult(CONFIG.historys[30])} ${coverLastResult(CONFIG.historys[34])} ${coverLastResult(CONFIG.historys[38])}
|
||||
${coverLastResult(CONFIG.historys[3])} ${coverLastResult(CONFIG.historys[7])} ${coverLastResult(CONFIG.historys[11])} ${coverLastResult(CONFIG.historys[15])} ${coverLastResult(CONFIG.historys[19])} ${coverLastResult(CONFIG.historys[23])} ${coverLastResult(CONFIG.historys[27])} ${coverLastResult(CONFIG.historys[31])} ${coverLastResult(CONFIG.historys[35])} ${coverLastResult(CONFIG.historys[39])}
|
||||
`;
|
||||
}
|
||||
|
||||
/**
|
||||
* Lấy trạng thái nến
|
||||
* @param resultArg - kết quả nến
|
||||
* @returns - icon nến
|
||||
*/
|
||||
function coverLastResult(resultArg) {
|
||||
if (typeof resultArg === "undefined") return "⚪️";
|
||||
switch (typeof resultArg === "number" ? resultArg : resultArg.lastResult) {
|
||||
case 0:
|
||||
return "🟢";
|
||||
case 1:
|
||||
return "🔴";
|
||||
case 2:
|
||||
return "🏳️️";
|
||||
|
||||
default:
|
||||
return "⚪";
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user