forked from jeffersonlicet/price-prediction-bot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfig.js
61 lines (52 loc) · 1.43 KB
/
config.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
const inquirer = require('inquirer');
const fs = require('fs');
const { error } = require('./utils');
function getConfigFile() {
try {
const configFile = fs.readFileSync('./config.json');
return JSON.parse(configFile);
} catch (ex) {
return null;
}
}
async function generateConfiguration() {
inquirer
.prompt([
{
type: 'input',
name: 'configName',
message: 'Enter a name for your configuration',
default() {
return `My Config`;
},
},
{
type: 'input',
name: 'amountPerTrade',
message: 'Enter the amount per position (BNB)',
default() {
return `0.001`;
},
},
])
.then((res) => {
console.table(res);
console.info(`Config saved as ${res.configName}`);
let existingConfigs;
let result = [];
try {
existingConfigs = fs.readFileSync('config.json', 'utf8');
} catch {}
if (existingConfigs) {
const parsed = JSON.parse(existingConfigs);
if (parsed.find(({ configName }) => configName === res.configName)) {
error('Another config exists with the same name');
return generateConfiguration();
}
result.push(...JSON.parse(existingConfigs));
}
result.push(res);
fs.writeFileSync('config.json', JSON.stringify(result), 'utf8');
});
}
module.exports = { generateConfiguration, getConfigFile };