Skip to content

thiras/clobster

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

49 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

CLOBster

Crates.io License: MIT Rust Documentation

CLOBster is a terminal user interface (TUI) framework for Polymarket prediction markets. Built with Rust, ratatui, and polymarket-rs.

Features

  • πŸ–₯️ Modern TUI β€” Beautiful terminal interface with vim-style navigation
  • πŸ“Š Real-time Data β€” Live market updates via WebSocket
  • πŸ€– Programmable Strategies β€” Build and deploy custom trading strategies
  • ⚑ High Performance β€” Built in Rust for speed and reliability
  • πŸ›‘οΈ Risk Management β€” Built-in guards and position limits
  • βš™οΈ Configurable β€” TOML-based configuration with sensible defaults

Installation

Requirements

  • Rust 1.85+ (2024 edition)
  • A Polymarket account with API credentials

From Crates.io

cargo install clobster

From Source

git clone https://github.com/thiras/clobster.git
cd clobster
cargo build --release

The binary will be at target/release/clobster.

Quick Start

  1. Create a configuration file at ~/.config/clobster/config.toml:
[api]
base_url = "https://clob.polymarket.com"
ws_url = "wss://ws-subscriptions-clob.polymarket.com/ws"
timeout_secs = 30

[ui]
tick_rate_ms = 100
mouse_support = true
unicode_symbols = true

[keybindings]
up = "k"
down = "j"
left = "h"
right = "l"
quit = "q"
help = "?"
refresh = "r"
  1. Run CLOBster:
clobster
  1. Enable debug logging (optional):
RUST_LOG=clobster=debug clobster

Architecture

CLOBster follows a unidirectional data flow pattern (Redux/Elm-inspired):

Events β†’ Actions β†’ Store (reduce) β†’ UI renders from Store

Core Modules

Module Purpose
app Event loop, terminal setup, async action handling
state Centralized state with Store, Action enum, and domain states
ui Ratatui rendering, layout, widgets
events Input handling, key bindings β†’ Action dispatch
api Polymarket API wrapper via polymarket-rs
strategy Programmable trading strategies with signals and risk management

Data Flow

  1. User presses key β†’ EventHandler::handle_key() returns Action
  2. App::handle_action() processes async actions (API calls) or delegates to Store::reduce()
  3. Store::reduce() updates state immutably
  4. Ui::render() reads from Store and draws widgets

Trading Strategies

CLOBster provides a powerful framework for building automated trading strategies.

Quick Example

use clobster::strategy::{Strategy, StrategyContext, Signal};
use rust_decimal_macros::dec;

struct MyStrategy {
    threshold: Decimal,
}

impl Strategy for MyStrategy {
    fn name(&self) -> &str { "my_strategy" }

    fn evaluate(&mut self, ctx: &StrategyContext) -> Vec<Signal> {
        let mut signals = vec![];
        for market in ctx.markets() {
            if let Some(outcome) = market.outcomes.first() {
                if outcome.price < self.threshold {
                    signals.push(Signal::buy(
                        market.id.clone(),
                        outcome.token_id.clone(),
                        dec!(0.10),
                    ));
                }
            }
        }
        signals
    }
}

Built-in Strategies

  • Momentum β€” Trend-following based on price movement
  • Mean Reversion β€” Capitalize on price deviations from historical averages
  • Spread β€” Market-making by capturing bid-ask spreads

Risk Management

All strategies pass through a risk guard before execution:

pub struct RiskConfig {
    pub max_position_size: Decimal,
    pub max_order_size: Decimal,
    pub max_daily_loss: Decimal,
    pub max_open_orders: usize,
}

Development

Build Commands

cargo build                          # Debug build
cargo build --release                # Optimized release build
cargo test                           # Run all tests
cargo clippy                         # Run lints
cargo doc --open                     # Generate and view documentation

Run with Debug Logging

RUST_LOG=clobster=debug cargo run

Project Structure

src/
β”œβ”€β”€ app.rs              # Application lifecycle
β”œβ”€β”€ lib.rs              # Public API exports
β”œβ”€β”€ main.rs             # Entry point
β”œβ”€β”€ error.rs            # Error types
β”œβ”€β”€ api/                # Polymarket API client
β”œβ”€β”€ config/             # Configuration management
β”œβ”€β”€ events/             # Input handling
β”œβ”€β”€ state/              # State management (Store, Actions)
β”œβ”€β”€ strategy/           # Trading strategy framework
β”‚   └── strategies/     # Built-in strategy implementations
└── ui/                 # Terminal UI rendering
    └── widgets/        # Reusable UI components

Documentation

Full documentation is available at thiras.github.io/clobster or build locally:

cd docs
mdbook serve

Contributing

Contributions are welcome! Please follow Conventional Commits for commit messages:

  • feat: new features
  • fix: bug fixes
  • refactor: code restructuring
  • test: test additions
  • docs: documentation

License

CLOBster is licensed under the MIT License.

Acknowledgments