From 1614399ef7580bc42fb5c7aad8c775feb1f6a590 Mon Sep 17 00:00:00 2001 From: CollinLiu813 Date: Tue, 28 Jun 2022 13:54:20 +0200 Subject: [PATCH] Improved data saving for visualizer --- orderbook-delta-visualizer/README.md | 3 ++- orderbook-delta-visualizer/parameters.py | 16 ++++++++++++---- .../{ => src}/orderbook_delta_visualizer.py | 0 3 files changed, 14 insertions(+), 5 deletions(-) rename orderbook-delta-visualizer/{ => src}/orderbook_delta_visualizer.py (100%) diff --git a/orderbook-delta-visualizer/README.md b/orderbook-delta-visualizer/README.md index 5ba7ce1..a41e2da 100644 --- a/orderbook-delta-visualizer/README.md +++ b/orderbook-delta-visualizer/README.md @@ -28,4 +28,5 @@ This will start a dash server, which you can open in your browser. ### To modify parameters - All parameters are stored in `parameters.py/Parameters` -- All parameters can be updated live, the server will restart automatically \ No newline at end of file +- All parameters can be updated live, the server will restart automatically +- Running the visualizer generates saves a time series (`pandas.DataFrame`) of all observed data on exit \ No newline at end of file diff --git a/orderbook-delta-visualizer/parameters.py b/orderbook-delta-visualizer/parameters.py index 1c8be68..e577679 100644 --- a/orderbook-delta-visualizer/parameters.py +++ b/orderbook-delta-visualizer/parameters.py @@ -6,6 +6,13 @@ from strategy import BaseStrategy, BollingerBandStrategy +def get_formatted_filepath(folder: str, base_filename: str, spot_market: str, perp_future: str) -> str: + """ Example output filename: 2022-06-28_08-52-21_BTC-USD_BTC-PERP_orderbook_delta_logger.csv """ + filename = f"{datetime.datetime.utcnow().strftime('%Y-%m-%d_%H-%M-%S')}_{'-'.join(spot_market.split('/'))}_" \ + f"{'-'.join(perp_future.split('-'))}_{base_filename}.csv" + return os.path.join(folder, filename) + + @dataclass(frozen=True) class Parameters: """ Parameters to use when running visualizer """ @@ -22,8 +29,9 @@ class Parameters: # 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" + logfile: Union[str, bool] = get_formatted_filepath( + folder="data", + base_filename="orderbook_delta_logger", + spot_market=spot_market, + perp_future=perp_future ) diff --git a/orderbook-delta-visualizer/orderbook_delta_visualizer.py b/orderbook-delta-visualizer/src/orderbook_delta_visualizer.py similarity index 100% rename from orderbook-delta-visualizer/orderbook_delta_visualizer.py rename to orderbook-delta-visualizer/src/orderbook_delta_visualizer.py