Building a Grid Trading Bot on Bithumb

🌐 한국어

Predicting direction is hard. Bull or bear? It's a guessing game. Grid trading flips the approach. Instead of predicting, monetize volatility itself. I built a grid bot on Bithumb and learned its mechanics and limits.

Grid Trading Basics

Place a grid of buy/sell levels at regular intervals, then mechanically buy and sell at each level as price oscillates.

  • Price falls → buy at the lower grid level
  • Price rises → sell at the upper grid level

Buy low, sell high—the timeless rule, automated and emotion-free. Shines in ranging markets, where price bounces between bounds. Each oscillation yields the grid interval as profit. It struggles in persistent downtrends (buy orders accumulate, losses mount). Understanding this weakness is critical.

Buy/Sell Gap Strategy

The key parameter: gap, the distance between buy and sell prices. This gap is where profit originates per cycle.

Current price: 100, Gap: 2%

├─ Sell order: 102 (target price to lock gains)

├─ Current:    100

└─ Buy order:   98 (buy dips to lower cost basis)

Conceptually:

type GridConfig struct {

    OrderCount int     // how many grid levels

    GapPercent float64 // buy/sell spacing (%)

    OrderQty   float64 // size per order

}

// Derive buy/sell targets from current price

func gridLevels(price float64, cfg GridConfig) (buys, sells []float64) {

    for i := 1; i <= cfg.OrderCount; i++ {

        gap := cfg.GapPercent / 100 * float64(i)

        buys  = append(buys,  price*(1-gap)) // below, for buys

        sells = append(sells, price*(1+gap)) // above, for sells

    }

    return

}

When a buy fills, place a sell above it. When that sell fills, place a new buy below. The cycle repeats, stacking profit equal to the gap.

Narrow gap = frequent cycles but higher trading fees eat you. Wide gap = infrequent but bigger per-turn profit. The art: pick a gap that survives fees.

Monitoring with a Web Dashboard

Running a grid bot by watching console logs is torture. You need to see active orders, balances, and coin holdings at a glance, and adjust parameters without restarting.

http.HandleFunc("/api/status",   handleStatus)   // price, order count, balances

http.HandleFunc("/api/settings", handleSettings) // gap, qty, symbol—query/update

http.HandleFunc("/api/orders",   handleOrders)   // active buy/sell orders

http.HandleFunc("/api/reset",    handleReset)    // cancel all, reinit at current price

Essential dashboard features:

  • Real-time state — current price, active buy/sell order count, coin and cash balance (10-second poll)
  • Live parameter tuning — adjust gap, order size, symbol without restart
  • Order reset — if the grid drifts one-sided, wipe all orders and redeploy centered on current price

Order reset especially matters. When price escapes the grid range, only one side remains. Reset recenter the grid at current price.

Security and Operations

For exchange API bots, never skip:

  • Minimize API key permissions — trading only; output/withdrawal absolutely forbidden
  • Dashboard exposure scope — default: localhost (127.0.0.1). If exposed externally, require auth and HTTPS (keys can leak)
  • Downtrend defense — grids are weak in persistent falls. Add stop-loss or range-exit logic; don't skip it

Summary

  • Grid trading monetizes volatility, not direction; strong in ranges, weak in trends
  • Gap is the profit source per cycle—pick a width that survives fees
  • Web dashboard monitors orders and balances in real time; adjust parameters live
  • One-directional falls expose a weakness; add range-exit logic and minimize API permissions

Grid trading is simple, thus powerful. But it's not magic. Respect market regime and defend against weaknesses—then it becomes a genuinely useful tool.

This is educational material, not investment advice. Automation carries risk of total loss. You alone are responsible for outcomes.

댓글

이 블로그의 인기 게시물

한국투자증권 KIS API로 실시간 시세 받기 (WebSocket 실전)

파이썬으로 업비트 API 연동하기 — 시세 조회부터 주문까지 기초

Go로 자동매매 신호봇 프레임워크 설계하기