tradingstrategy-ai / frontend

Web frontend for TradingStrategy.ai
https://tradingstrategy.ai
125 stars 23 forks source link

Jupyterlite and Pyodide integration #111

Open miohtama opened 2 years ago

miohtama commented 2 years ago

This is the epic issue for integrating the Python-based backtest execution with our website. It is based on the proof of concept built by @joemarshall.

UI

Spec

TODO

Milestones

Out of scope

For the future

joemarshall commented 2 years ago

One thought on the notebook interface - There's 2 options here I think 1) The interface is a stripped down full notebook interface, in that you can add text / code cells etc. 2) The interface gives you just a set of text cells with instructions and a fixed set of code cells in between, but with no ability to edit the text. This is even more stripped down, and would allow the text to be styled in with the main site content really nicely, but obviously does limit how much users can mess with it.

From a tech side it doesn't make that much difference - there needs to be a per-page python kernel whatever. Number 2 would just reduce the amount of UI on the page.

kenkunz commented 1 year ago

Frontend integration Proof-of-Concept

Based on Joe's guidance, I was able to get a basic PoC working in frontend

I ran into some styling issues where some of the jupyterlab CSS applies global styles to the page. I spent some time trying to scope the CSS to the <jupyter-notebook> component using shadow DOM. I experimented with this for a while and got it sort-of working, but it caused other issues. For now, it looks like there are some manageable work-arounds we can use to fix the global page CSS issues.

Joe's feedback on global CSS issue:

I also tried shadow dom briefly, I think jupyterlab makes some assumptions it shouldn't about the Dom. I think because jupyter haven't really focused on this usage, it is slightly brittle. I think a good longer term plan would be try to get jupyter folks to support jupyterlite as an embeddable webcomponent. I think this is a nice proof of concept that you can do it mostly by plugging together existing node packages and without having to build your own jupyterlite/lab tree. I suspect that may be a non starter until jupyterlite becomes an official project though.

test.ipynb running in frontend

jupyterlite-poc

kenkunz commented 1 year ago

MVP / v1 requirements

Now that we've proven we can load a a JupyterLite notebook in frontend, the next step is to integrate this into our trading-pair workflow.

Based on discussion with Mikko, here is a basic v1 user flow:

Questions

1. If user navigates to a different pair and clicks the same button, does this load the same notebook or a new one?

A: it generates a new notebook based on the original template, with the new exchange and trading pair values

2. If the user navigates back to a pair they have previously opened / saved a notebook for, what happens?

A: preferably, it opens their modified / saved notebook for that pair; this is "nice-to-have" and can be addressed in v2.

Eventually, we'll need to add a nav option to the site where users can get back to "your backtests / your strategies"

For now, the most important thing is that you can successfully run a notebook that used the trading-strategy-client to conduct technical analysis based on data from our APIs.