-
Notifications
You must be signed in to change notification settings - Fork 0
/
_hsvsha_papet_fronttest.js.txt
459 lines (320 loc) · 17 KB
/
_hsvsha_papet_fronttest.js.txt
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
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
require('punycode/')
const fetchAllMarketCapAndCorrelationData = require('./utils/main-bot--GetMArketCap_Corr');
const RetreveTV_Data_MongoDBpush = require('./utils/main-bot--TVretrive'); // Adjust the path as needed
const updateGooglesheets = require('./utils/main-bot--GoogleSheets'); // Adjust the path as needed
const {getValidCredentials} = require('./utils/main-bot__testcredentials'); // Adjust the path as needed
const makeNonprovisionaDailySignal = require('./utils/main-bot--nonProvisional'); // Adjust the path as needed
const {weightedaverage,MultipleWeightedAverage } = require('./utils/main-bot--CalculateWaightedSignals'); // Adjust the path as needed
const {alerts, MakeAlerts ,MakeAlertsFast} = require("./utils/main-bot--alerts");
const {fetchActiveOrders, DisplayBinanceData} = require("./utils/main-bot--bybit");
const { RestClientV5 }= require('bybit-api');
const TradingView = require('@mathieuc/tradingview');
const cron = require('node-cron');
const { MongoClient } = require('mongodb');
// Replace this URI with your MongoDB connection string.
const uri = "_replace_";
const client = new MongoClient(uri);
async function connectToMongoDB() {
try {
await client.connect();
console.log("Connected successfully to MongoDB");
} catch (error) {
console.error(`Connection to MongoDB failed: ${error}`);
}
}
// Connect to MongoDB when the application starts
connectToMongoDB();
async function main3(id,certificate) {
const dbname="HSVSHA_paper_fronttest"
const type_mybe_provisional = "summary_data_for_"
const type_mybe_provisional2 = "no_provisional_summary_"
const indicator_id = "USER;91bdff47320b4284a375f428f683b21e"
const timeframes = ['4H','12H','1D', '2D', '3D', '4D', '5D', '6D', 'W', '1M'];
let markets = [
'BYBIT:TIAUSDT.P',
'BYBIT:ROSEUSDT.P', 'BYBIT:BANDUSDT.P',
'BYBIT:ENJUSDT.P', 'BYBIT:1INCHUSDT.P',
'BYBIT:MINAUSDT.P',
'BYBIT:RNDRUSDT.P',
'BYBIT:ALGOUSDT.P',
'BYBIT:BAKEUSDT.P', 'BYBIT:AXSUSDT.P',
'BYBIT:ONDOUSDT.P', 'BYBIT:OPUSDT.P',
'BYBIT:CFXUSDT.P', 'BYBIT:DOGEUSDT.P',
'BYBIT:LDOUSDT.P', 'BYBIT:UNIUSDT.P'
]; // const markets = ['BYBIT:BTCUSDT.P','BYBIT:ETHUSDT.P'];
const sheetTitle = "HSVSHA"; // gogle sheets Replace with your sheet title
const spreadsheetId = "";
// await RetreveTV_Data_MongoDBpush(client_bybit,client,markets,timeframes,indicator_id,id,certificate,dbname); // check if fata exist and not call it
// await makeNonprovisionaDailySignal(client,markets,timeframes,dbname);
// await updateGooglesheets( client,markets, timeframes, type_mybe_provisional,sheetTitle,spreadsheetId);
// const apiKey = '_replace_';
// const url_coinbase = 'https://pro-api.coinmarketcap.com/v1/cryptocurrency/quotes/latest';
// const cryptoSymbols = ['BTC', 'ETH','SOL']; // Ensure this is an array
// const periods = [5];
// const marketCapAndCorrelationData = await fetchAllMarketCapAndCorrelationData(client, dbname, apiKey, url_coinbase, cryptoSymbols, periods);
// console.log('Market Cap and Correlation Data:', marketCapAndCorrelationData);
// const btc = marketCapAndCorrelationData['BTC_MarketCap'];
// const eth = marketCapAndCorrelationData['ETH_MarketCap'];
// const sol = marketCapAndCorrelationData['SOL_MarketCap'];
// console.log('BTC Market Cap:', btc);
// console.log('ETH Market Cap:', eth);
// console.log('SOL Market Cap:', sol);
console.log("done");
// // Define multiple sets of weights
// const weightsSets = [
// [1, 1,1,1,1,1,1,1,1,1],
// [5, 0,1,1,0,1,5,1,1,1] // Example set 1
// // ... add more sets of weights as needed ...
// ];
// MakeAlertsFast(markets, weightsSets, client, type_mybe_provisional, timeframes,webhookUrl);
// const allocations = {
// 'MATICUSDT': 0.5, // 50% allocation
// 'ENJUSDT': 0.5 // 50% allocation
// };
let leverage = '2.8';
let NofCoins = 18;
let lev = 1.2;
let weights_no_prov = [66.78, 33.75, 39.98, 37.35, 32.12, 46.02,0, 0, 29.86, 20.05]; // Example weights
let weights_prov = [1.00,5.00,5.00,5.00,0,5.00,0,0,1.00,2.00]; // Example weights
let webhookUrl = 'https://discord.com/api/webhooks/12286Rl0lGvrJKAT8sWu';
//DisplayBinanceData(client_bybit,webhookUrl,lev);
let client_tv = new TradingView.Client({ token: id, signature: certificate });
// await TraderBotS(client,client_tv, client_bybit, weights_no_prov,weights_prov, indicator_id, id, certificate, dbname, markets, timeframes, webhookUrl,lev,NofCoins,leverage)
// //MakeAlerts(markets, weights_prov, client, type_mybe_provisional, timeframes,webhookUrl,"ProvisionalBottomAlts", 0);
// await sleep(1500 );
// MakeAlerts(markets, weights_no_prov, client, type_mybe_provisional2, timeframes,webhookUrl,"NotProvisionalBottomAlts",0);
// await sleep(1500 );
// updateGooglesheets( client,markets, timeframes, type_mybe_provisional,"PBottomAlts",spreadsheetId);
// await sleep(1500 );
// updateGooglesheets( client,markets, timeframes, type_mybe_provisional2,"NoPlBottomAlts",spreadsheetId);
// DisplayBinanceData(client_bybit,webhookUrl,lev);
markets = ['BYBIT:BTCUSDT.P', 'BYBIT:ETHUSDT.P'];
weights_prov = [1.25 ,13.00, 1.25, 2.19, 1.10, 4.06, 1.10, 1.10, 1.00, 1.06]; // Example weights
weights_no_prov =[66.78, 33.75, 39.98, 37.35,0, 46.02,0, 0, 29.86, 20.05]; // Example weights
lev = 1.2;
NofCoins = 2;
client_tv.end();
client_tv = new TradingView.Client({ token: id, signature: certificate });
//DisplayBinanceData(client_bybit,webhookUrl,lev);
await RetreveTV_Data_MongoDBpush(client_tv,client, markets, timeframes, indicator_id, id, certificate, dbname);
await makeNonprovisionaDailySignal(client, markets, timeframes, dbname);
await sleep(2500 );
MakeAlerts(markets, weights_prov, client, type_mybe_provisional, timeframes,webhookUrl,"ProvisionalGiants",2);
await sleep(1500 );
MakeAlerts(markets, weights_no_prov, client, type_mybe_provisional2, timeframes,webhookUrl,"NoProvisionalGiants",2);
await sleep(1500 );
updateGooglesheets( client,markets, timeframes, type_mybe_provisional,"PGiants2"+sheetTitle,spreadsheetId);
await sleep(1500 );
updateGooglesheets( client,markets, timeframes, type_mybe_provisional2,"NoPGiants2"+sheetTitle,spreadsheetId);
//DisplayBinanceData(client_bybit,webhookUrl,lev);
markets = ['BYBIT:MATICUSDT.P','BYBIT:SOLUSDT.P','BYBIT:BNBUSDT.P','BYBIT:XRPUSDT.P','BYBIT:ADAUSDT.P','BYBIT:AVAXUSDT.P','BYBIT:TRXUSDT.P','BYBIT:DOTUSDT.P','BYBIT:LINKUSDT.P','BYBIT:TONUSDT.P','BYBIT:ICPUSDT.P','BYBIT:LTCUSDT.P','BYBIT:BCHUSDT.P','BYBIT:ATOMUSDT.P','BYBIT:UNIUSDT.P','BYBIT:XLMUSDT.P','BYBIT:NEARUSDT.P','BYBIT:AAVEUSDT.P'];
//weights_no_prov = [0 ,1, 2.00, 7.00, 0, 2.00, 0, 0, 1, 0]; // Example weights
//weights_prov = [1.00,5.00,5.00,5.00,0,5.00,0,0,1.00,2.00]; // Example weights
lev = 1.2;
NofCoins = 18;
client_tv.end();
client_tv = new TradingView.Client({ token: id, signature: certificate });
//DisplayBinanceData(client_bybit,webhookUrl,lev);
await RetreveTV_Data_MongoDBpush(client_tv,client, markets, timeframes, indicator_id, id, certificate, dbname);
await makeNonprovisionaDailySignal(client, markets, timeframes, dbname);
await sleep(2500 );
await MakeAlerts(markets, weights_prov, client, type_mybe_provisional, timeframes,webhookUrl,"ProvisionalTopAlts",0);
await sleep(1500 );
await MakeAlerts(markets, weights_no_prov, client, type_mybe_provisional2, timeframes,webhookUrl,"NotProvisionalTopAlts",0);
await sleep(1500 );
await updateGooglesheets( client,markets, timeframes, type_mybe_provisional,"PlTopAlts"+sheetTitle,spreadsheetId);
await sleep(1500 );
await updateGooglesheets( client,markets, timeframes, type_mybe_provisional2,"NotPTopAlts"+sheetTitle,spreadsheetId);
//DisplayBinanceData(client_bybit,webhookUrl,lev);
console.log('DONE');
client_tv.end();
markets = [
'BYBIT:TIAUSDT.P',
'BYBIT:ROSEUSDT.P', 'BYBIT:BANDUSDT.P',
'BYBIT:ENJUSDT.P', 'BYBIT:1INCHUSDT.P',
'BYBIT:MINAUSDT.P',
'BYBIT:RNDRUSDT.P',
'BYBIT:ALGOUSDT.P',
'BYBIT:BAKEUSDT.P', 'BYBIT:AXSUSDT.P',
'BYBIT:ONDOUSDT.P', 'BYBIT:OPUSDT.P',
'BYBIT:CFXUSDT.P', 'BYBIT:DOGEUSDT.P',
'BYBIT:LDOUSDT.P', 'BYBIT:UNIUSDT.P'
];
key = "_replace_";
secret = "_replace_"; // lowcaps
client_bybit = new RestClientV5({
key: key,
secret: secret,
});
// const allocations = {
// 'MATICUSDT': 0.5, // 50% allocation
// 'ENJUSDT': 0.5 // 50% allocation
// };
NofCoins = 18;
lev = 1.2;
//weights_no_prov = [0 ,1, 2.00, 7.00, 0, 2.00, 0, 0, 1, 0]; // Example weights
//weights_prov = [1 ,2, 3.00, 7.00, 0, 2.00, 0, 0, 1, 0];; // Example weights
//DisplayBinanceData(client_bybit,webhookUrl,lev);
client_tv = new TradingView.Client({ token: id, signature: certificate });
await RetreveTV_Data_MongoDBpush(client_tv,client, markets, timeframes, indicator_id, id, certificate, dbname);
await makeNonprovisionaDailySignal(client, markets, timeframes, dbname);
await sleep(2500 );
MakeAlerts(markets, weights_prov, client, type_mybe_provisional, timeframes,webhookUrl,"ProvisionalBottomAlts", 0);
await sleep(1500 );
MakeAlerts(markets, weights_no_prov, client, type_mybe_provisional2, timeframes,webhookUrl,"NotProvisionalBottomAlts",0);
await sleep(1500 );
updateGooglesheets( client,markets, timeframes, type_mybe_provisional,"PBottomAlts"+sheetTitle,spreadsheetId);
await sleep(1500 );
updateGooglesheets( client,markets, timeframes, type_mybe_provisional2,"NoPlBottomAlts"+sheetTitle,spreadsheetId);
//DisplayBinanceData(client_bybit,webhookUrl,lev);
client_tv.end();
console.log('DONE');
}
async function abs(a){
if (a>0) { return a}
return -a
}
function delay(ms) {
return new Promise(resolve => setTimeout(resolve, ms));
}
async function TraderBotS(client,client_tv, client_bybit, weights_no_prov,weights_prov, indicator_id, id, certificate, dbname, markets, timeframes, webhookUrl, lev, NofCoins, leverage) {
const type_mybe_provisional = "provisional_summary_";
const type_mybe_provisional2 = "no_provisional_summary_";
const processMarket = async (market) => {
try {
console.log(`Starting operations for market: ${market}`);
await RetreveTV_Data_MongoDBpush(client_tv,client, [market], timeframes, indicator_id, id, certificate, dbname);
await makeNonprovisionaDailySignal(client, [market], timeframes, dbname);
await sleep(2500 );
const weight = await weightedaverage(market, weights_prov, client, type_mybe_provisional, timeframes, 0);
const weight2 = await weightedaverage(market, weights_no_prov, client, type_mybe_provisional2, timeframes, 0);
let signal = 0;
if (weight !== 0) {
signal = weight / Math.abs(weight)
}
if (weight2 !== 0) {
signal += weight2 / Math.abs(weight2) ;
}
signal /=2;
let coin_bybit = market.split(':')[1].replace('.P', '');
let allocationKey = coin_bybit.replace('.P', '');
const allocations = { [allocationKey]: signal / NofCoins };
await fetchActiveOrders(client_bybit, [market], allocations, webhookUrl, leverage, NofCoins, lev);
await sleep(2500 );
// Uncomment these if alerts are needed
// MakeAlerts([market], weights, client, type_mybe_provisional, timeframes, webhookUrl);
// MakeAlerts([market], weights, client, type_mybe_provisional2, timeframes, webhookUrl);
console.log(`Operations completed for market: ${market}`);
} catch (error) {
console.error(`Error in processing market: ${market}:`, error);
}
}
for (const market of markets) {
processMarket(market);
// Wait for 10 seconds before starting the next market
await delay(10000);
}
console.log('All markets initiated.');
}
async function TraderBotSalts(client,client_tv, client_bybit, weights_no_prov,weights_prov, indicator_id, id, certificate, dbname, markets, timeframes, webhookUrl, lev, NofCoins, leverage, marketCapAndCorrelationData) {
const type_mybe_provisional = "summary_data_for_";
const type_mybe_provisional2 = "no_provisional_summary_";
//markets = ['BYBIT:BTCUSDT.P', 'BYBIT:ETHUSDT.P'];
const weight2btc = await weightedaverage('BYBIT:BTCUSDT.P', weights_prov, client, type_mybe_provisional2, timeframes, 0);
const weight2eth = await weightedaverage('BYBIT:ETHUSDT.P', weights_prov, client, type_mybe_provisional2, timeframes, 0);
const weight2sol = await weightedaverage('BYBIT:SOLUSDT.P', weights_prov, client, type_mybe_provisional2, timeframes, 0);
const btc = marketCapAndCorrelationData['BTC_MarketCap'];
const eth = marketCapAndCorrelationData['ETH_MarketCap'];
const sol = marketCapAndCorrelationData['SOL_MarketCap'];
console.log('BTC Market Cap:', btc);
console.log('ETH Market Cap:', eth);
console.log('SOL Market Cap:', sol);
const giants = (btc*weight2btc + eth*weight2eth + sol*weight2sol ) / (btc+eth+sol);
const processMarket = async (market) => {
try {
console.log(`Starting operations for market: ${market}`);
await RetreveTV_Data_MongoDBpush(client_tv,client, [market], timeframes, indicator_id, id, certificate, dbname);
await makeNonprovisionaDailySignal(client, [market], timeframes, dbname);
await sleep(2500 );
//const weight = await weightedaverage(market, weights_prov, client, type_mybe_provisional, timeframes, 0);
const weight2 = await weightedaverage(market, weights_no_prov, client, type_mybe_provisional2, timeframes, 0);
let signal = 0;
console.log(giants );
if (Math.abs(giants) > 0.0769) {
signal = giants / Math.abs(giants)
}
console.log(signal );
signal /=3;
console.log(weight2);
if (weight2 !== 0) {
signal += weight2 / Math.abs(weight2) ;
}
signal /=1.33;
console.log(signal );
let coin_bybit = market.split(':')[1].replace('.P', '');
let allocationKey = coin_bybit.replace('.P', '');
const allocations = { [allocationKey]: signal / NofCoins };
await fetchActiveOrders(client_bybit, [market], allocations, webhookUrl, leverage, NofCoins, lev);
await sleep(2500 );
// Uncomment these if alerts are needed
// MakeAlerts([market], weights, client, type_mybe_provisional, timeframes, webhookUrl);
// MakeAlerts([market], weights, client, type_mybe_provisional2, timeframes, webhookUrl);
console.log(`Operations completed for market: ${market}`);
} catch (error) {
console.error(`Error in processing market: ${market}:`, error);
}
}
for (const market of markets) {
processMarket(market);
// Wait for 10 seconds before starting the next market
await delay(10000);
}
console.log('All markets initiated.');
}
function sleep(ms) {
return new Promise(resolve => setTimeout(resolve, ms));
}
const { promisify } = require('util');
const setTimeoutPromise = promisify(setTimeout);
async function M() {
const id = "fyb8tc8yps6ju7uarv8vippr62gsi7l5";
const certificate = "v2:WFPAGDvBqzuPp0YrFtMXiovmN5fJAvfgMytaPpLeIKI=";
// Run main3 with a timeout of 15 minutes (1800000 milliseconds)
const main3Promise = main3(id, certificate);
const timeoutPromise = setTimeoutPromise(1800000, 'Timeout');
try {
await Promise.race([main3Promise, timeoutPromise]);
} catch (error) {
if (error === 'Timeout') {
console.log('main3 function timed out after 15 minutes.');
} else {
console.error('Error in main3:', error);
}
}
console.log('DONE');
}
// async function M(){
// // const credentials = await getValidCredentials()
// // const id = credentials.session
// // const certificate = credentials.signature
// const id = "fyb8tc8yps6ju7uarv8vippr62gsi7l5";
// const certificate = "v2:WFPAGDvBqzuPp0YrFtMXiovmN5fJAvfgMytaPpLeIKI=";
// //if (false){
// await main3(id,certificate)
// //}
// }
// M();
// Schedule M to run every 4 hours
cron.schedule('30 */4 * * *', () => {
console.log('Running M every 4 hours');
connectToMongoDB();
M();
});
console.log('Running M every 4 hours startig 00:01 UTC');
console.log('Running M every 4 hours startig 00:01 UTC');
console.log('Running M every 4 hours startig 00:01 UTC');
console.log('Running M every 4 hours startig 00:01 UTC');
console.log('Running M every 4 hours startig 00:01 UTC');
console.log('Running M every 4 hours startig 00:01 UTC');
console.log('Running M every 4 hours startig 00:01 UTC');
M();