Skip to content

Commit

Permalink
nav-trades-table added
Browse files Browse the repository at this point in the history
  • Loading branch information
awb99 committed Sep 10, 2023
1 parent 29594c0 commit d6201f4
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 10 deletions.
25 changes: 15 additions & 10 deletions lib/joseph/src/joseph/page/nav.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,14 @@
(:require
[tick.core :as t]
[goldly.page :as page]
[demo.goldly.lib.loader :refer [clj->p]]
[ta.viz.nav-table :refer [nav-table]]
[container :refer [tab]]
[ta.viz.nav-vega :refer [nav-vega]]
))
(defn d [s]
(-> (str s "T00:00")
(t/date-time)
(t/inst)))
[ta.viz.nav-table :refer [nav-table]]
[ta.viz.trades-table :refer [trades-table]]
[demo.goldly.lib.loader :refer [clj->p]]))

(defn hack-date [row]
; inst converts a tick data to a javascript/date
(update row :date t/inst))

(defn vega-data-hacks [nav]
Expand All @@ -26,9 +24,16 @@
:loading [:p "loading"]
:error [:p "error!"]
:data [:div.w-screen.h-screen.flex.flex-cols
[:div.w.full.h-full.overflow-scroll
[nav-vega (vega-data-hacks (:nav(:data @nav)))]]
[nav-table (:nav (:data @nav))]]
;vega nav chart
[:div.w-full.h-full.overflow-scroll
[nav-vega (vega-data-hacks (:nav (:data @nav)))]]
;aggrid table (nav or trades)
[:div.w-full.h-full.overflow-scroll
[tab {:box :fl}
"nav"
[nav-table (:nav (:data @nav))]
"trades"
[trades-table (:trades (:data @nav))]]]]
[:p "unknown: status:" (pr-str @nav)]))))


Expand Down
30 changes: 30 additions & 0 deletions lib/trateg/src/ta/viz/trades_table.cljs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
(ns ta.viz.trades-table
(:require
[goldly.js :refer [to-fixed]]
[tick.goldly]
[tick.core :as tick]
[ui.aggrid :refer [aggrid]]))

(defn fmt-yyyymmdd [dt]
(if dt
(tick/format (tick/formatter "YYYY-MM-dd") dt)
""))

(defn round-number-digits
[digits number] ; digits is first parameter, so it can easily be applied (data last)
(if (nil? number) "" (to-fixed number digits)))


(defn trades-table [trades]
[aggrid {:data trades
:columns [{:field :symbol}
{:field :direction}
{:field :qty}
{:field :entry-date :format fmt-yyyymmdd}
{:field :exit-date :format fmt-yyyymmdd}
{:field :entry-price}
{:field :exit-price}
{:field :pl :format #(round-number-digits 0 %)}]
:box :fl
:pagination :false
:paginationAutoPageSize true}])

0 comments on commit d6201f4

Please sign in to comment.