Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions TradierClient/Exceptions/TradierClientException.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ public TradierClientException(string message)
public TradierClientException(HttpResponseMessage response)
{
Task<string> resp = response.Content.ReadAsStringAsync();
if ( response.StatusCode == System.Net.HttpStatusCode.BadRequest)
{
throw new TradierClientException($"Server returned 401 Bad Request: {resp.Result}");
}
if (!string.IsNullOrEmpty(resp.Result))
{
if (Equals(response.Content.Headers.ContentType, MediaTypeHeaderValue.Parse("application/json")))
Expand Down
2 changes: 1 addition & 1 deletion TradierClient/TradierClient.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
<PackageRequireLicenseAcceptance>true</PackageRequireLicenseAcceptance>
<RepositoryType>Git</RepositoryType>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<Version>1.0.11</Version>
<Version>1.0.18</Version>
<AssemblyVersion>1.0.11.0</AssemblyVersion>
<FileVersion>1.0.11.0</FileVersion>
<PackageTags>Trading StockMarket Investing Brokerage API .NET C#</PackageTags>
Expand Down
19 changes: 19 additions & 0 deletions TradierClient/TradierClient/TradierClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,25 @@ public class TradierClient
// TODO: Coming soon
//public Streaming Streaming { get; set; }

/// <summary>
/// The TradierClient constructor (with an existing HttpClient that's already configured with token and url)
/// This allows setting up a proxy server to intercept requests and responses to record them to a file.
/// This is useful bother for debugging and for creating unit tests.
/// </summary>
public TradierClient(HttpClient httpClient, string defaultAccountNumber = null)
{
Requests request = new Requests(httpClient);

Authentication = new Authentication(request);
Account = new Account(request, defaultAccountNumber);
MarketData = new MarketData(request);
Trading = new Trading(request, defaultAccountNumber);
Watchlist = new WatchlistEndpoint(request);

// TODO: Coming soon
//Streaming = new Streaming(request);
}

/// <summary>
/// The TradierClient constructor (with an existing HttpClient)
/// </summary>
Expand Down
2 changes: 2 additions & 0 deletions TradierClient/TradierClient/Trading.cs
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,8 @@ public async Task<IOrder> PlaceMultilegOrder(string accountNumber, string symbol
{ "price", price.ToString() }
};

if (preview) { data.Add("preview", preview.ToString()); }

int index = 0;

foreach (var leg in legs)
Expand Down