diff --git a/lib/tradingview/src/ta/tradingview/goldly/algo/interaction.cljs b/lib/tradingview/src/ta/tradingview/goldly/algo/interaction.cljs index 8a6aff5a..2a2ae05a 100644 --- a/lib/tradingview/src/ta/tradingview/goldly/algo/interaction.cljs +++ b/lib/tradingview/src/ta/tradingview/goldly/algo/interaction.cljs @@ -4,6 +4,9 @@ [ta.tradingview.goldly.interact2 :as i] )) +(defn on-load-finished [& args] + (println "on-load-finished: " args)) + (defn symbol-changed? [old-value new-value] (let [old (get-in old-value [:opts :symbol]) new (get-in new-value [:opts :symbol])] @@ -12,16 +15,31 @@ false true))) -(defn on-load-finished [& args] - (println "on-load-finished: " args) - ) +(defn algo-changed? [old-value new-value] + (let [old (get-in old-value [:algo]) + new (get-in new-value [:algo])] + (println "algo old: " old " new: " new) + (if (= old new) + false + true))) -(defn on-symbol-change [algo-ctx tv s] - (println "symbol changed to: " s) +(defn on-input-change [algo-ctx tv old new] (let [{:keys [algo opts]} (c/get-algo-input algo-ctx) - {:keys [symbol frequency]} opts] - (c/set-algo-data algo-ctx nil) - (i/set-symbol tv s frequency on-load-finished) + {:keys [symbol frequency]} opts + symbol-changed (symbol-changed? old new) + algo-changed (algo-changed? old new) + ] + (when symbol-changed + (println "symbol changed to: " symbol)) + (when algo-changed + (println "algo changed to: " algo)) + + (when (or symbol-changed algo-changed) + (println "resetting algo-ctx data..") + (c/set-algo-data algo-ctx nil) + (println "switching tv symbol..") + (i/set-symbol tv symbol frequency on-load-finished)) + nil)) (defn track-interactions [algo-ctx tv] @@ -30,7 +48,5 @@ (add-watch input :algo-input (fn [key state old-value new-value] (println "algo-ctx input changed to:" new-value) - (when (symbol-changed? old-value new-value) - (on-symbol-change algo-ctx tv (get-in new-value [:opts :symbol]))) - - )))) \ No newline at end of file + (on-input-change algo-ctx tv old-value new-value)) + ))) \ No newline at end of file diff --git a/lib/tradingview/src/ta/tradingview/goldly/algo/tradingview.cljs b/lib/tradingview/src/ta/tradingview/goldly/algo/tradingview.cljs index 3fc06f6f..71c3d526 100644 --- a/lib/tradingview/src/ta/tradingview/goldly/algo/tradingview.cljs +++ b/lib/tradingview/src/ta/tradingview/goldly/algo/tradingview.cljs @@ -42,7 +42,7 @@ :options {:autosize true :symbol symbol}})] (reset! tv widget) - (i/track-interactions algo-ctx @tv) + (i/track-interactions algo-ctx widget) (.onChartReady @tv #(println "TradingView ChartWidget has loaded!")))) :component-will-unmount (fn [this] (println "TradingViewChart.ComponentDid-UN-Mount") diff --git a/lib/tradingview/src/ta/tradingview/goldly/interact2.cljs b/lib/tradingview/src/ta/tradingview/goldly/interact2.cljs index 211782b1..b2a3f62b 100644 --- a/lib/tradingview/src/ta/tradingview/goldly/interact2.cljs +++ b/lib/tradingview/src/ta/tradingview/goldly/interact2.cljs @@ -12,6 +12,6 @@ ;(println "tv set symbol:" symbol "interval: " interval) (set-symbol tv symbol interval on-data-loaded)) ([tv symbol interval on-load-finished] - ;(println "tv set symbol:" symbol "interval: " interval) - (.setSymbol tv symbol interval on-load-finished) - nil)) \ No newline at end of file + (println "tv set symbol:" symbol "interval: " interval) + (.setSymbol tv symbol interval on-load-finished) + nil)) \ No newline at end of file