From 9176db539b4d7c4112deee34baba2d9f6b71527d Mon Sep 17 00:00:00 2001 From: awb99 Date: Mon, 18 Sep 2023 17:24:16 -0500 Subject: [PATCH] kibot realtime-snapshot-bugfix --- app/demo/src/demo/goldly/page/main.cljs | 3 +- app/joseph/resources/ext/joseph.edn | 3 +- app/joseph/src/joseph/lib/quote_table.cljs | 20 +++---- app/joseph/src/joseph/page/live.cljs | 69 ---------------------- app/joseph/src/joseph/realtime.clj | 21 +++---- lib/data/src/ta/data/api_ds/kibot.clj | 9 ++- lib/trateg/src/ta/viz/trades_table.cljs | 36 +++++------ 7 files changed, 45 insertions(+), 116 deletions(-) delete mode 100644 app/joseph/src/joseph/page/live.cljs diff --git a/app/demo/src/demo/goldly/page/main.cljs b/app/demo/src/demo/goldly/page/main.cljs index aa4fe245..cf29b5bb 100644 --- a/app/demo/src/demo/goldly/page/main.cljs +++ b/app/demo/src/demo/goldly/page/main.cljs @@ -27,8 +27,7 @@ [:h1.text-xl.text-red-600 "joseph"] [link-href "/joseph" "tradingview"] [link-dispatch [:bidi/goto 'joseph.page.nav/page-joseph-nav] "nav"] - [link-dispatch [:bidi/goto 'joseph.page.live/page-joseph-live] "live"] - [link-dispatch [:bidi/goto 'joseph.page.live2/page-live-trading] "live v2"]] + [link-dispatch [:bidi/goto 'joseph.page.live2/page-live-trading] "live"]] [:div.bg-blue-300.m-5 [:h1.text-xl.text-red-600 "gann tools"] diff --git a/app/joseph/resources/ext/joseph.edn b/app/joseph/resources/ext/joseph.edn index edd361cc..8d605717 100644 --- a/app/joseph/resources/ext/joseph.edn +++ b/app/joseph/resources/ext/joseph.edn @@ -11,8 +11,7 @@ :cljs-routes {"joseph" {"" joseph.page.tradingview/tradingview-trades-page "/nav" joseph.page.nav/page-joseph-nav - "/live" joseph.page.live/page-joseph-live - "/live2" joseph.page.live2/page-live-trading}} + "/live" joseph.page.live2/page-live-trading}} :sci-cljs-ns [; lib joseph.lib.live-pl diff --git a/app/joseph/src/joseph/lib/quote_table.cljs b/app/joseph/src/joseph/lib/quote_table.cljs index 82591d8a..ffd0cee8 100644 --- a/app/joseph/src/joseph/lib/quote_table.cljs +++ b/app/joseph/src/joseph/lib/quote_table.cljs @@ -12,19 +12,19 @@ (defn quote-table [quotes] [aggrid {:box :fl :data quotes - :columns [{:field :symbol :width 50} - {:field :date :width 50} - {:field :time :width 50} + :columns [{:field :symbol :width 80} + {:field :date :width 100} + {:field :time :width 80} ;{:field :timezone} - {:field :open :width 50} - {:field :high :width 50} - {:field :low :width 50} - {:field :close :width 50} - {:field :volume :width 50} - {:field :changepercent :width 50} + {:field :open :width 70 :type "rightAligned"} + {:field :high :width 70 :type "rightAligned"} + {:field :low :width 70 :type "rightAligned"} + {:field :close :width 70 :type "rightAligned"} + {:field :volume :width 80 :type "rightAligned"} + {:field :changepercent :width 50 :type "rightAligned"} ;{:field :lastprice} ;{:field :lastvolume} ] - + :autosize-columns false :pagination :false :paginationAutoPageSize false}]) \ No newline at end of file diff --git a/app/joseph/src/joseph/page/live.cljs b/app/joseph/src/joseph/page/live.cljs deleted file mode 100644 index 4543503d..00000000 --- a/app/joseph/src/joseph/page/live.cljs +++ /dev/null @@ -1,69 +0,0 @@ -(ns joseph.page.live - (:require - [reagent.core :as r] - [clojure.string :as str] - ; trateg - [ta.viz.lib.layout :as layout] - [ta.viz.trades-table :refer [trades-table-live]] - [ta.viz.lib.loader :refer [clj->p]] - ; joseph - [joseph.lib.select :refer [select-string]] - [joseph.lib.live-pl :refer [trades-with-pl]] - [joseph.lib.trade-filter :refer [filter-trades]] - [joseph.lib.quote-table :refer [quote-table]])) - -(defn accounts [trades] - (->> trades - (map :account) - (into #{}) - (into []))) - -(defn symbols [trades] - (->> trades - (map :symbol) - (into #{}) - (into []))) - -(defn live-trade-ui [trades] - (let [account-a (r/atom "") - on-change-account (fn [account] - (println (str "selected: " account)) - (reset! account-a account)) - live-symbols (into [] (symbols trades)) - quotes-ra (clj->p {:timeout 120000} 'joseph.realtime/realtime-snapshot-stocks live-symbols) - quotes-futures-ra (clj->p 'joseph.realtime/daily-snapshot-futures live-symbols) - ] - (fn [trades] - (let [live-trades (filter-trades {:account @account-a - :status :live} trades) - quotes (concat (or (:data @quotes-ra) []) - (or (:data @quotes-futures-ra) [])) - ] - (println "quotes: " quotes) - [layout/left-right-top - {:top [:div - "Live-Trades " - (str "#" (count live-trades) " ") - [select-string {:value @account-a - :items (concat [""] (accounts trades)) - :on-change on-change-account}]] - :left [trades-table-live (trades-with-pl live-trades quotes)] - :right ; [:div "quotes" (:status @quotes-ra) " - " (pr-str @quotes-ra)] - (case (:status @quotes-ra) - :loading [:p "loading"] - :error [:p "error!"] - :data ;[:div "quotes (loaded)"] - [quote-table quotes] - [:p "unknown: status:" (pr-str @quotes-ra)]) - - }])))) - - -(defn page-joseph-live [_route] - (let [trades-ra (clj->p 'joseph.trades/load-trades)] - (fn [_route] - (case (:status @trades-ra) - :loading [:p "loading"] - :error [:p "error!"] - :data [live-trade-ui (:data @trades-ra)] - [:p "unknown: status:" (pr-str @trades-ra)])))) \ No newline at end of file diff --git a/app/joseph/src/joseph/realtime.clj b/app/joseph/src/joseph/realtime.clj index 8485d8f1..1c72b5b4 100644 --- a/app/joseph/src/joseph/realtime.clj +++ b/app/joseph/src/joseph/realtime.clj @@ -1,10 +1,8 @@ (ns joseph.realtime (:require [taoensso.timbre :refer [trace debug info warnf error]] - ;[ta.helper.date :refer [parse-date]] - ;[tick.core :as t] - [tablecloth.api :as tc] - [ ta.warehouse.symbol-db :as db] + [tablecloth.api :as tc] + [ta.warehouse.symbol-db :as db] [ta.data.api-ds.kibot :as kibot] [ta.helper.ds :refer [ds->map]])) @@ -12,18 +10,17 @@ (let [data (kibot/get-snapshot symbols) data-ok (if data (ds->map data) - [{:symbol "DAX0" :close 17000.0} - {:symbol "INTC" :close 40.0}]) - ] + [])] (info "realtime snapshot symbols: " (map :symbol data-ok)) data-ok)) (defn get-last-daily [symbol] (info "get-last-daily: " symbol) - (-> (kibot/get-series symbol "D" 1 {}) - (tc/add-column :symbol symbol) - )) + (-> (kibot/get-series symbol "D" 3 {}) + (tc/add-column :symbol symbol) + (tc/select-rows [-1]))) + (defn get-last-daily-snapshot [symbols] (let [[symbol-first & symbols-rest] symbols @@ -49,8 +46,7 @@ (defn realtime-snapshot-stocks [symbols] (let [stocks (filter stock? symbols)] - (realtime-snapshot stocks) - )) + (realtime-snapshot stocks))) (defn daily-snapshot-futures-raw [symbols] (let [futures (remove stock? symbols) @@ -98,6 +94,7 @@ (daily-snapshot-futures-raw) (print-range :all)) + (kibot/get-series "NG0" "D" 2 {}) (daily-snapshot-futures-raw []) (daily-snapshot-futures-raw ["NG0"]) (daily-snapshot-futures ["NG0"]) diff --git a/lib/data/src/ta/data/api_ds/kibot.clj b/lib/data/src/ta/data/api_ds/kibot.clj index 3a2f3539..128ab47b 100644 --- a/lib/data/src/ta/data/api_ds/kibot.clj +++ b/lib/data/src/ta/data/api_ds/kibot.clj @@ -75,8 +75,8 @@ (= range :full) {:period 100000} - (= range 1) - {:period 1} + (int? range) + {:period range} :else {:startdate (fmt-yyyymmdd start)} ; :startdate "2023-09-01" @@ -170,7 +170,10 @@ "D" {:start (parse-date "2023-09-06")} {}) - + + (get-series "MSFT" "D" 10 {}) + (get-series "NG0" "D" 3 {}) + (symbol->provider "EURUSD") (get-series "EURUSD" "D" diff --git a/lib/trateg/src/ta/viz/trades_table.cljs b/lib/trateg/src/ta/viz/trades_table.cljs index 2b316d91..3bffd2a1 100644 --- a/lib/trateg/src/ta/viz/trades_table.cljs +++ b/lib/trateg/src/ta/viz/trades_table.cljs @@ -18,31 +18,31 @@ (defn trades-table [trades] [aggrid {:box :fl :data trades - :columns [{:field :symbol} - {:field :side :headerName "side"} - {:field :qty} - {:field :entry-date :format fmt-yyyymmdd :headerName "dt-E"} - {:field :entry-vol :format #(round-number-digits 0 %) :headerName "dt-E"} - {:field :exit-date :format fmt-yyyymmdd :headerName "dt-X"} - {:field :entry-price :headerName "px-E"} - {:field :exit-price :headerName "px-X"} - {:field :pl :format #(round-number-digits 0 %) :type "rightAligned"}] + :columns [{:field :symbol :width 50} + {:field :side :headerName "side" :width 50} + {:field :qty :width 50} + {:field :entry-date :format fmt-yyyymmdd :headerName "dt-E" :width 50} + {:field :entry-vol :format #(round-number-digits 0 %) :headerName "dt-E" :width 50} + {:field :exit-date :format fmt-yyyymmdd :headerName "dt-X" :width 50} + {:field :entry-price :headerName "px-E" :width 50} + {:field :exit-price :headerName "px-X" :width 50} + {:field :pl :format #(round-number-digits 0 %) :type "rightAligned" :width 50}] :pagination :false :paginationAutoPageSize true}]) (defn trades-table-live [trades] [aggrid {:box :fl :data trades - :columns [{:field :account} - {:field :symbol} - {:field :side :headerName "side"} - {:field :qty} - {:field :entry-date :format fmt-yyyymmdd :headerName "dt-E"} - {:field :entry-price :headerName "px-E"} - {:field :entry-vol :format #(round-number-digits 0 %) :headerName "dt-E"} + :columns [{:field :account :width 80} + {:field :symbol :width 80} + {:field :side :headerName "side" :width 70} + {:field :qty :width 70 :type "rightAligned"} + {:field :entry-date :format fmt-yyyymmdd :headerName "dt-E" :width 100} + {:field :entry-price :headerName "px-E" :width 80 :type "rightAligned" } + {:field :entry-vol :format #(round-number-digits 0 %) :headerName "dt-E" :width 80 :type "rightAligned" } - {:field :current-price :type "rightAligned" } - {:field :current-pl :type "rightAligned"} + {:field :current-price :type "rightAligned" :width 80} + {:field :current-pl :type "rightAligned" :width 80} ] :pagination :false :paginationAutoPageSize true}]) \ No newline at end of file