Skip to content

Commit

Permalink
moved DerivedCfg as public readonly object in the MarketData
Browse files Browse the repository at this point in the history
  • Loading branch information
jacopocinaark committed Jan 10, 2025
1 parent c4e5008 commit ab431db
Show file tree
Hide file tree
Showing 30 changed files with 120 additions and 100 deletions.
5 changes: 2 additions & 3 deletions Artesian/Artesian.SDK.Tests/Samples/DerivedTimeSerieTest.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using Artesian.SDK.Dto;
using Artesian.SDK.Dto.DerivedCfg;
using Artesian.SDK.Factory;
using Artesian.SDK.Service;

Expand Down Expand Up @@ -135,15 +134,15 @@ public async Task CreateDerivedCoalesceTimeSeries()
}

// Update DerivedCfg
if (marketData.Metadata.DerivedCfgCoalesce != null)
if (marketData.DerivedCfg.DerivedCfgCoalesce != null)
{
curveIds.Reverse();
var derivedCfgUpdate = new DerivedCfgCoalesce()
{
OrderedReferencedMarketDataIds = curveIds.ToArray(),
};

if (!marketData.Metadata.DerivedCfgCoalesce.OrderedReferencedMarketDataIds.SequenceEqual(derivedCfgUpdate.OrderedReferencedMarketDataIds))
if (!marketData.DerivedCfg.DerivedCfgCoalesce.OrderedReferencedMarketDataIds.SequenceEqual(derivedCfgUpdate.OrderedReferencedMarketDataIds))
{
marketData.UpdateDerivedConfiguration(derivedCfgUpdate, false).ConfigureAwait(true).GetAwaiter().GetResult();

Expand Down
4 changes: 2 additions & 2 deletions Artesian/Artesian.SDK/Common/ArtesianUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ public static void IsValidString(string validStringCheck, int minLenght, int max
throw new ArgumentException($"Invalid string '{validStringCheck}'. Must not be null or empty", callerParamName);
if (validStringCheck.Length < minLenght || validStringCheck.Length > maxLenght)
throw new ArgumentException($"Invalid string '{validStringCheck}'. Must be between 1 and 50 characters.", callerParamName);
if (!ArtesianConstants.StringValidator.Match(validStringCheck).Success)
if (!ArtesianConstants._stringValidator.Match(validStringCheck).Success)
throw new ArgumentException($"Invalid string '{validStringCheck}'. Should not contain trailing or leading whitespaces or any of the following characters: ,:; '\"<space>", callerParamName);
}

Expand Down Expand Up @@ -133,7 +133,7 @@ public static void IsValidMarketDataName(string name, int minLenght, int maxLeng
throw new ArgumentException($"Invalid MarketData name {name}. Must not be null or empty", callerParamName);
if (name.Length < minLenght || name.Length > maxLenght)
throw new ArgumentException($"Invalid MarketData name {name}. Must be between 1 and 250 characters.", callerParamName);
if (!ArtesianConstants.MarketDataNameValidator.Match(name).Success)
if (!ArtesianConstants._marketDataNameValidator.Match(name).Success)
throw new ArgumentException($"Invalid MarketData name '{name}'. Should not contain trailing or leading whitespaces and no other whitespace than <space> in the middle.", callerParamName);
}
}
Expand Down
38 changes: 38 additions & 0 deletions Artesian/Artesian.SDK/Dto/DerivedCfg/DerivedCfg.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
namespace Artesian.SDK.Dto
{
/// <summary>
/// The DerivedCfg containing the three type of derived configurations (DerivedCfgCoalesce, DerivedCfgSum, DerivedCfgMuv)
/// </summary>
public record DerivedCfg
{
/// <summary>
/// DerivedCfg constructor
/// </summary>
/// <param name="derivedCfg"></param>
internal DerivedCfg(DerivedCfgBase derivedCfg)
{
if (derivedCfg is DerivedCfgCoalesce)
DerivedCfgCoalesce = new DerivedCfgCoalesceReadOnly(derivedCfg as DerivedCfgCoalesce);
else if (derivedCfg is DerivedCfgSum)
DerivedCfgSum = new DerivedCfgSumReadOnly(derivedCfg as DerivedCfgSum);
else if (derivedCfg is DerivedCfgMuv)
DerivedCfgMuv = new DerivedCfgMuvReadOnly(derivedCfg as DerivedCfgMuv);
}

/// <summary>
/// DerivedCfgCoalesce
/// </summary>
public DerivedCfgCoalesceReadOnly? DerivedCfgCoalesce { get; protected set; } = null;

/// <summary>
/// DerivedCfgSum
/// </summary>
public DerivedCfgSumReadOnly? DerivedCfgSum { get; protected set; } = null;

/// <summary>
/// DerivedCfgMuv
/// </summary>
public DerivedCfgMuvReadOnly? DerivedCfgMuv { get; protected set; } = null;

}
}
6 changes: 3 additions & 3 deletions Artesian/Artesian.SDK/Dto/DerivedCfg/DerivedCfgBase.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
using Artesian.SDK.Dto.DerivedCfg.Enums;
using Artesian.SDK.Dto.DerivedCfg.Serialize;
using Artesian.SDK.Dto.Enums;
using Artesian.SDK.Dto.Serialize;

using MessagePack;

using Newtonsoft.Json;

namespace Artesian.SDK.Dto.DerivedCfg
namespace Artesian.SDK.Dto
{
/// <summary>
/// Base class for Derived Configuration.
Expand Down
4 changes: 2 additions & 2 deletions Artesian/Artesian.SDK/Dto/DerivedCfg/DerivedCfgCoalesce.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
using Artesian.SDK.Dto.DerivedCfg.Enums;
using Artesian.SDK.Dto.Enums;

using MessagePack;

namespace Artesian.SDK.Dto.DerivedCfg
namespace Artesian.SDK.Dto
{
/// <summary>
/// Represents a derived configuration that uses the Coalesce algorithm.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
using Artesian.SDK.Dto.DerivedCfg.Enums;
using Artesian.SDK.Dto.Enums;

using System.Collections.Generic;

namespace Artesian.SDK.Dto.DerivedCfg
namespace Artesian.SDK.Dto
{
/// <summary>
/// DerivedCoalesce Configuration Readonly
Expand Down
4 changes: 2 additions & 2 deletions Artesian/Artesian.SDK/Dto/DerivedCfg/DerivedCfgMuv.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
using Artesian.SDK.Dto.DerivedCfg.Enums;
using Artesian.SDK.Dto.Enums;

using MessagePack;

namespace Artesian.SDK.Dto.DerivedCfg
namespace Artesian.SDK.Dto
{
/// <summary>
/// Represents the configuration for the MostUpdatedVersion derived algorithm.
Expand Down
4 changes: 2 additions & 2 deletions Artesian/Artesian.SDK/Dto/DerivedCfg/DerivedCfgMuvReadOnly.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using Artesian.SDK.Dto.DerivedCfg.Enums;
using Artesian.SDK.Dto.Enums;

namespace Artesian.SDK.Dto.DerivedCfg
namespace Artesian.SDK.Dto
{
/// <summary>
/// DerivedMuv Configuration Readonly
Expand Down
4 changes: 2 additions & 2 deletions Artesian/Artesian.SDK/Dto/DerivedCfg/DerivedCfgSum.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
using Artesian.SDK.Dto.DerivedCfg.Enums;
using Artesian.SDK.Dto.Enums;

using MessagePack;

namespace Artesian.SDK.Dto.DerivedCfg
namespace Artesian.SDK.Dto
{
/// <summary>
/// Represents a derived configuration that uses the Sum algorithm.
Expand Down
4 changes: 2 additions & 2 deletions Artesian/Artesian.SDK/Dto/DerivedCfg/DerivedCfgSumReadOnly.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
using Artesian.SDK.Dto.DerivedCfg.Enums;
using Artesian.SDK.Dto.Enums;

using System.Collections.Generic;

namespace Artesian.SDK.Dto.DerivedCfg
namespace Artesian.SDK.Dto
{
/// <summary>
/// DerivedSum Configuration Readonly
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using MessagePack;

namespace Artesian.SDK.Dto.DerivedCfg
namespace Artesian.SDK.Dto
{
/// <summary>
/// Represents a configuration with referenced market data IDs for derived data.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace Artesian.SDK.Dto.DerivedCfg.Enums
namespace Artesian.SDK.Dto.Enums
{
/// <summary>
/// Enumeration for specifying the derived algorithm.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
using Artesian.SDK.Dto.DerivedCfg.Enums;
using Artesian.SDK.Dto.Enums;

using Newtonsoft.Json;
using Newtonsoft.Json.Linq;

using System;

namespace Artesian.SDK.Dto.DerivedCfg.Serialize
namespace Artesian.SDK.Dto.Serialize
{
sealed class DerivedCfgBaseConverter : JsonCreationConverter<DerivedCfgBase>
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
using System;
using System.Text.Json.Serialization;

namespace Artesian.SDK.Dto.DerivedCfg.Serialize
namespace Artesian.SDK.Dto.Serialize
{
internal abstract class JsonPolymorphicConverter<TBase, TDiscriminatorEnum> : JsonConverter<TBase>
where TDiscriminatorEnum : struct, Enum
Expand Down
2 changes: 1 addition & 1 deletion Artesian/Artesian.SDK/Dto/MarketData/MarketDataEntity.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright (c) ARK LTD. All rights reserved.
// Licensed under the MIT License. See LICENSE in the project root for
// license information.
using Artesian.SDK.Dto.DerivedCfg;
using Artesian.SDK.Dto;

using MessagePack;
using NodaTime;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
using Artesian.SDK.Dto.DerivedCfg;

using System;
using System;

namespace Artesian.SDK.Dto.MarketData
{
Expand Down
2 changes: 1 addition & 1 deletion Artesian/Artesian.SDK/Factory/BidAsk.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public AddBidAskOperationResult AddData(Instant time, string product, BidAskValu
private AddBidAskOperationResult _addBidAsk(LocalDateTime reportTime, string product, BidAskValue value)
{
//Relative products
if (ArtesianConstants.RelativeProductValidator.IsMatch(product))
if (ArtesianConstants._relativeProductValidator.IsMatch(product))
throw new NotSupportedException("Relative Products are not supported");

if (_entity.OriginalGranularity.IsTimeGranularity())
Expand Down
6 changes: 5 additions & 1 deletion Artesian/Artesian.SDK/Factory/IMarketData.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using Artesian.SDK.Dto;
using Artesian.SDK.Dto.DerivedCfg;

using NodaTime;

Expand Down Expand Up @@ -29,6 +28,11 @@ public interface IMarketData
/// </summary>
MarketDataMetadata Metadata { get; }

/// <summary>
/// DerivedCfg
/// </summary>
DerivedCfg DerivedCfg { get; }

/// <summary>
/// MarketData Load Metadata
/// </summary>
Expand Down
2 changes: 1 addition & 1 deletion Artesian/Artesian.SDK/Factory/MarketAssessment.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public AddAssessmentOperationResult AddData(Instant time, string product, Market
private AddAssessmentOperationResult _addAssessment(LocalDateTime reportTime, string product, MarketAssessmentValue value)
{
//Relative products
if (ArtesianConstants.RelativeProductValidator.IsMatch(product))
if (ArtesianConstants._relativeProductValidator.IsMatch(product))
throw new NotSupportedException("Relative Products are not supported");

if (_entity.OriginalGranularity.IsTimeGranularity())
Expand Down
18 changes: 17 additions & 1 deletion Artesian/Artesian.SDK/Factory/MarketData.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using Artesian.SDK.Common;
using Artesian.SDK.Dto;
using Artesian.SDK.Dto.DerivedCfg;
using Artesian.SDK.Dto.MarketData;
using Artesian.SDK.Service;

Expand Down Expand Up @@ -34,6 +33,11 @@ public class MarketData : IMarketData
/// </summary>
public MarketDataMetadata Metadata { get; protected set; }

/// <summary>
/// DerivedCfg
/// </summary>
public DerivedCfg DerivedCfg { get; protected set; }

/// <summary>
/// MarketData Constructor by Id
/// </summary>
Expand Down Expand Up @@ -71,6 +75,8 @@ public async Task Register(MarketDataEntity.Input metadata, CancellationToken ct

_entity = await _marketDataService.RegisterMarketDataAsync(metadata, ctk).ConfigureAwait(false);

DerivedCfg = new DerivedCfg(_entity.DerivedCfg);

Metadata = new MarketDataMetadata(_entity);
}

Expand Down Expand Up @@ -106,7 +112,11 @@ public async Task Load(CancellationToken ctk = default)
_entity = await _marketDataService.ReadMarketDataRegistryAsync(Identifier, ctk).ConfigureAwait(false);

if (_entity != null)
{
DerivedCfg = new DerivedCfg(_entity.DerivedCfg);

Metadata = new MarketDataMetadata(_entity);
}
}

/// <summary>
Expand Down Expand Up @@ -249,6 +259,8 @@ public async Task UpdateDerivedConfiguration(DerivedCfgMuv derivedCfg, bool forc

_entity = await _marketDataService.UpdateDerivedConfigurationAsync(_entity.MarketDataId, derivedCfg, force, ctk).ConfigureAwait(false);

DerivedCfg = new DerivedCfg(_entity.DerivedCfg);

Metadata = new MarketDataMetadata(_entity);
}

Expand Down Expand Up @@ -276,6 +288,8 @@ public async Task UpdateDerivedConfiguration(DerivedCfgCoalesce derivedCfg, bool

_entity = await _marketDataService.UpdateDerivedConfigurationAsync(_entity.MarketDataId, derivedCfg, force, ctk).ConfigureAwait(false);

DerivedCfg = new DerivedCfg(_entity.DerivedCfg);

Metadata = new MarketDataMetadata(_entity);
}

Expand Down Expand Up @@ -303,6 +317,8 @@ public async Task UpdateDerivedConfiguration(DerivedCfgSum derivedCfg, bool forc

_entity = await _marketDataService.UpdateDerivedConfigurationAsync(_entity.MarketDataId, derivedCfg, force, ctk).ConfigureAwait(false);

DerivedCfg = new DerivedCfg(_entity.DerivedCfg);

Metadata = new MarketDataMetadata(_entity);
}
}
Expand Down
40 changes: 0 additions & 40 deletions Artesian/Artesian.SDK/Factory/MarketDataMetadata.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using Artesian.SDK.Dto;
using Artesian.SDK.Dto.DerivedCfg;

using NodaTime;

Expand Down Expand Up @@ -90,44 +89,5 @@ internal MarketDataMetadata(MarketDataEntity.Output output)
/// The time the market data has been created
/// </summary>
public Instant Created => _output.Created;
/// <summary>
/// The DerivedCfgCoalesce
/// </summary>
public DerivedCfgCoalesceReadOnly? DerivedCfgCoalesce
{
get
{
if (_output.DerivedCfg is DerivedCfgCoalesce)
return new DerivedCfgCoalesceReadOnly(_output.DerivedCfg as DerivedCfgCoalesce);
else
return null;
}
}
/// <summary>
/// The DerivedCfgSum
/// </summary>
public DerivedCfgSumReadOnly? DerivedCfgSum
{
get
{
if (_output.DerivedCfg is DerivedCfgSum)
return new DerivedCfgSumReadOnly(_output.DerivedCfg as DerivedCfgSum);
else
return null;
}
}
/// <summary>
/// The DerivedCfgMuv
/// </summary>
public DerivedCfgMuvReadOnly? DerivedCfgMuv
{
get
{
if (_output.DerivedCfg is DerivedCfgMuv)
return new DerivedCfgMuvReadOnly(_output.DerivedCfg as DerivedCfgMuv);
else
return null;
}
}
}
}
2 changes: 1 addition & 1 deletion Artesian/Artesian.SDK/Service/Clients/Client.cs
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ public Client(IArtesianServiceConfig config, string Url, ArtesianPolicyConfig po
}

_client = new FlurlClient(_url);
_client.WithTimeout(TimeSpan.FromMinutes(ArtesianConstants.ServiceRequestTimeOutMinutes));
_client.WithTimeout(TimeSpan.FromMinutes(ArtesianConstants._serviceRequestTimeOutMinutes));
}


Expand Down
Loading

0 comments on commit ab431db

Please sign in to comment.