Skip to content
Merged
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: 1 addition & 3 deletions src/Nexus.Crypto.SDK/INexusAPIService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@ namespace Nexus.Crypto.SDK;

public interface INexusAPIService
{
IDocumentStoreSettingsService DocumentStoreSettings { get; }
IDocumentStoreTypeService DocumentStoreType { get; }
IDocumentStoreRecordService DocumentStoreRecord { get; }
IDocumentStoreService DocumentStore { get; }
ICustomerService Customer { get; }
Task<CustomResultHolder<GetLabelPartner>> GetLabelPartner();
Task<CustomResultHolder<GetCurrencies>> GetCurrencies();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
using System.ComponentModel.DataAnnotations;
using System.IO;
using System.Text.Json.Serialization;

namespace Nexus.Crypto.SDK.Models;
namespace Nexus.Crypto.SDK.Models.DocumentStore;

public class DocumentStoreRecordResponse
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
using System.ComponentModel.DataAnnotations;
using System.Text.Json.Serialization;


namespace Nexus.Crypto.SDK.Models;
namespace Nexus.Crypto.SDK.Models.DocumentStore;

public class DocumentStoreSettingsRequest
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using System.ComponentModel.DataAnnotations;

namespace Nexus.Crypto.SDK.Models;

namespace Nexus.Crypto.SDK.Models.DocumentStore;

public record DocumentStoreTypeResponse
{
Expand Down
66 changes: 34 additions & 32 deletions src/Nexus.Crypto.SDK/NexusAPIService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,39 +8,39 @@
namespace Nexus.Crypto.SDK;

public class NexusAPIService(INexusApiClientFactory nexusApiClientFactory)
: BaseService(nexusApiClientFactory), INexusBrokerAPIService, INexusCustodianAPIService
: BaseService(nexusApiClientFactory),
INexusBrokerAPIService,
INexusCustodianAPIService
{
Comment thread
raymens marked this conversation as resolved.
public IDocumentStoreSettingsService DocumentStoreSettings { get; } = new DocumentStoreSettingsService(nexusApiClientFactory);
public IDocumentStoreTypeService DocumentStoreType { get; } = new DocumentStoreTypeService(nexusApiClientFactory);
public IDocumentStoreRecordService DocumentStoreRecord { get; } = new DocumentStoreRecordService(nexusApiClientFactory);
public ICustomerService Customer { get; } = new CustomerService(nexusApiClientFactory);

public NexusAPIService AddHeader(string key, string value)
public new NexusAPIService AddHeader(string key, string value)
{
_headers.Add(key, value);
base.AddHeader(key, value);
return this;
}

public IDocumentStoreService DocumentStore => new DocumentStoreService(this);
public ICustomerService Customer => new CustomerService(this);
Comment thread
raymens marked this conversation as resolved.
Comment thread
raymens marked this conversation as resolved.

public async Task<CustomResultHolder<GetCurrencies>> GetCurrencies()
{
return await GetAsync<CustomResultHolder<GetCurrencies>>("currencies", "1.2");
return await GetAsync<CustomResultHolder<GetCurrencies>>("currencies", ApiVersion1_2);
}

public async Task<CustomResultHolder<GetPrices>> GetPrices(string currency)
{
return await GetAsync<CustomResultHolder<GetPrices>>($"prices/{currency}", "1.2");
return await GetAsync<CustomResultHolder<GetPrices>>($"prices/{currency}", ApiVersion1_2);
}

public async Task<CustomResultHolder<GetLabelPartner>> GetLabelPartner()
{
return await GetAsync<CustomResultHolder<GetLabelPartner>>("labelpartner", "1.2");
return await GetAsync<CustomResultHolder<GetLabelPartner>>("labelpartner", ApiVersion1_2);
}

public async Task<CustomResultHolder<GetReserves>> GetReserves(string? reservesTimeStamp = null)
{
return await GetAsync<CustomResultHolder<GetReserves>>(
$"reserves?reservesTimeStamp={reservesTimeStamp}",
"1.2");
ApiVersion1_2);
}

public async Task<CustomResultHolder<GetBrokerBalances_1_1>> GetBrokerBalances()
Expand All @@ -55,54 +55,54 @@ public async Task<CustomResultHolder<GetBrokerBalances_1_1>> GetBrokerBalances()

public async Task<CustomResultHolder<GetCustodianBalances>> GetCustodianBalances()
{
return await GetAsync<CustomResultHolder<GetCustodianBalances>>("balances", "1.2");
return await GetAsync<CustomResultHolder<GetCustodianBalances>>("balances", ApiVersion1_2);
}

public async Task<CustomResultHolder<PagedResult<GetBalanceMutation>>> GetBalanceMutations(
Dictionary<string, string> queryParams)
{
return await GetAsync<CustomResultHolder<PagedResult<GetBalanceMutation>>>(
$"balances/hotwallet/mutations{CreateUriQuery(queryParams)}",
"1.2");
ApiVersion1_2);
}

public async Task<CustomResultHolder<PagedResult<GetMail>>> GetMails(
Dictionary<string, string> queryParams)
{
return await GetAsync<CustomResultHolder<PagedResult<GetMail>>>(
$"mail{CreateUriQuery(queryParams)}",
"1.2");
ApiVersion1_2);
}

public async Task<CustomResultHolder<GetTransaction>> GetBrokerTransaction(string txCode)
{
return await GetAsync<CustomResultHolder<GetTransaction>>($"transaction/{txCode}", "1.2");
return await GetAsync<CustomResultHolder<GetTransaction>>($"transaction/{txCode}", ApiVersion1_2);
}

public async Task<CustomResultHolder<PagedResult<GetTransaction>>> GetBrokerTransactions(
Dictionary<string, string> queryParams)
{
return await GetAsync<CustomResultHolder<PagedResult<GetTransaction>>>(
$"transaction{CreateUriQuery(queryParams)}", "1.2");
$"transaction{CreateUriQuery(queryParams)}", ApiVersion1_2);
}

public async Task<CustomResultHolder<TotalsResult<TransactionTotals>>> GetBrokerTransactionTotals(
Dictionary<string, string> queryParams)
{
return await GetAsync<CustomResultHolder<TotalsResult<TransactionTotals>>>(
$"transaction/totals{CreateUriQuery(queryParams)}", "1.2");
$"transaction/totals{CreateUriQuery(queryParams)}", ApiVersion1_2);
}

public async Task<CustomResultHolder<PagedResult<GetTransfer>>> GetTransfers(GetTransfersRequest? request = null)
{
return await GetAsync<CustomResultHolder<PagedResult<GetTransfer>>>(
$"/transfers?{QueryParameterHelper.ToQueryString(request)}", "1.2");
$"/transfers?{QueryParameterHelper.ToQueryString(request)}", ApiVersion1_2);
}

public async Task<CustomResultHolder<PagedResult<ListOrder>>> GetOrders(GetOrdersRequest? request = null)
{
return await GetAsync<CustomResultHolder<PagedResult<ListOrder>>>(
$"/orders?{QueryParameterHelper.ToQueryString(request)}", "1.2");
$"/orders?{QueryParameterHelper.ToQueryString(request)}", ApiVersion1_2);
}

public async Task<IEnumerable<ChartSeriesModelPT>> GetMinutePrices(int timeSpan, string currencyCode,
Expand All @@ -118,44 +118,46 @@ public async Task<CustomResultHolder<PagedResult<TransactionNotificationCallback
{
return await GetAsync<CustomResultHolder<PagedResult<TransactionNotificationCallbackResponse>>>(
$"transaction/{transactionCode}/callbacks",
"1.2");
ApiVersion1_2);
}

public Task<CustomResultHolder<ListCustodianTransactionResponse>> GetCustodianTransaction(string txCode)
{
return GetAsync<CustomResultHolder<ListCustodianTransactionResponse>>(
$"transactions/custodian/{txCode}",
"1.2");
ApiVersion1_2);
}

public Task<CustomResultHolder<CustodianCancelResponse>> CancelCustodianTransaction(string txCode)
{
return PostAsync<CustomResultHolder<CustodianCancelResponse>>(
$"transactions/custodian/{txCode}/cancel",
"1.2");
ApiVersion1_2);
}

public async Task<CustomResultHolder<List<GetPortfolio>>> GetPortfolios()
{
return await GetAsync<CustomResultHolder<List<GetPortfolio>>>("portfolios", "1.2");
return await GetAsync<CustomResultHolder<List<GetPortfolio>>>("portfolios", ApiVersion1_2);
}

public async Task<CustomResultHolder<PagedResult<GetTrustLevel>>> GetTrustLevels()
{
return await GetAsync<CustomResultHolder<PagedResult<GetTrustLevel>>>("labelpartner/trustlevels", "1.2");
return await GetAsync<CustomResultHolder<PagedResult<GetTrustLevel>>>("labelpartner/trustlevels", ApiVersion1_2);
}

public async Task<CustomResultHolder<PagedResult<CustomerBankAccountResponse>>> GetCustomerBankAccounts(string customerCode, Dictionary<string, string> queryParams)
public async Task<CustomResultHolder<PagedResult<CustomerBankAccountResponse>>> GetCustomerBankAccounts(
string customerCode, Dictionary<string, string> queryParams)
{
return await GetAsync<CustomResultHolder<PagedResult<CustomerBankAccountResponse>>>(
return await GetAsync<CustomResultHolder<PagedResult<CustomerBankAccountResponse>>>(
$"customer/{customerCode}/bankaccounts{CreateUriQuery(queryParams)}",
"1.2");
ApiVersion1_2);
}

public async Task<CustomResultHolder<CustomerBankAccountResponse>> CreateCustomerBankAccount(string customerCode, CreateBankAccountRequestModel request)
public async Task<CustomResultHolder<CustomerBankAccountResponse>> CreateCustomerBankAccount(string customerCode,
CreateBankAccountRequestModel request)
{
return await PostAsync<CreateBankAccountRequestModel, CustomResultHolder<CustomerBankAccountResponse>>(
$"customer/{customerCode}/bankaccounts", request, "1.2");
$"customer/{customerCode}/bankaccounts", request, ApiVersion1_2);
}

public async Task<CustomResultHolder<CustomerBankAccountResponse>> UpdateCustomerBankAccount(string customerCode,
Expand All @@ -164,14 +166,14 @@ public async Task<CustomResultHolder<CustomerBankAccountResponse>> UpdateCustome
return await PutAsync<UpdateBankAccountRequest, CustomResultHolder<CustomerBankAccountResponse>>(
$"customer/{customerCode}/bankaccounts/{bankAccountId}",
request,
"1.2"
ApiVersion1_2
);
}

public Task DeleteCustomerBankAccount(string customerCode, Guid bankAccountId)
{
return DeleteAsync(
$"customer/{customerCode}/bankAccounts/{bankAccountId}",
"1.2");
ApiVersion1_2);
}
}
18 changes: 12 additions & 6 deletions src/Nexus.Crypto.SDK/Services/BaseService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,20 @@ namespace Nexus.Crypto.SDK.Services;

public class BaseService(INexusApiClientFactory nexusApiClientFactory): IHttpService
{
protected const string ISO8601DateTimeFormat = "yyyy-MM-ddTHH:mm:ssZ";
protected const string ApiVersion = "1.2";
protected readonly Dictionary<string, string> _headers = [];
public const string ApiVersion1_2 = "1.2";
public const string ISO8601DateTimeFormat = "yyyy-MM-ddTHH:mm:ssZ";

private readonly Dictionary<string, string> _headers = [];

protected readonly JsonSerializerOptions _serializerOptions = new()
private readonly JsonSerializerOptions _serializerOptions = new()
{
Converters = { new JsonStringEnumConverter() }, PropertyNameCaseInsensitive = true
};

public void AddHeader(string key, string value)
{
_headers.Add(key, value);
}
Comment thread
raymens marked this conversation as resolved.

private static async Task HandleErrorResponse<T>(HttpResponseMessage response)
{
Expand All @@ -31,7 +37,7 @@ private static async Task HandleErrorResponse<T>(HttpResponseMessage response)
throw exception;
}

protected async Task<HttpClient> GetApiClient(string apiVersion)
private async Task<HttpClient> GetApiClient(string apiVersion)
{
var client = await nexusApiClientFactory.GetClient(apiVersion);

Expand Down Expand Up @@ -153,7 +159,7 @@ public async Task<TResponse> DeleteAsync<TResponse>(string endPoint, string apiV
/// </summary>
/// <param name="queryParams"></param>
/// <returns></returns>
protected static string CreateUriQuery(Dictionary<string, string> queryParams)
public static string CreateUriQuery(Dictionary<string, string> queryParams)
{
var query = string.Empty;

Expand Down
36 changes: 19 additions & 17 deletions src/Nexus.Crypto.SDK/Services/CustomerService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,56 +3,58 @@

namespace Nexus.Crypto.SDK.Services;

public class CustomerService(INexusApiClientFactory nexusApiClientFactory) :BaseService(nexusApiClientFactory), ICustomerService
public class CustomerService(BaseService service) : ICustomerService
{
public Task<CustomResultHolder<GetCustomerTraceSummary[]>> GetCustomerTraceSummary(string customerCode,
DateTime startDate)
{
return GetAsync<CustomResultHolder<GetCustomerTraceSummary[]>>(
$"customer/{customerCode}/trace/summary?startDate={startDate.ToString(ISO8601DateTimeFormat)}",
ApiVersion);
return service.GetAsync<CustomResultHolder<GetCustomerTraceSummary[]>>(
$"customer/{customerCode}/trace/summary?startDate={startDate.ToString(BaseService.ISO8601DateTimeFormat)}",
BaseService.ApiVersion1_2);
}

public Task<CustomResultHolder<PagedResult<GetCustomerTrace>>> GetCustomerTraces(string customerCode,
DateTime startDate)
{
return GetAsync<CustomResultHolder<PagedResult<GetCustomerTrace>>>(
$"customer/{customerCode}/trace?startDate={startDate.ToString(ISO8601DateTimeFormat)}",
ApiVersion);
return service.GetAsync<CustomResultHolder<PagedResult<GetCustomerTrace>>>(
$"customer/{customerCode}/trace?startDate={startDate.ToString(BaseService.ISO8601DateTimeFormat)}",
BaseService.ApiVersion1_2);
}

public async Task<CustomResultHolder<GetCustomer>> GetCustomer(string customerCode)
{
return await GetAsync<CustomResultHolder<GetCustomer>>($"customer/{customerCode}", ApiVersion);
return await service.GetAsync<CustomResultHolder<GetCustomer>>($"customer/{customerCode}",
BaseService.ApiVersion1_2);
}

public async Task<CustomResultHolder<PagedResult<GetCustomer>>> GetCustomers(Dictionary<string, string> queryParams)
{
return await GetAsync<CustomResultHolder<PagedResult<GetCustomer>>>(
$"customer{CreateUriQuery(queryParams)}",
ApiVersion);
return await service.GetAsync<CustomResultHolder<PagedResult<GetCustomer>>>(
$"customer{BaseService.CreateUriQuery(queryParams)}",
BaseService.ApiVersion1_2);
}

public async Task<CustomResultHolder<CreateCustomerResponse>> CreateCustomer(CreateCustomerRequest request)
{
return await PostAsync<CreateCustomerRequest, CustomResultHolder<CreateCustomerResponse>>(
return await service.PostAsync<CreateCustomerRequest, CustomResultHolder<CreateCustomerResponse>>(
"customer",
request,
ApiVersion
BaseService.ApiVersion1_2
);
}

public async Task<CustomResultHolder<DeleteCustomerResponse>> DeleteCustomer(string customerCode)
{
return await DeleteAsync<CustomResultHolder<DeleteCustomerResponse>>($"customer/{customerCode}", ApiVersion);
return await service.DeleteAsync<CustomResultHolder<DeleteCustomerResponse>>($"customer/{customerCode}",
BaseService.ApiVersion1_2);
}

public async Task<CustomResultHolder<GetCustomer>> UpdateCustomer(string customerCode,
UpdateCustomerRequest request)
{
return await PutAsync<UpdateCustomerRequest, CustomResultHolder<GetCustomer>>(
return await service.PutAsync<UpdateCustomerRequest, CustomResultHolder<GetCustomer>>(
$"customer/{customerCode}",
request,
ApiVersion);
BaseService.ApiVersion1_2);
}
}
Loading
Loading