From 681b75055deed8f1c9b00df007f0ee203319d353 Mon Sep 17 00:00:00 2001 From: cardosofede Date: Tue, 23 Jul 2024 15:02:00 +0300 Subject: [PATCH] (feat) update mm controllers --- pages/config/dman_maker_v2/app.py | 11 ++--- pages/config/dman_maker_v2/user_inputs.py | 6 ++- pages/config/pmm_dynamic/app.py | 41 +++++++++++-------- .../spread_and_price_multipliers.py | 2 +- pages/config/pmm_dynamic/user_inputs.py | 3 +- pages/config/pmm_simple/app.py | 14 +++---- pages/config/pmm_simple/user_inputs.py | 8 ++-- 7 files changed, 46 insertions(+), 39 deletions(-) diff --git a/pages/config/dman_maker_v2/app.py b/pages/config/dman_maker_v2/app.py index 830fe99..0649f9c 100644 --- a/pages/config/dman_maker_v2/app.py +++ b/pages/config/dman_maker_v2/app.py @@ -1,16 +1,13 @@ import streamlit as st -from CONFIG import BACKEND_API_HOST, BACKEND_API_PORT -from backend.services.backend_api_client import BackendAPIClient from frontend.components.backtesting import backtesting_section from frontend.components.config_loader import get_default_config_loader from frontend.components.dca_distribution import get_dca_distribution_inputs from frontend.components.save_config import render_save_config from frontend.pages.config.dman_maker_v2.user_inputs import user_inputs -from frontend.st_utils import initialize_st_page, get_backend_api_client +from frontend.st_utils import get_backend_api_client, initialize_st_page from frontend.visualization.backtesting import create_backtesting_figure -from frontend.visualization.backtesting_metrics import render_backtesting_metrics, render_accuracy_metrics, \ - render_close_types +from frontend.visualization.backtesting_metrics import render_accuracy_metrics, render_backtesting_metrics, render_close_types from frontend.visualization.dca_builder import create_dca_graph from frontend.visualization.executors_distribution import create_executors_distribution_traces @@ -18,14 +15,14 @@ from frontend.visualization.executors_distribution import create_executors_distr initialize_st_page(title="D-Man Maker V2", icon="🧙‍♂️") backend_api_client = get_backend_api_client() - # Page content st.text("This tool will let you create a config for D-Man Maker V2 and upload it to the BackendAPI.") get_default_config_loader("dman_maker_v2") inputs = user_inputs() with st.expander("Executor Distribution:", expanded=True): - fig = create_executors_distribution_traces(inputs["buy_spreads"], inputs["sell_spreads"], inputs["buy_amounts_pct"], inputs["sell_amounts_pct"], inputs["total_amount_quote"]) + fig = create_executors_distribution_traces(inputs["buy_spreads"], inputs["sell_spreads"], inputs["buy_amounts_pct"], + inputs["sell_amounts_pct"], inputs["total_amount_quote"]) st.plotly_chart(fig, use_container_width=True) dca_inputs = get_dca_distribution_inputs() diff --git a/pages/config/dman_maker_v2/user_inputs.py b/pages/config/dman_maker_v2/user_inputs.py index 5ccf4d9..8f207f3 100644 --- a/pages/config/dman_maker_v2/user_inputs.py +++ b/pages/config/dman_maker_v2/user_inputs.py @@ -5,8 +5,10 @@ from frontend.components.market_making_general_inputs import get_market_making_g def user_inputs(): - connector_name, trading_pair, leverage, total_amount_quote, position_mode, cooldown_time, executor_refresh_time, _, _, _ = get_market_making_general_inputs() - buy_spread_distributions, sell_spread_distributions, buy_order_amounts_pct, sell_order_amounts_pct = get_executors_distribution_inputs() + connector_name, trading_pair, leverage, total_amount_quote, position_mode, cooldown_time,\ + executor_refresh_time, _, _, _ = get_market_making_general_inputs() + buy_spread_distributions, sell_spread_distributions, buy_order_amounts_pct, \ + sell_order_amounts_pct = get_executors_distribution_inputs() with st.expander("Custom D-Man Maker V2 Settings"): c1, c2 = st.columns(2) with c1: diff --git a/pages/config/pmm_dynamic/app.py b/pages/config/pmm_dynamic/app.py index f154444..3c7eb52 100644 --- a/pages/config/pmm_dynamic/app.py +++ b/pages/config/pmm_dynamic/app.py @@ -1,23 +1,21 @@ -import streamlit as st import plotly.graph_objects as go +import streamlit as st from plotly.subplots import make_subplots -from frontend.components.config_loader import get_default_config_loader -from frontend.components.executors_distribution import get_executors_distribution_inputs -from frontend.components.save_config import render_save_config - # Import submodules from frontend.components.backtesting import backtesting_section +from frontend.components.config_loader import get_default_config_loader +from frontend.components.executors_distribution import get_executors_distribution_inputs +from frontend.components.save_config import render_save_config from frontend.pages.config.pmm_dynamic.spread_and_price_multipliers import get_pmm_dynamic_multipliers from frontend.pages.config.pmm_dynamic.user_inputs import user_inputs from frontend.pages.config.utils import get_candles -from frontend.st_utils import initialize_st_page, get_backend_api_client +from frontend.st_utils import get_backend_api_client, initialize_st_page from frontend.visualization import theme from frontend.visualization.backtesting import create_backtesting_figure +from frontend.visualization.backtesting_metrics import render_accuracy_metrics, render_backtesting_metrics, render_close_types from frontend.visualization.candles import get_candlestick_trace from frontend.visualization.executors_distribution import create_executors_distribution_traces -from frontend.visualization.backtesting_metrics import render_backtesting_metrics, render_close_types, \ - render_accuracy_metrics from frontend.visualization.indicators import get_macd_traces from frontend.visualization.utils import add_traces_to_fig @@ -35,16 +33,25 @@ st.text("The MACD is used to shift the mid price and the NATR to make the spread "In the order distributions graph, we are going to see the values of the orders affected by the average NATR") days_to_visualize = st.number_input("Days to Visualize", min_value=1, max_value=365, value=7) # Load candle data -candles = get_candles(connector_name=inputs["candles_connector"], trading_pair=inputs["candles_trading_pair"], interval=inputs["interval"], days=days_to_visualize) +candles = get_candles(connector_name=inputs["candles_connector"], trading_pair=inputs["candles_trading_pair"], + interval=inputs["interval"], days=days_to_visualize) with st.expander("Visualizing PMM Dynamic Indicators", expanded=True): fig = make_subplots(rows=4, cols=1, shared_xaxes=True, - vertical_spacing=0.02, subplot_titles=('Candlestick with Bollinger Bands', 'MACD', "Price Multiplier", "Spreads Multiplier"), + vertical_spacing=0.02, subplot_titles=("Candlestick with Bollinger Bands", "MACD", + "Price Multiplier", "Spreads Multiplier"), row_heights=[0.8, 0.2, 0.2, 0.2]) add_traces_to_fig(fig, [get_candlestick_trace(candles)], row=1, col=1) - add_traces_to_fig(fig, get_macd_traces(df=candles, macd_fast=inputs["macd_fast"], macd_slow=inputs["macd_slow"], macd_signal=inputs["macd_signal"]), row=2, col=1) - price_multiplier, spreads_multiplier = get_pmm_dynamic_multipliers(candles, inputs["macd_fast"], inputs["macd_slow"], inputs["macd_signal"], inputs["natr_length"]) - add_traces_to_fig(fig, [go.Scatter(x=candles.index, y=price_multiplier, name="Price Multiplier", line=dict(color="blue"))], row=3, col=1) - add_traces_to_fig(fig, [go.Scatter(x=candles.index, y=spreads_multiplier, name="Base Spread", line=dict(color="red"))], row=4, col=1) + add_traces_to_fig(fig, get_macd_traces(df=candles, macd_fast=inputs["macd_fast"], macd_slow=inputs["macd_slow"], + macd_signal=inputs["macd_signal"]), row=2, col=1) + price_multiplier, spreads_multiplier = get_pmm_dynamic_multipliers(candles, inputs["macd_fast"], + inputs["macd_slow"], inputs["macd_signal"], + inputs["natr_length"]) + add_traces_to_fig(fig, [ + go.Scatter(x=candles.index, y=price_multiplier, name="Price Multiplier", line=dict(color="blue"))], row=3, + col=1) + add_traces_to_fig(fig, + [go.Scatter(x=candles.index, y=spreads_multiplier, name="Base Spread", line=dict(color="red"))], + row=4, col=1) fig.update_layout(**theme.get_default_layout(height=1000)) fig.update_yaxes(tickformat=".2%", row=3, col=1) fig.update_yaxes(tickformat=".2%", row=4, col=1) @@ -53,7 +60,8 @@ with st.expander("Visualizing PMM Dynamic Indicators", expanded=True): st.write("### Executors Distribution") st.write("The order distributions are affected by the average NATR. This means that if the first order has a spread of " "1 and the NATR is 0.005, the first order will have a spread of 0.5% of the mid price.") -buy_spread_distributions, sell_spread_distributions, buy_order_amounts_pct, sell_order_amounts_pct = get_executors_distribution_inputs(use_custom_spread_units=True) +buy_spread_distributions, sell_spread_distributions, buy_order_amounts_pct, \ + sell_order_amounts_pct = get_executors_distribution_inputs(use_custom_spread_units=True) inputs["buy_spreads"] = [spread * 100 for spread in buy_spread_distributions] inputs["sell_spreads"] = [spread * 100 for spread in sell_spread_distributions] inputs["buy_amounts_pct"] = buy_order_amounts_pct @@ -64,7 +72,8 @@ with st.expander("Executor Distribution:", expanded=True): buy_spreads = [spread * natr_avarage for spread in inputs["buy_spreads"]] sell_spreads = [spread * natr_avarage for spread in inputs["sell_spreads"]] st.write(f"Average NATR: {natr_avarage:.2%}") - fig = create_executors_distribution_traces(buy_spreads, sell_spreads, inputs["buy_amounts_pct"], inputs["sell_amounts_pct"], inputs["total_amount_quote"]) + fig = create_executors_distribution_traces(buy_spreads, sell_spreads, inputs["buy_amounts_pct"], + inputs["sell_amounts_pct"], inputs["total_amount_quote"]) st.plotly_chart(fig, use_container_width=True) bt_results = backtesting_section(inputs, backend_api_client) diff --git a/pages/config/pmm_dynamic/spread_and_price_multipliers.py b/pages/config/pmm_dynamic/spread_and_price_multipliers.py index dfb85f2..efd99c5 100644 --- a/pages/config/pmm_dynamic/spread_and_price_multipliers.py +++ b/pages/config/pmm_dynamic/spread_and_price_multipliers.py @@ -1,4 +1,4 @@ -import pandas_ta as ta # noqa: F401 +import pandas_ta as ta # noqa: F401 def get_pmm_dynamic_multipliers(df, macd_fast, macd_slow, macd_signal, natr_length): diff --git a/pages/config/pmm_dynamic/user_inputs.py b/pages/config/pmm_dynamic/user_inputs.py index 21e7736..1487e42 100644 --- a/pages/config/pmm_dynamic/user_inputs.py +++ b/pages/config/pmm_dynamic/user_inputs.py @@ -10,7 +10,8 @@ def user_inputs(): macd_slow = default_config.get("macd_slow", 42) macd_signal = default_config.get("macd_signal", 9) natr_length = default_config.get("natr_length", 14) - connector_name, trading_pair, leverage, total_amount_quote, position_mode, cooldown_time, executor_refresh_time, candles_connector, candles_trading_pair, interval = get_market_making_general_inputs(custom_candles=True) + connector_name, trading_pair, leverage, total_amount_quote, position_mode, cooldown_time, executor_refresh_time, \ + candles_connector, candles_trading_pair, interval = get_market_making_general_inputs(custom_candles=True) sl, tp, time_limit, ts_ap, ts_delta, take_profit_order_type = get_risk_management_inputs() with st.expander("PMM Dynamic Configuration", expanded=True): c1, c2, c3, c4 = st.columns(4) diff --git a/pages/config/pmm_simple/app.py b/pages/config/pmm_simple/app.py index 445c362..e6f2598 100644 --- a/pages/config/pmm_simple/app.py +++ b/pages/config/pmm_simple/app.py @@ -1,23 +1,20 @@ import streamlit as st -from backend.services.backend_api_client import BackendAPIClient -from CONFIG import BACKEND_API_HOST, BACKEND_API_PORT + +from frontend.components.backtesting import backtesting_section from frontend.components.config_loader import get_default_config_loader from frontend.components.save_config import render_save_config # Import submodules from frontend.pages.config.pmm_simple.user_inputs import user_inputs -from frontend.components.backtesting import backtesting_section -from frontend.st_utils import initialize_st_page, get_backend_api_client +from frontend.st_utils import get_backend_api_client, initialize_st_page from frontend.visualization.backtesting import create_backtesting_figure +from frontend.visualization.backtesting_metrics import render_accuracy_metrics, render_backtesting_metrics, render_close_types from frontend.visualization.executors_distribution import create_executors_distribution_traces -from frontend.visualization.backtesting_metrics import render_backtesting_metrics, render_close_types, \ - render_accuracy_metrics # Initialize the Streamlit page initialize_st_page(title="PMM Simple", icon="👨‍🏫") backend_api_client = get_backend_api_client() - # Page content st.text("This tool will let you create a config for PMM Simple, backtest and upload it to the Backend API.") get_default_config_loader("pmm_simple") @@ -26,7 +23,8 @@ inputs = user_inputs() st.session_state["default_config"].update(inputs) with st.expander("Executor Distribution:", expanded=True): - fig = create_executors_distribution_traces(inputs["buy_spreads"], inputs["sell_spreads"], inputs["buy_amounts_pct"], inputs["sell_amounts_pct"], inputs["total_amount_quote"]) + fig = create_executors_distribution_traces(inputs["buy_spreads"], inputs["sell_spreads"], inputs["buy_amounts_pct"], + inputs["sell_amounts_pct"], inputs["total_amount_quote"]) st.plotly_chart(fig, use_container_width=True) bt_results = backtesting_section(inputs, backend_api_client) diff --git a/pages/config/pmm_simple/user_inputs.py b/pages/config/pmm_simple/user_inputs.py index b160481..6c4f62d 100644 --- a/pages/config/pmm_simple/user_inputs.py +++ b/pages/config/pmm_simple/user_inputs.py @@ -1,13 +1,13 @@ -import streamlit as st - from frontend.components.executors_distribution import get_executors_distribution_inputs from frontend.components.market_making_general_inputs import get_market_making_general_inputs from frontend.components.risk_management import get_risk_management_inputs def user_inputs(): - connector_name, trading_pair, leverage, total_amount_quote, position_mode, cooldown_time, executor_refresh_time, _, _, _ = get_market_making_general_inputs() - buy_spread_distributions, sell_spread_distributions, buy_order_amounts_pct, sell_order_amounts_pct = get_executors_distribution_inputs() + connector_name, trading_pair, leverage, total_amount_quote, position_mode, cooldown_time, \ + executor_refresh_time, _, _, _ = get_market_making_general_inputs() + buy_spread_distributions, sell_spread_distributions, buy_order_amounts_pct, \ + sell_order_amounts_pct = get_executors_distribution_inputs() sl, tp, time_limit, ts_ap, ts_delta, take_profit_order_type = get_risk_management_inputs() # Create the config config = {