37 releases (breaking)

new 0.27.0 May 21, 2024
0.26.0 Oct 5, 2022
0.25.0 Aug 16, 2022
0.24.0 Jul 30, 2022
0.5.0 Oct 2, 2020

#14 in #symbol

Download history 5/week @ 2024-02-17 20/week @ 2024-02-24 1/week @ 2024-03-02 9/week @ 2024-03-30 41/week @ 2024-04-06 3/week @ 2024-04-13 143/week @ 2024-05-18

143 downloads per month

MIT license

67KB
1.5K SLoC

tastyworks-rs

Crates.io Docs Status

Unofficial tastyworks/tastytrade API for Rust. Requires API access to be enabled for your account.

Example

use tastyworks::Session;
use num_traits::ToPrimitive;

// Requests made by the API are asynchronous, so you must use a runtime such as `tokio`.
#[tokio::main]
async fn main() {
  let login = "username"; // or email
  let password = "password";
  let otp = Some("123456"); // 2FA code, may be None::<String>
  let session = Session::from_credentials(login, password, otp)
      .await.expect("Failed to login");

  let accounts = tastyworks::accounts(&session)
      .await.expect("Failed to fetch accounts");
  let account = accounts.first().expect("No accounts found");

  let positions = tastyworks::positions(account, &session)
      .await.expect("Failed to fetch positions");

  println!("Your active positions:");
  for position in &positions {
      let signed_quantity = position.signed_quantity();

      // Quantities in the API that could potentially be decimal values are stored as
      // `num_rational::Rational64`. To convert these to floats include the `num-traits` crate
      // in your project and use the `ToPrimitive` trait. To convert these to integers no
      // additional crate is required.
      println!(
          "{:>10} x {}",
          if signed_quantity.is_integer() {
              signed_quantity.to_integer().to_string()
          } else {
              signed_quantity.to_f64().unwrap().to_string()
          },
          position.symbol
      );
  }
}

Dependencies

~14–30MB
~436K SLoC