@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.
- package/go/models/constants.go +4 -0
- package/go/utils/market.go +17 -10
- package/package.json +1 -1
package/go/models/constants.go
CHANGED
|
@@ -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
|
)
|
package/go/utils/market.go
CHANGED
|
@@ -11,18 +11,25 @@ import (
|
|
|
11
11
|
)
|
|
12
12
|
|
|
13
13
|
// IsMarketHours determines if the given time falls within the preset market hours.
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
//
|
|
19
|
-
//
|
|
20
|
-
|
|
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
|
-
// -
|
|
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
|
-
//
|
|
25
|
-
|
|
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 {
|