Skip to content

Commit

Permalink
goto-date working
Browse files Browse the repository at this point in the history
  • Loading branch information
awb99 committed Aug 31, 2023
1 parent 71c007c commit c8cfa8c
Show file tree
Hide file tree
Showing 11 changed files with 172 additions and 90 deletions.
2 changes: 1 addition & 1 deletion app/demo/deps.edn
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{:paths ["src"
"classes"
;"classes"
]
:deps {org.clojure/clojure {:mvn/version "1.11.1"}
aysylu/loom {:mvn/version "1.0.2"}
Expand Down
3 changes: 3 additions & 0 deletions app/demo/src/demo/algo/astro.clj
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,6 @@
{:volume "column"}]
:options {:show-moon false}
:marks astro-marks})



49 changes: 3 additions & 46 deletions app/demo/src/demo/goldly/repl/tradingview/admin.clj
Original file line number Diff line number Diff line change
Expand Up @@ -24,42 +24,6 @@

;(set! (.-bongo js/globalThis) i-clj)

(eval-code!
(add-header-button
"re-gann" "my tooltip"
(fn []
(println "button clicked "))))

(eval-code!
(ta.tradingview.goldly.interact/add-context-menu
[{"position" "top"
"text" (str "First top menu item"); , time: " unixtime ", price: " price)
"click" (fn [] (js/alert "First clicked."))}
{:text "-"
:position "top"}
{:text "-Objects Tree..."}
{:position "top"
:text "Second top menu item 2"
:click (fn [] (js/alert "second clicked."))}
{:position "bottom"
:text "Bottom menu item"
:click (fn [] (js/alert "third clicked."))}]))

(eval-code!
(deref tvalgo/algo-state))

(eval-code!
(deref tvalgo/window-state))

(eval-code!
(do (ta.tradingview.goldly.interact/demo-crosshair)
(ta.tradingview.goldly.interact/demo-range)))

(eval-code!
(ta.tradingview.goldly.interact/get-range))

(eval-code!
(ta.tradingview.goldly.interact/track-range))

(eval-code!
(deref tv/state))
Expand Down Expand Up @@ -111,8 +75,6 @@
;(set! (.-foo js/globalThis) foo)
(js/eval "new foo().a")))

(eval-code!
(tv/add-demo-menu))

(eval-code!
(set-symbol "TLT" "1D"))
Expand All @@ -122,19 +84,14 @@

;"BB:BTCUSD"

(eval-code!
(let [p (tv/set-range
{:from 1420156800 :to 1451433600}
{:percentRightMargin 30})]
(.then p (fn [] (println "new visible range applied!")
;widget.activeChart () .refreshMarks ();
))))

;widget.selectedLineTool () ; returns "cursor"
;widget.activeChart () .getAllShapes () .forEach (({name}) => console.log (name));
;widget.activeChart().setPriceToBarRatio(0.7567, { disableUndo: true });
;widget.activeChart () .getPanes () [1] .moveTo (0);
;widget.activeChart () .getTimeScaleLogicalRange ()


; not working - tradingview widget does not have layout features
(eval-code!
(ta.tradingview.goldly.interact2/set-layout "2h"))
(ta.tradingview.goldly.interact2/set-layout "2h"))
2 changes: 1 addition & 1 deletion app/demo/src/demo/goldly/repl/tradingview/algo.clj
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
(ns demo.goldly.repl.tradingview.algo
(:require
[eval.cljs-eval :refer [eval-code!]]))
[reval.cljs-eval :refer [eval-code!]]))

(eval-code!
(+ 5 5))
Expand Down
3 changes: 2 additions & 1 deletion app/demo/src/demo/goldly/repl/tradingview/execution.clj
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
(ns demo.goldly.repl.tradingview.execution
(:require
[eval.cljs-eval :refer [eval-code!]]))
[reval.cljs-eval :refer [eval-code!]]))


(eval-code!
(-> (tv/chart-active)
Expand Down
32 changes: 32 additions & 0 deletions app/demo/src/demo/goldly/repl/tradingview/menu.clj
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
(ns demo.goldly.repl.tradingview.menu
(:require
[reval.cljs-eval :refer [eval-code!]]))




(eval-code!
(ta.tradingview.goldly.interact2/add-header-button
@ta.tradingview.goldly.interact/tv-widget-atom
"re-gann" "my tooltip"
(fn []
(js/alert "re-gann button clicked "))))


(eval-code!
(ta.tradingview.goldly.interact2/add-context-menu
@ta.tradingview.goldly.interact/tv-widget-atom
[{"position" "top"
"text" (str "First top menu item"); , time: " unixtime ", price: " price)
"click" (fn [] (js/alert "First clicked."))}
{:text "-"
:position "top"}
{:text "-Paste"} ; Removes the existing item from the menu
{:text "-" ; Adds a separator between buttons
:position "top"}
{:position "top"
:text "Second top menu item 2"
:click (fn [] (js/alert "second clicked."))}
{:position "bottom"
:text "Bottom menu item"
:click (fn [] (js/alert "third clicked."))}]))
79 changes: 79 additions & 0 deletions app/demo/src/demo/goldly/repl/tradingview/move.clj
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
(ns demo.goldly.repl.tradingview.move
(:require
[ta.helper.date :as dt :refer [parse-date ->epoch-second epoch-second->datetime]]
[reval.cljs-eval :refer [eval-code!]]))

(eval-code!
(ta.tradingview.goldly.interact2/get-range
@ta.tradingview.goldly.interact/tv-widget-atom
))
;; {:from 1644796800, :to 1697155200}

(eval-code!
(ta.tradingview.goldly.interact/track-range))



(defn epoch [yyyy-mm-dd]
(-> yyyy-mm-dd parse-date ->epoch-second))

(epoch "2023-01-01")
;; => 1672531200

(epoch "2023-12-31")
;; => 1703980800

(epoch "2022-01-01")
;; => 1640995200

(epoch "2022-12-31")
;; => 1672444800

(epoch "2019-04-01")
;; => 1554076800

;; => Syntax error compiling at (src/demo/goldly/repl/tradingview/move.clj:32:1).
;; Unable to resolve symbol: epoch in this context

;; => 1672444800
(eval-code! ; year 2023
(let [p (ta.tradingview.goldly.interact2/set-range
@ta.tradingview.goldly.interact/tv-widget-atom
{:from 1672531200
:to 1703980800 }
;{:percentRightMargin 5}
{}
)]
(.then p (fn []
(println "new visible range applied!")
;widget.activeChart () .refreshMarks ();
))))

(eval-code! ; year 2022
(let [p (ta.tradingview.goldly.interact2/set-range
@ta.tradingview.goldly.interact/tv-widget-atom
{:from 1640995200
:to 1672444800}
{}
;{:percentRightMargin 5}
)]
(.then p (fn []
(println "new visible range applied!")
;widget.activeChart () .refreshMarks ();
))))


(eval-code! ; 2019-04-01 (as midpoint in the chart)
(ta.tradingview.goldly.interact2/goto-date!
@ta.tradingview.goldly.interact/tv-widget-atom
1554076800))
;set-visible-range {:from 1545868800, :to 1562284800} {:percentRightMargin 5}

(epoch-second->datetime 1554076800)
(epoch-second->datetime 1545868800)
(epoch-second->datetime 1562284800)

; widget.onChartReady(() => {
; const chart = widget.chart();
; chart.setTimeFrame({val: {type: 'period-back', value: '12M'}, res: '1W'});
; });
2 changes: 1 addition & 1 deletion app/demo/src/demo/goldly/repl/tradingview/shape.clj
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
(ns demo.goldly.repl.tradingview.shape
(:require
[eval.cljs-eval :refer [eval-code!]]))
[reval.cljs-eval :refer [eval-code!]]))

(eval-code!
(+ 5 5))
Expand Down
1 change: 0 additions & 1 deletion app/demo/src/demo/goldly/repl/tradingview/study.clj
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
(eval-code!
(+ 5 5))


(eval-code!
(ta.tradingview.goldly.interact/add-study
"Moving Average" [30 "close"]))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
:custom_indicators_getter (config/algo-all-custom-indicator-promise algo-ctx)
}})]
(reset! tv widget)
(set! (-> js/window .-tvwidget) widget)
(i/track-interactions algo-ctx widget)
(.onChartReady @tv #(println "TradingView ChartWidget has loaded!"))))
:component-will-unmount (fn [this]
Expand Down
Loading

0 comments on commit c8cfa8c

Please sign in to comment.