Skip to content

belivenn/openbook-cli

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

22 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

OpenBook CLI

A comprehensive command-line interface for interacting with OpenBook and Serum DEX markets on Solana.

πŸš€ Features

  • Auto-detection: Automatically detects OpenBook vs Serum markets
  • Real-time data: Fetches live order book data from the blockchain
  • Market management: Add and list known markets
  • Universal support: Works with any market address (known or unknown)
  • Separate storage: Maintains separate files for OpenBook and Serum markets

πŸ“¦ Installation

npm install -g openbook-cli

Or install locally:

npm install openbook-cli

🎯 Quick Start

# Fetch market data (auto-detects OpenBook/Serum)
openbook-cli Gc4tfUHRNnpVwvASfQD3q26G8GNmLYuz4KzB4QNkNuiQ

# Add market to known markets
openbook-cli 8nqjw5UVN65GyfdqiXnfJNbDVBgbk8RpFFd7uACXenbx --add

# List OpenBook markets
openbook-cli --list

# List Serum markets
openbook-cli --list --serum

πŸ“‹ Commands

Fetch Market Data

openbook-cli <market_address>

Fetches real-time market information and order book data.

Add Market to Known Markets

openbook-cli <market_address> --add

Adds a market to the persistent storage for future quick access.

List Known Markets

# List OpenBook markets
openbook-cli --list

# List Serum markets
openbook-cli --list --serum

πŸ” Auto-Detection

The CLI automatically detects whether a market belongs to OpenBook or Serum by checking the market account owner:

  • OpenBook: srmqPvymJeFKQ4zGQed1GFppgkRHL9kaELCbyksJtPX
  • Serum: 9xQeWvG816bUx9EPjHmaT23yvVM2ZWbrrpZb9PusVFin

πŸ“Š Data Storage

The CLI maintains separate files for different market types in the installation directory:

  • known_openbook_markets.json - OpenBook markets and token symbols
  • known_serum_markets.json - Serum markets and token symbols

File Location: The market files are stored in the CLI's installation directory:

~/.nvm/versions/node/v24.2.0/lib/node_modules/openbook-cli/dist/

You can find the exact location by running:

npm list -g openbook-cli

πŸ“ˆ Order Book Data

The CLI fetches live order book data directly from the blockchain:

  • Bids: Buy orders sorted by price (highest first)
  • Asks: Sell orders sorted by price (lowest first)
  • Depth: Configurable depth (default: 15 levels)

Market Statistics

  • Total Bids/Asks: Number of orders on each side
  • Best Bid/Ask: Highest bid and lowest ask prices
  • Spread: Difference between best ask and best bid
  • Spread %: Spread as a percentage of best bid

πŸ› οΈ Development

Prerequisites

  • Node.js >= 16.0.0
  • TypeScript

Setup

git clone https://github.com/belivenn/openbook-cli.git
cd openbook-cli
npm install

Build

npm run build

Development

npm run dev

πŸ“ Examples

Basic Market Fetch

# Fetch any market (auto-detects type)
openbook-cli Gc4tfUHRNnpVwvASfQD3q26G8GNmLYuz4KzB4QNkNuiQ

Add New Markets

# Add OpenBook market
openbook-cli EgnTFXgaQ8CzVSQJyTD2sT3Yx8esLgKf5e6YGvQfm2U7 --add

# Add Serum market
openbook-cli 8nqjw5UVN65GyfdqiXnfJNbDVBgbk8RpFFd7uACXenbx --add

List Markets

# List OpenBook markets
openbook-cli --list

# List Serum markets
openbook-cli --list --serum

Check Market Files Location

# Find where market files are stored
npm list -g openbook-cli
ls -la $(npm list -g openbook-cli | grep openbook-cli | awk '{print $2}')/dist/*.json

πŸ”§ Configuration

The CLI uses the following configuration:

  • RPC Endpoint: Default Solana RPC
  • Market Files: Stored in the current directory
  • Token Symbols: Cached for faster access

🚨 Error Handling

Common Issues

  1. Market not found: Invalid market address
  2. Network issues: Connection problems to Solana RPC
  3. Token metadata unavailable: Missing Metaplex data
  4. Program ownership mismatch: Market belongs to different program

Error Messages

  • ❌ Market account not found - Invalid market address
  • ❌ Market verification failed - Program ownership issue
  • No Metaplex metadata found - Token symbol resolution failed

πŸ“Š Performance

Response Times

  • Known markets: ~2-3 seconds
  • Unknown markets: ~3-5 seconds (includes metadata fetch)
  • Order book data: ~1-2 seconds

Network Usage

  • Each market fetch requires multiple RPC calls
  • Order book data is fetched in real-time
  • Token metadata is cached after first fetch

πŸ”’ Security

Data Sources

  • All data comes directly from Solana blockchain
  • No third-party API dependencies
  • Real-time verification of market ownership

Market Validation

  • Verifies market account exists
  • Checks program ownership
  • Validates token mint addresses

πŸ“„ License

MIT License - see LICENSE file for details.

🀝 Contributing

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add some amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors