newsfilter.io - Stock Market News API

newsfilter.io - Stock Market News API

  • Home

›Stream API

Overview

  • Introduction
  • News Sources
  • Companies & Exchanges

Query API

  • Overview
  • API Endpoint
  • Authentication
  • Request & Response Formats
  • Example: Python
  • Example: cURL
  • Example: Node.js
  • Tutorials

Stream API

  • Overview
  • API Endpoint
  • Authentication
  • Message Format
  • Example: Python
  • Example: Node.js
  • Example: Browser + JS

Integrations

  • Discord

Node.js Example

You have to two options for connecting to the Stream API.

  1. Use our financial-news-api npm package
  2. Use your own socket.io/websocket client

1. Financial-News-API SDK

Start by installing the package with npm install financial-news-api. Setting up a news streaming API to receive newly published articles in real-time can be done in less than 10 lines of code.

const { StreamApi } = require('financial-news-api');

const API_KEY = 'YOUR_API_KEY';

const streamApi = StreamApi(API_KEY);

streamApi.on('articles', (articles) => console.log(articles[0].title));
streamApi.on('error', (err) => console.log('Connection error ' + err));
streamApi.on('open', () => console.log('Connection open'));
streamApi.on('close', () => console.log('Connection closed'));

2. Socket.io Connection

Install socket.io for Node.js:

npm i socket.io-client@2

Please use the exact socket.io-client version above.

The example below creates a socket.io client, connects to our server and prints all articles as they are received.

const io = require('socket.io-client');

const apikey = 'your-api-key';

const socket = io.connect('http://stream.newsfilter.io?apiKey=' + apikey);

socket.on('connect', function () {
  console.log('connected');
});

socket.on('articles', function (articles) {
  console.log(articles);
});
← Example: PythonExample: Browser + JS →
  • 1. Financial-News-API SDK
  • 2. Socket.io Connection
newsfilter.io - Stock Market News API
Documentation
IntroductionNews Query API News Stream APINews Render APIDiscord News Bot
Contact
support@newsfilter.io
Social
Follow @newsfilterio
Follow Us on Stocktwits
Copyright © 2022 newsfilter.io