2 releases

Uses new Rust 2024

new 0.1.1 Mar 9, 2025
0.1.0 Mar 7, 2025

#53 in Finance

Download history 214/week @ 2025-03-04

214 downloads per month

MIT license

105KB
2.5K SLoC

tastytrade

tastytrade

tastytrade is a Rust client library for the Tastytrade API, providing programmatic access to trading functionality, market data, and account information.

Features

  • Authentication with Tastytrade accounts
  • Real-time market data streaming via DxFeed
  • Account and positions information
  • Order management (placing, modifying, canceling)
  • Real-time account streaming for balance updates and order status changes

Usage

use tastytrade::TastyTrade;
use tastytrade::utils::config::Config;

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    // Login to Tastytrade

    let config = Config::from_env();
    let tasty = TastyTrade::login(&config).await?;

    // Get account information
    let accounts = tasty.accounts().await?;
    for account in accounts {
        println!("Account: {}", account.number().0);

        // Get positions
        let positions = account.positions().await?;
        println!("Positions: {}", positions.len());
    }

    Ok(())
}

Real-time Data

The library supports real-time data streaming for both market data and account updates using DXLink:

// Create a quote streamer
use tastytrade::{Symbol, TastyTrade};
use tastytrade::utils::config::Config;
use dxfeed::{Event, EventData};

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let config = Config::from_env();
    let tasty = TastyTrade::login(&config)
           .await
           .unwrap();
    let mut quote_streamer = tasty.create_quote_streamer().await?;
    let mut quote_sub = quote_streamer.create_sub(dxfeed::DXF_ET_QUOTE | dxfeed::DXF_ET_GREEKS);

    // Add symbols to subscribe to
    quote_sub.add_symbols(&[Symbol("AAPL".to_string())]);

    // Listen for events
    if let Ok(Event { sym, data }) = quote_sub.get_event().await {
        match data {
            EventData::Quote(quote) => {
                println!("Quote for {}: {}/{}", sym, quote.bid_price, quote.ask_price);
            }
            _ => {}
        }
    }
    Ok(())
}

Setup Instructions

  1. Clone the repository:
git clone https://github.com/joaquinbejar/tastytrade
cd tastytrade
  1. Build the project:
make build
  1. Run tests:
make test
  1. Format the code:
make fmt
  1. Run linting:
make lint
  1. Clean the project:
make clean
  1. Run the project:
make run
  1. Fix issues:
make fix
  1. Run pre-push checks:
make pre-push
  1. Generate documentation:
make doc
  1. Publish the package:
make publish
  1. Generate coverage report:
make coverage

CLI Example

This crate also includes a sample CLI application in the tastytrade-cli directory that demonstrates a portfolio viewer with real-time updates.

Testing

To run unit tests:

make test

To run tests with coverage:

make coverage

Contribution and Contact

We welcome contributions to this project! If you would like to contribute, please follow these steps:

  1. Fork the repository.
  2. Create a new branch for your feature or bug fix.
  3. Make your changes and ensure that the project still builds and all tests pass.
  4. Commit your changes and push your branch to your forked repository.
  5. Submit a pull request to the main repository.

If you have any questions, issues, or would like to provide feedback, please feel free to contact the project maintainer:

Joaquín Béjar García

We appreciate your interest and look forward to your contributions!

License: MIT

Dependencies

~23–40MB
~499K SLoC