How to stream real-time DEX token prices with SSE (curl, JavaScript, Python)

Mateusz Sroka

(about 1 month ago)

5 min read

Share:

Stream live DEX token prices over a single HTTP connection with Server-Sent Events: no WebSocket setup, and working curl, JavaScript, and Python examples across all 35 supported chains.

How to stream real-time DEX token prices with SSE (curl, JavaScript, Python)

You can stream live DEX token prices over a single HTTP connection using Server-Sent Events (SSE), with no WebSocket setup. Point an EventSource (or a plain curl) at the DexPaprika streaming endpoint, pass a chain and token address, and you get a price push roughly every second. This guide shows the working calls in curl, JavaScript, and Python, across all 35 supported chains.

I reached for this while building a price ticker and did not want to stand up a WebSocket client, handle the handshake, and write reconnect logic just to show a number that ticks. SSE turned out to be the lazy-in-a-good-way option: it's just an HTTP response that never ends.

SSE or WebSocket?

For a one-directional feed (server pushes prices, client listens) SSE is the simpler tool. You open one HTTP connection and read events off it. There's no upgrade handshake, the browser's built-in EventSource reconnects automatically if the connection drops, and it rides over plain HTTP/2 so proxies and firewalls leave it alone. WebSocket earns its keep when you also need to push messages back up the same socket, which a price feed doesn't. If you're still weighing the two protocols, we wrote a deeper SSE vs WebSocket comparison with implementation details for both.

It's also worth noting where the wind is blowing: several of the real-time crypto feeds developers leaned on for years have shut down or moved behind restrictive plans. DexPaprika's streaming API keeps the barrier low: every example in this guide runs as-is with nothing but curl, which is the main reason this guide is short.


Quick start with curl

Stream the price of wrapped SOL on Solana:

curl -N "https://streaming.dexpaprika.com/sse/prices?method=token_price&chain=solana&address=So11111111111111111111111111111111111111112"

The -N flag tells curl not to buffer, so you see events as they arrive. You'll get a stream like this, updating about once a second:

event: token_price
data: {"address":"So11111111111111111111111111111111111111112","chain":"solana","price":"78.08898582500176","timestamp":1783590010,"timestamp_price":1783590010,"token_price":1783590010}

Three things to notice: price is a string (parse it before doing math), timestamp is Unix seconds (the extra timestamp_price and token_price fields mirror it, so timestamp is the one to read), and the event is named token_price, which matters for the client code below.


In the browser with EventSource

EventSource is built into every modern browser and is purpose-built for SSE. No library needed:

const url =
  "https://streaming.dexpaprika.com/sse/prices?method=token_price&chain=solana&address=So11111111111111111111111111111111111111112";

const stream = new EventSource(url);

stream.addEventListener("token_price", (event) => {
  const { price, timestamp } = JSON.parse(event.data);
  console.log(`SOL: $${Number(price).toFixed(2)} @ ${new Date(timestamp * 1000).toLocaleTimeString()}`);
});

stream.onerror = () => console.log("reconnecting...");

That's a complete live price feed. EventSource handles reconnection for you, so the onerror handler is mostly there to tell you it's happening.


In Python

No SSE library required, just stream the response line by line:

import json
import requests

url = "https://streaming.dexpaprika.com/sse/prices"
params = {
    "method": "token_price",
    "chain": "solana",
    "address": "So11111111111111111111111111111111111111112",
}

with requests.get(url, params=params, stream=True) as r:
    for line in r.iter_lines():
        if line and line.startswith(b"data:"):
            data = json.loads(line[5:])
            print(data["chain"], data["price"])

Multiple tokens on one connection

For a dashboard or portfolio you don't want a connection per token. POST a JSON array (up to 25 entries) and get them all on one stream:

curl -N -X POST "https://streaming.dexpaprika.com/sse/prices" \
  -H "Content-Type: application/json" \
  -d '[
    {"chain": "solana", "address": "So11111111111111111111111111111111111111112", "method": "token_price"},
    {"chain": "ethereum", "address": "0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2", "method": "token_price"}
  ]'

Each event still carries its own address and chain, so you route updates to the right row in your UI by reading those fields. For more than 25 subscriptions, open a second stream. And if your dashboard is heading toward hundreds or thousands of tokens, we covered the architecture for that in building a scalable crypto price feed from 1 to 10,000 tokens.


Bonus: live pool reserves

The same transport has a second feed for pool liquidity. Swap /sse/prices for /sse/reserves to watch block-level reserve changes, which is what you want for TVL dashboards, slippage estimation, or spotting liquidity drains:

curl -N "https://streaming.dexpaprika.com/sse/reserves?method=token_reserves&chain=ethereum&address=0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2"

We built a whole open-source liquidity-drain detector on this exact feed, so it holds up beyond toy examples.


Why not just poll?

A polling loop that hits a REST endpoint every second is 86,400 requests per token per day, most of them returning a price that didn't change. SSE flips that around: one connection, and the server speaks only when there's something to say. Less bandwidth, lower latency, and far fewer wasted requests.


FAQ

Do I need an API key to stream prices?

Not to run the examples in this guide: they work as-is with plain curl, no signup step. For the current access model and limits, the streaming docs are the source of truth.

Is this WebSocket?

No, it's Server-Sent Events (SSE) over HTTP. For a server-to-client price feed, SSE is simpler than WebSocket and the browser's EventSource handles reconnection automatically.

How often do prices update?

Roughly once per second per token for the price feed. Reserve updates land block-by-block as on-chain liquidity changes.

Which chains are supported?

All 35 chains DexPaprika indexes, including Ethereum, Solana, Base, BSC, and Arbitrum. Pass the chain ID and a token address from that chain.

How many tokens can one connection handle?

Up to 25 via the POST form. Beyond that, open additional parallel streams.

Why is price a string?

To preserve precision for very small or very large token prices. Convert it to a number in your code before doing arithmetic.


Where to go next

Related articles

Latest articles

Coinpaprika education

Discover practical guides, definitions, and deep dives to grow your crypto knowledge.

Cryptocurrencies are highly volatile and involve significant risk. You may lose part or all of your investment.

All information on Coinpaprika is provided for informational purposes only and does not constitute financial or investment advice. Always conduct your own research (DYOR) and consult a qualified financial advisor before making investment decisions.

Coinpaprika is not liable for any losses resulting from the use of this information.

Go back to Education