lightweight-charts-python icon indicating copy to clipboard operation
lightweight-charts-python copied to clipboard

Version 2.0

Open louisnw01 opened this issue 1 year ago • 23 comments

Hello everyone!

I have created a new 2.0 branch which i’m planning on releasing in the coming days/weeks. It includes:

  • A complete rework of the backend, which now uses TypeScript
  • A rewrite of the drawing objects (written as plugins) including rectangles
  • Test cases

Now that we are using plugins (and the js/ts source code is readable!) I hope that it will be easier for others to contribute their own ideas, especially on the typescript/javascript side of things.

Some ideas that others could contribute:

  • Fib lines
  • Markers that can be placed at locations on the Y axis
  • Other control panel widgets

Any feedback/testing would be much appreciated!

To Install this branch:

  1. download/clone the 2.0 branch.
  2. in your own venv:
    • pip uninstall lightweight_charts
    • pip install -e path/to/lightweight-charts-python/lightweight_charts/

Louis

louisnw01 avatar Mar 30 '24 15:03 louisnw01

I could notice that the horizontal line uses 2 clicks and not 1 as before. changing colors in the lines and box work well. I could see that the center of the rectangle always remains gray and only the edges change color. deleting the drawings do not work or styles do not work either. Suggestion for styles to be able to adjust the tickness of the lines please. Otherwise it works very well, I will be testing it more thoroughly to see if I find more problems. A request for future fibbonacci retracement. Good job, the light weight charts python project looks better every day.

cilindro5432 avatar Mar 31 '24 17:03 cilindro5432

After second click on horizontal line cant move again. if change time frame drawings desappear and When you return to the tf where the drawings were created, they appear.

cilindro5432 avatar Mar 31 '24 18:03 cilindro5432

Thanks for your feedback @cilindro5432, ill get those ironed out soon.

louisnw01 avatar Mar 31 '24 23:03 louisnw01

@louisnw01 How to use this new 2.0 version please guide through installation??

alloc7260 avatar Apr 03 '24 12:04 alloc7260

I would love if you can simply make the drawing tools color/behaviour default to same as in tradingview app. They are pretty good already

isshin1 avatar Apr 05 '24 02:04 isshin1

Great to hear, thanks for all your work on this @louisnw01 !

Will there be support for PyQt6 in this version?

axalon avatar Apr 06 '24 15:04 axalon

I have waited for long for BOX / RECTANGLE to be implemented thanks for your great work. I am using something like FIBs in my project maybe after 2.0 I will help but only in python.

One suggestion if possible add some examples for BANDs like macd. Also make separate SECTION for questions and answers, Maybe discord also

armeya25 avatar Apr 09 '24 15:04 armeya25

Hello, can someone help me set up lightweight-charts on Ubuntu 20.4 WLS Installation? I managed to get a static chart but no live one, I get an error about python gtk which I cannot resolve. I use Python 3.11 on Anaconda. Sorry for posting this, maybe a Q&A like armeya25 said would be usefull

bobest avatar Apr 12 '24 01:04 bobest

I could notice that the horizontal line uses 2 clicks and not 1 as before. changing colors in the lines and box work well. I could see that the center of the rectangle always remains gray and only the edges change color. deleting the drawings do not work or styles do not work either. Suggestion for styles to be able to adjust the tickness of the lines please. Otherwise it works very well, I will be testing it more thoroughly to see if I find more problems. A request for future fibbonacci retracement. Good job, the light weight charts python project looks better every day.

horizontal lines are back to a single click, delete should work now.

Louis

louisnw01 avatar Apr 14 '24 15:04 louisnw01

@louisnw01 How to use this new 2.0 version please guide through installation??

I have added an installation section to this issue.

Louis

louisnw01 avatar Apr 14 '24 15:04 louisnw01

Hi Mr. Lois In the latest version notice that a horizontal line is created with one click and not 2 and the new vertical line uses 2 clicks instead of one. The way clicks are implemented shouldn't matter after they work. I use the Oanda API to get the data. In the first version of the Light weight chart 2.0 I could draw with the problems I had but the drawings were still visible. In this latest version it keeps the drawings in static data but with tick data the drawings disappear from the chart when updating. I tried saving and loading the drawings in drawings.json and it doesn't save or load the drawings. I don't know if it's my mistake but try to verify it as soon as you can. In the previous version it had a handler error at the beginning that many times it did not open the app and other times it did, that was resolved in the latest version and it works very well. Anyway, this latest version works better than the previous one, it's just that the drawings with tick data don't work well for me and the previous version does. Could you tell me which specific files I need to manipulate to control the thinness of the lines, if possible? In the previous version as in this last one I found the same error in the price scale. When you press click and slide up and down the image of the candles look as if the candles were reduced or enlarged. The image does not stay in that position where I left it, in seconds it returns to its original state.

cilindro5432 avatar Apr 18 '24 23:04 cilindro5432

@armeya25 If you dont have any or just a little knolodge in python try chat gpt to setup your chat.

cilindro5432 avatar Apr 19 '24 15:04 cilindro5432

@armeya25 If you dont have any or just a little knolodge in python try chat gpt to setup your chat.

I am noob in python but I used lightweight charts before it was working fine for 2.0 it's shows error for same code that was working fine for older version of lightweight charts

armeya25 avatar Apr 19 '24 15:04 armeya25

@armeya25 If you dont have any or just a little knolodge in python try chat gpt to setup your chat.

I am noob in python but I used lightweight charts before it was working fine for 2.0 it's shows error for same code that was working fine for older version of lightweight charts

I had some issues with my code too in first version of this branch. The first version of this branch had several problems when starting the app. I had to modify my code. The second version does not have these problems, try with the latest update of light weight charts. As I told you, if you don't have much experience in python, chat gpt can help you a lot, it can identify errors more clearly.

cilindro5432 avatar Apr 19 '24 23:04 cilindro5432

export WEBKIT_DISABLE_COMPOSITING_MODE="1"

After this command works on arch linux i3wm

armeya25 avatar Apr 30 '24 04:04 armeya25

@louisnw01 box implementation working or not Test works fine but It didn't draw box This is code, What I am doing wrong here

https://github.com/louisnw01/lightweight-charts-python/issues/344

armeya25 avatar Apr 30 '24 13:04 armeya25

the drawings disappear https://github.com/louisnw01/lightweight-charts-python/assets/150294229/31d06830-ee18-4c2a-b34f-c9431d19eecc

cilindro5432 avatar May 04 '24 13:05 cilindro5432

the drawings disappear https://github.com/louisnw01/lightweight-charts-python/assets/150294229/31d06830-ee18-4c2a-b34f-c9431d19eecc

My drawing doesn't disappeared though, But it's only working on manual drawing, Chart.box() doesn't draw it automatically

armeya25 avatar May 04 '24 15:05 armeya25

Should that also be raised as big ?

armeya25 avatar May 04 '24 15:05 armeya25

@armeya25

"A complete rework of the backend, which now uses TypeScript A rewrite of the drawing objects (written as plugins) including rectangles Test cases Now that we are using plugins (and the js/ts source code is readable!) I hope that it will be easier for others to contribute their own ideas, especially on the typescript/javascript side of things.

Some ideas that others could contribute:

Fib lines ### Markers that can be placed at locations on the Y axis Other control panel widgets Any feedback/testing would be much appreciated!"

You want a marker as rectangle. Now is time to be creative

cilindro5432 avatar May 05 '24 02:05 cilindro5432

It gives error : DEBUG:PyQt5.uic.uiparser:pop widget QStatusBar statusbar DEBUG:PyQt5.uic.uiparser:new topwidget MainWindow DEBUG:PyQt5.uic.uiparser:pop widget QMainWindow MainWindow DEBUG:PyQt5.uic.uiparser:new topwidget None Traceback (most recent call last): File "D:\Installed_Python\lib\runpy.py", line 196, in _run_module_as_main return _run_code(code, main_globals, None, File "D:\Installed_Python\lib\runpy.py", line 86, in _run_code exec(code, run_globals) File "E:\Works\Project VI\charting\chart_project_1_prblm.py", line 711, in window = HistoricalChart() File "E:\Works\Project VI\charting\chart_project_1_prblm.py", line 121, in init self.chart = QtChart(self, toolbox=True) File "D:\Py_Env\v311\lib\site-packages\lightweight_charts\widgets.py", line 89, in init {abstract.TEMPLATE[:85]} AttributeError: module 'lightweight_charts.abstract' has no attribute 'TEMPLATE'

Tapanhaz avatar May 09 '24 14:05 Tapanhaz

My app has a lot of early development rust on it at this point. Very excited for the next 2.0 release so I can finally rebuild it.

Thanks for your hard work, Louis. Without this library a lot of the ideas would just stay in our heads forever.

emma-uw avatar May 15 '24 22:05 emma-uw

Encountered a bug in 2.0 presented here: https://github.com/louisnw01/lightweight-charts-python/issues/362

amirzamli avatar May 17 '24 23:05 amirzamli

in python-lightweight-charts v 2.0 adding marker throwing the following error:

chart.marker(time=date.at[i], position = 'above', shape= 'arrow_down', color= 'red', text ='SEXIT')

Exception in thread Thread-2 (loop): Traceback (most recent call last): File "/home/anil/pyprojects/trado5/lightweight-charts-python/lightweight_charts/chart.py", line 89, in loop window.evaluate_js(arg) File "/home/anil/pyprojects/trado5/venv5/lib/python3.11/site-packages/webview/window.py", line 50, in wrapper return function(self, *args, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/anil/pyprojects/trado5/venv5/lib/python3.11/site-packages/webview/window.py", line 444, in evaluate_js raise JavascriptException(result) webview.errors.JavascriptException: {'name': 'SyntaxError', 'message': "Unexpected number '09'. Expected '}' to end an object literal.", 'line': 4, 'column': 33, 'sourceURL': 'http://127.0.0.1:52941/test.html', 'stack': 'eval@[native code]\nglobal code@http://127.0.0.1:52941/test.html:4:33'}

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "/usr/lib/python3.11/threading.py", line 1038, in _bootstrap_inner self.run() File "/usr/lib/python3.11/threading.py", line 975, in run self._target(*self._args, **self._kwargs) File "/home/anil/pyprojects/trado5/lightweight-charts-python/lightweight_charts/chart.py", line 94, in loop raise JavascriptException(f"\n\nscript -> '{arg}',\nerror -> {msg['name']}[{msg['line']}:{msg['column']}]\n{msg['message']}") webview.errors.JavascriptException:

script -> ' window.dppwcgvk.markers.push({ time: 2024-04-24 09:15:00, position: 'aboveBar', color: 'red', shape: 'arrowDown', text: 'SEXIT 349.8', id: 'window.zcmtakbs' }); window.dppwcgvk.series.setMarkers(window.dppwcgvk.markers)', error -> SyntaxError[4:33] Unexpected number '09'. Expected '}' to end an object literal.

anilwarbhe avatar May 22 '24 17:05 anilwarbhe

Is this v2.0 based on https://github.com/rwitzlib/lightweight-charts fork ?

Tapanhaz avatar May 23 '24 16:05 Tapanhaz

Is this v2.0 based on https://github.com/rwitzlib/lightweight-charts fork ?

Nope; all drawing plugins have only been written by me (so far)

louisnw01 avatar May 25 '24 13:05 louisnw01

in python-lightweight-charts v 2.0 adding marker throwing the following error:

chart.marker(time=date.at[i], position = 'above', shape= 'arrow_down', color= 'red', text ='SEXIT')

Exception in thread Thread-2 (loop): Traceback (most recent call last): File "/home/anil/pyprojects/trado5/lightweight-charts-python/lightweight_charts/chart.py", line 89, in loop window.evaluate_js(arg) File "/home/anil/pyprojects/trado5/venv5/lib/python3.11/site-packages/webview/window.py", line 50, in wrapper return function(self, *args, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/anil/pyprojects/trado5/venv5/lib/python3.11/site-packages/webview/window.py", line 444, in evaluate_js raise JavascriptException(result) webview.errors.JavascriptException: {'name': 'SyntaxError', 'message': "Unexpected number '09'. Expected '}' to end an object literal.", 'line': 4, 'column': 33, 'sourceURL': 'http://127.0.0.1:52941/test.html', 'stack': 'eval@[native code]\nglobal code@http://127.0.0.1:52941/test.html:4:33'}

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "/usr/lib/python3.11/threading.py", line 1038, in _bootstrap_inner self.run() File "/usr/lib/python3.11/threading.py", line 975, in run self._target(*self._args, **self._kwargs) File "/home/anil/pyprojects/trado5/lightweight-charts-python/lightweight_charts/chart.py", line 94, in loop raise JavascriptException(f"\n\nscript -> '{arg}',\nerror -> {msg['name']}[{msg['line']}:{msg['column']}]\n{msg['message']}") webview.errors.JavascriptException:

script -> ' window.dppwcgvk.markers.push({ time: 2024-04-24 09:15:00, position: 'aboveBar', color: 'red', shape: 'arrowDown', text: 'SEXIT 349.8', id: 'window.zcmtakbs' }); window.dppwcgvk.series.setMarkers(window.dppwcgvk.markers)', error -> SyntaxError[4:33] Unexpected number '09'. Expected '}' to end an object literal.

Fixed

louisnw01 avatar May 25 '24 13:05 louisnw01

I am receiving following error when I am doing following:

  1. I have created lines
  2. I have set the lines
  3. I delete all the lines
  4. I am creating the lines again
  5. I am setting them again

When I get a bar data for a perticulat stock I create indicators and set them. I search the stock and set the candle data for another stock and now I have to delete the old indicator lines and recreate and reset them.

Exception in thread Thread-2 (loop): Traceback (most recent call last): File "/home/anil/pyprojects/trado5/lightweight-charts-python/lightweight_charts/chart.py", line 89, in loop window.evaluate_js(arg) File "/home/anil/pyprojects/trado5/venv5/lib/python3.11/site-packages/webview/window.py", line 50, in wrapper return function(self, *args, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/anil/pyprojects/trado5/venv5/lib/python3.11/site-packages/webview/window.py", line 444, in evaluate_js raise JavascriptException(result) webview.errors.JavascriptException: {'name': 'TypeError', 'message': "undefined is not an object (evaluating 'window.vcaisayp.legend.lines.forEach')", 'line': 3, 'column': 41, 'stack': 'eval code@\neval@[native code]\nglobal code@http://127.0.0.1:32628/test.html:4:33'}

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "/usr/lib/python3.11/threading.py", line 1038, in _bootstrap_inner self.run() File "/usr/lib/python3.11/threading.py", line 975, in run self._target(*self._args, **self._kwargs) File "/home/anil/pyprojects/trado5/lightweight-charts-python/lightweight_charts/chart.py", line 94, in loop raise JavascriptException(f"\n\nscript -> '{arg}',\nerror -> {msg['name']}[{msg['line']}:{msg['column']}]\n{msg['message']}") webview.errors.JavascriptException:

anilwarbhe avatar May 25 '24 17:05 anilwarbhe

@louisnw01 I think clear_markers missing self._update_markers() call after the clear.

emma-uw avatar May 25 '24 21:05 emma-uw

@louisnw01 Hello, good sir. If I understood implementation correctly, saveDrawings() missing type: d._type, which leads to being unable to load them during switch (d.type) case.

saveDrawings = () => {
        const drawingMeta = []
        for (const d of this._drawingTool.drawings) {
            drawingMeta.push({
                type: d._type,
                points: d.points,
                options: d._options
            });
        }
        const string = JSON.stringify(drawingMeta);
        window.callbackFunction(`save_drawings${this._handlerID}_~_${string}`)
    }

Also it seems like deleting drawings only deletes them visually, but they persist on load/export. Maybe this part is not implimented yet, since workaround is just to pass this.saveDrawings as parameter to delete method and call it. (like in ColorPicker and etc cases).

emma-uw avatar May 28 '24 09:05 emma-uw