Subscribe to articles

The Finlight.me WebSocket API allows you to subscribe to article updates in real-time. Once connected and subscribed, you receive the latest article matching your query immediately, followed by any newly published articles that match your criteria as they appear.


Article model

The articles returned via WebSocket follow the same model as the REST API articles:

  • Name
    link
    Type
    string
    Description

    URL to the full article.

  • Name
    source
    Type
    string
    Description

    Source website. E.g. www.reuters.com.

  • Name
    title
    Type
    string
    Description

    Title of the article.

  • Name
    summary
    Type
    string
    Description

    Summary of the article (if extended is true).

  • Name
    publishDate
    Type
    Date
    Description

    Publication date as ISO date.

  • Name
    language
    Type
    string
    Description

    Language code in ISO 639-1. E.g. en | de | fr.

  • Name
    sentiment
    Type
    string
    Description

    Sentiment analysis result. Values: positive | neutral | negative.

  • Name
    confidence
    Type
    number
    Description

    Confidence level of sentiment analysis from 0 to 1.

  • Name
    images
    Type
    string[]
    Description

    Array of image URLs from the article.

  • Name
    content
    Type
    string
    Description

    Full content of the article (if extended is true).


WEBSOCKETdefault route

Get articles

When you subscribe, you’ll first receive the latest article matching your query, followed by any new articles as they are published.

When subscribing, you can specify various parameters to filter the articles you receive:

  • Name
    query
    Type
    string
    Description

    Search query to find relevant articles. Advanced queries

  • Name
    sources
    Type
    string[]
    Description

    Filter by article single or multiple sources. E.g. ["www.reuters.com", "www.cnbc.com"]. See source endpoint for valid values.

  • Name
    excludeSources
    Type
    string[]
    Description

    Excludes single or multiple sources. E.g. ["www.reuters.com", "www.cnbc.com"]. See source endpoint for valid values.

  • Name
    language
    Type
    string
    Description

    Filter by language. Language code in ISO 639-1

  • Name
    extended
    Type
    boolean
    Description

    true to receive extended article information (includes content and summary).

Request

WEBSOCKET
/
import { FinlightApi } from 'finlight-client'

const client = new FinlightApi({
  apiKey: 'YOUR_API_KEY', // Replace with your API key
})

client.websocket.connect(
  {
    query: 'Nvidia',
    language: 'en',
    extended: true,
  },
  (article) => {
    console.log('New article received:', article)
  },
)
{
  "link": "https://www.example.com/nvidia-article",
  "title": "Nvidia Announces New GPU Architecture",
  "publishDate": "2023-10-05T09:00:00Z",
  "source": "www.example.com",
  "language": "en",
  "sentiment": "positive",
  "confidence": 0.92,
  "content": "Full article content here...",
  "summary": "A brief summary of the article..."
}

You can keep the connection open and receive articles in real-time without additional requests. As new articles become available, they are pushed directly to your callback function.

Was this page helpful?