-
Notifications
You must be signed in to change notification settings - Fork 2
/
Bot8.js
509 lines (424 loc) · 24.1 KB
/
Bot8.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
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
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
// Copyright Ananou Kevin 2022
// Trading Bot to copie trades from binance learderboard into ftx / kraken account
module.exports = require('./libs/pnlManager')
const axios = require('axios');
const TelegramBot = require('node-telegram-bot-api');
const pnlWatcher = require("binance-leaderboard-listener")
const token = '5403941417:AAHLZTets1DDYojOOKDP_4LGVco29HAcFgs';
const bot = new TelegramBot(token, {polling: false});
const cf = require('./cfRestApiV3')
const baseUrl = 'https://futures.kraken.com'
const apiKey = '5dqU/cGLd3fua+cur+O0vp7DtJtwEl03qmY4N2WCqVHXEctqHd2KAytn'
const apiSecret = 'XZsstx1ioEPohljB8mjF+IHiLAncIKOu0kJu1e4tHe7OJnpfAleV7ABhbMrPR7+qpWTcaSBESXRwMEBhKqP+exs6'
const apiKey2 = 'DrjOTDmu8yoVdb4fFi3Vb3wj9gunGMODZe7WgL2Tyr+waIw25lrFpdXB'
const apiSecret2 = 'p0H8mV9Y5C8myk9ujcfiDHtBGymqdQewCF2vswADb5KBhp+6iGuFor/LXcAUsjif/SpCrCeZCGZFd3qPJ2PPo67t'
const requestTimeoutMs = 5000
const cfRest = new cf.CfRestApiV3(baseUrl, apiKey, apiSecret, requestTimeoutMs)
const cfRest2 = new cf.CfRestApiV3(baseUrl, apiKey2, apiSecret2, requestTimeoutMs)
const liste = [cfRest,cfRest2]
const listener = pnlWatcher.listen({
encryptedUid: "91CDA0C27F7A387F7FDA5D0CA4781194",
delay: 5000,
tradeType: "PERPETUAL"
})
const name = "Anonymous User-4eb68"
console.log("Bot Lancé");
var alldata = []
var alldata2 = []
var number = 0
var firstSize = {}
var firstPrice = {}
var MT4Size = {}
var firstTime = {}
var wins = 0
var trades = 0
var actualSize = 0
const order = async (namecurrency,sens,reduceOnly,sizeof, name, entryPrice, updateTime) =>
{
for (let i = 0; i < liste.length; i++)
{
try
{
var balance = 0
var size = 0
var nameOfSide = "long"
let impossible = false
if(sens === "BUY")
{
nameOfSide = "short"
}
if(namecurrency === "BTC")
{
namecurrency = "xbt"
}
await liste[i].getAccounts().then(async result =>
{
balance = JSON.parse(result.body).accounts.flex.balanceValue
await liste[i].getOpenPositions().then(result => JSON.parse(result.body)["openPositions"].map(position =>
{
if(!reduceOnly && position.symbol === "pf_"+namecurrency.toLowerCase()+"usd" && position.side === nameOfSide )
{
impossible = true
console.log("Another trade in the other direction already exist !")
}
else if (reduceOnly && position.symbol === "pf_"+namecurrency.toLowerCase()+"usd")
{
size = position.size
if(i === 0)
{
actualSize = size
console.log("Actual Size : " + actualSize)
}
}
}))
if(!impossible)
{
if(!reduceOnly)
{
size = balance * 0.20 / sizeof
}
console.log("Size of " + i + " : " + size)
await liste[i].sendOrder("mkt",sens.toLowerCase(), size.toFixed(3),"pf_"+namecurrency.toLowerCase()+"usd",reduceOnly).then(async result => {
if(size !== 0 && JSON.parse(result.body).hasOwnProperty("sendStatus") && JSON.parse(result.body).sendStatus.status === "invalidSize" )
{
await liste[i].sendOrder("mkt",sens.toLowerCase(), size.toFixed(2),"pf_"+namecurrency.toLowerCase()+"usd",reduceOnly).then(async result => {
if(JSON.parse(result.body).hasOwnProperty("sendStatus") && JSON.parse(result.body).sendStatus.status == "invalidSize")
{
await liste[i].sendOrder("mkt",sens.toLowerCase(), size.toFixed(1),"pf_"+namecurrency.toLowerCase()+"usd",reduceOnly).then(async result => {
if(JSON.parse(result.body).hasOwnProperty("sendStatus") && JSON.parse(result.body).sendStatus.status == "invalidSize")
{
await liste[i].sendOrder("mkt",sens.toLowerCase(), size.toFixed(0),"pf_"+namecurrency.toLowerCase()+"usd",reduceOnly).then(result => {
if(JSON.parse(result.body).hasOwnProperty("sendStatus") && JSON.parse(result.body).sendStatus.status == "invalidSize")
{
console.log("Can't open this order")
}
}
)
}
}
)
}
}
)
}
if(!reduceOnly && size !== 0 && !JSON.parse(result.body).hasOwnProperty("error") && i === 0)
{
firstSize[name] = size
firstPrice[name] = entryPrice
firstTime[name] = updateTime
console.log("Variables initialised with success ! ")
}
})
}
})
} catch (e)
{
console.error('Order problem : ', e);
}
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////// MT4 ///////////////////////////////////////////////////////////////////////////////////
try {
let MT4name = ""
if(namecurrency === "DOGE")
{
MT4name = "DOG"
}
else{
MT4name = namecurrency
}
if(!reduceOnly)
{
var balanceMT4 = 0
await axios.get("https://mt-client-api-v1.london.agiliumtrade.ai/users/current/accounts/36c532e6-1652-458d-818e-0a029d33466d/accountInformation",
{headers : {
"auth-token" : "eyJhbGciOiJSUzUxMiIsInR5cCI6IkpXVCJ9.eyJfaWQiOiJiNzhkNTllNWUzY2EyNzk2MGIzYWY0MTIyODI0ZjBhMCIsInBlcm1pc3Npb25zIjpbXSwidG9rZW5JZCI6IjIwMjEwMjEzIiwiaWF0IjoxNjY4NzAzMDgwLCJyZWFsVXNlcklkIjoiYjc4ZDU5ZTVlM2NhMjc5NjBiM2FmNDEyMjgyNGYwYTAifQ.HjxPLfeOlY_Ggrf5_5rS5V6edXwGJrhtk8NG5KuFPQTaa0bbfu9GvkND5U6CrN9W1LoITJWOeGv4Ut578vtwpE61EHOFIhkHmNfZMYY2qbgJPsvVO7E8B1TdzAXSiOWkTBjx__ANzb7RV5mClG53HsV4nTgoIJqd3AJnASwWCWWOFF3OTtyfihojx1iJUb9T7qalb8a2SwhfKqTcqxw7J0egggWSFKXkTsX4wVgGMINdHeZmqo8Xd38yR-hGQNgGtbF0xT8TkUM3uG41tlAtqIUW-Sl_nJxvwPNVPkU6IoaRQR0kOQLtYSqu1dJsn8KaSPvy-nusiv52ujOpmRk0UDPodQz8xdCqlGP0n1Ie9qnTjxg6BQxwii1tzJ1-7vIYw2Tib0r4LwMARLb74S_UJ3lh568bNNa82xhEJXZSXALQWdCEbwg_iLKfuBCBkSRj4oAhwngv4k-H7S5lQFM83nDjKF9E_q_VtiXlWP2tfJELpCwLsMIhfIKxlzudImxa6UK93jklZ1uw-x3jgRoyO4Bxq3NwKEGNPskynY_Q1tVXBEuZaGrT3I48gzEsGOC8_9lo3KahISLv2UqiLAG70Z_bw3ZH_wBgKQlwhfC7Gj5rGmYWX2ZTNpQSQT0r2Zw_eSHeWRoyX3e8v0TXDpnetDiymfOjersCtu2kiU6_7LY"
}
},
{
"accountId": "36c532e6-1652-458d-818e-0a029d33466d"
}
).then(result => balanceMT4 = result.data.balance);
let sizeMT4 = 0.05 * (balanceMT4/1000).toFixed(0)
if(balanceMT4 < 1000)
{
sizeMT4 = 0.01
}
await axios.post("https://mt-client-api-v1.london.agiliumtrade.ai/users/current/accounts/36c532e6-1652-458d-818e-0a029d33466d/trade",
{
"actionType": "ORDER_TYPE_" + sens,
"symbol": MT4name+"USD",
"volume": sizeMT4
},
{headers : {
"Content-Type": "application/json",
"auth-token" : "eyJhbGciOiJSUzUxMiIsInR5cCI6IkpXVCJ9.eyJfaWQiOiJiNzhkNTllNWUzY2EyNzk2MGIzYWY0MTIyODI0ZjBhMCIsInBlcm1pc3Npb25zIjpbXSwidG9rZW5JZCI6IjIwMjEwMjEzIiwiaWF0IjoxNjY4NzAzMDgwLCJyZWFsVXNlcklkIjoiYjc4ZDU5ZTVlM2NhMjc5NjBiM2FmNDEyMjgyNGYwYTAifQ.HjxPLfeOlY_Ggrf5_5rS5V6edXwGJrhtk8NG5KuFPQTaa0bbfu9GvkND5U6CrN9W1LoITJWOeGv4Ut578vtwpE61EHOFIhkHmNfZMYY2qbgJPsvVO7E8B1TdzAXSiOWkTBjx__ANzb7RV5mClG53HsV4nTgoIJqd3AJnASwWCWWOFF3OTtyfihojx1iJUb9T7qalb8a2SwhfKqTcqxw7J0egggWSFKXkTsX4wVgGMINdHeZmqo8Xd38yR-hGQNgGtbF0xT8TkUM3uG41tlAtqIUW-Sl_nJxvwPNVPkU6IoaRQR0kOQLtYSqu1dJsn8KaSPvy-nusiv52ujOpmRk0UDPodQz8xdCqlGP0n1Ie9qnTjxg6BQxwii1tzJ1-7vIYw2Tib0r4LwMARLb74S_UJ3lh568bNNa82xhEJXZSXALQWdCEbwg_iLKfuBCBkSRj4oAhwngv4k-H7S5lQFM83nDjKF9E_q_VtiXlWP2tfJELpCwLsMIhfIKxlzudImxa6UK93jklZ1uw-x3jgRoyO4Bxq3NwKEGNPskynY_Q1tVXBEuZaGrT3I48gzEsGOC8_9lo3KahISLv2UqiLAG70Z_bw3ZH_wBgKQlwhfC7Gj5rGmYWX2ZTNpQSQT0r2Zw_eSHeWRoyX3e8v0TXDpnetDiymfOjersCtu2kiU6_7LY" }
},
)
MT4Size[MT4name+"USD"] = sizeMT4
console.log(MT4Size[MT4name+"USD"])
}
else
{
var positions = []
await axios.get("https://mt-client-api-v1.london.agiliumtrade.ai/users/current/accounts/36c532e6-1652-458d-818e-0a029d33466d/positions",
{headers : {
"auth-token" : "eyJhbGciOiJSUzUxMiIsInR5cCI6IkpXVCJ9.eyJfaWQiOiJiNzhkNTllNWUzY2EyNzk2MGIzYWY0MTIyODI0ZjBhMCIsInBlcm1pc3Npb25zIjpbXSwidG9rZW5JZCI6IjIwMjEwMjEzIiwiaWF0IjoxNjY4NzAzMDgwLCJyZWFsVXNlcklkIjoiYjc4ZDU5ZTVlM2NhMjc5NjBiM2FmNDEyMjgyNGYwYTAifQ.HjxPLfeOlY_Ggrf5_5rS5V6edXwGJrhtk8NG5KuFPQTaa0bbfu9GvkND5U6CrN9W1LoITJWOeGv4Ut578vtwpE61EHOFIhkHmNfZMYY2qbgJPsvVO7E8B1TdzAXSiOWkTBjx__ANzb7RV5mClG53HsV4nTgoIJqd3AJnASwWCWWOFF3OTtyfihojx1iJUb9T7qalb8a2SwhfKqTcqxw7J0egggWSFKXkTsX4wVgGMINdHeZmqo8Xd38yR-hGQNgGtbF0xT8TkUM3uG41tlAtqIUW-Sl_nJxvwPNVPkU6IoaRQR0kOQLtYSqu1dJsn8KaSPvy-nusiv52ujOpmRk0UDPodQz8xdCqlGP0n1Ie9qnTjxg6BQxwii1tzJ1-7vIYw2Tib0r4LwMARLb74S_UJ3lh568bNNa82xhEJXZSXALQWdCEbwg_iLKfuBCBkSRj4oAhwngv4k-H7S5lQFM83nDjKF9E_q_VtiXlWP2tfJELpCwLsMIhfIKxlzudImxa6UK93jklZ1uw-x3jgRoyO4Bxq3NwKEGNPskynY_Q1tVXBEuZaGrT3I48gzEsGOC8_9lo3KahISLv2UqiLAG70Z_bw3ZH_wBgKQlwhfC7Gj5rGmYWX2ZTNpQSQT0r2Zw_eSHeWRoyX3e8v0TXDpnetDiymfOjersCtu2kiU6_7LY"
}
},
{
"accountId": "36c532e6-1652-458d-818e-0a029d33466d"
}
).then(result => positions = result.data);
positions.forEach(async element => {
if(element.symbol === MT4name+"USD" && element.type !== "POSITION_TYPE_"+sens)
{
await axios.post("https://mt-client-api-v1.london.agiliumtrade.ai/users/current/accounts/36c532e6-1652-458d-818e-0a029d33466d/trade",
{
"actionType": "POSITIONS_CLOSE_SYMBOL",
"symbol": MT4name+"USD"
},
{headers : {
"Content-Type": "application/json",
"auth-token" : "eyJhbGciOiJSUzUxMiIsInR5cCI6IkpXVCJ9.eyJfaWQiOiJiNzhkNTllNWUzY2EyNzk2MGIzYWY0MTIyODI0ZjBhMCIsInBlcm1pc3Npb25zIjpbXSwidG9rZW5JZCI6IjIwMjEwMjEzIiwiaWF0IjoxNjY4NzAzMDgwLCJyZWFsVXNlcklkIjoiYjc4ZDU5ZTVlM2NhMjc5NjBiM2FmNDEyMjgyNGYwYTAifQ.HjxPLfeOlY_Ggrf5_5rS5V6edXwGJrhtk8NG5KuFPQTaa0bbfu9GvkND5U6CrN9W1LoITJWOeGv4Ut578vtwpE61EHOFIhkHmNfZMYY2qbgJPsvVO7E8B1TdzAXSiOWkTBjx__ANzb7RV5mClG53HsV4nTgoIJqd3AJnASwWCWWOFF3OTtyfihojx1iJUb9T7qalb8a2SwhfKqTcqxw7J0egggWSFKXkTsX4wVgGMINdHeZmqo8Xd38yR-hGQNgGtbF0xT8TkUM3uG41tlAtqIUW-Sl_nJxvwPNVPkU6IoaRQR0kOQLtYSqu1dJsn8KaSPvy-nusiv52ujOpmRk0UDPodQz8xdCqlGP0n1Ie9qnTjxg6BQxwii1tzJ1-7vIYw2Tib0r4LwMARLb74S_UJ3lh568bNNa82xhEJXZSXALQWdCEbwg_iLKfuBCBkSRj4oAhwngv4k-H7S5lQFM83nDjKF9E_q_VtiXlWP2tfJELpCwLsMIhfIKxlzudImxa6UK93jklZ1uw-x3jgRoyO4Bxq3NwKEGNPskynY_Q1tVXBEuZaGrT3I48gzEsGOC8_9lo3KahISLv2UqiLAG70Z_bw3ZH_wBgKQlwhfC7Gj5rGmYWX2ZTNpQSQT0r2Zw_eSHeWRoyX3e8v0TXDpnetDiymfOjersCtu2kiU6_7LY" }
},
)
}
});
delete MT4Size[MT4name+"USD"]
}
} catch (error) {
console.error('Order problem MT4 : ', error);
}
}
const orderModify = async (namecurrency,sens,reduceOnly,sizeof) =>
{
for (let i = 0; i < liste.length; i++)
{
try
{
var sizeOfCurrentPosition = 0
if(namecurrency === "BTC")
{
namecurrency = "xbt"
}
await liste[i].getOpenPositions().then(result => JSON.parse(result.body)["openPositions"].map(position => {
if(position.symbol === "pf_"+namecurrency.toLowerCase()+"usd")
{
sizeOfCurrentPosition = position.size
}
}))
console.log("Size " + sizeOfCurrentPosition)
console.log("Adding or remove " + sizeOfCurrentPosition * sizeof)
await liste[i].sendOrder("mkt",sens.toLowerCase(), Math.abs(sizeOfCurrentPosition * sizeof).toFixed(3),"pf_"+namecurrency.toLowerCase()+"usd",reduceOnly).then(async result => {
if(sizeOfCurrentPosition !== 0 && JSON.parse(result.body).hasOwnProperty("sendStatus") && JSON.parse(result.body).sendStatus.status === "invalidSize" )
{
await liste[i].sendOrder("mkt",sens.toLowerCase(), Math.abs(sizeOfCurrentPosition * sizeof).toFixed(2),"pf_"+namecurrency.toLowerCase()+"usd",reduceOnly).then(async result => {
if(JSON.parse(result.body).hasOwnProperty("sendStatus") && JSON.parse(result.body).sendStatus.status == "invalidSize")
{
await liste[i].sendOrder("mkt",sens.toLowerCase(), Math.abs(sizeOfCurrentPosition * sizeof).toFixed(1),"pf_"+namecurrency.toLowerCase()+"usd",reduceOnly).then(async result => {
if(JSON.parse(result.body).hasOwnProperty("sendStatus") && JSON.parse(result.body).sendStatus.status == "invalidSize")
{
await liste[i].sendOrder("mkt",sens.toLowerCase(), Math.abs(sizeOfCurrentPosition * sizeof).toFixed(0),"pf_"+namecurrency.toLowerCase()+"usd",reduceOnly).then(result => {
if(JSON.parse(result.body).hasOwnProperty("sendStatus") && JSON.parse(result.body).sendStatus.status == "invalidSize")
{
console.log("Can't open this order")
}
}
)
}
}
)
}
}
)
}
}
)
} catch (e)
{
console.error('OrderModify problem : ', e);
}
}
////////////////////////////////////////////////////////////////////////////// MT4 ////////////////////////////////////////////
try {
let MT4name = ""
if(namecurrency === "xbt")
{
MT4name = "BTC"
}
else if(namecurrency === "DOGE")
{
MT4name = "DOG"
}
else{
MT4name = namecurrency
}
if(!reduceOnly && MT4Size.hasOwnProperty(MT4name+"USD"))
{
let sizeModified = MT4Size[MT4name+"USD"] * sizeof
await axios.post("https://mt-client-api-v1.london.agiliumtrade.ai/users/current/accounts/36c532e6-1652-458d-818e-0a029d33466d/trade",
{
"actionType": "ORDER_TYPE_" + sens,
"symbol": MT4name+"USD",
"volume": sizeModified
},
{headers : {
"Content-Type": "application/json",
"auth-token" : "eyJhbGciOiJSUzUxMiIsInR5cCI6IkpXVCJ9.eyJfaWQiOiJiNzhkNTllNWUzY2EyNzk2MGIzYWY0MTIyODI0ZjBhMCIsInBlcm1pc3Npb25zIjpbXSwidG9rZW5JZCI6IjIwMjEwMjEzIiwiaWF0IjoxNjY4NzAzMDgwLCJyZWFsVXNlcklkIjoiYjc4ZDU5ZTVlM2NhMjc5NjBiM2FmNDEyMjgyNGYwYTAifQ.HjxPLfeOlY_Ggrf5_5rS5V6edXwGJrhtk8NG5KuFPQTaa0bbfu9GvkND5U6CrN9W1LoITJWOeGv4Ut578vtwpE61EHOFIhkHmNfZMYY2qbgJPsvVO7E8B1TdzAXSiOWkTBjx__ANzb7RV5mClG53HsV4nTgoIJqd3AJnASwWCWWOFF3OTtyfihojx1iJUb9T7qalb8a2SwhfKqTcqxw7J0egggWSFKXkTsX4wVgGMINdHeZmqo8Xd38yR-hGQNgGtbF0xT8TkUM3uG41tlAtqIUW-Sl_nJxvwPNVPkU6IoaRQR0kOQLtYSqu1dJsn8KaSPvy-nusiv52ujOpmRk0UDPodQz8xdCqlGP0n1Ie9qnTjxg6BQxwii1tzJ1-7vIYw2Tib0r4LwMARLb74S_UJ3lh568bNNa82xhEJXZSXALQWdCEbwg_iLKfuBCBkSRj4oAhwngv4k-H7S5lQFM83nDjKF9E_q_VtiXlWP2tfJELpCwLsMIhfIKxlzudImxa6UK93jklZ1uw-x3jgRoyO4Bxq3NwKEGNPskynY_Q1tVXBEuZaGrT3I48gzEsGOC8_9lo3KahISLv2UqiLAG70Z_bw3ZH_wBgKQlwhfC7Gj5rGmYWX2ZTNpQSQT0r2Zw_eSHeWRoyX3e8v0TXDpnetDiymfOjersCtu2kiU6_7LY" }
},
)
MT4Size[MT4name+"USD"] += sizeModified
}
} catch (error) {
console.error('Order problem MT4 : ', error);
}
}
listener.on('update', (data) =>
{
try
{
if(number === 0 && data != null)
{
data.map((newdata) => {alldata.push(newdata); alldata2.push(newdata)})
number ++
}
else
{
alldata2 = [];
if(data != null)
{
data.map((newdata) => {alldata2.push(newdata)})
}
if(alldata2.length > alldata.length) //if there is a new trade
{
console.log(alldata.length + " trade(s) to " + alldata2.length)
alldata2.map(newList =>
{
if(alldata.some(oldList => newList.symbol === oldList.symbol) === false)
{
let sens = "SELL"
let fleche = "⬇"
let namecurrency = newList.symbol.slice(0,-4)
if(newList.amount > 0) //BUY trade
{
sens = "BUY"
fleche = "⬆"
}
order(namecurrency,sens,false,newList.markPrice, newList.symbol, newList.entryPrice, newList.updateTime);
console.log("New order " + newList.symbol +" " + newList.entryPrice + " " +(new Date()).toGMTString())
bot.sendMessage("-1001769991025", "🔱 Author " + name + "\n" + fleche + " OPEN " + sens + " " + newList.symbol +"\nPrice " + newList.entryPrice.toFixed(4))
}
})
alldata = alldata2
}
else if(alldata2.length < alldata.length)
{
console.log(alldata.length + " trade(s) to " + alldata2.length)
alldata.map(async oldList =>
{
if (alldata2.some(newList => oldList.symbol === newList.symbol) === false)
{
let Pourcentage;
if(oldList.amount < 0)
{
Pourcentage = (oldList.entryPrice - oldList.markPrice)/oldList.entryPrice * 100
if(firstPrice.hasOwnProperty(oldList.symbol) === true)
{
PourcentageFirst = (firstPrice[oldList.symbol] - oldList.markPrice)/oldList.entryPrice * 100
}
}
else{
Pourcentage = (oldList.markPrice - oldList.entryPrice)/oldList.entryPrice * 100
if(firstPrice.hasOwnProperty(oldList.symbol) === true)
{
PourcentageFirst = (oldList.markPrice - firstPrice[oldList.symbol])/oldList.entryPrice * 100
}
}
let smyle =""
if(Pourcentage > 0)
{
smyle = "✅"
wins += 1
}
else
{
smyle = "❌"
}
let sens = "BUY"
if(oldList.amount > 0){
sens = "SELL"
}
let namecurrency = oldList.symbol.slice(0,-4)
await order(namecurrency,sens,true,oldList.markPrice, oldList.symbol, oldList.entryPrice, oldList.updateTime);
trades += 1
console.log("Order Closed" + oldList.symbol +" " + oldList.markPrice + " " +(new Date()).toGMTString())
if(firstSize.hasOwnProperty(oldList.symbol))
{
bot.sendMessage("-1001769991025","🔱 Author " + name + "\n" + "🛑 CLOSE " + oldList.symbol +"\nPrice " + oldList.markPrice.toFixed(4) + "\n" + smyle + " Percentage : " + (Pourcentage*(actualSize / firstSize[oldList.symbol])).toFixed(2) + "%" + "\n" + "📊" + " With 20% of capital : " + (20 * (Pourcentage*(actualSize / firstSize[oldList.symbol])/100)).toFixed(2) + "%")
delete firstSize[oldList.symbol]
delete firstPrice[oldList.symbol]
delete firstTime[oldList.symbol]
}
else
{
bot.sendMessage("-1001769991025","🔱 Author " + name + "\n" + "🛑 CLOSE " + oldList.symbol +"\nPrice " + oldList.markPrice.toFixed(4) + "\n" + smyle + " Percentage : " + Pourcentage.toFixed(2) + "%" + "\n" + "📊" + " With 20% of capital : " + (20 * Pourcentage / 100).toFixed(2) + "%" )
}
}
})
alldata = alldata2
}
else if(alldata2.length === alldata.length)
{
for (let i = 0; i < alldata2.length; i++)
{
if(alldata2[i].amount !== alldata[i].amount && alldata2[i].symbol === alldata[i].symbol)
{
let check = true
let namecurrency = alldata[i].symbol.slice(0,-4)
let sens = "BUY"
let reduceOnly = false
let change = ((alldata2[i].amount - alldata[i].amount)/alldata[i].amount * 100).toFixed(0)
if(alldata[i].amount > 0 && change > 0)
{
sens = "BUY"
}
else if (alldata[i].amount > 0 && change < 0)
{
check = false
sens = "SELL"
reduceOnly = true
change = change - change*2
}
else if (alldata[i].amount < 0 && change < 0)
{
check = false
sens = "BUY"
reduceOnly = true
change = change - change*2
}
else if (alldata[i].amount < 0 && change > 0)
{
sens = "SELL"
}
if(firstTime.hasOwnProperty(alldata2[i].symbol) && ( (parseInt(firstTime[alldata2[i].symbol][3]) === parseInt(alldata2[i].updateTime[3]) && parseInt(firstTime[alldata2[i].symbol][4]) < parseInt(alldata2[i].updateTime[4])) || (parseInt(firstTime[alldata2[i].symbol][3]) !== parseInt(alldata2[i].updateTime[3]))) && check && change >= 10 ) //check if the trade with opened by this trader
{
console.log("Modification sent")
orderModify(namecurrency,sens,reduceOnly,(change/100));
}
else{
console.log("Modification skiped")
}
console.log("Size modified for " + alldata2[i].symbol +" by " + (alldata2[i].amount - alldata[i].amount)/alldata[i].amount * 100 + "% " + alldata[i].amount + " to " + alldata2[i].amount + "\nLast entryPrice " + alldata[i].entryPrice + " New entryPrice " + alldata2[i].entryPrice + " " +(new Date()).toGMTString())
alldata = alldata2
}
else
{
alldata[i].markPrice = alldata2[i].markPrice
}
}
}
}
} catch (error) {
console.error('Order problem : ', error);
}
})