Crypto Domination: Create a Trading Bot for Pump.fun That Knows When to Buy and Sell
A single-file Python bot that watches every Pump.fun launch, tracks live trades over WebSocket, and applies entry, take-profit, and stop-loss rules automatically. The capstone of our Pump.fun series.
On this page +
This is the most requested follow-up to our Pump.fun WebSocket series: a bot that watches every new token launch, tracks the trades that follow, and decides when to buy and when to get out. We'll build it in Python, in one file, using two WebSocket subscriptions and three price thresholds. By the end you'll have a running signal engine you can extend into a real trading system.
01What we're building#
The bot does three things. It subscribes to Pump.fun coin creation events, so it knows about every token the moment it launches. It subscribes to the trade stream for all coins, so it sees every buy and sell as it happens. And it runs simple position logic on top: when a tracked coin trades at or above your entry price, it registers a buy; from there it watches for either a take-profit or a stop-loss and prints the exit.
One thing worth being upfront about: this version signals trades, it doesn't sign them. The printed BUY and SELL lines are where you'd wire in an actual swap if you want to trade with real funds. Keeping the detection logic separate from execution is also just good practice. You can paper-trade the strategy for a week and see how it behaves before risking a single lamport.
02What you need#
- Python 3.x. Any recent version works. If you're somehow still on 2.x, this is your sign to upgrade.
- The
websocket-clientpackage (pip install websocket-client). - A NoLimitNodes API key, which is free. That's next.
03Get an API key#
Head to nolimitnodes.com and click Start Building to create an account. A token is generated for you by default, and you can create another one from the dashboard with the Get button. Copy it somewhere handy; every connection in this guide uses it.
04How the WebSocket API works#
Before writing any Python, it helps to see the raw requests and responses. Everything goes through one endpoint:
wss://api.nolimitnodes.com/pump-fun?api_key=YOUR_API_KEY
With the socket open, you subscribe to coin creation events by sending this:
The server confirms the subscription:
From then on you receive a live stream of coins as they're created. Each event carries the mint address, the bonding curve accounts, the creator's wallet, and the metadata URI:
Trades work the same way, over the same endpoint. To follow a single coin, pass its address:
To follow every coin on the platform at once, pass "all":
After the confirmation:
you'll get a continuous stream of tradeEventNotification messages. Note the parts our bot will care about: token_out.token (which coin was traded) and price.sol (what it traded at):
05Setting up the script#
Open your editor of choice (I use PyCharm) and create trading_bot_pumpFun.py. Three imports cover everything:
Next, the three numbers that define the whole strategy. Prices on Pump.fun are tiny because supply is huge, so don't let the zeros throw you:
The logic these encode: buy when a tracked coin trades at buyPrice or better, take profit at 50% above entry, and cut the loss if price drops 20% below entry. Tune all three to your own appetite.
Then the two subscription messages from earlier, as Python dicts:
Finally, two dictionaries to hold state. buyDict is the watchlist: every newly created coin lands here. sellDict holds coins we've "bought" and are now managing toward an exit. Both are keyed by mint address:
06The trading logic#
Two message handlers do the actual work. The first one is simple: every time a coin is created, add it to the watchlist.
The second is the interesting one. For every trade on the network, it checks whether the coin is on our watchlist and whether the price satisfies the entry condition. If so, the coin moves from buyDict to sellDict and we print the buy. For coins we already hold, it checks the exits: take-profit hit, stop-loss hit, or neither.
07Running both sockets#
A small helper builds and runs a WebSocketApp with the right callbacks:
The coin stream and the trade stream are two separate connections, and both need to run at the same time, so each gets its own thread:
Run the script and you'll see both connections open, the two subscription confirmations, and then the output starts flowing: new coins joining the watchlist silently, BUY lines as entries trigger, and SELL lines as positions resolve one way or the other.
08Where to take it from here#
What you have now is an engine that:
- Knows about every Pump.fun launch within moments of it happening
- Tracks live prices for every coin on the platform over a single connection
- Applies entry, take-profit, and stop-loss rules automatically
The obvious next steps are the ones that turn signals into a real system: wire the BUY and SELL prints into actual swap execution, persist state across restarts, and add reconnect logic so a dropped socket doesn't take the bot down with it. The rest of the series covers smarter exit strategies like trailing stop-losses and drawdown-based entries if you want to push the strategy further.
A closing word of caution, because it matters: meme coin markets are brutal, and a bot that buys every new launch will buy a lot of garbage. Thresholds alone are not a strategy. Treat this as infrastructure for testing your own ideas, paper-trade it before funding it, and never risk money you can't afford to lose.
Every benchmark in this blog runs against our public endpoints.
Spin up an RPC, WebSocket, or gRPC endpoint in under a minute — flat pricing, no request caps — and reproduce the numbers for your own workload.