Expand description
§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::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(())
}§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::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(())
}§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 testTo 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!
Re-exports§
pub use api::accounts;pub use api::base::TastyResult;pub use api::client::TastyTrade;
Modules§
- api
- dxfeed
- Internal DXFeed types to replace external dxfeed dependency This module contains the essential types and constants needed for quote streaming
- prelude
- Prelude
- streaming
- utils
- Utils Module
Structs§
- ApiError
- Represents an error returned by the Tastytrade API.
- Brief
Position - Represents a brief overview of a position.
- Full
Position - Represents a full position for an account.
- Live
Order Record - Represents a live order record.
- Order
- Represents an order to be placed.
- Order
Builder - Builder for
Order. - Order
Leg - Represents a leg of an order.
- Order
LegBuilder - Builder for
OrderLeg. - Symbol
- Represents a trading symbol.
Enums§
- Action
- Represents an order action type.
- DxFeed
Error - Represents errors that can occur during interactions with DxFeed.
- Instrument
Type - Represents the different types of financial instruments.
- Order
Type - Represents the type of order being placed.
- Price
Effect - Represents the effect of a price on an account.
- Quantity
Direction - Represents the direction of a quantity, such as a trade or position.
- Tasty
Trade Error - Represents errors that can occur within the Tastytrade API client.
- Time
InForce - Represents the time-in-force instruction for an order.
Traits§
- AsSymbol
- Trait for converting types to
Symbol.