# Live News

`WS` `wss://socket.vantafin.com/v1/stocks`

Subscribe to live news and press releases over the same WebSocket connection. Use channel N.{ticker} for a specific ticker (e.g. N.AAPL) or N.* for every article market-wide. Each message is pushed the moment a new article is ingested and carries the headline, body text, publisher, source site, canonical URL, publish time, and a newsType of either 'stockNews' or 'pressRelease'. Unlike the live-quote channels, the news stream runs around the clock - it is not gated to market hours.

## Use cases

- Real-time news terminals and breaking-headline tickers
- Event-driven trading on press releases and market-moving news
- Streaming a watchlist's headlines without polling the REST news API
- Feeding NLP / sentiment pipelines as articles are published

## Subscribe

Subscribe to `N.{ticker}` (e.g. `N.AAPL`) for a single ticker, or `N.*` for every ticker:

```json
{"action":"subscribe","params":"N.AAPL"}
```

## Message fields

| Field | Type | Description |
| --- | --- | --- |
| `type` | string | Always 'news'. |
| `ticker` | string | Ticker the article is about. |
| `newsType` | string | 'stockNews' or 'pressRelease'. |
| `title` | string | Headline of the article. |
| `text` | string | Article body / snippet. |
| `publisher` | string | Publisher name, e.g. 'Business Wire'. |
| `site` | string | Source domain, e.g. 'businesswire.com'. |
| `url` | string | Canonical URL of the article. |
| `publishedDate` | string | Publish time in UTC (YYYY-MM-DD HH:MM:SS). |
| `id` | string | Stable article identifier (also used by the REST news API). |

## Example output

```json
{
  "type": "news",
  "ticker": "AAPL",
  "newsType": "pressRelease",
  "title": "Apple Announces Record June Quarter Results",
  "text": "Apple today announced financial results for its fiscal third quarter...",
  "publisher": "Business Wire",
  "site": "businesswire.com",
  "url": "https://www.businesswire.com/news/home/20260616/apple-q3-results",
  "publishedDate": "2026-06-16 12:30:00",
  "id": "a593d7c6618b5fb75641"
}
```

## Connection examples

### cURL

```bash
# install websocat: https://github.com/vi/websocat
echo '{"action":"subscribe","params":"N.AAPL"}' \
  | websocat "wss://socket.vantafin.com/v1/stocks?apiKey=$VANTAFIN_API_KEY"
```

### Python

```python
from vantafin import WebSocketClient

ws = WebSocketClient("vf-live-your_api_key")
ws.connect()
ws.subscribe(["N.AAPL"])

for message in ws:
    print(message)
```

### JavaScript

```javascript
import { WebSocketClient } from "vantafin";

const ws = new WebSocketClient("vf-live-your_api_key");
ws.on("message", (msg) => console.log(msg));

await ws.connect();
ws.subscribe(["N.AAPL"]);
```

### Go

```go
package main

import (
	"fmt"
	"log"

	"github.com/vantafin/vantafin-go"
)

func main() {
	ws := vantafin.NewWebSocketClient("vf-live-your_api_key")
	conn, err := ws.Connect()
	if err != nil {
		log.Fatal(err)
	}
	defer conn.Close()

	conn.Subscribe("N.AAPL")
	for {
		msg, err := conn.Read()
		if err != nil {
			break
		}
		fmt.Println(msg)
	}
}
```

### Java

```java
import com.vantafin.WebSocketClient;

public class Example {
    public static void main(String[] args) throws Exception {
        WebSocketClient ws = new WebSocketClient("vf-live-your_api_key");
        ws.connect(message -> System.out.println(message));
        ws.subscribe("N.AAPL");
    }
}
```

### Ruby

```ruby
require "vantafin"

ws = Vantafin::WebSocketClient.new("vf-live-your_api_key")
ws.on(:message) { |msg| pp msg }
ws.connect
ws.subscribe("N.AAPL")
sleep
```
