-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathagentbot.js
121 lines (112 loc) · 3.68 KB
/
agentbot.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
import { runCollectionUpdaterAgent, runCollectionAggregatorAgent } from './agents/collectionagents.js';
import { runBlurBiddingAgent } from './agents/blurbidagents.js';
import { runBlurListingAgent, runOpenSeaListingAgent } from './agents/listingagents.js';
import { runOpenSeaBiddingAgent } from './agents/openseabidagent.js';
import { CronJob } from 'cron';
import logger from "./helpers/logger.js";
let collections = [];
let isCollectionUpdatedAgentRunning = false;
let isCollectionAggregatorAgentRunning = false;
let isBlurListingAgentRunning = false;
let isOpenSeaListingAgentRunning = false;
let isBlurBiddingAgentRunning = false;
let isOpenSeaBiddingAgentRunning = false;
let lastOpenSeaBiddingAgentRun = new Date(0);
const runCollectionUpdatedAgentJob = new CronJob('0 * * * *', async () => {
if (isCollectionUpdatedAgentRunning || isCollectionAggregatorAgentRunning)
return;
isCollectionUpdatedAgentRunning = true;
try {
collections = await runCollectionUpdaterAgent(collections);
if (collections.length == 0)
return;
}
catch (err) {
console.error(err);
}
isCollectionUpdatedAgentRunning = false;
});
const runCollectionAggregatorAgentJob = new CronJob('0 0 * * *', async () => {
if (isCollectionUpdatedAgentRunning || isCollectionAggregatorAgentRunning)
return;
isCollectionUpdatedAgentRunning = true;
try {
collections = await runCollectionAggregatorAgent(collections);
if (collections.length == 0)
return;
}
catch (err) {
console.error(err);
}
isCollectionUpdatedAgentRunning = false;
});
const runBlurListingAgentJob = new CronJob('*/3 * * * *', async () => {
if (isBlurListingAgentRunning)
return;
isBlurListingAgentRunning = true;
try {
if (collections.length == 0)
return;
await runBlurListingAgent(collections);
}
catch (err) {
console.error(err);
}
isBlurListingAgentRunning = false;
});
const runOpenSeaListingAgentJob = new CronJob('*/3 * * * *', async () => {
if (isOpenSeaListingAgentRunning)
return;
isOpenSeaListingAgentRunning = true;
try {
if (collections.length == 0)
return;
await runOpenSeaListingAgent(collections);
}
catch (err) {
console.error(err);
}
isOpenSeaListingAgentRunning = false;
});
const runBlurBiddingAgentJob = new CronJob('* * * * *', async () => {
if (isBlurBiddingAgentRunning)
return;
isBlurBiddingAgentRunning = true;
try {
if (collections.length == 0)
return;
await runBlurBiddingAgent(collections);
}
catch (err) {
console.error(err);
}
isBlurBiddingAgentRunning = false;
});
const runOpenSeaBiddingAgentJob = new CronJob('* * * * *', async () => {
if (new Date() - lastOpenSeaBiddingAgentRun < 20 * 6e4 || isOpenSeaBiddingAgentRunning)
return;
lastOpenSeaBiddingAgentRun = new Date();
isOpenSeaBiddingAgentRunning = true;
try {
if (collections.length == 0)
return;
await runOpenSeaBiddingAgent(collections);
}
catch (err) {
console.error(err);
}
isOpenSeaBiddingAgentRunning = false;
});
async function main() {
logger("LOG", "MAIN BOT AGENT", "Starting bot v. 0.7.4...");
// do initial run of collection aggregator agent
collections = await runCollectionAggregatorAgent(collections);
// start cron jobs
runCollectionUpdatedAgentJob.start();
runCollectionAggregatorAgentJob.start();
runBlurListingAgentJob.start();
runOpenSeaListingAgentJob.start();
runBlurBiddingAgentJob.start();
runOpenSeaBiddingAgentJob.start();
}
main();