Real-time Updates
Stream real-time trading and token creation data by connecting to the PumpPortal Websocket at wss://pumpportal.fun/api/data
.
Once you connect, you can subscribe to different data streams. The following methods are available:
-
subscribeNewToken
For token creation events. -
subscribeTokenTrade
For all trades made on specific token(s). -
subscribeAccountTrade
For all trades made by specific account(s).
You should NOT open a new Websocket connection for every token or account you subscribe to. Instead, you should send any new subscribe messages to the same connection. Clients that repeatedly attempt to open many websocket connections at once may be blacklisted. If this happens you must reach out in Telegram so we can remove the ban.
Examples:
- Python
- JavaScript
import asyncio
import websockets
import json
async def subscribe():
uri = "wss://pumpportal.fun/api/data"
async with websockets.connect(uri) as websocket:
# Subscribing to token creation events
payload = {
"method": "subscribeNewToken",
}
await websocket.send(json.dumps(payload))
# Subscribing to trades made by accounts
payload = {
"method": "subscribeAccountTrade",
"keys": ["AArPXm8JatJiuyEffuC1un2Sc835SULa4uQqDcaGpAjV"] # array of accounts to watch
}
await websocket.send(json.dumps(payload))
# Subscribing to trades on tokens
payload = {
"method": "subscribeTokenTrade",
"keys": ["91WNez8D22NwBssQbkzjy4s2ipFrzpmn5hfvWVe2aY5p"] # array of token CAs to watch
}
await websocket.send(json.dumps(payload))
async for message in websocket:
print(json.loads(message))
# Run the subscribe function
asyncio.get_event_loop().run_until_complete(subscribe())
import WebSocket from 'ws';
const ws = new WebSocket('wss://pumpportal.fun/api/data');
ws.on('open', function open() {
// Subscribing to token creation events
let payload = {
method: "subscribeNewToken",
}
ws.send(JSON.stringify(payload));
// Subscribing to trades made by accounts
payload = {
method: "subscribeAccountTrade",
keys: ["AArPXm8JatJiuyEffuC1un2Sc835SULa4uQqDcaGpAjV"] // array of accounts to watch
}
ws.send(JSON.stringify(payload));
// Subscribing to trades on tokens
payload = {
method: "subscribeTokenTrade",
keys: ["91WNez8D22NwBssQbkzjy4s2ipFrzpmn5hfvWVe2aY5p"] // array of token CAs to watch
}
ws.send(JSON.stringify(payload));
});
ws.on('message', function message(data) {
console.log(JSON.parse(data));
});
You can also unsubscribe from any data stream in the same way, using the following methods:
-
unsubscribeNewToken
-
unsubscribeTokenTrade
-
unsubscribeAccountTrade
- Python
- JavaScript
import asyncio
import websockets
import json
async def subscribe():
uri = "wss://pumpportal.fun/api/data"
async with websockets.connect(uri) as websocket:
# Subscribing to token creation events
payload = {
"method": "subscribeNewToken",
}
await websocket.send(json.dumps(payload))
# Unsubscribing from new token events
payload = {
"method": "unsubscribeNewToken",
}
await websocket.send(json.dumps(payload))
async for message in websocket:
print(json.loads(message))
# Run the subscribe function
asyncio.get_event_loop().run_until_complete(subscribe())
const ws = new WebSocket(`wss://pumpportal.fun/api/data`);
ws.on('open', function open() {
ws.send(JSON.stringify({
method: "subscribeTokenTrade",
keys: ["Bwc4EBE65qXVzZ9ZiieBraj9GZL4Y2d7NN7B9pXENWR2"]
}));
// unsubscribe after 10 seconds
setTimeout(()=>{
ws.send(JSON.stringify({
method: "unsubscribeTokenTrade",
keys: ["Bwc4EBE65qXVzZ9ZiieBraj9GZL4Y2d7NN7B9pXENWR2"]
}));
}, 10000);
});