rsibot-utils 1.5.7 → 1.5.10
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 +26 -16
- package/index.js +69 -15
- 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,
|
@@ -59,27 +70,26 @@ mongoose
|
|
59
70
|
});
|
60
71
|
|
61
72
|
const models = {
|
62
|
-
HotCoin:undefined,
|
63
|
-
ActiveCoin:undefined,
|
64
|
-
Queue:undefined,
|
65
|
-
Historical:undefined,
|
66
|
-
}
|
67
|
-
|
73
|
+
HotCoin: undefined,
|
74
|
+
ActiveCoin: undefined,
|
75
|
+
Queue: undefined,
|
76
|
+
Historical: undefined,
|
77
|
+
};
|
68
78
|
|
69
79
|
const dbArray = [
|
70
|
-
{ tableName:'hot_coins',name: 'HotCoin', schema: hotCoinsSchema },
|
71
|
-
{ tableName:'active_coins',name: 'ActiveCoin', schema: activeSchema },
|
72
|
-
{ tableName:'queue_coins',name: 'Queue', schema: queueSchema },
|
73
|
-
{ tableName:'historical_coins',name: 'Historical', schema: historicalSchema },
|
80
|
+
{ tableName: 'hot_coins', name: 'HotCoin', schema: hotCoinsSchema },
|
81
|
+
{ tableName: 'active_coins', name: 'ActiveCoin', schema: activeSchema },
|
82
|
+
{ tableName: 'queue_coins', name: 'Queue', schema: queueSchema },
|
83
|
+
{ tableName: 'historical_coins', name: 'Historical', schema: historicalSchema },
|
84
|
+
{ tableName: 'suspended_coins', name: 'Suspended', schema: suspendedSchema },
|
74
85
|
];
|
75
86
|
|
76
|
-
dbArray.forEach(({name,schema,tableName }) => {
|
87
|
+
dbArray.forEach(({ name, schema, tableName }) => {
|
77
88
|
if (mongoose.models[tableName]) {
|
78
89
|
models[name] = mongoose.model(tableName);
|
79
90
|
} else {
|
80
91
|
models[name] = mongoose.model(tableName, schema);
|
81
92
|
}
|
82
|
-
})
|
83
|
-
|
93
|
+
});
|
84
94
|
|
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,17 +58,16 @@ 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
|
}
|
65
|
-
|
66
65
|
async function getActiveCoins() {
|
67
66
|
try {
|
68
67
|
const results = await ActiveCoin.find();
|
69
68
|
return results;
|
70
69
|
} catch (error) {
|
71
|
-
write(error.stack,true);
|
70
|
+
write(error.stack, true);
|
72
71
|
return [];
|
73
72
|
}
|
74
73
|
}
|
@@ -81,7 +80,7 @@ async function getQueue() {
|
|
81
80
|
return [];
|
82
81
|
}
|
83
82
|
} catch (error) {
|
84
|
-
write(error.stack,true);
|
83
|
+
write(error.stack, true);
|
85
84
|
return [];
|
86
85
|
}
|
87
86
|
}
|
@@ -92,7 +91,7 @@ async function setQueue(queue) {
|
|
92
91
|
const newQueue = new Queue({ queue });
|
93
92
|
await newQueue.save();
|
94
93
|
} catch (error) {
|
95
|
-
write(error.stack,true);
|
94
|
+
write(error.stack, true);
|
96
95
|
}
|
97
96
|
}
|
98
97
|
}
|
@@ -104,7 +103,7 @@ async function removeCoin(symbol, queue) {
|
|
104
103
|
const newQueue = new Queue({ queue: modifiedQueue });
|
105
104
|
await newQueue.save();
|
106
105
|
} catch (error) {
|
107
|
-
write(error.stack,true);
|
106
|
+
write(error.stack, true);
|
108
107
|
}
|
109
108
|
}
|
110
109
|
function initQueueListener() {
|
@@ -115,7 +114,7 @@ async function getAbandonedCoins() {
|
|
115
114
|
const abandonedCoins = await ActiveCoin.find({ abandoned: true });
|
116
115
|
return abandonedCoins && [];
|
117
116
|
} catch (error) {
|
118
|
-
write(error.stack,true);
|
117
|
+
write(error.stack, true);
|
119
118
|
return [];
|
120
119
|
}
|
121
120
|
}
|
@@ -124,30 +123,80 @@ async function createNewHistory(coinObj) {
|
|
124
123
|
const newHistory = new Historical(coinObj);
|
125
124
|
await newHistory.save();
|
126
125
|
} catch (error) {
|
127
|
-
write(error.stack,true);
|
126
|
+
write(error.stack, true);
|
128
127
|
}
|
129
128
|
}
|
130
129
|
async function deleteHotCoins() {
|
131
130
|
try {
|
132
131
|
await HotCoin.deleteMany({ symbol: { $exists: true } });
|
133
132
|
} catch (error) {
|
134
|
-
write(error.stack,true);
|
133
|
+
write(error.stack, true);
|
135
134
|
}
|
136
135
|
}
|
137
136
|
async function deleteActiveCoins() {
|
138
137
|
try {
|
139
138
|
await ActiveCoin.deleteMany({ symbol: { $exists: true } });
|
140
139
|
} catch (error) {
|
141
|
-
write(error,true);
|
140
|
+
write(error, true);
|
141
|
+
}
|
142
|
+
}
|
143
|
+
async function deleteQueueCoins() {
|
144
|
+
try {
|
145
|
+
await Queue.deleteMany({ created: { $exists: true } });
|
146
|
+
} catch (error) {
|
147
|
+
write(error.stack, true);
|
142
148
|
}
|
143
149
|
}
|
144
150
|
async function deleteQueueCoins() {
|
145
151
|
try {
|
146
152
|
await Queue.deleteMany({ created: { $exists: true } });
|
147
153
|
} catch (error) {
|
148
|
-
write(error.stack,true);
|
154
|
+
write(error.stack, true);
|
155
|
+
}
|
156
|
+
}
|
157
|
+
async function deleteSuspendCoin(id) {
|
158
|
+
try {
|
159
|
+
await Suspended.findByIdAndDelete(id);
|
160
|
+
} catch (error) {
|
161
|
+
write(error.stack, true);
|
162
|
+
}
|
163
|
+
}
|
164
|
+
async function createSuspendedCoin(coinObj) {
|
165
|
+
try {
|
166
|
+
const suspendedCoin = new Suspended(coinObj);
|
167
|
+
await suspendedCoin.save();
|
168
|
+
} catch (error) {
|
169
|
+
write(error.stack, true);
|
149
170
|
}
|
150
171
|
}
|
172
|
+
async function getSuspendedCoins() {
|
173
|
+
try {
|
174
|
+
const abandonedCoins = await Suspended.find();
|
175
|
+
return abandonedCoins;
|
176
|
+
} catch (error) {
|
177
|
+
write(error.stack, true);
|
178
|
+
return [];
|
179
|
+
}
|
180
|
+
}
|
181
|
+
function suspendedWatcher(deleteRangeTime) {
|
182
|
+
setInterval(async () => {
|
183
|
+
try {
|
184
|
+
await Suspended.deleteMany({ created: { $lte: new Date(new Date().getTime() - deleteRangeTime * 60 * 60 * 1000) } });
|
185
|
+
} catch (error) {
|
186
|
+
write(error);
|
187
|
+
}
|
188
|
+
}, 1000);
|
189
|
+
}
|
190
|
+
async function isSuspended(symbol) {
|
191
|
+
try {
|
192
|
+
const isExist = await Suspended.findOne({ symbol });
|
193
|
+
console.log(Boolean(isExist));
|
194
|
+
return Boolean(isExist);
|
195
|
+
} catch (error) {
|
196
|
+
write(error);
|
197
|
+
}
|
198
|
+
}
|
199
|
+
|
151
200
|
module.exports = {
|
152
201
|
sortByPercent,
|
153
202
|
write,
|
@@ -166,4 +215,9 @@ module.exports = {
|
|
166
215
|
deleteHotCoins,
|
167
216
|
deleteActiveCoins,
|
168
217
|
deleteQueueCoins,
|
218
|
+
createSuspendedCoin,
|
219
|
+
deleteSuspendCoin,
|
220
|
+
getSuspendedCoins,
|
221
|
+
suspendedWatcher,
|
222
|
+
isSuspended
|
169
223
|
};
|