Skip to content

Commit 5f1fdc0

Browse files
committed
async command controle with telegram
1 parent 752d23a commit 5f1fdc0

File tree

3 files changed

+77
-31
lines changed

3 files changed

+77
-31
lines changed

lib/telegram.js

Lines changed: 53 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,62 @@
11

22
import { TelegramBot, ENV } from "../deps.js";
33
const { TOKEN_TELEGRAM } = ENV;
4+
export default (hooks) => {
5+
const bot = new TelegramBot(TOKEN_TELEGRAM);
6+
// Error handler
7+
bot.use(async (ctx, next) => {
8+
try {
9+
await next(ctx);
10+
} catch (err) {
11+
console.error(err.message);
12+
}
13+
});
414

5-
export const bot = new TelegramBot(TOKEN_TELEGRAM);
6-
// Error handler
7-
bot.use(async (ctx, next) => {
8-
try {
9-
await next(ctx);
10-
} catch (err) {
11-
console.error(err.message);
12-
}
13-
});
14-
/*
15-
bot.on("text", async (ctx) => {
16-
const text = ctx.message?.text;
15+
bot.on("text", async (ctx) => {
16+
const text = ctx.message?.text;
1717

18-
if (text === "/start") {
19-
await ctx.reply("HI, Im Deno Trad Bot");
20-
}
18+
//console.info(ctx.message)
19+
/*
20+
{
21+
message_id: 64,
22+
from: {
23+
id: 1664500170,
24+
is_bot: false,
25+
first_name: "Bot",
26+
last_name: "Js",
27+
username: "bot_js",
28+
language_code: "fr"
29+
},
30+
chat: {
31+
id: 1664500170,
32+
first_name: "Bot",
33+
last_name: "Js",
34+
username: "bot_js",
35+
type: "private"
36+
},
37+
date: 1622945574,
38+
text: "hfhghh"
39+
}
40+
*/
41+
if (text === "/connect") {
42+
hooks.dataConnect = text;
43+
await ctx.reply("HI, Im Deno Trading Bot \n https://github.com/Zizwar/deno-trading-bot");
44+
}
2145

22-
if (text === "/stars" || text === "/stars@DenoBot") {
46+
if (text === "/stars" || text === "/stars@DenoBot")
47+
await ctx.reply(`Stars: :star:`);
2348

24-
await ctx.reply(`Stars: :star:`);
25-
}
49+
const has = (val) => text.includes(val)
50+
if (has('$:')) {
2651

27-
});
52+
if (has("buy:"))
53+
hooks.dataConnect = 'buy'
54+
if (has("stop:"))
55+
hooks.dataConnect = "stop"
56+
}
2857

29-
bot.launch();
30-
*/
58+
});
59+
60+
bot.launch();
61+
return bot;
62+
}

main.js

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ const { INTERVAL_TIME = 1 } = ENV;
44

55
const denoBot = new DenoBot();
66
const ping = await denoBot.ping;
7-
console.log("isDenoBotConectToFutures="+ping ? "yes :)":"no :(")
7+
console.log("isDenoBotConectToFutures=" + ping ? "conect denoBot :)" : "no conect denoBot :(")
88
denoBot.stratigy = "onlyRsis";
99
//const balanceUSDT = await denoBot.getBalance("USDT");
1010
//const balanceBUSD = await denoBot.getBalance("BUSD");
@@ -46,10 +46,10 @@ console.info(
4646
)
4747
*/
4848
//console.log(await denoBot.binance.withdrawHistory())
49-
/*
50-
setInterval(async _ => {
49+
///*
50+
const _thisInterval = setInterval(async _ => {
5151
const options = {
52-
candeles: { symbol: "DOGEUSDT",interval:"3m" }
52+
candeles: { symbol: "DOGEUSDT", interval: "5m" }
5353
}
5454
const listenMyCoins = await denoBot.listenCoins(options);
5555
const action = denoBot.action(listenMyCoins);
@@ -82,8 +82,14 @@ stratigy=${stratigy}
8282
console.error(error)
8383
}
8484
}
85+
const dataConnect = denoBot.dataConnect
86+
console.log({ action, dataConnect})
87+
if(dataConnect==="stop"){
88+
clearInterval(_thisInterval)
89+
console.warn('Stop Deno Bot')
90+
}
8591
// denoBot.postMessageSlacK(action)
86-
console.log({ action, ...listenMyCoins })
92+
//console.log({ action, ...listenMyCoins })
8793
}, INTERVAL_TIME * 1000)
8894

8995
//*/

wino/denoBot.js

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { BinanceApi, Technicalindicators, SlackApi, ENV } from '../deps.js';
22
import { OnlyRsis } from './stratigy/index.js'
3-
import { bot as TelegramBot } from "../lib/telegram.js";
3+
import TelegramBot from "../lib/telegram.js";
44
const { API_KEY_BINANCE, API_SECRET_BINANCE, TOKEN_SLACK, CHANEL_SLACK, ID_CHAT_TELEGRAM } = ENV;
55
//console.info(await Binance.futuresCandles({ symbol: 'BTCUSDT' }));
66
const { SMA, EMA, BollingerBands, RSI, StochasticRSI } = Technicalindicators;
@@ -16,8 +16,10 @@ export default class DenoBot {
1616
test: true
1717
});
1818
//
19-
this.slack = new SlackApi(TOKEN_SLACK)
20-
this.telegramBot = TelegramBot
19+
this.slack = new SlackApi(TOKEN_SLACK);
20+
this._dataConnect = [];
21+
this._telegramBot = TelegramBot(this);
22+
2123
}
2224
async getBalance(symbol = "USDT") {
2325
const balancFutures = await this._binance.futuresAccountBalance();
@@ -30,7 +32,7 @@ export default class DenoBot {
3032
})
3133
}
3234
postMessageTelegram(text) {
33-
return this.telegramBot.telegram.sendMessage({
35+
return this._telegramBot.telegram.sendMessage({
3436
chat_id: ID_CHAT_TELEGRAM,
3537
text,
3638
})
@@ -44,7 +46,7 @@ export default class DenoBot {
4446
}
4547

4648
futuresCandles(args = []) {
47-
const { symbol = "BTCUSDT", interval = '1m', limit = 30 } = args
49+
const { symbol = "BTCUSDT", interval = '5m', limit = 30 } = args
4850
return this._binance.futuresCandles({ symbol, interval, limit })
4951
}
5052

@@ -116,6 +118,12 @@ export default class DenoBot {
116118
get stratigy() {
117119
return this._stratigy
118120
}
121+
set dataConnect(_dataConnect) {
122+
this.__dataConnect = _dataConnect
123+
}
124+
get dataConnect() {
125+
return this.__dataConnect
126+
}
119127
action(properties) {
120128
switch (this._stratigy) {
121129
case "onlyRsis": return OnlyRsis(properties);

0 commit comments

Comments
 (0)