Skip to content

Commit

Permalink
General cleanup for visualizer
Browse files Browse the repository at this point in the history
  • Loading branch information
golden-lucky-monkey committed Jun 28, 2022
1 parent 1bb8614 commit 38ec326
Show file tree
Hide file tree
Showing 8 changed files with 232 additions and 32 deletions.
160 changes: 160 additions & 0 deletions orderbook-delta-visualizer/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,160 @@
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

# C extensions
*.so

# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
share/python-wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.nox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
*.py,cover
.hypothesis/
.pytest_cache/
cover/

# Translations
*.mo
*.pot

# Django stuff:
*.log
local_settings.py
db.sqlite3
db.sqlite3-journal

# Flask stuff:
instance/
.webassets-cache

# Scrapy stuff:
.scrapy

# Sphinx documentation
docs/_build/

# PyBuilder
.pybuilder/
target/

# Jupyter Notebook
.ipynb_checkpoints

# IPython
profile_default/
ipython_config.py

# pyenv
# For a library or package, you might want to ignore these files since the code is
# intended to run in multiple environments; otherwise, check them in:
# .python-version

# pipenv
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
# However, in case of collaboration, if having platform-specific dependencies or dependencies
# having no cross-platform support, pipenv may install dependencies that don't work, or not
# install all needed dependencies.
#Pipfile.lock

# poetry
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
# This is especially recommended for binary packages to ensure reproducibility, and is more
# commonly ignored for libraries.
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
#poetry.lock

# pdm
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
#pdm.lock
# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
# in version control.
# https://pdm.fming.dev/#use-with-ide
.pdm.toml

# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
__pypackages__/

# Celery stuff
celerybeat-schedule
celerybeat.pid

# SageMath parsed files
*.sage.py

# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/

# Spyder project settings
.spyderproject
.spyproject

# Rope project settings
.ropeproject

# mkdocs documentation
/site

# mypy
.mypy_cache/
.dmypy.json
dmypy.json

# Pyre type checker
.pyre/

# pytype static type analyzer
.pytype/

# Cython debug symbols
cython_debug/

# PyCharm
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
# and can be added to the global gitignore or merged into this file. For a more nuclear
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
#.idea/
31 changes: 31 additions & 0 deletions orderbook-delta-visualizer/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Orderbook Delta Visualizer

A GUI visualizer written in Python using Dash and Plotly.

## Installation

### Install poetry (if you haven't already)
Follow the installation instructions on the [poetry website](https://python-poetry.org/docs/).

### Install all dependencies
```shell
poetry install
```
### Run the visualizer
```shell
poetry run python orderbook_delta_visualizer.py
```

This will start a dash server, which you can open in your browser.

## Usage

### To modify strategy
- The abstract base class `strategy.py/BaseStrategy` defines all strategies
- Create a new class inheriting from `BaseStrategy` abstract base class
- Create all required functions as defined in the base class
- Update the `strategy` attribute of `parameters.py/Parameters` dataclass to point to the new strategy

### To modify parameters
- All parameters are stored in `parameters.py/Parameters`
- All parameters can be updated live, the server will restart automatically
12 changes: 7 additions & 5 deletions orderbook-delta-visualizer/orderbook_delta_visualizer.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
import csv
import dash
import datetime
from collections import deque
from typing import Tuple

import dash
import plotly.express as px
import plotly.graph_objects as go
import plotly.io as pio
from collections import deque
from dash import dcc, html
from dash.dependencies import Output, Input
from ftx import FtxClient
from plotly.subplots import make_subplots
from typing import Tuple

from ftx_websocket_client import FtxWebsocketClient
from orderbook_delta_strategies import Position, Parameters, BaseStrategy
from parameters import Parameters
from src.ftx_websocket_client import FtxWebsocketClient
from strategy import Position, BaseStrategy


def get_bid_ask_and_delta(market: str) -> Tuple[float, float, float, float, float]:
Expand Down
29 changes: 29 additions & 0 deletions orderbook-delta-visualizer/parameters.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import datetime
import os
from dataclasses import dataclass
from typing import Union

from strategy import BaseStrategy, BollingerBandStrategy


@dataclass(frozen=True)
class Parameters:
""" Parameters to use when running visualizer """
# Name of spot market to track on FTX e.g. BTC/USD, ETH/USD
spot_market: str = "BTC/USD"
# Name of futures market to track on FTX e.g. BTC-PERP, ETH-PERP
perp_future: str = "BTC-PERP"
# Class of strategy to use
strategy: BaseStrategy = BollingerBandStrategy(bband_length=20, bband_std=3)
# Maximum number of data points visible on the screens
max_visible_length: int = 1000
# Template for graph theme e.g. plotly_dark, plotly, seaborn
template: str = "plotly_dark"
# Size of window in pixels
window_size: (int, int) = (1400, 850)
# Log live data to a csv file, use False to disable
logfile: Union[str, bool] = os.path.join(
"data",
f"{datetime.datetime.utcnow().strftime('%Y-%m-%d_%H-%M-%S')}_orderbook_delta_logger_"
f"{'_'.join(spot_market.split('/'))}_{'_'.join(perp_future.split('-'))}.csv"
)
2 changes: 1 addition & 1 deletion orderbook-delta-visualizer/pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[tool.poetry]
name = "orderbook-delta-visualizer"
version = "0.1.0"
description = "A GUI visualizer for orderbook-delta-bot"
description = "A GUI visualizer in Python for orderbook-delta-bot"
authors = ["dineshpinto <[email protected]>"]
license = "Apache-v2"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from itertools import zip_longest
from typing import DefaultDict, Deque, List, Dict, Tuple, Optional

from ftx_websocket_manager import WebsocketManager
from src.ftx_websocket_manager import WebsocketManager


class FtxWebsocketClient(WebsocketManager):
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
import datetime
from abc import ABC, abstractmethod
from enum import Enum

import pandas as pd
import pandas_ta as ta
import plotly.graph_objects as go
from abc import ABC, abstractmethod
from dataclasses import dataclass
from enum import Enum
from typing import Union


class Position(Enum):
Expand Down Expand Up @@ -95,23 +93,3 @@ def plot_strategy(self, timestamps: list, fig: go.Figure) -> go.Figure:
col=1
)
return fig


@dataclass(frozen=True)
class Parameters:
""" Parameters to use when running visualizer """
# Name of spot market to track on FTX e.g. BTC/USD, ETH/USD
spot_market: str = "BTC/USD"
# Name of futures market to track on FTX e.g. BTC-PERP, ETH-PERP
perp_future: str = "BTC-PERP"
# Class of strategy to use
strategy: BaseStrategy = BollingerBandStrategy(bband_length=20, bband_std=3)
# Maximum number of data points visible on the screens
max_visible_length: int = 1000
# Template for graph theme e.g. plotly_dark, plotly, seaborn
template: str = "plotly_dark"
# Size of window in pixels
window_size: (int, int) = (1400, 850)
# Log live data to a csv file, use False to disable
logfile: Union[str, bool] = f"{datetime.datetime.utcnow().strftime('%Y-%m-%d_%H-%M-%S')}_orderbook_delta_logger_" \
f"{'_'.join(spot_market.split('/'))}_{'_'.join(perp_future.split('-'))}.csv "

0 comments on commit 38ec326

Please sign in to comment.