Stop Losses & Take Profits on Serum

One thing that might be frustrating with Serum and DEXs in general is the lack of complex order types and in particular stop losses and take profits.

The main reason why DEXs don’t offer them is because you don’t want your stop losses and take profits to be fully visible on chain as this could give information about your position to other market participants.

One way to solve this problem is to have a small off chain program constantly checking the price of the asset and send an on chain transaction when certain conditions are met. For instance, for a take profit, it would be a sell order transaction if BTC price gets above a certain threshold.

Sounds like automating a trading strategy? Well it actually is, and this is where Bonfida Bots and Trading View kick in! 🤖

Let’s say you have created a Bonfida Bot that trades on BTC/USDC, this bot is holding a certain amount of BTC and you want to take profit when BTC gets above $100,000. All you have to do is, go to Trading View on the chart page of BTC/USD and click on Alert on the top bar

The condition is when BTC is crossing up the value 100,000

Then check the box Webhook URL and enter the following address https://tradingview-cranker.bonfida.com/alerts

If your pool address is GwEMLqoRVRz2h2D3GCy2tkwTEyqJ8xouFgVip3W1BkKp , and your TradingView auth token received when creating the pool is 3evM6HU1GEKd5wfR47N1zwGJ9V5gqcHgfecH58nhJRtMVMHnVKaZQ1zGswVZYiQsna1JG9gecj7M

Then your Alert message will be:

{

“auth”:”3evM6HU1GEKd5wfR47N1zwGJ9V5gqcHgfecH58nhJRtMVMHnVKaZQ1zGswVZYiQsna1JG9gecj7M”, “poolSeed”:”GwEMLqoRVRz2h2D3GCy2tkwTEyqJ8xouFgVip3W1BkKp”,

“marketName: “BTC/USDC”,

“side”:”sell”,

“size”:100

}

For a stop loss everything would be identical except for the condition where it would be: BTC is crossing down the value X. Where X is your stop loss price.

Create a bot here: https://bots.bonfida.org/#/create

Learn how to create a bot with this video: https://www.youtube.com/watch?v=6BFmyi0qnEI

Generate TradingView messages: https://bots.bonfida.org/#/tradingview-generator