2 releases
Uses new Rust 2024
new 0.1.1 | Mar 9, 2025 |
---|---|
0.1.0 | Mar 7, 2025 |
#53 in Finance
214 downloads per month
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
- Clone the repository:
git clone https://github.com/joaquinbejar/tastytrade
cd tastytrade
- Build the project:
make build
- Run tests:
make test
- Format the code:
make fmt
- Run linting:
make lint
- Clean the project:
make clean
- Run the project:
make run
- Fix issues:
make fix
- Run pre-push checks:
make pre-push
- Generate documentation:
make doc
- Publish the package:
make publish
- 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:
- Fork the repository.
- Create a new branch for your feature or bug fix.
- Make your changes and ensure that the project still builds and all tests pass.
- Commit your changes and push your branch to your forked repository.
- 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
- Email: jb@taunais.com
- GitHub: joaquinbejar
We appreciate your interest and look forward to your contributions!
License: MIT
Dependencies
~23–40MB
~499K SLoC