# Trending symbols

The stock tickers with the most coverage right now.

`GET https://api.marketnewsapi.com/v1/trending`

Ranks symbols by article count in the chosen window. Great for a "most talked about" widget, a screener input, or detecting unusual news volume.

Requires an API key. See [authentication](/docs/authentication).

## Query parameters

- `window` (string) Look-back window. Default: `24h`. One of `1h`, `24h`, `7d`.
- `kind` (string) Stock tickers. Default: `ticker`. One of `ticker`.
- `category` (string) Only count articles in this category. One of `stocks`.
- `limit` (integer) Number of symbols, 1–50. Default: `20`.

## Example request

```curl
curl "https://api.marketnewsapi.com/v1/trending?window=24h&limit=10" \
 -H "Authorization: Bearer $MARKETNEWSAPI_KEY"
```

```python
import json
import os

import requests

resp = requests.get(
 "https://api.marketnewsapi.com/v1/trending",
 params={"window": "24h", "limit": 10},
 headers={"Authorization": f"Bearer {os.environ['MARKETNEWSAPI_KEY']}"},
 timeout=10,
)
resp.raise_for_status()
print(json.dumps(resp.json(), indent=2))
```

```javascript
const params = new URLSearchParams({ window: "24h", limit: "10" });
const res = await fetch(`https://api.marketnewsapi.com/v1/trending?${params}`, {
 headers: { Authorization: `Bearer ${process.env.MARKETNEWSAPI_KEY}` },
});
if (!res.ok) throw new Error(`HTTP ${res.status}`);
console.log(await res.json());
```

```go
package main

import (
	"fmt"
	"io"
	"net/http"
	"os"
)

func main() {
	req, _ := http.NewRequest("GET", "https://api.marketnewsapi.com/v1/trending?window=24h&limit=10", nil)
	req.Header.Set("Authorization", "Bearer "+os.Getenv("MARKETNEWSAPI_KEY"))

	res, err := http.DefaultClient.Do(req)
	if err != nil {
 panic(err)
	}
	defer res.Body.Close()

	body, _ := io.ReadAll(res.Body)
	fmt.Println(string(body))
}
```

```php
<?php
$query = http_build_query(['window' => '24h', 'limit' => 10]);
$ch = curl_init("https://api.marketnewsapi.com/v1/trending?$query");
curl_setopt_array($ch, [
 CURLOPT_RETURNTRANSFER => true,
 CURLOPT_HTTPHEADER => ['Authorization: Bearer ' . getenv('MARKETNEWSAPI_KEY')],
]);
$body = json_decode(curl_exec($ch), true);
curl_close($ch);

print_r($body);
```

```ruby
require "json"
require "net/http"

uri = URI("https://api.marketnewsapi.com/v1/trending")
uri.query = URI.encode_www_form(window: "24h", limit: 10)
req = Net::HTTP::Get.new(uri)
req["Authorization"] = "Bearer #{ENV.fetch('MARKETNEWSAPI_KEY')}"

res = Net::HTTP.start(uri.host, uri.port, use_ssl: true) { |http| http.request(req) }
puts JSON.pretty_generate(JSON.parse(res.body))
```

```csharp
using System.Net.Http.Headers;

using var http = new HttpClient();
http.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue(
 "Bearer", Environment.GetEnvironmentVariable("MARKETNEWSAPI_KEY"));

var json = await http.GetStringAsync("https://api.marketnewsapi.com/v1/trending?window=24h&limit=10");
Console.WriteLine(json);
```

```java
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;

public class Main {
 public static void main(String[] args) throws Exception {
 HttpRequest req = HttpRequest.newBuilder()
 .uri(URI.create("https://api.marketnewsapi.com/v1/trending?window=24h&limit=10"))
 .header("Authorization", "Bearer " + System.getenv("MARKETNEWSAPI_KEY"))
 .build();

 HttpResponse<String> res = HttpClient.newHttpClient()
 .send(req, HttpResponse.BodyHandlers.ofString());
 System.out.println(res.body());
 }
}
```

## Example response

200 OK

```json
{
 "data": [
 {
 "symbol": "NVDA",
 "kind": "ticker",
 "articles": 142
 },
 {
 "symbol": "AAPL",
 "kind": "ticker",
 "articles": 118
 },
 {
 "symbol": "TSLA",
 "kind": "ticker",
 "articles": 97
 }
 ],
 "meta": {
 "window": "24h",
 "category": null
 }
}
```

## Try it

## Errors

This endpoint returns the standard [error format](/docs/errors). The most common errors are `400 invalid_parameter`, `401 invalid_api_key` and `429 daily_limit_reached` (Free plan).
