-
Notifications
You must be signed in to change notification settings - Fork 6
/
main.js
331 lines (296 loc) · 13.9 KB
/
main.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
const fs = require('fs');
const path = require('path');
const axios = require('axios');
const colors = require('colors');
const readline = require('readline');
class OKX {
headers() {
return {
"Accept": "application/json",
"Accept-Encoding": "gzip, deflate, br, zstd",
"Accept-Language": "en-US,en;q=0.9",
"App-Type": "web",
"Content-Type": "application/json",
"Origin": "https://www.okx.com",
"Referer": "https://www.okx.com/mini-app/racer?tgWebAppStartParam=linkCode_88910038",
"Sec-Ch-Ua": '"Not/A)Brand";v="8", "Chromium";v="126", "Microsoft Edge";v="126"',
"Sec-Ch-Ua-Mobile": "?0",
"Sec-Ch-Ua-Platform": '"Windows"',
"Sec-Fetch-Dest": "empty",
"Sec-Fetch-Mode": "cors",
"Sec-Fetch-Site": "same-origin",
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/126.0.0.0 Safari/537.36 Edg/126.0.0.0",
"X-Cdn": "https://www.okx.com",
"X-Locale": "en_US",
"X-Utc": "7",
"X-Zkdex-Env": "0"
};
}
async postToOKXAPI(extUserId, extUserName, queryId) {
const url = `https://www.okx.com/priapi/v1/affiliate/game/racer/info?t=${Date.now()}`;
const headers = { ...this.headers(), 'X-Telegram-Init-Data': queryId };
const payload = {
"extUserId": extUserId,
"extUserName": extUserName,
"gameId": 1,
"linkCode": "88910038"
};
return axios.post(url, payload, { headers });
}
async assessPrediction(extUserId, predict, queryId) {
const url = `https://www.okx.com/priapi/v1/affiliate/game/racer/assess?t=${Date.now()}`;
const headers = { ...this.headers(), 'X-Telegram-Init-Data': queryId };
const payload = {
"extUserId": extUserId,
"predict": predict,
"gameId": 1
};
return axios.post(url, payload, { headers });
}
async checkDailyRewards(extUserId, queryId) {
const url = `https://www.okx.com/priapi/v1/affiliate/game/racer/tasks?t=${Date.now()}`;
const headers = { ...this.headers(), 'X-Telegram-Init-Data': queryId };
try {
const response = await axios.get(url, { headers });
const tasks = response.data.data;
const dailyCheckInTask = tasks.find(task => task.id === 4);
if (dailyCheckInTask) {
if (dailyCheckInTask.state === 0) {
this.log('Start checkin ...');
await this.performCheckIn(extUserId, dailyCheckInTask.id, queryId);
} else {
this.log('Today you have attended!');
}
}
} catch (error) {
this.log(`Daily reward check error: ${error.message}`);
}
}
async performCheckIn(extUserId, taskId, queryId) {
const url = `https://www.okx.com/priapi/v1/affiliate/game/racer/task?t=${Date.now()}`;
const headers = { ...this.headers(), 'X-Telegram-Init-Data': queryId };
const payload = {
"extUserId": extUserId,
"id": taskId
};
try {
await axios.post(url, payload, { headers });
this.log('Daily attendance successfully!');
} catch (error) {
this.log(`Error: ${error.message}`);
}
}
log(msg) {
console.log(`[*] ${msg}`);
}
async sleep(ms) {
return new Promise(resolve => setTimeout(resolve, ms));
}
async waitWithCountdown(seconds) {
for (let i = seconds; i >= 0; i--) {
readline.cursorTo(process.stdout, 0);
process.stdout.write(`===== Completed all accounts, waiting ${i} seconds to continue the loop =====`);
await new Promise(resolve => setTimeout(resolve, 1000));
}
console.log('');
}
async Countdown(seconds) {
for (let i = seconds; i >= 0; i--) {
readline.cursorTo(process.stdout, 0);
process.stdout.write(`[*] Wait ${i} Seconds to continue ...`);
await new Promise(resolve => setTimeout(resolve, 1000));
}
console.log('');
}
extractUserData(queryId) {
const urlParams = new URLSearchParams(queryId);
const user = JSON.parse(decodeURIComponent(urlParams.get('user')));
return {
extUserId: user.id,
extUserName: user.username
};
}
async getBoosts(queryId) {
const url = `https://www.okx.com/priapi/v1/affiliate/game/racer/boosts?t=${Date.now()}`;
const headers = { ...this.headers(), 'X-Telegram-Init-Data': queryId };
try {
const response = await axios.get(url, { headers });
return response.data.data;
} catch (error) {
console.log(`BOOSTS Information Error: ${error.message}`);
return [];
}
}
async useBoost(queryId) {
const url = `https://www.okx.com/priapi/v1/affiliate/game/racer/boost?t=${Date.now()}`;
const headers = { ...this.headers(), 'X-Telegram-Init-Data': queryId };
const payload = { id: 1 };
try {
const response = await axios.post(url, payload, { headers });
if (response.data.code === 0) {
this.log('Reload Fuel Tank Success!!'.yellow);
await this.Countdown(5);
} else {
this.log(`Reload Fuel Tank Failed: ${response.data.msg}`.red);
}
} catch (error) {
this.log(`Error: ${error.message}`.red);
}
}
async upgradeFuelTank(queryId) {
const url = `https://www.okx.com/priapi/v1/affiliate/game/racer/boost?t=${Date.now()}`;
const headers = { ...this.headers(), 'X-Telegram-Init-Data': queryId };
const payload = { id: 2 };
try {
const response = await axios.post(url, payload, { headers });
if (response.data.code === 0) {
this.log('Successful Fuel Tank upgrade!'.yellow);
} else {
this.log(`Fuel tank upgrade error: ${response.data.msg}`.red);
}
} catch (error) {
this.log(`Error: ${error.message}`.red);
}
}
async upgradeTurbo(queryId) {
const url = `https://www.okx.com/priapi/v1/affiliate/game/racer/boost?t=${Date.now()}`;
const headers = { ...this.headers(), 'X-Telegram-Init-Data': queryId };
const payload = { id: 3 };
try {
const response = await axios.post(url, payload, { headers });
if (response.data.code === 0) {
this.log('Successful Turbo Charger upgrade!'.yellow);
} else {
this.log(`Turbo Charger upgrade error: ${response.data.msg}`.red);
}
} catch (error) {
this.log(`Error: ${error.message}`.red);
}
}
async getCurrentPrice() {
const url = 'https://www.okx.com/api/v5/market/ticker?instId=BTC-USDT';
try {
const response = await axios.get(url);
if (response.data.code === '0' && response.data.data && response.data.data.length > 0) {
return parseFloat(response.data.data[0].last);
} else {
throw new Error('Error when taking the current price');
}
} catch (error) {
throw new Error(`The current price error: ${error.message}`);
}
}
askQuestion(query) {
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout
});
return new Promise(resolve => rl.question(query, ans => {
rl.close();
resolve(ans);
}));
}
async main() {
const dataFile = path.join(__dirname, 'data.txt');
const userData = fs.readFileSync(dataFile, 'utf8')
.replace(/\r/g, '')
.split('\n')
.filter(Boolean);
const nangcapfueltank = await this.askQuestion('Do you want to upgrade Fuel Tank?(y/n): ');
const hoinangcap = nangcapfueltank.toLowerCase() === 'y';
const nangcapturbo = await this.askQuestion('Do you want to upgrade Turbo Charger?(y/n): ');
const hoiturbo = nangcapturbo.toLowerCase() === 'y';
while (true) {
for (let i = 0; i < userData.length; i++) {
const queryId = userData[i];
const { extUserId, extUserName } = this.extractUserData(queryId);
try {
console.log(`========== Account ${i + 1} | ${extUserName} ==========`.blue);
await this.checkDailyRewards(extUserId, queryId);
let boosts = await this.getBoosts(queryId);
boosts.forEach(boost => {
this.log(`${boost.context.name.green}: ${boost.curStage}/${boost.totalStage}`);
});
let reloadFuelTank = boosts.find(boost => boost.id === 1);
let fuelTank = boosts.find(boost => boost.id === 2);
let turbo = boosts.find(boost => boost.id === 3);
if (fuelTank && hoinangcap) {
const balanceResponse = await this.postToOKXAPI(extUserId, extUserName, queryId);
const balancePoints = balanceResponse.data.data.balancePoints;
if (fuelTank.curStage < fuelTank.totalStage && balancePoints > fuelTank.pointCost) {
await this.upgradeFuelTank(queryId);
boosts = await this.getBoosts(queryId);
const updatedFuelTank = boosts.find(boost => boost.id === 2);
const updatebalanceResponse = await this.postToOKXAPI(extUserId, extUserName, queryId);
const updatedBalancePoints = updatebalanceResponse.data.data.balancePoints;
if (updatedFuelTank.curStage >= fuelTank.totalStage || updatedBalancePoints < fuelTank.pointCost) {
this.log('Not eligible to upgrade Fuel Tank!'.red);
continue;
}
} else {
this.log('Not eligible to upgrade Fuel Tank!'.red);
}
}
if (turbo && hoiturbo) {
const balanceResponse = await this.postToOKXAPI(extUserId, extUserName, queryId);
const balancePoints = balanceResponse.data.data.balancePoints;
if (turbo.curStage < turbo.totalStage && balancePoints > turbo.pointCost) {
await this.upgradeTurbo(queryId);
boosts = await this.getBoosts(queryId);
const updatedTurbo = boosts.find(boost => boost.id === 3);
const updatebalanceResponse = await this.postToOKXAPI(extUserId, extUserName, queryId);
const updatedBalancePoints = updatebalanceResponse.data.data.balancePoints;
if (updatedTurbo.curStage >= turbo.totalStage || updatedBalancePoints < turbo.pointCost) {
this.log('Upgrading Turbo Charger failed!'.red);
continue;
}
} else {
this.log('Not eligible to upgrade Turbo Charger!'.red);
}
}
while (true) {
const price1 = await this.getCurrentPrice();
await this.sleep(4000);
const price2 = await this.getCurrentPrice();
let predict;
let action;
if (price1 > price2) {
predict = 0; // Sell
action = 'Sell';
} else {
predict = 1; // Buy
action = 'First';
}
const response = await this.postToOKXAPI(extUserId, extUserName, queryId);
const balancePoints = response.data.data.balancePoints;
this.log(`${'Balance Points:'.green} ${balancePoints}`);
const assessResponse = await this.assessPrediction(extUserId, predict, queryId);
const assessData = assessResponse.data.data;
const result = assessData.won ? 'Win'.green : 'Lose'.red;
const calculatedValue = assessData.basePoint * assessData.multiplier;
this.log(`Forecast ${action} | Result: ${result} x ${assessData.multiplier}! Balance: ${assessData.balancePoints}, Receive: ${calculatedValue}, Old price: ${assessData.prevPrice}, Current price: ${assessData.currentPrice}`.magenta);
if (assessData.numChance > 0) {
await this.Countdown(1);
} else if (assessData.numChance <= 0 && reloadFuelTank && reloadFuelTank.curStage < reloadFuelTank.totalStage) {
await this.useBoost(queryId);
boosts = await this.getBoosts(queryId);
reloadFuelTank = boosts.find(boost => boost.id === 1);
} else {
break;
}
}
} catch (error) {
this.log(`${'Error:'.red} ${error.message}`);
}
}
await this.waitWithCountdown(600);
}
}
}
if (require.main === module) {
const okx = new OKX();
okx.main().catch(err => {
console.error(err.toString().red);
process.exit(1);
});
}