Skip to content

Commit d18f10a

Browse files
committed
Add support date navigation fro Traders list
1 parent bb8a19e commit d18f10a

File tree

2 files changed

+54
-3
lines changed

2 files changed

+54
-3
lines changed

bn_lightweight_charts/js/index_bn.html

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,14 @@
1919
Cantarell, "Helvetica Neue", sans-serif;
2020
}
2121

22+
td.dt0, td.dt1, td.dt {
23+
cursor: pointer;
24+
text-decoration: underline;
25+
}
26+
td.dt0, td.dt1{
27+
color: blue;
28+
}
29+
2230
.tableview {
2331
background: darkgrey;
2432
color: black;
@@ -165,6 +173,30 @@ <h6>Performance Report for [ <span id="strategy-title"></span> ] </h6>
165173
return []
166174
}
167175
}
176+
177+
function scrollToTime(chart, stm0, stm1)
178+
{
179+
const tm0 = (new Date((stm0+":00").replace(' ','T')+'Z')).getTime()/1000
180+
const tm1 = stm1 ? (new Date((stm1+":00").replace(' ','T')+'Z')).getTime()/1000 : null
181+
182+
const scale = chart.timeScale()
183+
const tc0 = scale.timeToCoordinate(tm0)
184+
if (tc0) {
185+
const idx0 = scale.coordinateToLogical(tc0)
186+
if (tm1) {
187+
const tc1 = scale.timeToCoordinate(tm1)
188+
if (tc1) {
189+
const idx1 = scale.coordinateToLogical(tc1)
190+
scale.setVisibleLogicalRange({ from: idx0 - 5, to: idx1 + 5 });
191+
document.querySelector("#nav-home-tab").click();
192+
}
193+
}
194+
else {
195+
scale.setVisibleLogicalRange({ from: idx0 - 5, to: idx0 + 200 + 5 });
196+
document.querySelector("#nav-home-tab").click();
197+
}
198+
}
199+
}
168200
</script>
169201
</body>
170202
</html>

bn_lightweight_charts/widgets.py

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -259,8 +259,8 @@ def _prepare_html(self):
259259
}}
260260
const pos = v.size > 0 ? 'Long' : 'Short';
261261
_html += `<tr><td>${{v.ref}}</td> <td>${{pos}}</td><td>${{v.tradeid}}</td>`
262-
+`<td>${{v.dateopen}}</td><td>${{v.priceopen}}</td>`
263-
+`<td>${{v.dateclose}}</td><td>${{v.priceclose}}</td>`
262+
+`<td class="dt0">${{v.dateopen}}</td><td>${{v.priceopen}}</td>`
263+
+`<td class="dt1">${{v.dateclose}}</td><td>${{v.priceclose}}</td>`
264264
+`<td>${{v.pnlcomm}}</td><td>${{v.return_pct}}</td><td>${{v.commission}}</td>`
265265
+`<td>${{v.barlen}}</td></tr>`;
266266
}}
@@ -274,7 +274,7 @@ def _prepare_html(self):
274274
state = 1;
275275
}}
276276
const pos = v.o_ordtype===0 ? 'Buy' : 'Sell';
277-
_html += `<tr><td>${{v.o_ref}}</td><td>${{v.o_datetime}}</td><td>${{pos}}</td>`
277+
_html += `<tr><td>${{v.o_ref}}</td><td class="dt">${{v.o_datetime}}</td><td>${{pos}}</td>`
278278
+`<td>${{v.o_price}}</td><td>${{v.o_size}}</td></tr>`;
279279
}}
280280
}}
@@ -314,6 +314,25 @@ def _prepare_html(self):
314314
}}
315315
}}
316316
document.querySelectorAll('#slist a')[0]?.click()
317+
318+
document.querySelector('#trades tbody').ondblclick = (e) => {{
319+
const n = e.target;
320+
const chart = {self.id}.chart;
321+
if (n.nodeName==='TD' && n.classList.contains('dt0')) {{
322+
const dt0 = n.innerText
323+
const dt1 = n.parentNode.querySelector('td.dt1')?.innerText
324+
scrollToTime(chart, dt0, dt1)
325+
}}
326+
else if (n.nodeName==='TD' && n.classList.contains('dt1')) {{
327+
const dt1 = n.innerText
328+
const dt0 = n.parentNode.querySelector('td.dt0')?.innerText
329+
scrollToTime(chart, dt0, dt1)
330+
}}
331+
else if (n.nodeName==='TD' && n.classList.contains('dt')) {{
332+
const dt0 = n.innerText
333+
scrollToTime(chart, dt0)
334+
}}
335+
}}
317336
\n</script></body></html>
318337
'''
319338
return html_code

0 commit comments

Comments
 (0)