Skip to content
Open
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
26 changes: 26 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,32 @@ All notable changes to PSExchangeClock will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]

### Added

- **Nasdaq Copenhagen (`XCSE`)** — main-market equities 09:00–17:00 Copenhagen time (`Romance Standard Time`), with the 08:45–09:00 opening auction and 16:55–17:00 closing auction shown as auctions rather than pre-market or continuous trading; map marker, flyout details and world clock via the existing mechanisms; not active by default
- Official Nasdaq Copenhagen closures for 2025–2027 in `holidays.json`
- Optional `OpeningAuctionStart` and `ClosingAuctionStart` fields on exchange records
- **OMX Copenhagen 25 (`OMXC25`)** on the Indices tab via Twelve Data symbol `OMXC25`. It needs a Twelve Data Pro plan, so it is **turned off by default** and shown with a note saying why; enable it with the new optional `EnabledIndices` preference. When enabled it is fetched separately from the ETF batch, with Intraday / Last close / Stale / Unavailable status, quote time in Copenhagen time, and a session-long back-off after HTTP 403/404
- Optional `EnabledIndices` user preference, carried through preference saves
- Pester tests under `Tests/` (run with `Invoke-Pester ./Tests`), starting with map preference restore
- Tests for Nasdaq Copenhagen session status, auctions, holidays, DST transitions, selection and exchange-data caching
- Tests for OMXC25 registration, opt-in, quote parsing, caching/back-off and quote status
- **FTSE 100** as an opt-in true index on the Indices tab (Twelve Data symbol `FTSE`, pinned to `mic_code=XLON` because the bare ticker is also a Euronext Paris ETF; needs a Grow plan, so off by default). Enable with `EnabledIndices: ["FTSE"]`

### Fixed

- Map style, projection and overlay choices were never restored at start-up and were dropped whenever preferences were saved. They are now saved when changed and restored on launch (`MapStyle`, `MapProjection`, `MapOverlays`)
- Countdowns are now measured in UTC, so they stay correct on DST transition days
- `Get-StockExchangeData` now appends built-in exchanges missing from a cache younger than 30 days, so new exchanges appear for existing installs

### Changed

- `PSExchangeClock.psm1` also loads non-exported helpers from `Private/`
- Exchange status and selection logic moved to `Private/` helpers so it can be tested without WPF
- Index-quote logic lives in `Private/IndexQuotes.ps1`; the ETF proxy list moved there unchanged

## [1.1.0] - 2026-09-28

### Fixed
Expand Down
17 changes: 17 additions & 0 deletions PSExchangeClock/Data/exchange-data.json
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,23 @@
"Latitude": 55.7558,
"Longitude": 37.6173,
"IsDefault": false
},
{
"Name": "Nasdaq Copenhagen",
"Code": "XCSE",
"Symbol": "OMXC",
"Country": "Denmark",
"City": "Copenhagen",
"TimeZoneId": "Romance Standard Time",
"OpenTimeLocal": "09:00",
"CloseTimeLocal": "17:00",
"OpeningAuctionStart": "08:45",
"ClosingAuctionStart": "16:55",
"LunchBreakStart": null,
"LunchBreakEnd": null,
"Latitude": 55.6761,
"Longitude": 12.5683,
"IsDefault": false
}
]
}
13 changes: 12 additions & 1 deletion PSExchangeClock/Data/exchange-details.json
Original file line number Diff line number Diff line change
Expand Up @@ -218,5 +218,16 @@
"Website": "https://www.moex.com/en",
"Regulator": "Bank of Russia",
"Description": "Moscow Exchange is Russia's largest exchange group, operating trading markets in equities, bonds, derivatives, currencies, and commodities."
},
"XCSE": {
"PrimaryIndex": "OMX Copenhagen 25 (OMXC25)",
"MarketCapUSD": "n/a",
"ListedCompanies": "n/a",
"Currency": "DKK",
"CurrencySymbol": "kr.",
"Founded": 1808,
"Website": "https://www.nasdaq.com/european-markets/about-nordic-exchanges",
"Regulator": "Finanstilsynet",
"Description": "Nasdaq Copenhagen (Nasdaq København) is Denmark's stock exchange and part of Nasdaq Nordic. Main-market equities trade 09:00-17:00 Copenhagen time, with a closing auction from 16:55. Its benchmark is the OMX Copenhagen 25 index."
}
}
}
11 changes: 10 additions & 1 deletion PSExchangeClock/Data/holidays.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,14 @@
"XMEX": [],
"XSES": [],
"XTAI": [],
"XMOS": []
"XMOS": [],
"_comment_XCSE": "Nasdaq Copenhagen equity closures from the official Nasdaq European Markets holiday schedule (https://www.nasdaq.com/european-market-activity/trading-hours), checked 2026-10-09. Nasdaq lists no half trading days for Copenhagen in 2025-2027. Not identical to Danish public holidays: Dec 24 and Dec 31 are exchange closures. Dates beyond 2027 are not yet published.",
"XCSE": [
"2025-01-01", "2025-04-17", "2025-04-18", "2025-04-21", "2025-05-29", "2025-05-30",
"2025-06-05", "2025-06-09", "2025-12-24", "2025-12-25", "2025-12-26", "2025-12-31",
"2026-01-01", "2026-04-02", "2026-04-03", "2026-04-06", "2026-05-14", "2026-05-15",
"2026-05-25", "2026-06-05", "2026-12-24", "2026-12-25", "2026-12-31",
"2027-01-01", "2027-03-25", "2027-03-26", "2027-03-29", "2027-05-06", "2027-05-07",
"2027-05-17", "2027-12-24", "2027-12-31"
]
}
2 changes: 1 addition & 1 deletion PSExchangeClock/PSExchangeClock.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
Author = 'PowerShellYoungTeam'
CompanyName = 'PowerShellYoungTeam'
Copyright = '(c) 2026 PowerShellYoungTeam. All rights reserved.'
Description = 'A real-time WPF dashboard for monitoring global stock exchange closing times, market data, forex, crypto, commodities, indices, and financial news — covering 20 major exchanges worldwide.'
Description = 'A real-time WPF dashboard for monitoring global stock exchange closing times, market data, forex, crypto, commodities, indices, and financial news — covering 21 major exchanges worldwide.'
PowerShellVersion = '7.0'
CLRVersion = '4.0'

Expand Down
11 changes: 11 additions & 0 deletions PSExchangeClock/PSExchangeClock.psm1
Original file line number Diff line number Diff line change
@@ -1,6 +1,17 @@
# PSExchangeClock module loader
$PSModuleRoot = $PSScriptRoot

# Dot-source private helpers (not exported)
$privateFunctions = Get-ChildItem -Path "$PSModuleRoot\Private\*.ps1" -ErrorAction SilentlyContinue
foreach ($function in $privateFunctions) {
try {
. $function.FullName
}
catch {
Write-Error "Failed to import private helpers $($function.BaseName): $_"
}
}

# Dot-source all public functions
$publicFunctions = Get-ChildItem -Path "$PSModuleRoot\Public\*.ps1" -ErrorAction SilentlyContinue
foreach ($function in $publicFunctions) {
Expand Down
180 changes: 180 additions & 0 deletions PSExchangeClock/Private/Get-ExchangeSessionStatus.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,180 @@
function Format-CountdownSpan {
<#
.SYNOPSIS
Formats a TimeSpan as HH:MM:SS, truncating (not rounding) whole hours.
#>
[CmdletBinding()]
[OutputType([string])]
param([Parameter(Mandatory)][TimeSpan]$TimeSpan)

'{0:D2}:{1:D2}:{2:D2}' -f [int][math]::Floor($TimeSpan.TotalHours), $TimeSpan.Minutes, $TimeSpan.Seconds
}

function Get-ExchangeSessionStatus {
<#
.SYNOPSIS
Computes the trading status of an exchange at a given UTC instant.
.DESCRIPTION
Pure status calculation used by the dashboard. The exchange's local wall
clock is derived from its Windows timezone ID, so DST is handled by the
operating system's timezone rules rather than fixed UTC offsets.
Countdowns are measured in UTC, so they stay correct on DST transition days.

An exchange may optionally define OpeningAuctionStart and ClosingAuctionStart
(HH:mm). From OpeningAuctionStart until OpenTimeLocal, and from
ClosingAuctionStart until CloseTimeLocal, the status text reports the
auction (call phase) rather than pre-market or continuous trading. The
status values themselves are unchanged (PreMarket / ClosingSoon /
ClosingImminent), so colours and notifications behave as before.
.PARAMETER Exchange
Exchange object with Code, TimeZoneId, OpenTimeLocal, CloseTimeLocal and
optional LunchBreakStart, LunchBreakEnd, OpeningAuctionStart and
ClosingAuctionStart.
.PARAMETER UtcNow
The instant to evaluate. Defaults to the current UTC time.
.PARAMETER Holidays
Hashtable of exchange code to an array of yyyy-MM-dd closure dates.
Missing or empty data means only weekends and session hours apply.
#>
[CmdletBinding()]
[OutputType([hashtable])]
param(
[Parameter(Mandatory)][PSCustomObject]$Exchange,
[datetime]$UtcNow = [DateTime]::UtcNow,
[hashtable]$Holidays = @{}
)

if ($UtcNow.Kind -eq [DateTimeKind]::Local) {
$UtcNow = $UtcNow.ToUniversalTime()
}
else {
$UtcNow = [DateTime]::SpecifyKind($UtcNow, [DateTimeKind]::Utc)
}

$tz = $null
try {
$tz = [System.TimeZoneInfo]::FindSystemTimeZoneById($Exchange.TimeZoneId)
$localNow = [System.TimeZoneInfo]::ConvertTimeFromUtc($UtcNow, $tz)
}
catch {
$localNow = $UtcNow
}

# Converts an exchange-local wall-clock time to UTC for countdown arithmetic
$toUtc = {
param([datetime]$Local)
if ($tz) {
try {
return [System.TimeZoneInfo]::ConvertTimeToUtc([DateTime]::SpecifyKind($Local, [DateTimeKind]::Unspecified), $tz)
}
catch {
# Wall-clock time inside a DST gap; fall back to treating it as UTC
Write-Verbose "Cannot convert $Local in $($Exchange.TimeZoneId) to UTC: $($_.Exception.Message)"
}
}
return [DateTime]::SpecifyKind($Local, [DateTimeKind]::Utc)
}

$dayOfWeek = $localNow.DayOfWeek

# Weekend check
if ($dayOfWeek -eq 'Saturday' -or $dayOfWeek -eq 'Sunday') {
return @{ Status = 'Closed'; Text = 'Weekend'; TimeRemaining = $null; CountdownTarget = $null }
}

# Holiday check
$todayStr = $localNow.ToString('yyyy-MM-dd')
if ($Holidays -and $Holidays.ContainsKey($Exchange.Code) -and $Holidays[$Exchange.Code] -contains $todayStr) {
return @{ Status = 'Holiday'; Text = 'Holiday - Closed'; TimeRemaining = $null; CountdownTarget = $null }
}

# Parse times
$openParts = $Exchange.OpenTimeLocal -split ':'
$closeParts = $Exchange.CloseTimeLocal -split ':'
$openTime = $localNow.Date.AddHours([int]$openParts[0]).AddMinutes([int]$openParts[1])
$closeTime = $localNow.Date.AddHours([int]$closeParts[0]).AddMinutes([int]$closeParts[1])

# Lunch break
$lunchStart = $null
$lunchEnd = $null
if ($Exchange.LunchBreakStart -and $Exchange.LunchBreakEnd) {
$lsParts = $Exchange.LunchBreakStart -split ':'
$leParts = $Exchange.LunchBreakEnd -split ':'
$lunchStart = $localNow.Date.AddHours([int]$lsParts[0]).AddMinutes([int]$lsParts[1])
$lunchEnd = $localNow.Date.AddHours([int]$leParts[0]).AddMinutes([int]$leParts[1])
}

# Opening auction (optional)
$openAuctionStart = $null
if ($Exchange.OpeningAuctionStart) {
$oaParts = $Exchange.OpeningAuctionStart -split ':'
$openAuctionStart = $localNow.Date.AddHours([int]$oaParts[0]).AddMinutes([int]$oaParts[1])
}

# Closing auction (optional)
$auctionStart = $null
if ($Exchange.ClosingAuctionStart) {
$caParts = $Exchange.ClosingAuctionStart -split ':'
$auctionStart = $localNow.Date.AddHours([int]$caParts[0]).AddMinutes([int]$caParts[1])
}

# Pre-market
if ($localNow -lt $openTime) {
$remaining = (& $toUtc $openTime) - $UtcNow
$prefix = if ($openAuctionStart -and $localNow -ge $openAuctionStart) { 'Opening auction - opens in' } else { 'Opens in' }
return @{ Status = 'PreMarket'; Text = "$prefix $(Format-CountdownSpan -TimeSpan $remaining)"; TimeRemaining = $remaining; CountdownTarget = 'Open' }
}

# Post-close
if ($localNow -ge $closeTime) {
return @{ Status = 'Closed'; Text = 'Closed'; TimeRemaining = $null; CountdownTarget = $null }
}

# Lunch break
if ($lunchStart -and $lunchEnd -and $localNow -ge $lunchStart -and $localNow -lt $lunchEnd) {
$remaining = (& $toUtc $lunchEnd) - $UtcNow
return @{ Status = 'LunchBreak'; Text = "Lunch - Reopens in $(Format-CountdownSpan -TimeSpan $remaining)"; TimeRemaining = $remaining; CountdownTarget = 'Reopen' }
}

# Open - countdown to close
$remaining = (& $toUtc $closeTime) - $UtcNow
$countdownStr = Format-CountdownSpan -TimeSpan $remaining
$text = "Closes in $countdownStr"

if ($auctionStart -and $localNow -ge $auctionStart) {
# Closing call: no continuous matching, uncross at the end of the period
$text = "Closing auction - ends in $countdownStr"
}

if ($remaining.TotalMinutes -le 5) {
return @{ Status = 'ClosingImminent'; Text = $text; TimeRemaining = $remaining; CountdownTarget = 'Close' }
}
elseif ($remaining.TotalMinutes -le 30) {
return @{ Status = 'ClosingSoon'; Text = $text; TimeRemaining = $remaining; CountdownTarget = 'Close' }
}
else {
return @{ Status = 'Open'; Text = $text; TimeRemaining = $remaining; CountdownTarget = 'Close' }
}
}

function Test-ExchangeActive {
<#
.SYNOPSIS
Decides whether an exchange is active from saved user preferences.
.DESCRIPTION
Saved ActiveExchanges take precedence; exchanges absent from the saved
list stay inactive, so new exchanges never alter an existing selection.
With no saved list, the exchange's IsDefault flag applies.
#>
[CmdletBinding()]
[OutputType([bool])]
param(
[Parameter(Mandatory)][PSCustomObject]$Exchange,
$UserPreferences
)

if ($UserPreferences -and $UserPreferences.ActiveExchanges) {
return [bool](@($UserPreferences.ActiveExchanges) -contains $Exchange.Code)
}
return [bool]$Exchange.IsDefault
}
37 changes: 37 additions & 0 deletions PSExchangeClock/Private/Get-MapPreferenceState.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
function Get-MapPreferenceState {
<#
.SYNOPSIS
Resolves the saved map style, projection and overlays from user preferences.
.DESCRIPTION
Unknown or missing values resolve to $null so the caller keeps its own
defaults. Overlays resolve to $null only when MapOverlays is absent; an
empty saved list means "all overlays off". Unknown overlay names (for
example 'TimeLine' from older example files, which has no toggle) are
ignored.
.OUTPUTS
Hashtable with Style, Projection and Overlays.
#>
[CmdletBinding()]
[OutputType([hashtable])]
param(
$UserPreferences,
[string[]]$ValidStyles = @(),
[string[]]$ValidProjections = @(),
[string[]]$OverlayNames = @()
)

$state = @{ Style = $null; Projection = $null; Overlays = $null }
if (-not $UserPreferences) { return $state }

if ($UserPreferences.MapStyle -and $ValidStyles -contains $UserPreferences.MapStyle) {
$state.Style = [string]$UserPreferences.MapStyle
}
if ($UserPreferences.MapProjection -and $ValidProjections -contains $UserPreferences.MapProjection) {
$state.Projection = [string]$UserPreferences.MapProjection
}
if ($UserPreferences.PSObject.Properties['MapOverlays']) {
$saved = @($UserPreferences.MapOverlays | Where-Object { $_ })
$state.Overlays = @($OverlayNames | Where-Object { $saved -contains $_ })
}
return $state
}
Loading