forked from jjttjj/trateg
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
moved calendar from quanta-studio to quanta.calendar-info
fixed zoned date time
- Loading branch information
Showing
1 changed file
with
61 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
(ns quanta.calendar.calendar-info | ||
(:require | ||
[tick.core :as t] | ||
[ta.calendar.core :as cal] | ||
[ta.calendar.calendars :as caldb] | ||
[ta.calendar.helper :as calhelp] | ||
;[missionary.core :as m] | ||
)) | ||
|
||
(defn market-info [market-kw] | ||
(let [cal (caldb/get-calendar market-kw) | ||
dt (t/instant) | ||
dt-cal (-> dt | ||
(t/zoned-date-time) | ||
(t/in (:timezone cal))) | ||
open? (calhelp/time-open? cal dt-cal) | ||
business? (calhelp/day-open? cal dt-cal)] | ||
{:calendar market-kw | ||
:open open? | ||
:business business? | ||
:calendar-time (t/date-time dt-cal)})) | ||
|
||
(defn gather-calendar [calendar-kw interval-kw dt] | ||
(let [current-close-dt (cal/current-close calendar-kw interval-kw dt)] | ||
(assoc (market-info calendar-kw) | ||
:calendar [calendar-kw interval-kw] | ||
;:prior (t/instant (cal/prior-close calendar-kw interval-kw dt)) | ||
:current (t/instant current-close-dt) | ||
:next (t/instant (cal/next-close calendar-kw interval-kw current-close-dt))))) | ||
|
||
(defn gather-calendars [dt] | ||
(let [cals (for [c [:us :crypto :forex | ||
:eu :jp] | ||
i [:m :m5 :m15 :h :d]] | ||
(gather-calendar c i dt))] | ||
{:dt dt | ||
:cals cals})) | ||
|
||
;(defn calendar-time [] | ||
; ;(m/stream | ||
; (m/ap | ||
; (loop [dt (t/instant)] | ||
; (let [cal (gather-calendars dt)] | ||
; (m/amb | ||
; (m/? (m/sleep 500 cal)) | ||
; (recur (t/instant))))))) | ||
|
||
(comment | ||
(market-info :crypto) | ||
(market-info :eu) | ||
|
||
(gather-calendar :crypto :m (t/instant)) | ||
|
||
(gather-calendars (t/instant)) | ||
|
||
(filter #(= true (:business %)) (:cals (gather-calendars (t/instant)))) | ||
|
||
(filter #(= (last (:calendar %)) :d) (:cals (gather-calendars (t/instant)))) | ||
|
||
; | ||
) |