TastyTrade.Api.Client 1.0.5

dotnet add package TastyTrade.Api.Client --version 1.0.5
                    
NuGet\Install-Package TastyTrade.Api.Client -Version 1.0.5
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="TastyTrade.Api.Client" Version="1.0.5" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="TastyTrade.Api.Client" Version="1.0.5" />
                    
Directory.Packages.props
<PackageReference Include="TastyTrade.Api.Client" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add TastyTrade.Api.Client --version 1.0.5
                    
#r "nuget: TastyTrade.Api.Client, 1.0.5"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package TastyTrade.Api.Client@1.0.5
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=TastyTrade.Api.Client&version=1.0.5
                    
Install as a Cake Addin
#tool nuget:?package=TastyTrade.Api.Client&version=1.0.5
                    
Install as a Cake Tool

TastyTrade.Api.Client

A C# client library for the Tasty Trade API

For updates and issues refer to https://github.com/glyphard/TastyTrade.Api.Client

Authentication

The TastyTrade API supports OAuth2 authentication using refresh tokens. This is the recommended authentication method.

Setup
  1. First, obtain your OAuth credentials from TastyTrade:

    • Client ID
    • Client Secret
    • Refresh Token
  2. Create an instance of TastyTradeClient and authenticate:

using TastyTrade.Client;

var client = new TastyTradeClient();

var credentials = new TastyOAuthCredentials
{
    ClientId = "your-client-id",
    ClientSecret = "your-client-secret",
    RefreshToken = "your-refresh-token",
    UserAgent = "YourApp/1.0",
    ApiBaseUrl = "https://api.tastyworks.com",           // or "https://api.cert.tastyworks.com" for certification
    StreamingApiBaseUrl = "wss://streamer.tastyworks.com" // used for account/order streaming
};

// Authenticate with default token refresh interval
await client.AuthenticateOAuth(credentials);

// Or specify a custom refresh interval
await client.AuthenticateOAuth(credentials, refreshTokenLifetimeMax: TimeSpan.FromMinutes(15));

// Alternative shorthand method
await client.Authenticate(credentials);
Token Management

The client automatically handles token management:

  • Automatic Refresh: Tokens are proactively refreshed before expiration (default: 17 minutes)
  • Retry on 401: If a request receives a 401 Unauthorized response, the token is refreshed and the request is automatically retried
  • Thread-Safe: Token refresh operations are protected by a semaphore to prevent race conditions

You can also manually refresh the token if needed:

await client.RefreshAccessTokenAsync();

Usage Examples

Get Customer Information

var customer = await client.GetCustomer();
Console.WriteLine($"Customer: {customer.Data.FirstName} {customer.Data.LastName}");

Get Accounts

var accounts = await client.GetAccounts();
foreach (var account in accounts.Data.Items)
{
    Console.WriteLine($"Account: {account.AccountNumber}");
}

Get Account Positions

var positions = await client.GetPositions("YOUR_ACCOUNT_NUMBER");
foreach (var position in positions.Data.Items)
{
    Console.WriteLine($"Symbol: {position.Symbol}, Quantity: {position.Quantity}");
}

Get Market Data

var marketData = await client.GetMarketData(
    index: null,
    equity: new[] { "AAPL", "MSFT" },
    equityOption: null,
    future: null,
    futureOption: null,
    cryptocurrency: null
);

Get Option Chains

var optionChain = await client.GetOptionChains("AAPL");
foreach (var option in optionChain.Data.Items)
{
    Console.WriteLine($"Strike: {option.StrikePrice}, Expiration: {option.ExpirationDate}");
}

Get Transactions with Pagination

// Get last 12 months of transactions (automatically handles pagination)
var transactions = await client.GetTransactions("YOUR_ACCOUNT_NUMBER");

// Or specify a custom date range
var startDate = new DateTime(2024, 1, 1);
var endDate = DateTime.UtcNow;
var transactionsInRange = await client.GetTransactions("YOUR_ACCOUNT_NUMBER", startDate, endDate);

Place an Order

var orderRequest = new PlaceOrderRequest
{
    // Configure your order details here
    // See TastyTrade API documentation for order structure
};

var orderResponse = await client.PostOrderSubmission("YOUR_ACCOUNT_NUMBER", orderRequest);

Best Practices

  1. Store credentials securely: Never hardcode credentials in your source code. Use environment variables, Azure Key Vault, or other secure credential management solutions.

  2. Reuse client instances: Create a single TastyTradeClient instance and reuse it for multiple API calls to benefit from automatic token management.

  3. Handle exceptions: Wrap API calls in try-catch blocks to handle network errors and API exceptions gracefully.

  4. Rate limiting: Be mindful of API rate limits and implement appropriate throttling in your application.

Requirements

  • .NET 8 or higher

License

Refer to the repository for license information.

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.5 139 5/7/2026