Looking to build a debt hedging bot for Centralised exchanges for Linear Stakers

Hey Linear Fam

This isn’t an official proposal I’m just looking to gauge team and community interest.

I’m working on building a debt hedging program for centralised exchanges. It’s fairly straightforward, Stakers will stake Lina as normal and then hedge the debt pool by shorting the assets in the pool by weight. I’m sure most people are already doing this manually. I just wanted to build a way to do this automatically with auto-rebalancing at a chosen time frame.

The current way I’ve started working on doing it is by running a cloud python instance and using exchange api keys to interact with an FTX subaccount. The account will use perps to short the debt pool and keep the staker delta neutral. I’m using the ccxt trading library as it can be easily modified to use other exchanges (currently starting off with just FTX). I believe using an exchange is fine as most people already do for one and secondly, it can be more capital efficient if you use even a small amount of leverage.

So firstly I’m looking to gauge interest from the team and community. I’m also looking to see what kinds of features you’d like to see if I go ahead with it. For example a GUI, Lending USD positions, an app etc. Any feedback will be greatly appreciated.

1 Like

Hey, can you explain the detailed benefits for investors and project by this approach. What would be the value by doing this?

1 Like

Overall it’s an ease of use thing.

It makes hedging simpler as it’s done automatically. We currently have a lot of people getting liquidated and hence the need for the liquidator bot (a great addition to the protocol). As a staker, if you correctly hedge you no longer run the risk of your debt ratio dropping too low. If we there’s an easy way to stake like this it should make staking more attractive to novice users or people who just don’t want to manage their positions all the time.

Currently SNX, a similar protocol offers this feature on chain via dhedge. I think it’ll be a useful to have this offchain as well as you can be more capital efficient with exchanges.


Okay. There is a good video about a “hedging” concept on youtube and there are no centralized exchanges involved. Maybe you want to look into it:

I wrote a dApp for adjusting holings like it is described in the video on the linear exchange. But I will not provide this tool for public usage because I don’t want to be reliable for any potential problems. I use it on a daily to weekly basis to balance my portfolio and the strategy works. Already presented it to the linear team and maybe some kind of balancing helper will be integrated in the future, but I don’t know if it will really happen. Maybe it depends on the demand by the community.

If you have another concept in mind I would like to hear the strategy details, if you would like to share them.

Best regards.

1 Like

Sorry in my first post I meant to long the debt pool instead of short. And yeah as you find a debt hedging bot useful I’m sure the rest of the community will too. You can do this on chain but as far as I know it’s difficult to use leverage and more complex strategies. I’ve chosen to use centralised exchanges for those reasons.

1 Like

overall, anything that provides users with the ability to stay balanced with the debt pool would be a welcome development from the linear community. the risk is if it fails and people were relying on it. that’s a big risk for people, so we’d have to think carefully about that.

ultimately, managing the portfolio against the debt pool is one of the most requested features i’ve seen from the community, and i think it would be worth further exploring this effort

welcome to the community, btw. nice to see some thoughtful ideas coming from new faces!


Hey @Captain_Trips_Linear, nice you joined this thread.

If this is one of the most requested features, maybe I can provide a first temp solution. Like mentioned earlier, there is a dApp I build which allows balancing your portfolio against the debt pool.

I don’t know if there is any possibility to publish it without getting red flagged. It’s a useful tool for my trading on the linear platform but theoretically everyone can connect and manage their own portfolio with it. Maybe we could find a way to bring this tool to production and share it with the community.

@Bowser_LinearFinance and Lap from Linear Team already looked into it and showed some interest.

Any ideas or suggestions?

Thanks for the positive feedback and great to be a part of the community. I’m happy to keep working on a centralized exchange solution for those who’d prefer that. Let me know if you have any suggestions or tips from the team.

what do you mean by “red flagged”? who would red flag it?

some of the best communities i’ve seen have their users build products to enhance the overall project. i think this would be a welcome tool for the community.

getting it integrated into the official linear dapp would take a vote from the community and approval from the core team. however, if you decided to create a LIP for some funds to create the tool for the community, as a community/non-official tool, i’d likely support it


If someone want to take a look it’s at linear-balancer.com. I will add missing and remove abandoned tokens soon. I will not take any responsibility for any bugs! Use it at your own risk and check the transaction details before using it! Please only use it if you know what you’re doing, it’s alpha stage software! I developed it in my spare time but I use this tool. Currently it’s not working in MM mobile but I will also look into this. You don’t need to connect your wallet if you are not comfortable, you only need to paste your crypto address. You can use it only to calculate the holdings. Instead of using the buttons to buy or sell, trade it with the shown amounts directly on the linear exchange. It’s based on all available liquids in the debt pool on BSC and ETH and uses these number for the calculations.

Hope it helps some people to manage their debt accordingly!
Best regards!

1 Like

wow, this is really interesting. i think it deserves a little more attention than hidden in this thread.

when you get the time, would you mind writing a separate general post on how to use?

this is something that should get more feedback from the community!



please see the above post

1 Like

Wow, I have to say this is looking good!
Looking forward to an article on how to use this tool.
Maybe the team can post the article on the Medium profile to reach the community?

1 Like

thank you for the feedback. I will do a separate thread when I reiterate over the the dApp. I have not much spare time atm, so this will likely be delayed for some time.

I can summarize the function here a bit:
The first view entering the dApp you can enter your crypto address where the liquids are stored or you can directly connect with Metamask (Use it at your own risk!).

After providing the address you will be automatically redirected to the balancer view. On the top you see some general controls.

The most important is the Balance button on the left. By clicking the algorithm will automatically calculate a balanced distribution of the activated liquids according to the overall debt pool. The inputs on the same line are setting some constrains on the balancing strategy:

  • max balance gain factor adjusts the width of the sliders below where you can in/decrease your balance to specific assets.
  • max position deviation adjusts the amount of deviation in lUSD from the desired balance when you wish to trade / adjust your balance. This will only suggest trading actions if the deviation is bigger than this value.
  • minimum lUSD left ensures that you will always have enough lUSD after trading to pay future trading fees. I don’t actually know if this works correctly because I never hit that edge.

The liquid views below shows the actual state of your portfolio and how it is currently balanced against the debt pool.

There is a slider in place where you can adjust your desired amount relatively to the debt pool. Below the slider there is a number which shows how it is currently balanced. In the example above the BNB amount relatively to the accounts liquids is 1.93x higher than it is in the overall debt pool. The Button below that value activates/deactivates the liquid for the balancing described in the first part. You can use this button to fix the current amount of that liquid by deactivating the liquid for balancing.

The view right to the slider shows the balancing information and allows the user to trade the asset according to the calculated Balance:

Here the balancer calculated, that the user should sell 2.092 lBNB to reach the desired balance. In case Metamask is connected you can click on that button and execute the transaction through the linear exchange spot contract. Ensure that Metamask shows the correct contract address like in the followoing:

The linear exchange address is: 0x2C33d6Fa54bB6Fa81B3a569D639Fe23ab36cca7f

You should also check the hex attributes in Metamask if everything is setup correctly for the transaction. especially you should look for your address in the transaction to ensure that it is the target address for the trade (third attribute):

Please only connect Metamask if you know what you are doing!
Otherwise you could also read the desired trade from the button and trade it directly on the linear exchange.

Hope this little tutorial helps. I will do a follow up if I had the time on overhaul the dApp. If there are questions you could reach out here, I will try to answer everything.

Best regards!


Hey, looks very good, that’s definitely something that could increase the activity on the exchange, I’d definitely use it if I don’t have too much time to spend to deeply research every single pairs to « beat » the debt pool.

1 Like

incredible, pho

you are a rockstar!