rsibot-utils 1.5.8 → 1.5.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/db.js +15 -5
- package/index.js +61 -14
- package/package.json +1 -1
package/db.js
CHANGED
@@ -15,9 +15,20 @@ const hotCoinsSchema = new Schema(
|
|
15
15
|
const activeSchema = new Schema(
|
16
16
|
{
|
17
17
|
symbol: { type: String, unique: true },
|
18
|
-
inPosition:
|
19
|
-
lastBuy:
|
20
|
-
abandoned:
|
18
|
+
inPosition: Boolean ,
|
19
|
+
lastBuy: Number ,
|
20
|
+
abandoned: Boolean ,
|
21
|
+
},
|
22
|
+
{
|
23
|
+
versionKey: false,
|
24
|
+
},
|
25
|
+
);
|
26
|
+
const suspendedSchema = new Schema(
|
27
|
+
{
|
28
|
+
symbol: String,
|
29
|
+
lastStatus: String,
|
30
|
+
percentChange: Number,
|
31
|
+
created: { type: Date, default: Date.now },
|
21
32
|
},
|
22
33
|
{
|
23
34
|
versionKey: false,
|
@@ -65,12 +76,12 @@ const models = {
|
|
65
76
|
Historical:undefined,
|
66
77
|
}
|
67
78
|
|
68
|
-
|
69
79
|
const dbArray = [
|
70
80
|
{ tableName:'hot_coins',name: 'HotCoin', schema: hotCoinsSchema },
|
71
81
|
{ tableName:'active_coins',name: 'ActiveCoin', schema: activeSchema },
|
72
82
|
{ tableName:'queue_coins',name: 'Queue', schema: queueSchema },
|
73
83
|
{ tableName:'historical_coins',name: 'Historical', schema: historicalSchema },
|
84
|
+
{ tableName:'suspended_coins',name: 'Suspended', schema: suspendedSchema },
|
74
85
|
];
|
75
86
|
|
76
87
|
dbArray.forEach(({name,schema,tableName }) => {
|
@@ -81,5 +92,4 @@ dbArray.forEach(({name,schema,tableName }) => {
|
|
81
92
|
}
|
82
93
|
})
|
83
94
|
|
84
|
-
|
85
95
|
module.exports = models;
|
package/index.js
CHANGED
@@ -2,7 +2,7 @@ const fs = require('fs');
|
|
2
2
|
const path = require('path');
|
3
3
|
const util = require('util');
|
4
4
|
const exec = util.promisify(require('child_process').exec);
|
5
|
-
const { HotCoin, ActiveCoin, Queue, Historical } = require('./db');
|
5
|
+
const { HotCoin, ActiveCoin, Queue, Historical, Suspended } = require('./db');
|
6
6
|
const CNAME = process.env.CNAME;
|
7
7
|
const LOGS_PATH = CNAME ? `${CNAME}_logs.txt` : 'host_logs.txt';
|
8
8
|
|
@@ -27,7 +27,7 @@ async function execute(command) {
|
|
27
27
|
write(`${stdout}`);
|
28
28
|
return stdout;
|
29
29
|
} catch (error) {
|
30
|
-
write(error,true);
|
30
|
+
write(error, true);
|
31
31
|
throw Error(error);
|
32
32
|
}
|
33
33
|
}
|
@@ -40,7 +40,7 @@ async function insertHotCoin({ symbol }) {
|
|
40
40
|
await newHotCoin.save();
|
41
41
|
return symbol;
|
42
42
|
} catch (error) {
|
43
|
-
write(error.stack,true);
|
43
|
+
write(error.stack, true);
|
44
44
|
return false;
|
45
45
|
}
|
46
46
|
}
|
@@ -49,7 +49,7 @@ async function getHotCoins() {
|
|
49
49
|
const results = await HotCoin.find();
|
50
50
|
return results;
|
51
51
|
} catch (error) {
|
52
|
-
write(error.stack,true);
|
52
|
+
write(error.stack, true);
|
53
53
|
return [];
|
54
54
|
}
|
55
55
|
}
|
@@ -58,7 +58,7 @@ async function removeHotCoin(symbol) {
|
|
58
58
|
await HotCoin.deleteOne({ symbol });
|
59
59
|
return symbol;
|
60
60
|
} catch (error) {
|
61
|
-
write(error.stack,true);
|
61
|
+
write(error.stack, true);
|
62
62
|
return false;
|
63
63
|
}
|
64
64
|
}
|
@@ -68,7 +68,7 @@ async function getActiveCoins() {
|
|
68
68
|
const results = await ActiveCoin.find();
|
69
69
|
return results;
|
70
70
|
} catch (error) {
|
71
|
-
write(error.stack,true);
|
71
|
+
write(error.stack, true);
|
72
72
|
return [];
|
73
73
|
}
|
74
74
|
}
|
@@ -81,7 +81,7 @@ async function getQueue() {
|
|
81
81
|
return [];
|
82
82
|
}
|
83
83
|
} catch (error) {
|
84
|
-
write(error.stack,true);
|
84
|
+
write(error.stack, true);
|
85
85
|
return [];
|
86
86
|
}
|
87
87
|
}
|
@@ -92,7 +92,7 @@ async function setQueue(queue) {
|
|
92
92
|
const newQueue = new Queue({ queue });
|
93
93
|
await newQueue.save();
|
94
94
|
} catch (error) {
|
95
|
-
write(error.stack,true);
|
95
|
+
write(error.stack, true);
|
96
96
|
}
|
97
97
|
}
|
98
98
|
}
|
@@ -104,7 +104,7 @@ async function removeCoin(symbol, queue) {
|
|
104
104
|
const newQueue = new Queue({ queue: modifiedQueue });
|
105
105
|
await newQueue.save();
|
106
106
|
} catch (error) {
|
107
|
-
write(error.stack,true);
|
107
|
+
write(error.stack, true);
|
108
108
|
}
|
109
109
|
}
|
110
110
|
function initQueueListener() {
|
@@ -115,7 +115,7 @@ async function getAbandonedCoins() {
|
|
115
115
|
const abandonedCoins = await ActiveCoin.find({ abandoned: true });
|
116
116
|
return abandonedCoins && [];
|
117
117
|
} catch (error) {
|
118
|
-
write(error.stack,true);
|
118
|
+
write(error.stack, true);
|
119
119
|
return [];
|
120
120
|
}
|
121
121
|
}
|
@@ -124,30 +124,74 @@ async function createNewHistory(coinObj) {
|
|
124
124
|
const newHistory = new Historical(coinObj);
|
125
125
|
await newHistory.save();
|
126
126
|
} catch (error) {
|
127
|
-
write(error.stack,true);
|
127
|
+
write(error.stack, true);
|
128
128
|
}
|
129
129
|
}
|
130
130
|
async function deleteHotCoins() {
|
131
131
|
try {
|
132
132
|
await HotCoin.deleteMany({ symbol: { $exists: true } });
|
133
133
|
} catch (error) {
|
134
|
-
write(error.stack,true);
|
134
|
+
write(error.stack, true);
|
135
135
|
}
|
136
136
|
}
|
137
137
|
async function deleteActiveCoins() {
|
138
138
|
try {
|
139
139
|
await ActiveCoin.deleteMany({ symbol: { $exists: true } });
|
140
140
|
} catch (error) {
|
141
|
-
write(error,true);
|
141
|
+
write(error, true);
|
142
142
|
}
|
143
143
|
}
|
144
144
|
async function deleteQueueCoins() {
|
145
145
|
try {
|
146
146
|
await Queue.deleteMany({ created: { $exists: true } });
|
147
147
|
} catch (error) {
|
148
|
-
write(error.stack,true);
|
148
|
+
write(error.stack, true);
|
149
149
|
}
|
150
150
|
}
|
151
|
+
async function deleteQueueCoins() {
|
152
|
+
try {
|
153
|
+
await Queue.deleteMany({ created: { $exists: true } });
|
154
|
+
} catch (error) {
|
155
|
+
write(error.stack, true);
|
156
|
+
}
|
157
|
+
}
|
158
|
+
async function deleteSuspendCoin(id) {
|
159
|
+
try {
|
160
|
+
await Suspended.findByIdAndDelete(id);
|
161
|
+
} catch (error) {
|
162
|
+
write(error.stack, true);
|
163
|
+
}
|
164
|
+
}
|
165
|
+
|
166
|
+
async function createSuspendedCoin(coinObj) {
|
167
|
+
try {
|
168
|
+
const suspendedCoin = new Suspended(coinObj);
|
169
|
+
await suspendedCoin.save();
|
170
|
+
} catch (error) {
|
171
|
+
write(error.stack, true);
|
172
|
+
}
|
173
|
+
}
|
174
|
+
|
175
|
+
async function getSuspendedCoins() {
|
176
|
+
try {
|
177
|
+
const abandonedCoins = await Suspended.find();
|
178
|
+
return abandonedCoins;
|
179
|
+
} catch (error) {
|
180
|
+
write(error.stack, true);
|
181
|
+
return [];
|
182
|
+
}
|
183
|
+
}
|
184
|
+
|
185
|
+
function suspendedWatcher(seconds) {
|
186
|
+
setInterval(async () => {
|
187
|
+
try {
|
188
|
+
await Suspended.deleteMany({ created: { $lte: new Date(new Date().getTime() - 1 * 60 * 60 * 1000) } });
|
189
|
+
} catch (error) {
|
190
|
+
write(error);
|
191
|
+
}
|
192
|
+
}, seconds);
|
193
|
+
}
|
194
|
+
|
151
195
|
module.exports = {
|
152
196
|
sortByPercent,
|
153
197
|
write,
|
@@ -166,4 +210,7 @@ module.exports = {
|
|
166
210
|
deleteHotCoins,
|
167
211
|
deleteActiveCoins,
|
168
212
|
deleteQueueCoins,
|
213
|
+
createSuspendedCoin,
|
214
|
+
deleteSuspendCoin,
|
215
|
+
getSuspendedCoins,
|
169
216
|
};
|