#trading #exchange #binance #crypto #okx #api-bindings

tuff

A powerful and flexible trading framework built in Rust

1 unstable release

new 0.0.1 Mar 16, 2025

#5 in #okx

Download history 59/week @ 2025-03-11

59 downloads per month

MIT license

6KB

Tuff Trading Framework

Tuff is a powerful and flexible trading framework built in Rust, designed for both novice and experienced traders. It provides a simple syntax for defining trading strategies, a comprehensive library of technical indicators, and robust risk management features, all while prioritizing user privacy.

Features

  • ๐Ÿ“ Simple Syntax: Define both simple and advanced trading strategies with the simplest syntax in the fastest time.
  • ๐Ÿ“Š Comprehensive Indicator Library: Access a complete library of technical indicators with easy-to-use syntax.
  • ๐Ÿ“ˆ Smart Ordering: Supports market, limit, and stop orders, automatically choosing the best one for you.
  • โฐ Multiple Timeframes and Symbols: Backtest and live trade multiple timeframes and symbols simultaneously without look-ahead bias.
  • ๐Ÿ”’ Self-Hosted and Privacy-First: Fully self-hosted to ensure your trading strategies and data remain secure.
  • ๐Ÿ›ก๏ธ Risk Management: Built-in helper functions for robust risk management.
  • ๐Ÿ“‹ Metrics System: A comprehensive metrics system to evaluate your trading strategy's performance.
  • ๐Ÿ” Debug Mode: Observe your strategy in action with a detailed debug mode.
  • ๐Ÿ”ง Optimize Mode: Fine-tune your strategies using AI, without needing a technical background.
  • ๐Ÿ“ˆ Leveraged and Short-Selling: First-class support for leveraged trading and short-selling.
  • ๐Ÿ”€ Partial Fills: Supports entering and exiting positions in multiple orders, allowing for greater flexibility.
  • ๐Ÿ”” Advanced Alerts: Create real-time alerts within your strategies for effective monitoring.
  • ๐Ÿ“‰ Auto-Generated Charts: View your portfolio's performance with automatically generated charts.
  • ๐Ÿงน Data Cleaning: Automatic handling of importing candles and cleaning data.
  • ๐Ÿ“ˆ First-Class Support for Trading Futures and Spot: Specialized support for both futures and spot markets.
  • ๐Ÿ” Support for Decentralized Exchanges (DEX): Maintain full custody of your assets while trading.

Getting Started

  1. Clone the repository:

    git clone https://github.com/jackson211/tuff.git
    cd tuff
    
  2. Build the project:

    cargo build
    
  3. Run the project:

    cargo run
    

Contributing

Contributions are welcome! Please open an issue or submit a pull request for any enhancements or bug fixes.

License

This project is licensed under the MIT License.

WebSocket Example

The repository includes a WebSocket example that demonstrates how to connect to Binance's WebSocket API with proxy support.

Running the WebSocket Example

By default, the example connects to Binance's WebSocket API:

cargo run --example binance -- -n 5

This will connect to Binance's WebSocket API and process 5 messages.

Using a Proxy

There are several ways to use a proxy (which is recommended for connecting to Binance):

  1. Command-line option: Use the -p option to specify a proxy:
cargo run --example binance -- -p http://your-proxy-address:port

For SOCKS5 proxies:

cargo run --example binance -- -p socks5://your-proxy-address:port
  1. Environment variables: The example will automatically use system proxy environment variables if set:
export https_proxy=http://127.0.0.1:7890
export http_proxy=http://127.0.0.1:7890
export all_proxy=socks5://127.0.0.1:7890
cargo run --example binance
  1. Default fallback: If no proxy is specified and no environment variables are found, the example defaults to using:

    • http://127.0.0.1:7890 for HTTP/HTTPS connections
    • socks5://127.0.0.1:7890 for other connections
  2. Disable proxies: To explicitly disable all proxies and connect directly:

cargo run --example binance -- --no-proxy

Using the Echo Server (for testing)

If you want to test with a simple echo server instead of Binance:

cargo run --example binance -- -u wss://echo.websocket.org

Command Line Options

For a full list of options:

cargo run --example binance -- --help

No runtime deps