|
@@ -0,0 +1,496 @@
|
|
|
|
|
+using GreenTree.Banking.API.comdirect.Configuration;
|
|
|
|
|
+using GreenTree.Banking.API.comdirect.Data;
|
|
|
|
|
+using GreenTree.Banking.API.comdirect.Data.Depot;
|
|
|
|
|
+using GreenTree.Banking.API.comdirect.Extension;
|
|
|
|
|
+using GreenTree.Banking.API.comdirect.Services;
|
|
|
|
|
+using Newtonsoft.Json;
|
|
|
|
|
+using RestSharp;
|
|
|
|
|
+using System;
|
|
|
|
|
+using System.Collections.Generic;
|
|
|
|
|
+using System.Text;
|
|
|
|
|
+using System.Threading;
|
|
|
|
|
+
|
|
|
|
|
+namespace GreenTree.Banking.API.comdirect.Web
|
|
|
|
|
+{
|
|
|
|
|
+ public class Session
|
|
|
|
|
+ {
|
|
|
|
|
+ #region DI fields
|
|
|
|
|
+
|
|
|
|
|
+ /// <summary>
|
|
|
|
|
+ /// The API authentication options
|
|
|
|
|
+ /// </summary>
|
|
|
|
|
+ private readonly AuthenticationOptions _authenticationOptions;
|
|
|
|
|
+
|
|
|
|
|
+ /// <summary>
|
|
|
|
|
+ /// The global session options
|
|
|
|
|
+ /// </summary>
|
|
|
|
|
+ private readonly SessionOptions _sessionOptions;
|
|
|
|
|
+
|
|
|
|
|
+ /// <summary>
|
|
|
|
|
+ /// The global data export service provider
|
|
|
|
|
+ /// </summary>
|
|
|
|
|
+ private readonly IDataExportService _dataExportService;
|
|
|
|
|
+
|
|
|
|
|
+ #endregion
|
|
|
|
|
+
|
|
|
|
|
+ #region Fields
|
|
|
|
|
+
|
|
|
|
|
+ // The REST client that sends requests to the API (values)
|
|
|
|
|
+ private RestClient valueRestClient;
|
|
|
|
|
+
|
|
|
|
|
+ // The REST client that sends requests to the API (authentication)
|
|
|
|
|
+ private RestClient authRestClient;
|
|
|
|
|
+
|
|
|
|
|
+ // The variables which shall be
|
|
|
|
|
+ private Dictionary<string, string> sessionVariables = new Dictionary<string, string>();
|
|
|
|
|
+
|
|
|
|
|
+ // The cookies to be used on any request
|
|
|
|
|
+ private IList<RestResponseCookie> cookies;
|
|
|
|
|
+
|
|
|
|
|
+ #endregion
|
|
|
|
|
+
|
|
|
|
|
+ #region Ctor
|
|
|
|
|
+
|
|
|
|
|
+ /// <summary>
|
|
|
|
|
+ /// Initializes a new instance of the Session class
|
|
|
|
|
+ /// </summary>
|
|
|
|
|
+ /// <param name="authenticationOptions">API authentication options.</param>
|
|
|
|
|
+ /// <param name="sessionOptions">The web API session options.</param>
|
|
|
|
|
+ /// <param name="dataExportService">The current data export service provider.</param>
|
|
|
|
|
+ public Session(
|
|
|
|
|
+ AuthenticationOptions authenticationOptions,
|
|
|
|
|
+ SessionOptions sessionOptions,
|
|
|
|
|
+ IDataExportService dataExportService)
|
|
|
|
|
+ {
|
|
|
|
|
+ _authenticationOptions = authenticationOptions;
|
|
|
|
|
+ _sessionOptions = sessionOptions;
|
|
|
|
|
+ _dataExportService = dataExportService;
|
|
|
|
|
+
|
|
|
|
|
+ valueRestClient = new RestClient(authenticationOptions.BaseUrl);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ #endregion
|
|
|
|
|
+
|
|
|
|
|
+ #region API authentication methods
|
|
|
|
|
+
|
|
|
|
|
+ /// <summary>
|
|
|
|
|
+ /// Authenticate against the API
|
|
|
|
|
+ /// </summary>
|
|
|
|
|
+ public void Authenticate()
|
|
|
|
|
+ {
|
|
|
|
|
+ Console.WriteLine("Begin authentication...");
|
|
|
|
|
+
|
|
|
|
|
+ InitAuthenticationToken();
|
|
|
|
|
+
|
|
|
|
|
+ Console.WriteLine("Created authentication token...");
|
|
|
|
|
+
|
|
|
|
|
+ InitSession();
|
|
|
|
|
+
|
|
|
|
|
+ Console.WriteLine("Created session...");
|
|
|
|
|
+
|
|
|
|
|
+ InitSessionTAN();
|
|
|
|
|
+
|
|
|
|
|
+ Console.WriteLine("Create TAN activation request... waiting {0} seconds for validation...",
|
|
|
|
|
+ _sessionOptions.TimeoutForTwoFactorTANAuthentication);
|
|
|
|
|
+
|
|
|
|
|
+ Thread.Sleep(_sessionOptions.TimeoutForTwoFactorTANAuthentication * 1000);
|
|
|
|
|
+
|
|
|
|
|
+ InitSeesionTANActivation();
|
|
|
|
|
+
|
|
|
|
|
+ Console.WriteLine("Finish authentication...");
|
|
|
|
|
+
|
|
|
|
|
+ InitAuthenticationFinish();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /// <summary>
|
|
|
|
|
+ /// Initiate authentication token
|
|
|
|
|
+ /// </summary>
|
|
|
|
|
+ private void InitAuthenticationToken()
|
|
|
|
|
+ {
|
|
|
|
|
+ authRestClient = new RestClient(_authenticationOptions.OAuthUrl + "/oauth/token");
|
|
|
|
|
+
|
|
|
|
|
+ var request = new RestRequest(Method.POST)
|
|
|
|
|
+ {
|
|
|
|
|
+ Timeout = _sessionOptions.RestTimeout
|
|
|
|
|
+ };
|
|
|
|
|
+
|
|
|
|
|
+ request.AddHeader("Content-Type", "application/x-www-form-urlencoded");
|
|
|
|
|
+ request.AddHeader("Accept", "application/json");
|
|
|
|
|
+ request.AddParameter("client_id", _authenticationOptions.ClientId);
|
|
|
|
|
+ request.AddParameter("client_secret", _authenticationOptions.ClientSecret);
|
|
|
|
|
+ request.AddParameter("grant_type", "password");
|
|
|
|
|
+ request.AddParameter("username", _authenticationOptions.LoginNumber);
|
|
|
|
|
+ request.AddParameter("password", _authenticationOptions.LoginPin);
|
|
|
|
|
+
|
|
|
|
|
+ var response = authRestClient.Execute(request);
|
|
|
|
|
+ cookies = response.Cookies;
|
|
|
|
|
+
|
|
|
|
|
+ if (response.StatusCode == System.Net.HttpStatusCode.OK)
|
|
|
|
|
+ {
|
|
|
|
|
+ var responseData = JsonConvert.DeserializeObject<OAuth2Response>(response.Content);
|
|
|
|
|
+
|
|
|
|
|
+ sessionVariables.Add("access_token", responseData.AccessToken.ToString());
|
|
|
|
|
+ sessionVariables.Add("refresh_token", responseData.RefreshToken.ToString());
|
|
|
|
|
+ sessionVariables.Add("session_id", Guid.NewGuid().ToString());
|
|
|
|
|
+ sessionVariables.Add("request_id", GenerateRequestId());
|
|
|
|
|
+ }
|
|
|
|
|
+ else
|
|
|
|
|
+ {
|
|
|
|
|
+ if (response.ErrorException != null)
|
|
|
|
|
+ throw response.ErrorException;
|
|
|
|
|
+
|
|
|
|
|
+ throw new Exception(String.Format("Status: {0} - {1}", response.StatusCode, response.Content));
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /// <summary>
|
|
|
|
|
+ /// Initiate the session UUID
|
|
|
|
|
+ /// </summary>
|
|
|
|
|
+ private void InitSession()
|
|
|
|
|
+ {
|
|
|
|
|
+ valueRestClient = new RestClient(_authenticationOptions.BaseUrl + "/session/clients/user/v1/sessions");
|
|
|
|
|
+
|
|
|
|
|
+ var request = new RestRequest(Method.GET)
|
|
|
|
|
+ {
|
|
|
|
|
+ Timeout = _sessionOptions.RestTimeout
|
|
|
|
|
+ };
|
|
|
|
|
+
|
|
|
|
|
+ request.AddHeader("Accept", "application/json");
|
|
|
|
|
+ request.AddHeader("Authorization", "Bearer " + sessionVariables["access_token"]);
|
|
|
|
|
+ request.AddHeader("x-http-request-info",
|
|
|
|
|
+ "{\"clientRequestId\":{\"sessionId\":\"" + sessionVariables["session_id"] + "\",\"requestId\":\"" +
|
|
|
|
|
+ sessionVariables["request_id"] + "\"}}");
|
|
|
|
|
+ request.AddHeader("Content-Type", "application/json");
|
|
|
|
|
+ request.AddCookies(cookies);
|
|
|
|
|
+
|
|
|
|
|
+ var response = valueRestClient.Execute(request);
|
|
|
|
|
+ cookies = response.Cookies;
|
|
|
|
|
+
|
|
|
|
|
+ if (response.StatusCode == System.Net.HttpStatusCode.OK)
|
|
|
|
|
+ {
|
|
|
|
|
+ var responseData = JsonConvert.DeserializeObject<SessionResponse[]>(response.Content);
|
|
|
|
|
+
|
|
|
|
|
+ sessionVariables.Add("session_uuid", responseData[0].Identifier);
|
|
|
|
|
+ }
|
|
|
|
|
+ else
|
|
|
|
|
+ {
|
|
|
|
|
+ if (response.ErrorException != null)
|
|
|
|
|
+ throw response.ErrorException;
|
|
|
|
|
+
|
|
|
|
|
+ throw new Exception(String.Format("Status: {0} - {1}", response.StatusCode, response.Content));
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /// <summary>
|
|
|
|
|
+ /// Initiate the session TAN
|
|
|
|
|
+ /// </summary>
|
|
|
|
|
+ private void InitSessionTAN()
|
|
|
|
|
+ {
|
|
|
|
|
+ valueRestClient = new RestClient(
|
|
|
|
|
+ _authenticationOptions.BaseUrl + "/session/clients/user/v1/sessions/" + sessionVariables["session_uuid"] + "/validate");
|
|
|
|
|
+
|
|
|
|
|
+ var request = new RestRequest(Method.POST)
|
|
|
|
|
+ {
|
|
|
|
|
+ Timeout = _sessionOptions.RestTimeout
|
|
|
|
|
+ };
|
|
|
|
|
+
|
|
|
|
|
+ request.AddHeader("Accept", "application/json");
|
|
|
|
|
+ request.AddHeader("Authorization", "Bearer " + sessionVariables["access_token"]);
|
|
|
|
|
+ request.AddHeader("x-http-request-info",
|
|
|
|
|
+ "{\"clientRequestId\":{\"sessionId\":\"" + sessionVariables["session_id"] + "\",\"requestId\":\"" +
|
|
|
|
|
+ sessionVariables["request_id"] + "\"}}");
|
|
|
|
|
+ request.AddHeader("Content-Type", "application/json");
|
|
|
|
|
+ request.AddCookies(cookies);
|
|
|
|
|
+ request.AddParameter("application/json",
|
|
|
|
|
+ "{\"identifier\":\"" + sessionVariables["session_uuid"] + "\",\"sessionTanActive\": true,\"activated2FA\": true\r\n}",
|
|
|
|
|
+ ParameterType.RequestBody);
|
|
|
|
|
+
|
|
|
|
|
+ var response = valueRestClient.Execute(request);
|
|
|
|
|
+ cookies = response.Cookies;
|
|
|
|
|
+
|
|
|
|
|
+ if (response.StatusCode == System.Net.HttpStatusCode.Created)
|
|
|
|
|
+ {
|
|
|
|
|
+ foreach (var responseHeader in response.Headers)
|
|
|
|
|
+ {
|
|
|
|
|
+ if (responseHeader.Name == "x-once-authentication-info")
|
|
|
|
|
+ {
|
|
|
|
|
+ var responseData = JsonConvert.DeserializeObject<SessionTANResponse>(responseHeader.Value.ToString());
|
|
|
|
|
+
|
|
|
|
|
+ sessionVariables.Add("challange_id", responseData.Id.ToString());
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ else
|
|
|
|
|
+ {
|
|
|
|
|
+ if (response.ErrorException != null)
|
|
|
|
|
+ throw response.ErrorException;
|
|
|
|
|
+
|
|
|
|
|
+ throw new Exception(String.Format("Status: {0} - {1}", response.StatusCode, response.Content));
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /// <summary>
|
|
|
|
|
+ /// Initiate the TAN activation
|
|
|
|
|
+ /// </summary>
|
|
|
|
|
+ private void InitSeesionTANActivation()
|
|
|
|
|
+ {
|
|
|
|
|
+ valueRestClient = new RestClient(
|
|
|
|
|
+ _authenticationOptions.BaseUrl + "/session/clients/user/v1/sessions/" + sessionVariables["session_uuid"]);
|
|
|
|
|
+
|
|
|
|
|
+ var request = new RestRequest(Method.PATCH)
|
|
|
|
|
+ {
|
|
|
|
|
+ Timeout = _sessionOptions.RestTimeout
|
|
|
|
|
+ };
|
|
|
|
|
+
|
|
|
|
|
+ request.AddHeader("Accept", "application/json");
|
|
|
|
|
+ request.AddHeader("Authorization", "Bearer " + sessionVariables["access_token"]);
|
|
|
|
|
+ request.AddHeader("x-http-request-info",
|
|
|
|
|
+ "{\"clientRequestId\":{\"sessionId\":\"" + sessionVariables["session_id"] + "\",\"requestId\":\"" +
|
|
|
|
|
+ sessionVariables["request_id"] + "\"}}");
|
|
|
|
|
+ request.AddHeader("Content-Type", "application/json");
|
|
|
|
|
+ request.AddHeader("x-once-authentication-info", "{\"id\":\"" + sessionVariables["challange_id"] + "\"}");
|
|
|
|
|
+ request.AddCookies(cookies);
|
|
|
|
|
+ request.AddParameter("application/json",
|
|
|
|
|
+ "{\"identifier\":\"" + sessionVariables["session_uuid"] + "\",\"sessionTanActive\": true,\"activated2FA\": true\r\n}",
|
|
|
|
|
+ ParameterType.RequestBody);
|
|
|
|
|
+
|
|
|
|
|
+ var response = valueRestClient.Execute(request);
|
|
|
|
|
+ cookies = response.Cookies;
|
|
|
|
|
+
|
|
|
|
|
+ if (response.StatusCode == System.Net.HttpStatusCode.OK)
|
|
|
|
|
+ {
|
|
|
|
|
+
|
|
|
|
|
+ }
|
|
|
|
|
+ else
|
|
|
|
|
+ {
|
|
|
|
|
+ if (response.ErrorException != null)
|
|
|
|
|
+ throw response.ErrorException;
|
|
|
|
|
+
|
|
|
|
|
+ throw new Exception(String.Format("Status: {0} - {1}", response.StatusCode, response.Content));
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /// <summary>
|
|
|
|
|
+ /// Initiate the finalisation of the authentication
|
|
|
|
|
+ /// </summary>
|
|
|
|
|
+ private void InitAuthenticationFinish()
|
|
|
|
|
+ {
|
|
|
|
|
+ authRestClient = new RestClient(_authenticationOptions.OAuthUrl + "/oauth/token");
|
|
|
|
|
+
|
|
|
|
|
+ var request = new RestRequest(Method.POST)
|
|
|
|
|
+ {
|
|
|
|
|
+ Timeout = _sessionOptions.RestTimeout
|
|
|
|
|
+ };
|
|
|
|
|
+
|
|
|
|
|
+ request.AddHeader("Content-Type", "application/x-www-form-urlencoded");
|
|
|
|
|
+ request.AddHeader("Accept", "application/json");
|
|
|
|
|
+ request.AddParameter("client_id", _authenticationOptions.ClientId);
|
|
|
|
|
+ request.AddParameter("client_secret", _authenticationOptions.ClientSecret);
|
|
|
|
|
+ request.AddParameter("grant_type", "cd_secondary");
|
|
|
|
|
+ request.AddParameter("token", sessionVariables["access_token"]);
|
|
|
|
|
+
|
|
|
|
|
+ var response = authRestClient.Execute(request);
|
|
|
|
|
+ cookies = response.Cookies;
|
|
|
|
|
+
|
|
|
|
|
+ if (response.StatusCode == System.Net.HttpStatusCode.OK)
|
|
|
|
|
+ {
|
|
|
|
|
+ var responseData = JsonConvert.DeserializeObject<OAuth2Response>(response.Content);
|
|
|
|
|
+
|
|
|
|
|
+ if (!sessionVariables.ContainsKey("access_token"))
|
|
|
|
|
+ throw new Exception(
|
|
|
|
|
+ "The access token must be initiated first. Use the method 'InitAuthenticationToken' to begin the session authentication.");
|
|
|
|
|
+
|
|
|
|
|
+ if (!sessionVariables.ContainsKey("refresh_token"))
|
|
|
|
|
+ throw new Exception(
|
|
|
|
|
+ "The refresh token must be initiated first. Use the method 'InitAuthenticationToken' to begin the session authentication.");
|
|
|
|
|
+
|
|
|
|
|
+ sessionVariables["access_token"] = responseData.AccessToken.ToString();
|
|
|
|
|
+ sessionVariables["refresh_token"] = responseData.RefreshToken.ToString();
|
|
|
|
|
+ }
|
|
|
|
|
+ else
|
|
|
|
|
+ {
|
|
|
|
|
+ if (response.ErrorException != null)
|
|
|
|
|
+ throw response.ErrorException;
|
|
|
|
|
+
|
|
|
|
|
+ throw new Exception(String.Format("Status: {0} - {1}", response.StatusCode, response.Content));
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /// <summary>
|
|
|
|
|
+ /// Refresh current authenticated session
|
|
|
|
|
+ /// </summary>
|
|
|
|
|
+ public void RefreshAuthentication()
|
|
|
|
|
+ {
|
|
|
|
|
+ authRestClient = new RestClient(_authenticationOptions.OAuthUrl + "/oauth/token");
|
|
|
|
|
+
|
|
|
|
|
+ var request = new RestRequest(Method.POST)
|
|
|
|
|
+ {
|
|
|
|
|
+ Timeout = _sessionOptions.RestTimeout
|
|
|
|
|
+ };
|
|
|
|
|
+
|
|
|
|
|
+ request.AddHeader("Content-Type", "application/x-www-form-urlencoded");
|
|
|
|
|
+ request.AddHeader("Accept", "application/json");
|
|
|
|
|
+ request.AddParameter("client_id", _authenticationOptions.ClientId);
|
|
|
|
|
+ request.AddParameter("client_secret", _authenticationOptions.ClientSecret);
|
|
|
|
|
+ request.AddParameter("grant_type", "refresh_token");
|
|
|
|
|
+ request.AddParameter("refresh_token", sessionVariables["refresh_token"]);
|
|
|
|
|
+
|
|
|
|
|
+ var response = authRestClient.Execute(request);
|
|
|
|
|
+ cookies = response.Cookies;
|
|
|
|
|
+
|
|
|
|
|
+ if (response.StatusCode == System.Net.HttpStatusCode.OK)
|
|
|
|
|
+ {
|
|
|
|
|
+ var responseData = JsonConvert.DeserializeObject<OAuth2Response>(response.Content);
|
|
|
|
|
+
|
|
|
|
|
+ if (!sessionVariables.ContainsKey("access_token"))
|
|
|
|
|
+ throw new Exception(
|
|
|
|
|
+ "The access token must be initiated first. Use the method 'InitAuthenticationToken' to begin the session authentication.");
|
|
|
|
|
+
|
|
|
|
|
+ if (!sessionVariables.ContainsKey("refresh_token"))
|
|
|
|
|
+ throw new Exception(
|
|
|
|
|
+ "The refresh token must be initiated first. Use the method 'InitAuthenticationToken' to begin the session authentication.");
|
|
|
|
|
+
|
|
|
|
|
+ sessionVariables["access_token"] = responseData.AccessToken.ToString();
|
|
|
|
|
+ sessionVariables["refresh_token"] = responseData.RefreshToken.ToString();
|
|
|
|
|
+ }
|
|
|
|
|
+ else
|
|
|
|
|
+ {
|
|
|
|
|
+ if (response.ErrorException != null)
|
|
|
|
|
+ throw response.ErrorException;
|
|
|
|
|
+
|
|
|
|
|
+ throw new Exception(String.Format("Status: {0} - {1}", response.StatusCode, response.Content));
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ #endregion
|
|
|
|
|
+
|
|
|
|
|
+ #region API data methods
|
|
|
|
|
+
|
|
|
|
|
+ /// <summary>
|
|
|
|
|
+ /// Get the default depot
|
|
|
|
|
+ /// </summary>
|
|
|
|
|
+ public void GetDefaultDepot()
|
|
|
|
|
+ {
|
|
|
|
|
+ valueRestClient = new RestClient(_authenticationOptions.BaseUrl + "/brokerage/clients/user/v3/depots");
|
|
|
|
|
+
|
|
|
|
|
+ var request = new RestRequest(Method.GET)
|
|
|
|
|
+ {
|
|
|
|
|
+ Timeout = _sessionOptions.RestTimeout
|
|
|
|
|
+ };
|
|
|
|
|
+
|
|
|
|
|
+ request.AddHeader("Accept", "application/json");
|
|
|
|
|
+ request.AddHeader("Authorization", "Bearer " + sessionVariables["access_token"]);
|
|
|
|
|
+ request.AddHeader("x-http-request-info",
|
|
|
|
|
+ "{\"clientRequestId\":{\"sessionId\":\"" + sessionVariables["session_id"] + "\",\"requestId\":\"" +
|
|
|
|
|
+ sessionVariables["request_id"] + "\"}}");
|
|
|
|
|
+ request.AddHeader("Content-Type", "application/json");
|
|
|
|
|
+
|
|
|
|
|
+ var response = valueRestClient.Execute(request);
|
|
|
|
|
+ cookies = response.Cookies;
|
|
|
|
|
+
|
|
|
|
|
+ if (response.StatusCode == System.Net.HttpStatusCode.OK)
|
|
|
|
|
+ {
|
|
|
|
|
+ var responseData = JsonConvert.DeserializeObject<Depot>(response.Content);
|
|
|
|
|
+
|
|
|
|
|
+ sessionVariables.Add("depotUUID", responseData.Values[0].DepotId);
|
|
|
|
|
+ }
|
|
|
|
|
+ else
|
|
|
|
|
+ {
|
|
|
|
|
+ if (response.ErrorException != null)
|
|
|
|
|
+ throw response.ErrorException;
|
|
|
|
|
+
|
|
|
|
|
+ throw new Exception(String.Format("Status: {0} - {1}", response.StatusCode, response.Content));
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /// <summary>
|
|
|
|
|
+ /// Get the current portfolio data of the default depot
|
|
|
|
|
+ /// </summary>
|
|
|
|
|
+ public Depot GetDepotPortfolioData()
|
|
|
|
|
+ {
|
|
|
|
|
+ valueRestClient = new RestClient(_authenticationOptions.BaseUrl + "/brokerage/v3/depots/" + sessionVariables["depotUUID"] + "/positions");
|
|
|
|
|
+
|
|
|
|
|
+ var request = new RestRequest(Method.GET)
|
|
|
|
|
+ {
|
|
|
|
|
+ Timeout = _sessionOptions.RestTimeout
|
|
|
|
|
+ };
|
|
|
|
|
+
|
|
|
|
|
+ request.AddHeader("Accept", "application/json");
|
|
|
|
|
+ request.AddHeader("Authorization", "Bearer " + sessionVariables["access_token"]);
|
|
|
|
|
+ request.AddHeader("x-http-request-info",
|
|
|
|
|
+ "{\"clientRequestId\":{\"sessionId\":\"" + sessionVariables["session_id"] +
|
|
|
|
|
+ "\",\"requestId\":\"" + sessionVariables["request_id"] + "\"}}");
|
|
|
|
|
+ request.AddHeader("Content-Type", "application/json");
|
|
|
|
|
+
|
|
|
|
|
+ var response = valueRestClient.Execute(request);
|
|
|
|
|
+ cookies = response.Cookies;
|
|
|
|
|
+
|
|
|
|
|
+ if (response.StatusCode == System.Net.HttpStatusCode.OK)
|
|
|
|
|
+ {
|
|
|
|
|
+ var responseData = JsonConvert.DeserializeObject<Depot>(response.Content);
|
|
|
|
|
+
|
|
|
|
|
+ return responseData;
|
|
|
|
|
+ }
|
|
|
|
|
+ else
|
|
|
|
|
+ {
|
|
|
|
|
+ if (response.ErrorException != null)
|
|
|
|
|
+ throw response.ErrorException;
|
|
|
|
|
+
|
|
|
|
|
+ throw new Exception(String.Format("Status: {0} - {1}", response.StatusCode, response.Content));
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /// <summary>
|
|
|
|
|
+ /// Get the current additional portfolio data
|
|
|
|
|
+ /// </summary>
|
|
|
|
|
+ public AdditionalData GetDepotRevenueData()
|
|
|
|
|
+ {
|
|
|
|
|
+ valueRestClient = new RestClient(_authenticationOptions.BaseUrl + "/brokerage/v3/depots/" + sessionVariables["depotUUID"] + "/transactions");
|
|
|
|
|
+
|
|
|
|
|
+ var request = new RestRequest(Method.GET)
|
|
|
|
|
+ {
|
|
|
|
|
+ Timeout = _sessionOptions.RestTimeout
|
|
|
|
|
+ };
|
|
|
|
|
+
|
|
|
|
|
+ request.AddHeader("Accept", "application/json");
|
|
|
|
|
+ request.AddHeader("Authorization", "Bearer " + sessionVariables["access_token"]);
|
|
|
|
|
+ request.AddHeader("x-http-request-info",
|
|
|
|
|
+ "{\"clientRequestId\":{\"sessionId\":\"" + sessionVariables["session_id"] +
|
|
|
|
|
+ "\",\"requestId\":\"" + sessionVariables["request_id"] + "\"}}");
|
|
|
|
|
+ request.AddHeader("Content-Type", "application/json");
|
|
|
|
|
+
|
|
|
|
|
+ var response = valueRestClient.Execute(request);
|
|
|
|
|
+ cookies = response.Cookies;
|
|
|
|
|
+
|
|
|
|
|
+ if (response.StatusCode == System.Net.HttpStatusCode.OK)
|
|
|
|
|
+ {
|
|
|
|
|
+ var responseData = JsonConvert.DeserializeObject<AdditionalData>(response.Content);
|
|
|
|
|
+
|
|
|
|
|
+ return responseData;
|
|
|
|
|
+ }
|
|
|
|
|
+ else
|
|
|
|
|
+ {
|
|
|
|
|
+ if (response.ErrorException != null)
|
|
|
|
|
+ throw response.ErrorException;
|
|
|
|
|
+
|
|
|
|
|
+ throw new Exception(String.Format("Status: {0} - {1}", response.StatusCode, response.Content));
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ #endregion
|
|
|
|
|
+
|
|
|
|
|
+ #region Helper
|
|
|
|
|
+
|
|
|
|
|
+ /// <summary>
|
|
|
|
|
+ /// Generates a request id from the current timestamp
|
|
|
|
|
+ /// </summary>
|
|
|
|
|
+ private string GenerateRequestId()
|
|
|
|
|
+ {
|
|
|
|
|
+ var ticks = DateTime.Now.Ticks.ToString();
|
|
|
|
|
+
|
|
|
|
|
+ return ticks.Substring(ticks.Length - 10, 9);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ #endregion
|
|
|
|
|
+ }
|
|
|
|
|
+}
|