# News

Retrieve news articles for any supported stock symbol.

## Making Requests

Use the `news()` method on the `stocks` resource to fetch news.

| Output Format          | Result Payload                      | Description                                     |
|------------------------|-------------------------------------|-------------------------------------------------|
| **internal** (default) | `StockNews[]` or `StockNewsHuman[]` | Array of decoded news articles.                 |
| **json**               | Raw JSON object                     | The compressed, array-keyed response object.    |
| **csv**                | `Blob`                              | CSV payload. Use `.save(filename)` to write it. |

<a name="news"></a>
## news

```typescript
// Positional form
news<P>(
  symbol: string,
  params?: P,
): MarketDataPromise<StockNews[] | StockNewsHuman[]>

// Object form
news<P>(
  params: P & { symbol: string },
): MarketDataPromise<StockNews[] | StockNewsHuman[]>
```

Fetches news articles for a single symbol.

#### Parameters

- `symbol` (string)

  The stock symbol to fetch news for.

- `from` (string | Date, optional)

  Start of the date range for news articles.

- `to` (string | Date, optional)

  End of the date range for news articles.

- `date` (string | Date, optional)

  Fetch news for a specific date.

- `countback` (number, optional)

  Number of articles to return, counting backwards from `to`.

- [`outputFormat`](https://www.marketdata.app/docs/sdk/js/settings#output-format) (optional): The format of the returned data. Alias: `format`.
- [`dateFormat`](https://www.marketdata.app/docs/sdk/js/settings#date-format) (optional): Date format. Alias: `dateformat`.
- [`columns`](https://www.marketdata.app/docs/sdk/js/settings#columns) (optional): Columns to include.
- [`addHeaders`](https://www.marketdata.app/docs/sdk/js/settings#headers) (optional): Whether to include headers in CSV output. Alias: `headers`.
- [`useHumanReadable`](https://www.marketdata.app/docs/sdk/js/settings#human-readable) (optional): Use human-readable field names. Alias: `human`.
- [`mode`](https://www.marketdata.app/docs/sdk/js/settings#data-mode) (optional): The data mode to use.

#### Returns

- [`MarketDataPromise<StockNews[] | StockNewsHuman[] | Blob>`](https://www.marketdata.app/docs/sdk/js/client#MarketDataPromise)

### Default

```typescript
import { MarketDataClient } from "@marketdata/sdk";

const client = new MarketDataClient();

try {
  const articles = await client.stocks.news("AAPL");
  for (const a of articles) {
    console.log(`${a.source}: ${a.headline}`);
  }
} catch (error) {
  console.error(error);
}
```

### Date Range

```typescript
import { MarketDataClient } from "@marketdata/sdk";

const client = new MarketDataClient();

try {
  const articles = await client.stocks.news("AAPL", {
    from: "2024-01-01",
    to: "2024-01-31",
  });
  console.log(`Got ${articles.length} articles`);
} catch (error) {
  console.error(error);
}
```

<a name="StockNews"></a>
## StockNews

```typescript
interface StockNews {
  s?: string;
  symbol: string;
  headline: string;
  content: string;
  source: string;
  publicationDate: number;
}
```

#### Properties

- `symbol` (string): The stock symbol.
- `headline` (string): The news headline.
- `content` (string): The article content or summary.
- `source` (string): The news source publisher.
- `publicationDate` (number): Unix timestamp when the article was published.

<a name="StockNewsHuman"></a>
## StockNewsHuman

`StockNewsHuman` is returned when `human: true` is set. It uses the same field names as `StockNews` for most columns, but with `Symbol` capitalized.
