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
<PackageReference Include="TastyTrade.Api.Client" Version="1.0.5" />
<PackageVersion Include="TastyTrade.Api.Client" Version="1.0.5" />
<PackageReference Include="TastyTrade.Api.Client" />
paket add TastyTrade.Api.Client --version 1.0.5
#r "nuget: TastyTrade.Api.Client, 1.0.5"
#:package TastyTrade.Api.Client@1.0.5
#addin nuget:?package=TastyTrade.Api.Client&version=1.0.5
#tool nuget:?package=TastyTrade.Api.Client&version=1.0.5
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
OAuth2 Authentication (Recommended)
The TastyTrade API supports OAuth2 authentication using refresh tokens. This is the recommended authentication method.
Setup
First, obtain your OAuth credentials from TastyTrade:
- Client ID
- Client Secret
- Refresh Token
Create an instance of
TastyTradeClientand 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
Store credentials securely: Never hardcode credentials in your source code. Use environment variables, Azure Key Vault, or other secure credential management solutions.
Reuse client instances: Create a single
TastyTradeClientinstance and reuse it for multiple API calls to benefit from automatic token management.Handle exceptions: Wrap API calls in try-catch blocks to handle network errors and API exceptions gracefully.
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 | Versions 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. |
-
net8.0
- DxFeed.Graal.Net (>= 2.4.1)
- System.Text.Json (>= 9.0.0)
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 |