/* * QUANTCONNECT.COM - Democratizing Finance, Empowering Individuals. * Lean Algorithmic Trading Engine v2.0. Copyright 2014 QuantConnect Corporation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ using Newtonsoft.Json; using Newtonsoft.Json.Serialization; namespace QuantConnect.Brokerages.Authentication { /// /// Represents a Lean platform token request, including all fields required by the /// live/auth0/refresh endpoint. Optional fields are omitted from JSON when null. /// public class OAuthTokenRequest { /// /// Gets the name of the brokerage associated with the access token request. /// The value is normalized to lowercase. /// public string Brokerage { get; set; } /// /// Gets the account identifier associated with the brokerage. /// public string AccountId { get; set; } /// /// Gets the OAuth refresh token used to obtain a new access token. /// Omitted from JSON when null. /// public string RefreshToken { get; set; } /// /// Gets the Lean deploy identifier for brokerages that require it. /// Omitted from JSON when null. /// public string DeployId { get; set; } /// /// Initializes a new instance of with all fields. /// Use named parameters to supply only the fields required by the target brokerage. /// /// The brokerage name. Normalized to lowercase. /// The account number or identifier. /// OAuth refresh token; omitted from JSON when null. /// Lean deploy identifier; omitted from JSON when null. public OAuthTokenRequest( string brokerage, string accountId, string refreshToken = null, string deployId = null) { #pragma warning disable CA1308 // Normalize strings to uppercase Brokerage = brokerage.ToLowerInvariant(); #pragma warning restore CA1308 // Normalize strings to uppercase AccountId = accountId; RefreshToken = refreshToken; DeployId = deployId; } /// /// Serializes the request into a compact camelCase JSON string. /// Null properties are excluded from the output. /// /// A JSON string representing the current request. public string ToJson() { return JsonConvert.SerializeObject(this, new JsonSerializerSettings() { ContractResolver = new CamelCasePropertyNamesContractResolver(), NullValueHandling = NullValueHandling.Ignore, Formatting = Formatting.None }); } } }