-
Notifications
You must be signed in to change notification settings - Fork 1
/
sales.js
executable file
·60 lines (52 loc) · 2.27 KB
/
sales.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
#!/usr/bin/env node
const { ACCOUNT, COLLECTION } = require('./constants')
var argv = require('yargs/yargs')(process.argv.slice(2))
.command('Get NFTs listed for sale')
.example('$0 -a fred', 'Get NFTs for sale by fred')
.example('$0 -a fred -c monsters', 'Get "monsters" collection NFTs for sale by fred')
.describe('account', 'Account (account)')
.alias('a', 'account')
.default('account', ACCOUNT)
.describe('collection_name', 'Collection name')
.alias('c', 'collection_name')
.default('collection_name', COLLECTION)
.describe('template_id', 'template_id')
.alias('t', 'template_id')
.default('template_id', '')
.boolean(['debug'])
.argv
;
const { getListings } = require('./nft/get-listings');
const { sortDictionary } = require('./utils');
const main = async (account, collection_name, template_id) => {
console.log(`NFTs for sale by ${account}, collection ${collection_name}:`)
const listings = await getListings({
seller: account,
collection_name: collection_name,
template_id: template_id,
sort: 'collection_mint',
order: 'asc',
limit: 1000
})
if (argv.debug) console.log(listings) // debug
let groupedSales = {}
listings.forEach(l => {
const key = `${l.assets[0].template.template_id} "${l.assets[0].template.immutable_data.name}"`
const price = l.price.amount / Math.pow(10, l.price.token_precision)
const updateTime = new Date(parseInt(l.updated_at_time)).toISOString().slice(0, 19).replace('T', ' ')
const sale_info = `asset_id: ${l.assets[0].asset_id}, template_mint: ${l.assets[0].template_mint}, sale_id: ${l.sale_id},`
+ ` ${parseFloat(price).toLocaleString()} ${l.price.token_symbol} by ${l.assets[0].owner}, ${updateTime}`
if (key in groupedSales) {
groupedSales[key].push(sale_info)
} else {
groupedSales[key] = [sale_info]
}
if (argv.debug) console.log(l.assets[0]) // debug
})
let sortedSales = sortDictionary(groupedSales)
for (const [key, assets] of Object.entries(sortedSales)) {
console.log(`${key} (total: ${sortedSales[key].length})`)
assets.forEach(a => console.log(a))
}
}
main(argv.account, argv.collection_name, argv.template_id)