DEV Community

Cover image for Leverage trading math: position sizing for 5x perps
Lucas Gragg
Lucas Gragg

Posted on

Leverage trading math: position sizing for 5x perps

Packaged hyperliquid perpetual futures trading bot this week after running it in production for ~60 days. Notes on what worked and what didn't.

The problem

Leveraged perp futures trading bot for Hyperliquid DEX. Supports long and short positions, up to 50x leverage, with built-in risk management. Includes momentum, mean-reversion, and breakout strategies.

What's in the box

  • Hyperliquid DEX integration
  • Long & short trading
  • Configurable leverage (1-50x)
  • 3 built-in strategies
  • Trailing stop-loss
  • Web dashboard

Code sample

# Basic structure
class Bot:
    def __init__(self, config):
        self.config = config

    def run(self):
        while True:
            self.scan()
            self.execute()
Enter fullscreen mode Exit fullscreen mode

If you want the full working version with all the battle-tested edge cases
handled, I packaged it here: Hyperliquid Perpetual Futures Trading Bot

Happy to answer questions about the architecture in the comments.

Top comments (0)