@rivascva/dt-idl 1.1.182 → 1.1.184

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/dist/index.d.ts CHANGED
@@ -256,12 +256,12 @@ interface components$3 {
256
256
  */
257
257
  weekHigh52: number;
258
258
  /**
259
- * Format: int64
259
+ * Format: double
260
260
  * @example 164000000
261
261
  */
262
262
  volume: number;
263
263
  /**
264
- * Format: int64
264
+ * Format: double
265
265
  * @example 62000000
266
266
  */
267
267
  averageVolume: number;
@@ -0,0 +1,83 @@
1
+ package utils
2
+
3
+ import (
4
+ "fmt"
5
+ "strconv"
6
+ "strings"
7
+ "time"
8
+
9
+ "github.com/RivasCVA/dt-idl/go/models"
10
+ )
11
+
12
+ // SleepThroughMarketTransition sleeps until the buffer window passes if the current time falls within market open or close transition periods.
13
+ //
14
+ // The buffer window is the window around each transition period.
15
+ // For example, if the buffer window is 15 seconds and the market opens at 9:30:00 and closes at 16:00:00:
16
+ //
17
+ // - Market open transition period: 9:29:45 - 9:30:15
18
+ // - The function will sleep until the current time is 9:30:15
19
+ //
20
+ // - Market close transition period: 15:59:45 - 16:00:15
21
+ // - The function will sleep until the current time is 16:00:15
22
+ //
23
+ // The goal is to allow enough time for the market data to be updated before running asynchronous operations that depend on this data.
24
+ func SleepThroughMarketTransition(now time.Time, bufferWindow time.Duration) error {
25
+ // load the market timezone
26
+ loc, err := time.LoadLocation(models.MarketTimezone)
27
+ if err != nil {
28
+ return fmt.Errorf("unable to load the market timezone: %w", err)
29
+ }
30
+
31
+ // convert the current time to the market timezone
32
+ now = now.In(loc)
33
+ today := time.Date(now.Year(), now.Month(), now.Day(), 0, 0, 0, 0, loc)
34
+
35
+ // parse the open time
36
+ openTimeParts := strings.Split(models.MarketOpenTime, ":")
37
+ openHour, err := strconv.Atoi(openTimeParts[0])
38
+ if err != nil {
39
+ return fmt.Errorf("unable to parse the open hour: %w", err)
40
+ }
41
+ openMinute, err := strconv.Atoi(openTimeParts[1])
42
+ if err != nil {
43
+ return fmt.Errorf("unable to parse the open minute: %w", err)
44
+ }
45
+
46
+ // parse the close time
47
+ closeTimeParts := strings.Split(models.MarketCloseTime, ":")
48
+ closeHour, err := strconv.Atoi(closeTimeParts[0])
49
+ if err != nil {
50
+ return fmt.Errorf("unable to parse the close hour: %w", err)
51
+ }
52
+ closeMinute, err := strconv.Atoi(closeTimeParts[1])
53
+ if err != nil {
54
+ return fmt.Errorf("unable to parse the close minute: %w", err)
55
+ }
56
+
57
+ // windows is a list of time windows that represent the market transition periods
58
+ windows := []struct {
59
+ start time.Time
60
+ end time.Time
61
+ }{
62
+ {
63
+ // market open window
64
+ start: today.Add(time.Duration(openHour)*time.Hour + time.Duration(openMinute)*time.Minute - bufferWindow),
65
+ end: today.Add(time.Duration(openHour)*time.Hour + time.Duration(openMinute)*time.Minute + bufferWindow),
66
+ },
67
+ {
68
+ // market close window
69
+ start: today.Add(time.Duration(closeHour)*time.Hour + time.Duration(closeMinute)*time.Minute - bufferWindow),
70
+ end: today.Add(time.Duration(closeHour)*time.Hour + time.Duration(closeMinute)*time.Minute + bufferWindow),
71
+ },
72
+ }
73
+
74
+ // sleep until the current time is after the market transition period (if applicable)
75
+ for _, window := range windows {
76
+ if !now.Before(window.start) && now.Before(window.end) {
77
+ time.Sleep(window.end.Sub(now))
78
+ break
79
+ }
80
+ }
81
+
82
+ return nil
83
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rivascva/dt-idl",
3
- "version": "1.1.182",
3
+ "version": "1.1.184",
4
4
  "description": "Dream Trade - Interface Definition Language",
5
5
  "main": "dist/index.cjs.js",
6
6
  "module": "dist/index.esm.js",
@@ -399,13 +399,13 @@ components:
399
399
  format: double
400
400
  example: 192.75
401
401
  volume:
402
- type: integer
403
- format: int64
404
- example: 164000000
402
+ type: number
403
+ format: double
404
+ example: 164000000.00
405
405
  averageVolume:
406
- type: integer
407
- format: int64
408
- example: 62000000
406
+ type: number
407
+ format: double
408
+ example: 62000000.00
409
409
  marketCap:
410
410
  type: number
411
411
  format: double
@@ -255,12 +255,12 @@ export interface components {
255
255
  */
256
256
  weekHigh52: number;
257
257
  /**
258
- * Format: int64
258
+ * Format: double
259
259
  * @example 164000000
260
260
  */
261
261
  volume: number;
262
262
  /**
263
- * Format: int64
263
+ * Format: double
264
264
  * @example 62000000
265
265
  */
266
266
  averageVolume: number;