-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
86 lines (73 loc) · 1.93 KB
/
app.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
const crypto = require('crypto');
const fs = require('fs');
const RSS = require('rss');
const request = require('request-promise-native');
const sortBy = (accessors, type) =>
{
return (a, b) =>
{
let itemA, itemB;
for(const accessor of accessors)
{
itemA = a[accessor];
itemB = b[accessor];
}
switch(type)
{
case 'date':
itemA = new Date(itemA);
itemB = new Date(itemB);
break;
}
if(itemA < itemB)
{
return -1;
}
else if(itemA > itemB)
{
return 1;
}
else
{
return 0;
}
}
}
const main = async () =>
{
const feed = new RSS(
{
title: 'Bittrex - open and available trading markets',
feed_url: 'http://www.yourwebsite.com/feed.rss',
site_url: 'https://bittrex.com',
pubDate: new Date(),
ttl: 1440
});
const response = await request(
{
method: 'GET',
url: 'https://bittrex.com/api/v1.1/public/getmarkets',
json: true
});
const results = response.result
.filter((item) => item.BaseCurrency == 'BTC')
.sort(sortBy(['MarketCurrency'], 'date'))
.reverse();
results.forEach((result) =>
{
const hash = crypto.createHash('sha256')
.update(`${result.MarketCurrency}:${result.Created}`)
.digest('hex');
feed.item(
{
title: `${result.MarketCurrency} is now available on Bittrex`,
description: `${result.MarketCurrency} is now available on Bittrex.`,
url: `https://bittrex.com/Market/Index?MarketName=${result.BaseCurrency}-${result.MarketCurrency}`,
guid: hash,
date: new Date(result.Created)
});
});
const xml = feed.xml();
fs.writeFile('./feed.rss', xml, () => process.exit());
}
main();