-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
315 lines (242 loc) ยท 9.04 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
process.removeAllListeners('warning');
const { Contract, utils, BigNumber, ethers } = require("ethers")
const { parseEther } = require("@ethersproject/units");
const sleep = require("util").promisify(setTimeout);
const {
getClaimableEpochs,
getSignals,
getUserData,
percentage,
getStats,
predictionContract,
getBNBPrice,
checkBalance,
reduceWaitingTimeByTwoBlocks,
saveRound,
} = require('./helpers');
const {
TradingViewScan,
SCREENERS_ENUM,
EXCHANGES_ENUM,
INTERVALS_ENUM,
} = require('trading-view-recommends-parser-nodejs');
//Global Config
const GLOBAL_CONFIG = {
BET_AMOUNT: 1, //Bet in USD
STOP_LOSS: 1, //Stop Loss in USD, If the Balance is $1 or less the Bot is Stopped
DAILY_GOAL: 50, //In USD, Daily Goal in BNB
WAITING_TIME: 270000,
THRESHOLD: 54, //% Mandatory For the Bot (60 - 100), The Bot must comply that the % of Raise or Fall is greater than the % that we configure, otherwise that both Raise / Fall is less than the % configured then no bet is made
ESTRATEGIAUSE: 'Standar', //Standar, Avanzada
};
//Bet UP
const betUp = async (amount, epoch) => {
try {
const tx = await predictionContract.betBull(epoch, {
value: parseEther(amount.toFixed(18).toString()),
});
await tx.wait();
console.log(`
๐ค Successful bet of ${amount} BNB to UP[UP] ๐
===============================================================
`);
} catch (error) {
console.error(`
transaction error
`);
GLOBAL_CONFIG.WAITING_TIME = reduceWaitingTimeByTwoBlocks(
GLOBAL_CONFIG.WAITING_TIME
);
}
};
//Bet DOWN
const betDown = async (amount, epoch) => {
try {
const tx = await predictionContract.betBear(epoch, {
value: parseEther(amount.toFixed(18).toString()),
});
await tx.wait();
console.log(`
๐ค Successful bet of ${amount} BNB to DOWN[DOWN] ๐
===============================================================
`);
} catch (error) {
console.error(`
transaction error
`);
GLOBAL_CONFIG.WAITING_TIME = reduceWaitingTimeByTwoBlocks(
GLOBAL_CONFIG.WAITING_TIME
);
}
};
//Claim
const claimMoney = async (epoch,walletAddress) => {
let claimableEpochs = await getClaimableEpochs(predictionContract,epoch,walletAddress);
const gasPrice = 5000000000 //5 Gwei
const gasLimit = 93000 //93000
const optionsGas = {
gasPrice: gasPrice,
gasLimit: gasLimit,
}
try {
const tx = await predictionContract.claim(claimableEpochs,optionsGas);
await tx.wait();
console.log(`
๐ฐ Successful Claim #${epoch.toString()}
===============================================================
`);
} catch (error){
console.error(`
๐ฐ Claim Error #${epoch.toString()}
`);
}
};
const strategy = async (minAcurracy, epoch) => {
let BNBPrice = await getBNBPrice();
let getWalletUserData = await getUserData();
let walletUser = getWalletUserData.wallet;
let balanceWallet = getWalletUserData.saldo;
let stopLossUser = GLOBAL_CONFIG.STOP_LOSS / BNBPrice;
let earnings = await getStats();
await sleep(15000); //Wait 15 Seconds
let dataRond = await predictionContract.functions.rounds(epoch);
let bullTotalRond = dataRond.bullAmount;
let bearTotalRond = dataRond.bearAmount;
console.error(`
===============================================================
UP [${utils.formatUnits(bullTotalRond, '18')} BNB] | DOWN [${utils.formatUnits(bearTotalRond,'18')} BNB]
===============================================================
`);
if(earnings.profit_USD >= GLOBAL_CONFIG.DAILY_GOAL){
console.log(`
===============================================================
๐ง Daily goal achieved. Turning off... โจ
===============================================================
`);
process.exit();
}
//Stop Loss >> Stop If Balance in BNB is Equal to or Less than Stop Loss Set in USD
//if(balanceWallet <= parseFloat(stopLossUser)){
//console.error(`
//===============================================================
// ๐ง STOP LOSS!! $${GLOBAL_CONFIG.STOP_LOSS}[${parseFloat(stopLossUser)} BNB]. Shutting Down Bot To Avoid Losses...
//===============================================================
//`);
//process.exit();
//}
//Stop Loss >> Stop If Balance in BNB is Equal to or Less than Stop Loss Set in USD
let signals = await getSignals();
if(signals){
if (GLOBAL_CONFIG.ESTRATEGIAUSE == 'Standar' && signals.buy > signals.sell && percentage(signals.buy, signals.sell) >= minAcurracy){
console.log(`
===============================================================
Strategy[Standard] Round #${epoch.toString()} ๐ฎ Prediction: UP[UP] ๐ข ${percentage(signals.buy, signals.sell)}% :: Bet Started
`);
await betUp(GLOBAL_CONFIG.BET_AMOUNT / BNBPrice, epoch);
//Save Rond
await saveRound(epoch.toString(), [
{
round: epoch.toString(),
betAmount: (GLOBAL_CONFIG.BET_AMOUNT / BNBPrice).toString(),
bet: "bull",
},
]);
}else if(GLOBAL_CONFIG.ESTRATEGIAUSE == 'Standar' && signals.sell > signals.buy && percentage(signals.sell, signals.buy) >= minAcurracy){
console.log(`
===============================================================
Strategy[Standard] Round #${epoch.toString()} ๐ฎ Prediction: DOWN[DOWN] ๐ด ${percentage(signals.sell, signals.buy)}% :: Bet Started
`);
await betDown(GLOBAL_CONFIG.BET_AMOUNT / BNBPrice, epoch);
//Save Rond
await saveRound(epoch.toString(), [
{
round: epoch.toString(),
betAmount: (GLOBAL_CONFIG.BET_AMOUNT / BNBPrice).toString(),
bet: "bear",
},
]);
}else if(GLOBAL_CONFIG.ESTRATEGIAUSE == 'Avanzada' && bullTotalRond > bearTotalRond && signals.buy > signals.sell && percentage(signals.buy, signals.sell) >= minAcurracy){
console.log(`
===============================================================
Strategy[Advanced] Round #${epoch.toString()} ๐ฎ Prediction: UP[UP] ๐ข ${percentage(signals.buy, signals.sell)}% :: Bet Started
`);
await betUp(GLOBAL_CONFIG.BET_AMOUNT / BNBPrice, epoch);
//Save Rond
await saveRound(epoch.toString(), [
{
round: epoch.toString(),
betAmount: (GLOBAL_CONFIG.BET_AMOUNT / BNBPrice).toString(),
bet: "bull",
},
]);
}else if(GLOBAL_CONFIG.ESTRATEGIAUSE == 'Avanzada' && bearTotalRond > bullTotalRond && signals.sell > signals.buy && percentage(signals.sell, signals.buy) >= minAcurracy){
console.log(`
===============================================================
Strategy[Advanced] Round #${epoch.toString()} ๐ฎ Prediction: DOWN[DOWN] ๐ด ${percentage(signals.sell, signals.buy)}% :: Bet Started
`);
await betDown(GLOBAL_CONFIG.BET_AMOUNT / BNBPrice, epoch);
//Save Rond
await saveRound(epoch.toString(), [
{
round: epoch.toString(),
betAmount: (GLOBAL_CONFIG.BET_AMOUNT / BNBPrice).toString(),
bet: "bear",
},
]);
}else {
let lowPercentage;
let lowPercentageValue;
if(signals.buy > signals.sell){
lowPercentage = percentage(signals.buy, signals.sell);
lowPercentageValue = 'UP[UP] ๐ข';
}else {
lowPercentage = percentage(signals.sell, signals.buy);
lowPercentageValue = 'DOWN[DOWN] ๐ด';
}
console.log(`
===============================================================
Waiting for the next round๐ ${lowPercentageValue} ${lowPercentage} %
===============================================================
`);
}
//Iniciamos Analisis de Apuesta
}else{ //No Obtuvimos Seรฑales
console.log(`Failed to get signals`);
}
};
//Welcome >>
console.log(`๐ค Welcome! waiting for the next round...`);
checkBalance(GLOBAL_CONFIG.BET_AMOUNT);
//Betting >>
predictionContract.on('StartRound', async (epoch) => {
console.log(`
===============================================================
๐ฅ Round for the Bet ${epoch.toString()}
๐ Waiting for ${(GLOBAL_CONFIG.WAITING_TIME / 60000).toFixed(1)} minutes to start bet.
===============================================================
`);
await sleep(GLOBAL_CONFIG.WAITING_TIME);
await strategy(GLOBAL_CONFIG.THRESHOLD, epoch);
});
//Betting >>
//Show stats >>
predictionContract.on('EndRound', async (epoch) => {
let getWalletUserData = await getUserData();
let userWalletGetClaim = getWalletUserData.wallet;
await saveRound(epoch.toString());
let stats = await getStats();
let claimableEpochs = await predictionContract.claimable(epoch, userWalletGetClaim);
if(claimableEpochs){
claimMoney(epoch,userWalletGetClaim);
}
console.log(`
===============================================================
--------------- Stats #${epoch.toString()}-----------------
๐ Fortune: ${stats.percentage}
๐ ${stats.win}|${stats.loss} ๐
๐ฐ Profit: ${stats.profit_USD.toFixed(3)} USD
--------------- Stats -----------------
===============================================================
`);
});
//Show stats >>