rsibot-utils 1.5.9 → 1.5.10

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. package/db.js +17 -17
  2. package/index.js +14 -7
  3. package/package.json +1 -1
package/db.js CHANGED
@@ -15,9 +15,9 @@ const hotCoinsSchema = new Schema(
15
15
  const activeSchema = new Schema(
16
16
  {
17
17
  symbol: { type: String, unique: true },
18
- inPosition: Boolean ,
19
- lastBuy: Number ,
20
- abandoned: Boolean ,
18
+ inPosition: Boolean,
19
+ lastBuy: Number,
20
+ abandoned: Boolean,
21
21
  },
22
22
  {
23
23
  versionKey: false,
@@ -26,8 +26,8 @@ const activeSchema = new Schema(
26
26
  const suspendedSchema = new Schema(
27
27
  {
28
28
  symbol: String,
29
- lastStatus: String,
30
- percentChange: Number,
29
+ // lastStatus: String,
30
+ // percentChange: Number,
31
31
  created: { type: Date, default: Date.now },
32
32
  },
33
33
  {
@@ -70,26 +70,26 @@ mongoose
70
70
  });
71
71
 
72
72
  const models = {
73
- HotCoin:undefined,
74
- ActiveCoin:undefined,
75
- Queue:undefined,
76
- Historical:undefined,
77
- }
73
+ HotCoin: undefined,
74
+ ActiveCoin: undefined,
75
+ Queue: undefined,
76
+ Historical: undefined,
77
+ };
78
78
 
79
79
  const dbArray = [
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 },
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 },
85
85
  ];
86
86
 
87
- dbArray.forEach(({name,schema,tableName }) => {
87
+ dbArray.forEach(({ name, schema, tableName }) => {
88
88
  if (mongoose.models[tableName]) {
89
89
  models[name] = mongoose.model(tableName);
90
90
  } else {
91
91
  models[name] = mongoose.model(tableName, schema);
92
92
  }
93
- })
93
+ });
94
94
 
95
95
  module.exports = models;
package/index.js CHANGED
@@ -62,7 +62,6 @@ async function removeHotCoin(symbol) {
62
62
  return false;
63
63
  }
64
64
  }
65
-
66
65
  async function getActiveCoins() {
67
66
  try {
68
67
  const results = await ActiveCoin.find();
@@ -162,7 +161,6 @@ async function deleteSuspendCoin(id) {
162
161
  write(error.stack, true);
163
162
  }
164
163
  }
165
-
166
164
  async function createSuspendedCoin(coinObj) {
167
165
  try {
168
166
  const suspendedCoin = new Suspended(coinObj);
@@ -171,7 +169,6 @@ async function createSuspendedCoin(coinObj) {
171
169
  write(error.stack, true);
172
170
  }
173
171
  }
174
-
175
172
  async function getSuspendedCoins() {
176
173
  try {
177
174
  const abandonedCoins = await Suspended.find();
@@ -181,15 +178,23 @@ async function getSuspendedCoins() {
181
178
  return [];
182
179
  }
183
180
  }
184
-
185
- function suspendedWatcher(seconds) {
181
+ function suspendedWatcher(deleteRangeTime) {
186
182
  setInterval(async () => {
187
183
  try {
188
- await Suspended.deleteMany({ created: { $lte: new Date(new Date().getTime() - 1 * 60 * 60 * 1000) } });
184
+ await Suspended.deleteMany({ created: { $lte: new Date(new Date().getTime() - deleteRangeTime * 60 * 60 * 1000) } });
189
185
  } catch (error) {
190
186
  write(error);
191
187
  }
192
- }, seconds);
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
+ }
193
198
  }
194
199
 
195
200
  module.exports = {
@@ -213,4 +218,6 @@ module.exports = {
213
218
  createSuspendedCoin,
214
219
  deleteSuspendCoin,
215
220
  getSuspendedCoins,
221
+ suspendedWatcher,
222
+ isSuspended
216
223
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rsibot-utils",
3
- "version": "1.5.9",
3
+ "version": "1.5.10",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "scripts": {