-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcoinmarketcap.js
36 lines (30 loc) · 937 Bytes
/
coinmarketcap.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
import got from 'got';
import getPackageUserAgent from 'package-user-agent';
const apiUrl = 'https://api.coinmarketcap.com/shop/v3/product/list';
export async function getLatestRewardCreationDate() {
const packageUserAgent = await getPackageUserAgent();
const {data} = await got.post(apiUrl, {
json: {
currentPage: 1,
pageSize: 1,
sortField: 'date'
},
headers: packageUserAgent
}).json();
return data.list[0].createDate;
}
export async function fetchNewRewards(oldCreationDate) {
const packageUserAgent = await getPackageUserAgent();
const {data} = await got.post(apiUrl, {
json: {
currentPage: 1,
pageSize: 99_999,
sortField: 'date'
},
headers: packageUserAgent
}).json();
const rewards = data.list;
const newRewards = rewards.filter(reward => reward.createDate > oldCreationDate);
const latestRewardCreationDate = data.list[0].createDate;
return {latestRewardCreationDate, newRewards};
}