Skip to content

Commit

Permalink
switch to svg (#530)
Browse files Browse the repository at this point in the history
- switch `Content-Type` header to `image/svg+xml`
- adds format parameter to `open_bytes_in_browser` so that both svg and png show up in testing
  • Loading branch information
AlexTheLion123 authored Aug 17, 2023
1 parent 2b094b3 commit 139e686
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 10 deletions.
8 changes: 4 additions & 4 deletions tests/ethereum/test_uniswap_v3_live_stop_loss.py
Original file line number Diff line number Diff line change
Expand Up @@ -682,10 +682,10 @@ def test_refresh_visualisations(
large_image_png = loop.runner.run_state.visualisation.large_image_png

if os.environ.get('SHOW_IMAGE'):
open_bytes_in_browser(small_image)
open_bytes_in_browser(small_image_dark)
open_bytes_in_browser(large_image)
open_bytes_in_browser(large_image_dark)
open_bytes_in_browser(small_image, format="svg")
open_bytes_in_browser(small_image_dark, format="svg")
open_bytes_in_browser(large_image, format="svg")
open_bytes_in_browser(large_image_dark, format="svg")
open_bytes_in_browser(small_image_png)
open_bytes_in_browser(large_image_png)

Expand Down
4 changes: 4 additions & 0 deletions tradeexecutor/strategy/pandas_trader/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,10 @@ def update_strategy_thinking_image_data(self, small_figure, large_figure):
small_image, small_image_dark = self.get_small_images(small_figure)
large_image, large_image_dark = self.get_large_images(large_figure)

# uncomment if you want light mode for Discord
# small_figure.update_layout(template="plotly")
# large_figure.update_layout(template="plotly")

# don't need the dark images for png (only post light images to discord)
small_image_png, _ = self.get_image_and_dark_image(small_figure, format="png", width=512, height=512)
large_image_png, _ = self.get_image_and_dark_image(large_figure, format="png", width=1024, height=1024)
Expand Down
4 changes: 2 additions & 2 deletions tradeexecutor/visual/image_output.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,14 +59,14 @@ def open_plotly_figure_in_browser(figure: go.Figure, height:int = 512, width: in
webbrowser.open(f"file://{path.as_posix()}")


def open_bytes_in_browser(data: bytes) -> None:
def open_bytes_in_browser(data: bytes, format="png") -> None:
"""Open bytes in a browser. Useful for debugging.
:param data:
bytes data to be used to create an image
"""

path = Path("/tmp/test-image.png")
path = Path(f"/tmp/test-image.{format}")
with open(path, "wb") as out:
out.write(data)

Expand Down
6 changes: 2 additions & 4 deletions tradeexecutor/webhook/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,8 +177,7 @@ def web_visulisation(request: Request):
if not data:
return exception_response(501, detail=f"Image data not available. It will be generated on the first strategy cycle.")

# TODO: Switch to SVG
r = Response(content_type="image/png")
r = Response(content_type="image/svg+xml")
r.body = data
return r
elif type =="large":
Expand All @@ -191,8 +190,7 @@ def web_visulisation(request: Request):
if not data:
return exception_response(501, detail=f"Image data not available. It will be generated on the first strategy cycle.")

# TODO: Switch to SVG
r = Response(content_type="image/png")
r = Response(content_type="image/svg+xml")
r.body = data
return r
else:
Expand Down

0 comments on commit 139e686

Please sign in to comment.