@rivascva/dt-idl 1.1.185 → 1.1.186

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,5 +1,7 @@
1
1
  package models
2
2
 
3
+ import "time"
4
+
3
5
  // ContextKey is a type used to define keys for a request context.
4
6
  type ContextKey string
5
7
 
@@ -34,4 +36,6 @@ const (
34
36
  // MarketCloseTime is the closing time of the market in a 24-hour format (HH:mm).
35
37
  // Based on the timezone specified in MarketTimezone.
36
38
  MarketCloseTime = "16:00"
39
+ // MarketCloseGracePeriod is a grace period added after the official close time to allow in-flight operations to finish.
40
+ MarketCloseGracePeriod = 45 * time.Second
37
41
  )
@@ -11,18 +11,25 @@ import (
11
11
  )
12
12
 
13
13
  // IsMarketHours determines if the given time falls within the preset market hours.
14
- // The given open and close offsets are used as buffer window on market open and close.
15
- //
16
- // For example, if the open offset is 5 seconds and the market opens at 9:30:00:
17
- //
18
- // - The function will only return true if the current time is 9:30:05 or later
19
- //
20
- // For example, if the close offset is 20 seconds and the market closes at 16:00:00:
14
+ func IsMarketHours(now time.Time) (bool, error) {
15
+ return isMarketHoursWithOpenAndCloseOffsets(now, 0, 0)
16
+ }
17
+
18
+ // IsMarketHoursWithCloseGracePeriod determines if the given time falls within the preset market hours with a close grace period added after the official close time.
19
+ // This is useful for in-flight operations to complete after the market officially closes.
20
+ func IsMarketHoursWithCloseGracePeriod(now time.Time) (bool, error) {
21
+ return isMarketHoursWithOpenAndCloseOffsets(now, 0, models.MarketCloseGracePeriod)
22
+ }
23
+
24
+ // isMarketHoursWithOpenAndCloseOffsets determines if the given time falls within the preset market hours.
25
+ // The given open and close offsets are used as buffer window on market open and close:
21
26
  //
22
- // - The function will only return true if the current time is 16:00:20 or earlier
27
+ // - If the open offset is 5 seconds and the market opens at 9:30:00:
28
+ // - The function will only return true if the current time is 9:30:05 or later
23
29
  //
24
- // The purpose of the offset is to prevent certain operations from being executed during the market open and close transition periods.
25
- func IsMarketHours(now time.Time, openOffset time.Duration, closeOffset time.Duration) (bool, error) {
30
+ // - If the close offset is 20 seconds and the market closes at 16:00:00:
31
+ // - The function will only return true if the current time is 16:00:20 or earlier
32
+ func isMarketHoursWithOpenAndCloseOffsets(now time.Time, openOffset time.Duration, closeOffset time.Duration) (bool, error) {
26
33
  // load the market timezone
27
34
  loc, err := time.LoadLocation(models.MarketTimezone)
28
35
  if err != nil {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rivascva/dt-idl",
3
- "version": "1.1.185",
3
+ "version": "1.1.186",
4
4
  "description": "Dream Trade - Interface Definition Language",
5
5
  "main": "dist/index.cjs.js",
6
6
  "module": "dist/index.esm.js",