Skip to content

minhdqdev-org/dsta-cli

Repository files navigation

DSTA CLI

A professional command-line interface for DSTA (Dr. Strange Trading Analysis) system

Features

  • Comprehensive Trading Operations: Execute trades, manage positions, and monitor portfolio
  • Market Data Management: Fetch, sync, and export historical and real-time market data
  • Strategy Development: Create, backtest, and deploy trading strategies
  • Machine Learning: Train and deploy ML models for predictions
  • Advanced Analytics: Performance metrics, charts, and detailed reports
  • Multi-Environment Support: Switch between local, staging, and production contexts
  • Beautiful CLI: Rich terminal UI with colors, tables, and progress indicators
  • API-First Design: Fully integrated with DSTA microservices architecture

Installation

From Source

cd /home/minhdqdev/Projects/dsta/dsta-cli
mise install

# Install with uv (recommended)
uv tool install --from . dsta-cli

# Or install into the project environment
mise run install-cli

Quick Start

1. Authentication

# Login to DSTA
dsta login

# With specific endpoint
dsta login --endpoint https://api.dsta.dev

# Check current user
dsta whoami

# Logout
dsta logout

2. Market Data

# Fetch candlestick data
dsta data fetch BTCUSDT --interval 1h --limit 100

# List available symbols
dsta data symbols --exchange binance

# Sync historical data
dsta data sync BTCUSDT --start 2024-01-01 --end 2024-12-31

# Export data to file
dsta data export BTCUSDT --output btc_data.csv --format csv

# Get current tickers
dsta data tickers

3. Trading

# Place a market buy order
dsta trade buy BTCUSDT 0.001

# Place a limit sell order
dsta trade sell BTCUSDT 0.001 --price 50000

# View open positions
dsta trade positions

# Set stop-loss
dsta trade stop-loss BTCUSDT 48000 0.001

# Set take-profit
dsta trade take-profit BTCUSDT 52000 0.001

# Close a position
dsta trade close <position_id>

4. Exchange Operations

# Check account balance
dsta exchange balance

# List orders
dsta exchange orders --symbol BTCUSDT --status open

# View recent trades
dsta exchange trades --symbol BTCUSDT --limit 20

# Get open positions
dsta exchange positions

# Exchange information
dsta exchange info

5. Strategy Management

# List all strategies
dsta strategy list

# Get strategy details
dsta strategy get <strategy_id>

# Run a strategy
dsta strategy run <strategy_id> --symbol BTCUSDT

# Backtest a strategy
dsta strategy backtest <strategy_id> \
  --symbol BTCUSDT \
  --start 2024-01-01 \
  --end 2024-12-31 \
  --capital 10000

# Delete a strategy
dsta strategy delete <strategy_id>

6. Backtesting

# Run a backtest
dsta backtest run <strategy_id> \
  --symbol BTCUSDT \
  --start 2024-01-01 \
  --end 2024-12-31 \
  --capital 10000 \
  --interval 1h

# Get backtest results
dsta backtest results <backtest_id>

# List recent backtests
dsta backtest list --limit 20

# Generate detailed report
dsta backtest report <backtest_id> --output report.json

7. Machine Learning

# Train a model
dsta ml train lstm \
  --symbol BTCUSDT \
  --features close,volume,rsi,macd \
  --epochs 100

# Make predictions
dsta ml predict <model_id> --symbol BTCUSDT --steps 24

# List trained models
dsta ml models

# Evaluate model performance
dsta ml evaluate <model_id>

# Delete a model
dsta ml delete <model_id>

8. Analytics

# Get performance metrics
dsta analytics performance --start 2024-01-01 --end 2024-12-31

# Trading statistics
dsta analytics stats --symbol BTCUSDT --period 30d

# Generate charts
dsta analytics charts equity --start 2024-01-01
dsta analytics charts pnl --period 30d
dsta analytics charts drawdown

# Generate comprehensive report
dsta analytics report --output analytics_report.json

9. Configuration

# Show current configuration
dsta config show

# Get a config value
dsta config get api.endpoint

# Set a config value
dsta config set trading.default_exchange binance
dsta config set output.format table

# Reset to defaults
dsta config reset

# Show current context
dsta config context

# Switch context (environment)
dsta config context staging
dsta config context prod

# List all contexts
dsta config contexts

10. Utilities

# Check API health
dsta health

# Verbose health check
dsta health --verbose

# System status
dsta status

# Ping server
dsta utils ping

# Show version
dsta version

Configuration

DSTA CLI stores configuration in platform-specific directories:

  • Linux: ~/.config/dsta/
  • macOS: ~/Library/Application Support/dsta/
  • Windows: %APPDATA%\dsta\

Configuration File Structure

{
  "api": {
    "endpoint": "http://localhost:8000",
    "timeout": 30,
    "retry": 3
  },
  "auth": {
    "auto_refresh": true
  },
  "output": {
    "format": "table",
    "color": true,
    "compact": false
  },
  "trading": {
    "default_exchange": "binance",
    "default_symbol": "BTCUSDT",
    "default_interval": "1h"
  },
  "cache": {
    "enabled": true,
    "ttl": 300
  },
  "current_context": "local",
  "contexts": {
    "local": {
      "name": "local",
      "endpoint": "http://localhost:8000",
      "description": "Local development"
    },
    "staging": {
      "name": "staging",
      "endpoint": "https://staging.dsta.dev",
      "description": "Staging environment"
    },
    "prod": {
      "name": "prod",
      "endpoint": "https://api.dsta.dev",
      "description": "Production environment"
    }
  }
}

Output Formats

DSTA CLI supports multiple output formats:

# Table format (default, human-readable)
dsta data symbols --output table

# JSON format (for scripting/automation)
dsta data symbols --output json

# YAML format
dsta data symbols --output yaml

Environment Variables

# Enable debug logging
export DSTA_DEBUG=1

# Set default profile
export DSTA_PROFILE=production

# Override API endpoint
export DSTA_ENDPOINT=https://custom-api.dsta.dev

Profiles

Use profiles to manage multiple accounts or environments:

# Login with a specific profile
dsta login --profile work

# Use profile in commands
dsta trade positions --profile work

# List all profiles
ls ~/.config/dsta/

Development

Setup Development Environment

# Clone repository
cd /home/minhdqdev/Projects/dsta/dsta-cli

# Install with development dependencies
pip install -e ".[dev]"

# Or with uv
uv pip install -e ".[dev]"

Run Tests

# Run all tests with coverage
pytest --cov=src/dsta_cli --cov-report=term-missing

# Run specific test module
pytest tests/test_api_client.py -v

# Generate HTML coverage report
pytest --cov=src/dsta_cli --cov-report=html
# Open htmlcov/index.html in browser

Code Quality

# Format code with ruff
ruff format src/ tests/

# Lint code
ruff check src/ tests/

# Type checking with mypy
mypy src/

Architecture

DSTA CLI follows a modular architecture:

dsta-cli/
├── src/dsta_cli/
│   ├── commands/        # Command modules
│   │   ├── auth.py      # Authentication commands
│   │   ├── data.py      # Market data commands
│   │   ├── exchange.py  # Exchange operations
│   │   ├── trade.py     # Trading commands
│   │   ├── strategy.py  # Strategy management
│   │   ├── backtest.py  # Backtesting commands
│   │   ├── ml.py        # ML operations
│   │   ├── analytics.py # Analytics commands
│   │   ├── config.py    # Configuration
│   │   └── utils.py     # Utilities
│   ├── api/             # API client
│   │   ├── client.py    # HTTP client
│   │   └── endpoints.py # API endpoints
│   ├── models/          # Data models
│   │   ├── auth.py
│   │   ├── trading.py
│   │   └── market.py
│   ├── ui/              # UI components
│   │   ├── formatters.py
│   │   ├── tables.py
│   │   └── charts.py
│   ├── config.py        # Configuration management
│   └── main.py          # Entry point
└── tests/               # Test suite

Integration with DSTA Services

DSTA CLI integrates with the following microservices:

  • dsta-core-svc: Core authentication and user management
  • dsta-data-svc: Market data collection and storage
  • dsta-exchange-svc: Exchange connectivity and order management
  • dsta-trading-svc: Trading logic and position management
  • dsta-ml-svc: Machine learning models and predictions
  • dsta-qa: Analytics and reporting

Troubleshooting

Connection Issues

# Check API health
dsta health --verbose

# Test connectivity
dsta utils ping

# Verify configuration
dsta config show

Authentication Issues

# Re-login
dsta logout
dsta login

# Check current user
dsta whoami

# Clear credentials
rm ~/.local/share/dsta/default.credentials.json

Debug Mode

# Enable debug output
export DSTA_DEBUG=1
dsta data fetch BTCUSDT

License

MIT License - see LICENSE file for details

Support

For issues and questions:

Contributing

Contributions are welcome! Please see CONTRIBUTING.md for guidelines.

About

CLI tool for DSTA

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors