| Crates.io | tastytrade |
| lib.rs | tastytrade |
| version | 0.2.2 |
| created_at | 2025-03-07 19:04:07.457713+00 |
| updated_at | 2025-09-01 13:57:52.477661+00 |
| description | Library for trading through tastytrade's API |
| homepage | |
| repository | https://github.com/joaquinbejar/tastytrade |
| max_upload_size | |
| id | 1583494 |
| size | 350,993 |
tastytrade is a Rust client library for the Tastytrade API, providing programmatic access to
trading functionality, market data, and account information.
use tastytrade::TastyTrade;
use tastytrade::utils::config::TastyTradeConfig;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
// Login to Tastytrade
let config = TastyTradeConfig::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(())
}
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::TastyTradeConfig;
use tastytrade::dxfeed;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let config = TastyTradeConfig::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(dxfeed::Event { sym, data }) = quote_sub.get_event().await {
match data {
dxfeed::EventData::Quote(quote) => {
println!("Quote for {}: {}/{}", sym, quote.bid_price, quote.ask_price);
}
_ => {}
}
}
Ok(())
}
git clone https://github.com/joaquinbejar/tastytrade
cd tastytrade
make build
make test
make fmt
make lint
make clean
make run
make fix
make pre-push
make doc
make publish
make coverage
This crate also includes a sample CLI application in the tastytrade-cli directory
that demonstrates a portfolio viewer with real-time updates.
To run unit tests:
make test
To run tests with coverage:
make coverage
We welcome contributions to this project! If you would like to contribute, please follow these steps:
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!
We welcome contributions to this project! If you would like to contribute, please follow these steps:
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!
Licensed under MIT license