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.
- Loading branch information
awb99
committed
Aug 29, 2023
1 parent
b15110c
commit 3ed9a97
Showing
9 changed files
with
169 additions
and
34 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
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
36 changes: 36 additions & 0 deletions
36
lib/tradingview/src/ta/tradingview/goldly/algo/interaction.cljs
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,36 @@ | ||
(ns ta.tradingview.goldly.algo.interaction | ||
(:require | ||
[ta.tradingview.goldly.algo.context :as c] | ||
[ta.tradingview.goldly.interact2 :as i] | ||
)) | ||
|
||
(defn symbol-changed? [old-value new-value] | ||
(let [old (get-in old-value [:opts :symbol]) | ||
new (get-in new-value [:opts :symbol])] | ||
(println "symbol old: " old " new: " new) | ||
(if (= old new) | ||
false | ||
true))) | ||
|
||
(defn on-load-finished [& args] | ||
(println "on-load-finished: " args) | ||
) | ||
|
||
(defn on-symbol-change [algo-ctx tv s] | ||
(println "symbol changed to: " s) | ||
(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) | ||
nil)) | ||
|
||
(defn track-interactions [algo-ctx tv] | ||
(let [input (c/get-algo-input-atom algo-ctx)] | ||
(println "add-watch to algo-ctx input ..") | ||
(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]))) | ||
|
||
)))) |
69 changes: 69 additions & 0 deletions
69
lib/tradingview/src/ta/tradingview/goldly/algo/tradingview.cljs
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,69 @@ | ||
(ns ta.tradingview.goldly.algo.tradingview | ||
(:require | ||
[reagent.core :as r] | ||
[js-loader :refer [with-js browser-defined?]] | ||
[ta.tradingview.goldly.tradingview :as tv :refer [tradingview-chart show-tradingview-widget shutdown-tradingview!]] | ||
[ta.tradingview.goldly.feed.algo2 :refer [get-tradingview-options-algo-feed]] | ||
[ta.tradingview.goldly.algo.context :as c] | ||
[ta.tradingview.goldly.algo.interaction :as i] | ||
)) | ||
|
||
|
||
#_(defn tradingview-algo-widget [algo-ctx] | ||
(let [{:keys [algo opts]} (c/get-algo-input algo-ctx) | ||
symbol (:symbol opts)] | ||
(println "showing tradingview-widget algo-mode algo: " algo " symbol: " symbol) | ||
[tradingview-chart {:feed (get-tradingview-options-algo-feed algo-ctx) | ||
:options {:autosize true | ||
:symbol symbol}}] | ||
)) | ||
|
||
|
||
#_(defn tradingview-algo [algo-ctx] | ||
;(i/track-interactions algo-ctx) ; interactions tracking does not work. | ||
(tradingview-algo-widget algo-ctx) | ||
) | ||
|
||
|
||
(defn tradingview-widget-algo [algo-ctx] | ||
(let [id "tv-widget-1" ;(uuid/uuid-string (uuid/make-random-uuid)) | ||
tv (r/atom nil)] | ||
(r/create-class | ||
{:display-name "tradingview" | ||
:reagent-render (fn [_] | ||
[:div {:id id :style {:width "100%" :height "100%"}}]) | ||
:component-did-mount (fn [_] | ||
(println "TradingViewChart.ComponentDidMount") | ||
(let [{:keys [algo opts]} (c/get-algo-input algo-ctx) | ||
symbol (:symbol opts) | ||
widget (show-tradingview-widget | ||
id | ||
{:feed (get-tradingview-options-algo-feed algo-ctx) | ||
:options {:autosize true | ||
:symbol symbol}})] | ||
(reset! tv widget) | ||
(i/track-interactions algo-ctx @tv) | ||
(.onChartReady @tv #(println "TradingView ChartWidget has loaded!")))) | ||
:component-will-unmount (fn [this] | ||
(println "TradingViewChart.ComponentDid-UN-Mount") | ||
(shutdown-tradingview! @tv)) | ||
;:component-will-receive-props (fn [this new-argv] | ||
; (println "receive props: " new-argv)) | ||
:component-did-update (fn [this [_ prev-props prev-more]] | ||
(println "tradingview-algo-widget did update.") | ||
;(let [[_ new-config] (r/argv this)] | ||
; (println "TradingViewChart.ComponentDidUpdate " new-config) | ||
;(if (not (= | ||
;(reset! tv (change-feed-config id new-config @tv)) | ||
; ) | ||
)}))) | ||
|
||
|
||
(defn tradingview-algo [algo-ctx] | ||
[with-js | ||
{(browser-defined? "TradingView") "/r/tradingview/charting_library_21/charting_library.js" ; "/r/tradingview/charting_library.min.js" ; js/TradingView | ||
(browser-defined? "Datafeeds") "/r/tradingview/UDF_21/bundle.js" ; "/r/tradingview/UDF/bundle.js" | ||
(browser-defined? "MyStudy") "/r/tradingview/study.js"} ; js/Datafeeds | ||
;[:h1 "tv loaded!"] | ||
[tradingview-widget-algo algo-ctx]]) | ||
|
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
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
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,17 @@ | ||
(ns ta.tradingview.goldly.interact2 | ||
(:require | ||
[reagent.core :as r])) | ||
|
||
|
||
|
||
(defn on-data-loaded [& _args] | ||
(println "tv data has been loaded (called after set-symbol)")) | ||
|
||
(defn set-symbol | ||
([tv symbol interval] | ||
;(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)) |
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
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