1 | const ftp = require('ftp');
|
2 | const csv = require('fast-csv');
|
3 | const _ = require('lodash');
|
4 |
|
5 |
|
6 |
|
7 |
|
8 | class Nasdaq {
|
9 |
|
10 | |
11 |
|
12 |
|
13 |
|
14 | static _request(directory) {
|
15 | return new Promise((resolve, reject) => {
|
16 | const client = new ftp();
|
17 | client.on('ready', () => {
|
18 | client.get(directory, (error, stream) => {
|
19 | if (error) reject(error);
|
20 | stream.once('close', () => { client.end(); });
|
21 | let array = [];
|
22 | csv.fromStream(stream, { headers: true, delimiter: "|" })
|
23 | .on('data', data => {
|
24 | array.push(data);
|
25 | })
|
26 | .on('end', () => {
|
27 | resolve(array);
|
28 | })
|
29 | })
|
30 | });
|
31 | client.connect({ host: "ftp.nasdaqtrader.com" });
|
32 | });
|
33 | }
|
34 |
|
35 | |
36 |
|
37 |
|
38 |
|
39 |
|
40 | static getListings() {
|
41 | return Nasdaq._request("SymbolDirectory/nasdaqlisted.txt");
|
42 | }
|
43 |
|
44 | |
45 |
|
46 |
|
47 |
|
48 |
|
49 | static getTraded() {
|
50 | return Nasdaq._request("SymbolDirectory/nasdaqtraded.txt");
|
51 | }
|
52 |
|
53 | |
54 |
|
55 |
|
56 |
|
57 |
|
58 | static getOtherListings() {
|
59 | return Nasdaq._request("SymbolDirectory/otherlisted.txt");
|
60 | }
|
61 |
|
62 | |
63 |
|
64 |
|
65 |
|
66 |
|
67 | static getOTCListings() {
|
68 | return Nasdaq._request("SymbolDirectory/otclist.txt");
|
69 | }
|
70 |
|
71 | |
72 |
|
73 |
|
74 |
|
75 |
|
76 |
|
77 | static getByName(string) {
|
78 | return Nasdaq.getTraded().then(array => {
|
79 | return (_.filter(array, o => { return o["Security Name"].indexOf(string) !== -1; }))
|
80 | })
|
81 | }
|
82 |
|
83 | |
84 |
|
85 |
|
86 |
|
87 |
|
88 | static getETFs() {
|
89 | return Nasdaq.getTraded().then(array => {
|
90 | array = _.filter(array, o => { return o["ETF"] === "Y"; });
|
91 | return (_.map(array, 'Symbol'));
|
92 | })
|
93 | }
|
94 |
|
95 | }
|
96 |
|
97 | module.exports = Nasdaq; |
\ | No newline at end of file |