Private/Domain/MarketActivity.ps1
|
function New-MarketActivity { [CmdletBinding()] param( [Parameter(Mandatory)] [ValidateNotNullOrEmpty()] [string]$ExchangeId, [Parameter(Mandatory)] [ValidateNotNullOrEmpty()] [string]$SourceId, [Parameter(Mandatory)] [ValidateRange(0, [double]::MaxValue)] [decimal]$Value, [Parameter(Mandatory)] [ValidateNotNullOrEmpty()] [string]$Unit, [Parameter(Mandatory)] [ValidateNotNullOrEmpty()] [string]$Interval, [Parameter(Mandatory)] [datetimeoffset]$ObservedAtUtc, [Parameter(Mandatory)] [datetimeoffset]$RetrievedAtUtc, [Parameter()] [ValidateSet('live', 'delayed', 'cached', 'partial', 'unavailable')] [string]$Freshness = 'live', [Parameter()] [switch]$IsProxy, [Parameter()] [string]$ProxyLabel ) if ($IsProxy.IsPresent -and [string]::IsNullOrWhiteSpace($ProxyLabel)) { throw 'Proxy-backed activity must include a descriptive proxy label.' } if (-not $IsProxy.IsPresent -and -not [string]::IsNullOrWhiteSpace($ProxyLabel)) { throw 'A proxy label is valid only when activity is marked as a proxy.' } [pscustomobject][ordered]@{ exchangeId = $ExchangeId sourceId = $SourceId value = $Value unit = $Unit interval = $Interval observedAtUtc = $ObservedAtUtc.ToUniversalTime() retrievedAtUtc = $RetrievedAtUtc.ToUniversalTime() freshness = $Freshness isProxy = $IsProxy.IsPresent proxyLabel = if ($IsProxy.IsPresent) { $ProxyLabel.Trim() } else { $null } } } |