realtime-newsapi

repository·master·Indexed 18 days ago

https://github.com/janlukasschroeder/realtime-newsapi

A real-time and queryable API for financial news covering over 10,000 sources including Reuters, Bloomberg, and the SEC. Version 1.1.2 provides a WebSocket-based streaming API for live updates via Node.js or command line, and a RESTful Query API for searching historical articles via HTTP POST at api.newsfilter.io.

Tokens
1.2K
Snippets
6
Records
6
Agent score
13%

What's inside realtime-newsapi

  1. Use the Real Time Streaming API in Node.js

    master

    To integrate the real-time news stream into a Node.js application, install the realtime-newsapi package and listen for the articles event.

    1. Initialize your project: npm init -y
    2. Install the package: npm install realtime-newsapi
    3. Implement the listener in your entry point (e.g., index.js).

    The API returns an array of articles via the articles event listener.

    const api = require('realtime-newsapi')();
    
    api.on('articles', (articles) => {
      console.log(articles);
    });
  2. Install and use the Real Time Streaming API via Command Line

    master

    You can quickly view a live stream of financial news articles directly in your terminal by installing the package globally via npm.

    1. Install the package: npm install realtime-newsapi -g
    2. Run the command: realtime-newsapi

    New articles will be printed to your command line as soon as they are published on supported news platforms.

    npm install realtime-newsapi -g
    realtime-newsapi
  3. Query the News API via HTTP POST

    master

    The Query API allows you to search the newsfilter.io article database using specific filter criteria. You can use tools like curl or Postman to send requests.

    • Endpoint: https://api.newsfilter.io/public/actions
    • Method: POST
    • Content-Type: application/json

    To filter articles, send a JSON body containing a type of filterArticles and a queryString that uses boolean logic (e.g., OR) to target specific fields like title, description, or symbols.

    {
      "type": "filterArticles",
      "queryString": "title:\"FDA Approval\" OR description:\"FDA Approval\""
    }
  4. Reference: Article Response Format

    master

    The API returns articles in JSON format. Each article object contains the following fields:

    • id (string): Unique ID of the article
    • title (string): Title of the article
    • description (string): Description of the article
    • symbols (array): Array of ticker symbols mentioned (e.g., ['AAPL'])
    • url (string): URL to the original article
    • publishedAt (string): ISO 8601 formatted publication timestamp
    • source (object): Contains id (string) and name (string) of the news source
    • author (string): Name of the author
    [
        {
          "source": {
            "id": "seekingAlpha",
            "name": "Seeking Alpha"
          },
          "symbols": ["EWH"],
          "title": "Hang Seng soars despite massive rally",
          "description": "Hong Kong is gearing up for more protests...",
          "url": "https://seekingalpha.com/news/3492784-hang-seng-soars-despite-massive-rally",
          "publishedAt": "2019-08-19T03:23:00-04:00",
          "id": "c7007ef5eae6cf50225cc4f19d368fe5"
        }
    ]
  5. Close the real-time news connection

    master

    To gracefully terminate the Socket.io connection and stop receiving updates, call the .close() method exported by the module.

    const realtimeNews = require('realtime-newsapi');
    const newsEmitter = realtimeNews();
    
    // ... use the emitter ...
    
    // Close the connection
    realtimeNews.close();
  6. Connect to the real-time news stream

    master

    To start receiving real-time news articles, import the package and call the default exported function. This initializes a Socket.io connection to the configured server and returns an EventEmitter instance. You should listen for the 'articles' event on this emitter to receive incoming news data.

    Note: The connection configuration (server URI and filterId) is managed via the internal ./config module.

    const realtimeNews = require('realtime-newsapi');
    
    // Initialize the connection and get the event emitter
    const newsEmitter = realtimeNews();
    
    // Listen for new articles
    newsEmitter.on('articles', ({ articles }) => {
      console.log('Received articles:', articles);
    });