### Install Real Time News API Package (Node.js) Source: https://github.com/janlukasschroeder/realtime-newsapi/blob/master/README.md Install the realtime-newsapi package globally for command-line usage or locally for Node.js projects. ```bash npm install realtime-newsapi -g ``` ```bash npm install realtime-newsapi ``` -------------------------------- ### Install and Run Realtime News API CLI (Bash) Source: https://context7.com/janlukasschroeder/realtime-newsapi/llms.txt Install the package globally to use its command-line interface for streaming financial news directly to your terminal. Articles are outputted in JSON format. ```bash # Install the package globally npm install realtime-newsapi -g # Start streaming financial news realtime-newsapi # Articles will print to console as they are published: # { # 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...', # publishedAt: '2019-08-19T03:23:00-04:00', # id: 'c7007ef5eae6cf50225cc4f19d368fe5' # } ``` -------------------------------- ### Start Real Time News Stream (Node.js) Source: https://github.com/janlukasschroeder/realtime-newsapi/blob/master/README.md Connect to the real-time news stream using the Node.js client. This code snippet listens for new articles and logs them to the console. ```javascript const api = require('realtime-newsapi')(); api.on('articles', (articles) => { console.log(articles); }); ``` -------------------------------- ### News Article Data Structure Source: https://github.com/janlukasschroeder/realtime-newsapi/blob/master/README.md This example shows the structure of a news article object returned by the API. It includes details about the source, associated stock symbols, title, description, URL, and publication timestamp. Ensure the API key is correctly configured for requests. ```json [ { "source": { "id": "seekingAlpha", "name": "Seeking Alpha" }, "symbols": ["EWH"], "title": "Hang Seng soars despite massive rally", "description": "Hong Kong is gearing up for more protests this week after hundreds of thousands of anti-government demonstrators braved heavy rain to rally peacefully on Sunday, marking a change to what have often been violent clashes.The scenes showed that the movement is far from fizzling out, triggering fears about retail, tourism and business confidence, as well as worries over the city\'s stock and property markets.The Hang Seng index still rose 2.2% overnight following a healthy lead from Wall Street and key interest rate reforms from the People\'s Bank of China.ETFs: EWH, FHK, FLHK", "url": "https://seekingalpha.com/news/3492784-hang-seng-soars-despite-massive-rally", "publishedAt": "2019-08-19T03:23:00-04:00", "id": "c7007ef5eae6cf50225cc4f19d368fe5" }, { "source": { "id": "businesswire", "name": "BusinessWire" }, "symbols": ["CELG"], "title": "U.S. FDA Approves INREBICĀ® (Fedratinib) as First New Treatment in Nearly a Decade for Patients With Myelofibrosis", "description": "SUMMIT, N.J.--(BUSINESS WIRE)--Celgene Corporation (NASDAQ: CELG) today announced the U.S. Food and Drug Administration (FDA) has approved INREBICĀ® (fedratinib) for the treatment of adult patients with intermediate-2 or high-risk primary or secondary (post-polycythemia vera or post-essential thrombocythemia) myelofibrosis.1", "url": "https://www.businesswire.com/news/home/20190816005292/en/U.S.-FDA-Approves-INREBIC%C2%AE-Fedratinib-New-Treatment", "publishedAt": "2019-08-16T14:30:00+00:00", "id": "129bd08d615d573fed8e12dbb917436e" } ]; ``` -------------------------------- ### Close WebSocket Connection Source: https://context7.com/janlukasschroeder/realtime-newsapi/llms.txt Use the close method to gracefully terminate the WebSocket connection when no longer needed. This example demonstrates closing the connection after a 60-second delay. ```javascript const realtimeNewsApi = require('realtime-newsapi'); const api = realtimeNewsApi(); // Set up article listener api.on('articles', (articles) => { console.log(`Received ${articles.length} new articles`); }); // Close connection after 60 seconds setTimeout(() => { realtimeNewsApi.close(); console.log('Connection closed'); }, 60000); ``` -------------------------------- ### Listen for New Articles in Real-Time (JavaScript) Source: https://context7.com/janlukasschroeder/realtime-newsapi/llms.txt Use this snippet to listen for new articles streamed via WebSocket. It requires importing the 'realtime-newsapi' package and setting up an event listener for 'articles'. ```javascript const api = require('realtime-newsapi')(); // Listen for new articles in real-time api.on('articles', (articles) => { articles.forEach(article => { console.log(`[${article.source.name}] ${article.title}`); console.log(`Tickers: ${article.symbols.join(', ')}`); console.log(`URL: ${article.url}`); console.log(`Published: ${article.publishedAt}`); console.log('---'); }); }); ``` -------------------------------- ### Search for FDA Approval Articles (Bash) Source: https://context7.com/janlukasschroeder/realtime-newsapi/llms.txt Use curl to send a POST request to the Query API to search for articles related to 'FDA Approval'. This query targets the title and description fields. ```bash # Search for FDA Approval articles curl -X POST https://api.newsfilter.io/public/actions \ -H "Content-Type: application/json" \ -d '{ "type": "filterArticles", "queryString": "title:\"FDA Approval\" OR description:\"FDA Approval\"" }' ``` -------------------------------- ### Search for Articles Mentioning Apple (AAPL) (Bash) Source: https://context7.com/janlukasschroeder/realtime-newsapi/llms.txt This curl command searches the newsfilter.io database for articles mentioning 'AAPL', checking the title, description, and symbols fields. ```bash # Search for articles mentioning Apple (AAPL) curl -X POST https://api.newsfilter.io/public/actions \ -H "Content-Type: application/json" \ -d '{ "type": "filterArticles", "queryString": "title:AAPL OR description:AAPL OR symbols:AAPL" }' ``` -------------------------------- ### Query API - FDA Approvals Filter Source: https://github.com/janlukasschroeder/realtime-newsapi/blob/master/README.md Use this JSON payload with the Query API to retrieve articles related to 'FDA Approval' in their title or description. ```json { "type": "filterArticles", "queryString": "title:\"FDA Approval\" OR description:\"FDA Approval\"" } ``` -------------------------------- ### Article Response Schema (JavaScript) Source: https://context7.com/janlukasschroeder/realtime-newsapi/llms.txt This object structure defines the schema for articles returned by both the streaming and query APIs. It includes metadata like ID, title, symbols, URL, and publication timestamp. ```javascript // Article object structure const articleSchema = { id: "c7007ef5eae6cf50225cc4f19d368fe5", // Unique article ID title: "Hang Seng soars despite massive rally", // Article title description: "Hong Kong is gearing up...", // Article description/summary symbols: ["EWH", "FHK", "FLHK"], // Mentioned ticker symbols url: "https://seekingalpha.com/news/...", // Original article URL publishedAt: "2019-08-19T03:23:00-04:00", // ISO 8601 timestamp source: { id: "seekingAlpha", // Source identifier name: "Seeking Alpha" // Human-readable source name }, author: "John Smith" // Author name (if available) }; ``` -------------------------------- ### Query API - AAPL Mentions Filter Source: https://github.com/janlukasschroeder/realtime-newsapi/blob/master/README.md Use this JSON payload with the Query API to find articles mentioning 'AAPL', including in the title, description, or symbols. ```json { "type": "filterArticles", "queryString": "title:AAPL OR description:AAPL OR symbols:AAPL" } ``` -------------------------------- ### Filter Articles by Ticker Symbol (JavaScript) Source: https://context7.com/janlukasschroeder/realtime-newsapi/llms.txt This JavaScript snippet demonstrates how to filter the received articles to find news related to a specific ticker symbol, such as 'AAPL'. It uses the Array.prototype.filter method. ```javascript // Filter articles by ticker symbol api.on('articles', (articles) => { const appleNews = articles.filter(article => article.symbols.includes('AAPL') ); if (appleNews.length > 0) { console.log('New Apple news:', appleNews); } }); ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.