Skip to content

Commit c5aa319

Browse files
bumping axios dep
replaced socketio with websocket client
1 parent c3171b6 commit c5aa319

6 files changed

Lines changed: 373 additions & 237 deletions

File tree

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
.idea
22
.env
33
node_modules
4-
.deploy
4+
deploy.sh
5+
.npmrc

README.md

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -205,11 +205,29 @@ const filings = await fullTextSearchApi.getFilings(rawQuery);
205205
The Stream API provides a real-time feed of the latest filings submitted to the SEC EDGAR database via a WebSocket connection. This push-based technology ensures immediate delivery of metadata for each new filing as it becomes publicly available.
206206

207207
```js
208-
const { streamApi } = require('sec-api');
209-
210-
streamApi.connect('YOUR_API_KEY');
211-
212-
streamApi.on('filing', (filing) => console.log(filing));
208+
const WebSocket = require('ws');
209+
210+
const API_KEY = 'YOUR_API'; // replace this with your actual API key
211+
const STREAM_API_URL = 'wss://stream.sec-api.io?apiKey=' + API_KEY;
212+
213+
const ws = new WebSocket(STREAM_API_URL);
214+
215+
ws.on('open', () => console.log('✅ Connected to:', STREAM_API_URL));
216+
ws.on('close', () => console.log('Connection closed'));
217+
ws.on('error', (err) => console.log('Error:', err.message));
218+
219+
ws.on('message', (message) => {
220+
const filings = JSON.parse(message.toString());
221+
filings.forEach((filing) => {
222+
console.log(
223+
filing.id,
224+
filing.cik,
225+
filing.formType,
226+
filing.filedAt,
227+
filing.linkToFilingDetails,
228+
);
229+
});
230+
});
213231
```
214232

215233
> See the documentation for more details: https://sec-api.io/docs/stream-api
@@ -298,8 +316,9 @@ const xbrlJson3 = await xbrlApi.xbrlToJson({
298316
});
299317
```
300318

301-
### Example Response
302-
319+
<details>
320+
<summary>Example Response</summary>
321+
303322
```json
304323
{
305324
"CoverPage": {
@@ -398,6 +417,8 @@ const xbrlJson3 = await xbrlApi.xbrlToJson({
398417
}
399418
```
400419

420+
</details>
421+
401422
> See the documentation for more details: https://sec-api.io/docs/xbrl-to-json-converter-api
402423
403424
## 10-K/10-Q/8-K Section Extractor API

example.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ const renderApiExample = async () => {
8585
/**
8686
* Stream API
8787
*/
88-
const { streamApi } = secApi;
88+
// const { streamApi } = secApi;
8989

9090
// uncomment
9191
// streamApi.connect(yourApiKey);

index.js

Lines changed: 56 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
#!/usr/bin/env node
22

3-
const io = require('socket.io-client');
3+
// const io = require('socket.io-client');
44
const config = require('./config');
5-
const events = require('events');
5+
// const events = require('events');
66
const axios = require('axios');
77

88
const store = { apiKey: '' };
@@ -14,44 +14,44 @@ const setApiKey = (apiKey) => {
1414
/*
1515
* Stream API
1616
*/
17-
const streamApiStore = {};
18-
19-
const initSocket = (apiKey) => {
20-
const uri = config.io.server + '/' + config.io.namespace.allFilings;
21-
const params = {
22-
query: { apiKey },
23-
transports: ['websocket'], // ensure traffic goes through load balancer
24-
};
25-
streamApiStore.socket = io(uri, params);
26-
streamApiStore.socket.on('connect', () =>
27-
console.log('Socket connected to', uri),
28-
);
29-
streamApiStore.socket.on('filing', handleNewFiling);
30-
streamApiStore.socket.on('filings', handleNewFilings);
31-
streamApiStore.socket.on('error', console.error);
32-
};
33-
34-
const handleNewFiling = (filing) => {
35-
streamApiStore.eventEmitter.emit('filing', filing);
36-
};
37-
38-
const handleNewFilings = (filings) => {
39-
streamApiStore.eventEmitter.emit('filings', filings);
40-
};
41-
42-
const close = () => {
43-
if (streamApiStore.socket.close) {
44-
streamApiStore.socket.close();
45-
}
46-
};
47-
48-
const connect = (apiKey) => {
49-
setApiKey(apiKey);
50-
initSocket(apiKey);
51-
streamApiStore.eventEmitter = new events.EventEmitter();
52-
modules.streamApi.on = streamApiStore.eventEmitter.on;
53-
return streamApiStore.eventEmitter;
54-
};
17+
// const streamApiStore = {};
18+
19+
// const initSocket = (apiKey) => {
20+
// const uri = config.io.server + '/' + config.io.namespace.allFilings;
21+
// const params = {
22+
// query: { apiKey },
23+
// transports: ['websocket'], // ensure traffic goes through load balancer
24+
// };
25+
// streamApiStore.socket = io(uri, params);
26+
// streamApiStore.socket.on('connect', () =>
27+
// console.log('Socket connected to', uri),
28+
// );
29+
// streamApiStore.socket.on('filing', handleNewFiling);
30+
// streamApiStore.socket.on('filings', handleNewFilings);
31+
// streamApiStore.socket.on('error', console.error);
32+
// };
33+
34+
// const handleNewFiling = (filing) => {
35+
// streamApiStore.eventEmitter.emit('filing', filing);
36+
// };
37+
38+
// const handleNewFilings = (filings) => {
39+
// streamApiStore.eventEmitter.emit('filings', filings);
40+
// };
41+
42+
// const close = () => {
43+
// if (streamApiStore.socket.close) {
44+
// streamApiStore.socket.close();
45+
// }
46+
// };
47+
48+
// const connect = (apiKey) => {
49+
// setApiKey(apiKey);
50+
// initSocket(apiKey);
51+
// streamApiStore.eventEmitter = new events.EventEmitter();
52+
// modules.streamApi.on = streamApiStore.eventEmitter.on;
53+
// return streamApiStore.eventEmitter;
54+
// };
5555

5656
/*
5757
* Query API
@@ -228,11 +228,11 @@ const getSection = async (filingUrl, section = '1A', returnType = 'text') => {
228228
*/
229229
const modules = {
230230
setApiKey,
231-
streamApi: {
232-
setApiKey,
233-
connect,
234-
close,
235-
},
231+
// streamApi: {
232+
// setApiKey,
233+
// connect,
234+
// close,
235+
// },
236236
queryApi: {
237237
setApiKey,
238238
getFilings: getFilingsQuery,
@@ -265,13 +265,15 @@ module.exports = modules;
265265
* Command Line Execution - Stream API
266266
*/
267267
if (require.main === module) {
268-
const apiKey = process.argv[2];
269-
const emitter = connect(apiKey);
270-
let messageCounter = 0;
271-
272-
emitter.on('filing', (filing) => {
273-
// console.log(JSON.stringify(filing, null, 1))
274-
messageCounter++;
275-
console.log(filing.id, filing.formType, filing.filedAt, messageCounter);
276-
});
268+
// const apiKey = process.argv[2];
269+
// const emitter = connect(apiKey);
270+
// let messageCounter = 0;
271+
// emitter.on('filing', (filing) => {
272+
// // console.log(JSON.stringify(filing, null, 1))
273+
// messageCounter++;
274+
// console.log(filing.id, filing.formType, filing.filedAt, messageCounter);
275+
// });
276+
console.log(
277+
'sec-api npm package working. Please import the package and use the provided methods to interact with the API.',
278+
);
277279
}

0 commit comments

Comments
 (0)