Skip to content

Commit

Permalink
updated calendar tests and dev project
Browse files Browse the repository at this point in the history
  • Loading branch information
wizard50 committed Oct 28, 2024
1 parent f5cd5fd commit 92eff6a
Show file tree
Hide file tree
Showing 7 changed files with 401 additions and 16 deletions.
5 changes: 1 addition & 4 deletions lib/calendar/dev/src/dev/calendar_helper.clj
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,5 @@


(time-open? (:us calendars) (to-utc "2024-10-11T16:00:00"))
;=> false
;=> true
(time-open? (:us calendars) (t/instant))

(t/time (to-utc "2024-10-11T16:00:00"))
(t/time (t/instant))
118 changes: 112 additions & 6 deletions lib/calendar/dev/src/dev/calendar_seq.clj
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
(ns dev.calendar-seq
(:require
[tick.core :as t]
[quanta.calendar.core :refer [trailing-window calendar-seq calendar-seq-prior
fixed-window
close->open-dt open->close-dt]]
[ta.calendar.calendars :refer [calendars]]
[dev.utils :refer [to-utc]]))
[quanta.calendar.core :refer [calendar-seq calendar-seq-prior calendar-seq-prior-open
fixed-window-open fixed-window]]))


(->> (t/in (t/date-time "2024-10-01T16:20:00") "America/New_York")
Expand Down Expand Up @@ -110,4 +107,113 @@

(->> (t/in (t/date-time "2024-10-01T23:59:59.999999999") "UTC")
(calendar-seq-prior [:crypto :d])
(take 20))
(take 10))
;=>
;(#time/zoned-date-time"2024-10-01T23:59:59.999999999Z[UTC]"
; #time/zoned-date-time"2024-09-30T23:59:59.999999999Z[UTC]"
; #time/zoned-date-time"2024-09-29T23:59:59.999999999Z[UTC]"
; #time/zoned-date-time"2024-09-28T23:59:59.999999999Z[UTC]"
; #time/zoned-date-time"2024-09-27T23:59:59.999999999Z[UTC]"
; #time/zoned-date-time"2024-09-26T23:59:59.999999999Z[UTC]"
; #time/zoned-date-time"2024-09-25T23:59:59.999999999Z[UTC]"
; #time/zoned-date-time"2024-09-24T23:59:59.999999999Z[UTC]"
; #time/zoned-date-time"2024-09-23T23:59:59.999999999Z[UTC]"
; #time/zoned-date-time"2024-09-22T23:59:59.999999999Z[UTC]")


(-> (fixed-window [:crypto :h] {:start (t/instant "2024-01-01T01:00:00Z")
:end (t/instant "2024-01-01T23:59:59.999999999Z")})
count)
; => 24

(-> (fixed-window [:crypto :h] {:start (t/instant "2024-01-01T01:00:00Z")
:end (t/instant "2024-01-01T23:00:00Z")})
count)
; => 23


(-> (fixed-window [:crypto :d] {:start (t/instant "2024-01-01T23:59:59.999999999Z")
:end (t/instant "2024-01-07T23:59:59.999999999Z")}))
;=>
;(#time/zoned-date-time"2024-01-07T23:59:59.999999999Z[UTC]"
; #time/zoned-date-time"2024-01-06T23:59:59.999999999Z[UTC]"
; #time/zoned-date-time"2024-01-05T23:59:59.999999999Z[UTC]"
; #time/zoned-date-time"2024-01-04T23:59:59.999999999Z[UTC]"
; #time/zoned-date-time"2024-01-03T23:59:59.999999999Z[UTC]"
; #time/zoned-date-time"2024-01-02T23:59:59.999999999Z[UTC]"
; #time/zoned-date-time"2024-01-01T23:59:59.999999999Z[UTC]")

(-> (fixed-window-open [:crypto :d] {:start (t/instant "2024-09-01T00:00:00Z")
:end (t/instant "2024-09-08T00:00:00Z")}))
;=>
;(#time/zoned-date-time"2024-09-08T00:00Z[UTC]"
; #time/zoned-date-time"2024-09-07T00:00Z[UTC]"
; #time/zoned-date-time"2024-09-06T00:00Z[UTC]"
; #time/zoned-date-time"2024-09-05T00:00Z[UTC]"
; #time/zoned-date-time"2024-09-04T00:00Z[UTC]"
; #time/zoned-date-time"2024-09-03T00:00Z[UTC]"
; #time/zoned-date-time"2024-09-02T00:00Z[UTC]"
; #time/zoned-date-time"2024-09-01T00:00Z[UTC]")

(-> (fixed-window-open [:crypto :d] {:start (t/instant "2024-01-01T23:59:59.999999999Z")
:end (t/instant "2024-01-05T23:59:59.999999999Z")}))
; NOTE: start is not valid bar open time.
;=>
;(#time/zoned-date-time"2024-01-05T00:00Z[UTC]"
; #time/zoned-date-time"2024-01-04T00:00Z[UTC]"
; #time/zoned-date-time"2024-01-03T00:00Z[UTC]"
; #time/zoned-date-time"2024-01-02T00:00Z[UTC]")

(-> (fixed-window [:crypto :h] {:start (t/instant "2024-01-01T23:59:59.999999999Z")
:end (t/instant "2024-01-02T23:59:59.999999999Z")}))
;=>
;(#time/zoned-date-time"2024-01-02T23:59:59.999999999Z[UTC]"
; #time/zoned-date-time"2024-01-02T23:00Z[UTC]"
; #time/zoned-date-time"2024-01-02T22:00Z[UTC]"
; #time/zoned-date-time"2024-01-02T21:00Z[UTC]"
; #time/zoned-date-time"2024-01-02T20:00Z[UTC]"
; #time/zoned-date-time"2024-01-02T19:00Z[UTC]"
; #time/zoned-date-time"2024-01-02T18:00Z[UTC]"
; #time/zoned-date-time"2024-01-02T17:00Z[UTC]"
; #time/zoned-date-time"2024-01-02T16:00Z[UTC]"
; #time/zoned-date-time"2024-01-02T15:00Z[UTC]"
; #time/zoned-date-time"2024-01-02T14:00Z[UTC]"
; #time/zoned-date-time"2024-01-02T13:00Z[UTC]"
; #time/zoned-date-time"2024-01-02T12:00Z[UTC]"
; #time/zoned-date-time"2024-01-02T11:00Z[UTC]"
; #time/zoned-date-time"2024-01-02T10:00Z[UTC]"
; #time/zoned-date-time"2024-01-02T09:00Z[UTC]"
; #time/zoned-date-time"2024-01-02T08:00Z[UTC]"
; #time/zoned-date-time"2024-01-02T07:00Z[UTC]"
; #time/zoned-date-time"2024-01-02T06:00Z[UTC]"
; #time/zoned-date-time"2024-01-02T05:00Z[UTC]"
; #time/zoned-date-time"2024-01-02T04:00Z[UTC]"
; #time/zoned-date-time"2024-01-02T03:00Z[UTC]"
; #time/zoned-date-time"2024-01-02T02:00Z[UTC]"
; #time/zoned-date-time"2024-01-02T01:00Z[UTC]"
; #time/zoned-date-time"2024-01-01T23:59:59.999999999Z[UTC]")


(->> (calendar-seq-prior [:crypto :d] (t/instant "2024-01-02T23:59:59.999999999Z"))
(take 1))
; => (#time/zoned-date-time"2024-01-02T23:59:59.999999999Z[UTC]")

(->> (t/in (t/date-time "2024-09-08T00:00:00") "UTC")
(calendar-seq-prior-open [:crypto :d])
(take 1))
;=> (#time/zoned-date-time"2024-09-08T00:00Z[UTC]")

(->> (t/in (t/date-time "2024-01-02T23:59:59.999999999") "UTC")
(calendar-seq-prior-open [:crypto :d])
(take 1))
;=> (#time/zoned-date-time"2024-01-02T00:00Z[UTC]")

(fixed-window-open [:crypto :d] {:start (t/in (t/date-time "2024-02-05T23:59:59.999999999") "UTC")
:end (t/in (t/date-time "2024-02-11T23:59:59.999999999") "UTC")})
;=>
;(#time/zoned-date-time"2024-02-11T00:00Z[UTC]"
; #time/zoned-date-time"2024-02-10T00:00Z[UTC]"
; #time/zoned-date-time"2024-02-09T00:00Z[UTC]"
; #time/zoned-date-time"2024-02-08T00:00Z[UTC]"
; #time/zoned-date-time"2024-02-07T00:00Z[UTC]"
; #time/zoned-date-time"2024-02-06T00:00Z[UTC]")
35 changes: 32 additions & 3 deletions lib/calendar/dev/src/dev/core.clj
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
[tick.core :as t]
[ta.calendar.calendars :refer [calendars]]
[ta.calendar.interval :refer [intervals]]
[quanta.calendar.core :refer [next-close current-close close->open-dt open->close-dt current-close2]]
[dev.utils :refer [to-utc]]))
[ta.calendar.helper :refer [trading-open-time]]
[quanta.calendar.core :refer [next-close current-close]]))

(current-close [:crypto :m]
(t/in (t/date-time "2024-02-08T23:59:30") "UTC"))
Expand Down Expand Up @@ -77,4 +77,33 @@
:next-close-dt next-close-dt
:next-close-instant next-close-instant})

(t/instant)
(let [dt-str "2024-02-08T23:59:59.999999999"
inst (-> (str dt-str "Z") (t/instant))
utc (t/in (t/date-time dt-str) "UTC")]
{:inst inst
:utc utc})

(t/date (t/instant "2024-02-08T23:59:59.999999999"))

(let [calendar (:crypto calendars)
interval (:d intervals)
current-close-dt (:current-close interval)]
(current-close-dt calendar (t/in (t/date-time "2024-02-08T23:59:59.999999999") "UTC")))
;=> #time/zoned-date-time"2024-02-08T23:59:59.999999999Z[UTC]"

(let [calendar (:crypto calendars)
interval (:d intervals)
current-open-dt (:current-open interval)]
(current-open-dt calendar (t/in (t/date-time "2024-02-08T23:59:59.999999999") "UTC")))
; => #time/zoned-date-time"2024-02-08T00:00Z[UTC]"

(let [t (t/instant "2024-02-08T23:59:59.999999999Z")]
(trading-open-time (:crypto calendars) t))
;=> #time/zoned-date-time"2024-02-08T00:00Z[UTC]"


(let [calendar (:crypto calendars)
interval (:h4 intervals)
current-close-dt (:current-close interval)]
(current-close-dt calendar (t/in (t/date-time "2024-02-10T12:00:00") "UTC")))
; => #time/zoned-date-time"2024-02-10T12:00Z[UTC]"
51 changes: 51 additions & 0 deletions lib/calendar/dev/src/dev/date.clj
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
(ns dev.date
(:require
[tick.core :as t]
[ta.helper.date :as d]))

; !!!!! LOCAL timezone is used

(t/date (t/instant "2024-02-08T23:59:59.999999999Z"))
;=> #time/date"2024-02-08"
(t/date (t/instant "2024-02-08T00:00:00Z"))
;=> #time/date"2024-02-07"

(t/in (t/date-time (t/instant "2024-02-08T00:00:00Z")) "UTC")
;=> #time/zoned-date-time"2024-02-07T19:00Z[UTC]"

(t/date (t/zoned-date-time (t/instant "2024-02-08T00:00:00Z")))
;=> #time/date"2024-02-07"

(t/zoned-date-time (t/instant "2024-02-08T00:00:00Z"))
;=> #time/zoned-date-time"2024-02-07T21:00-05:00"

(t/date (t/zoned-date-time (t/instant "2024-02-08T00:00:00Z")))
; => #time/date"2024-02-07"

;
; CORRECT timezone
;
(t/in (t/instant "2024-02-08T00:00:00Z") "America/New_York")
; => #time/zoned-date-time"2024-02-07T19:00-05:00[America/New_York]"

(t/in (t/instant "2024-02-08T00:00:00Z") "UTC")
; => #time/zoned-date-time"2024-02-08T00:00Z[UTC]"

(t/date (t/zoned-date-time "2024-02-08T00:00:00Z"))
; => #time/date"2024-02-08"


(t/day-of-month (t/instant "2024-02-08T23:59:59.999999999Z"))
(t/year (t/instant "2024-02-08T23:59:59.999999999Z"))
(t/year-month (t/instant "2024-02-08T23:59:59.999999999Z"))

(t/last-day-of-month (t/in (t/instant "2024-02-08T00:00:00Z") "UTC"))

(t/day-of-week (t/instant "2024-02-08T00:00:00Z"))


(t/date? (t/date (t/zoned-date-time "2024-02-08T00:00:00Z")))
(t/date-time? (t/zoned-date-time "2024-02-08T00:00:00Z"))
(t/zoned-date-time? (t/zoned-date-time "2024-02-08T00:00:00Z"))

(t/at (t/date (t/in (t/instant "2024-02-08T00:00:00Z") "UTC")) (t/new-time 12 00))
6 changes: 3 additions & 3 deletions lib/calendar/src/ta/calendar/interval/day.clj
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
(ns ta.calendar.interval.day
(:require
[tick.core :as t]
[ta.helper.date :refer [at-time]]
[ta.calendar.helper :refer [before-trading-hours? after-trading-hours?
[tick.core :as t]
[ta.helper.date :refer [at-time]]
[ta.calendar.helper :refer [before-trading-hours? after-trading-hours?
trading-open-time trading-close-time
day-open?
day-with-open? day-with-close?
Expand Down
Loading

0 comments on commit 92eff6a

Please sign in to comment.