-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcancelTracker.js
39 lines (34 loc) · 1.02 KB
/
cancelTracker.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
const opensea = require("./opensea");
const db = require("./db");
const { Observable, filter, bufferTime } = require("rxjs");
const cancelTracker = () => {
const bidsCollection = db.collection("bidEvents");
const bids$ = new Observable((subscriber) => {
opensea.onItemSold("*", async (event) => {
let { payload } = event;
let { item } = payload;
return console.log(event);
//
subscriber.next({
id: item.nft_id,
price: payload.base_price,
createdAt: payload.event_timestamp,
expirationData: payload.expiration_date,
collection: payload.collection.slug,
maker: payload.maker.address,
quantity: payload.quantity,
});
});
});
bids$
.pipe(
// flush events every 1 second
bufferTime(800),
// move next only if there is at least one event
filter((events) => events.length > 0)
)
.subscribe(async (events) => {
//await bidsCollection.insertMany(events);
});
};
module.exports = cancelTracker;