mirror of
https://github.com/aljazceru/hummingbot-dashboard.git
synced 2026-01-04 05:54:25 +01:00
(feat) update dman_v2
This commit is contained in:
@@ -1,4 +1,3 @@
|
||||
from math import exp
|
||||
import streamlit as st
|
||||
from plotly.subplots import make_subplots
|
||||
import plotly.graph_objects as go
|
||||
@@ -8,73 +7,7 @@ import yaml
|
||||
from CONFIG import BACKEND_API_HOST, BACKEND_API_PORT
|
||||
from utils.backend_api_client import BackendAPIClient
|
||||
from utils.st_utils import initialize_st_page
|
||||
from hummingbot.smart_components.utils.distributions import Distributions
|
||||
|
||||
|
||||
def normalize(values):
|
||||
total = sum(values)
|
||||
return [Decimal(val / total) for val in values]
|
||||
|
||||
|
||||
def distribution_inputs(column, dist_type_name, levels=3):
|
||||
if dist_type_name == "Spread":
|
||||
dist_type = column.selectbox(
|
||||
f"Type of {dist_type_name} Distribution",
|
||||
("Manual", "GeoCustom", "Geometric", "Fibonacci", "Logarithmic", "Arithmetic"),
|
||||
key=f"{column}_{dist_type_name.lower()}_dist_type",
|
||||
# Set the default value
|
||||
)
|
||||
else:
|
||||
dist_type = column.selectbox(
|
||||
f"Type of {dist_type_name} Distribution",
|
||||
("Manual", "Geometric", "Fibonacci", "Logarithmic", "Arithmetic"),
|
||||
key=f"{column}_{dist_type_name.lower()}_dist_type",
|
||||
# Set the default value
|
||||
)
|
||||
base, scaling_factor, step, ratio, manual_values = None, None, None, None, None
|
||||
|
||||
if dist_type != "Manual":
|
||||
start = column.number_input(f"{dist_type_name} Start Value", value=1.0,
|
||||
key=f"{column}_{dist_type_name.lower()}_start")
|
||||
if dist_type == "Logarithmic":
|
||||
base = column.number_input(f"{dist_type_name} Log Base", value=exp(1),
|
||||
key=f"{column}_{dist_type_name.lower()}_base")
|
||||
scaling_factor = column.number_input(f"{dist_type_name} Scaling Factor", value=2.0,
|
||||
key=f"{column}_{dist_type_name.lower()}_scaling")
|
||||
elif dist_type == "Arithmetic":
|
||||
step = column.number_input(f"{dist_type_name} Step", value=0.1,
|
||||
key=f"{column}_{dist_type_name.lower()}_step")
|
||||
elif dist_type == "Geometric":
|
||||
ratio = column.number_input(f"{dist_type_name} Ratio", value=2.0,
|
||||
key=f"{column}_{dist_type_name.lower()}_ratio")
|
||||
elif dist_type == "GeoCustom":
|
||||
ratio = column.number_input(f"{dist_type_name} Ratio", value=2.0,
|
||||
key=f"{column}_{dist_type_name.lower()}_ratio")
|
||||
else:
|
||||
manual_values = [column.number_input(f"{dist_type_name} for level {i + 1}", value=i + 1.0,
|
||||
key=f"{column}_{dist_type_name.lower()}_{i}") for i in range(levels)]
|
||||
start = None # As start is not relevant for Manual type
|
||||
|
||||
return dist_type, start, base, scaling_factor, step, ratio, manual_values
|
||||
|
||||
|
||||
def get_distribution(dist_type, n_levels, start, base=None, scaling_factor=None, step=None, ratio=None,
|
||||
manual_values=None):
|
||||
if dist_type == "Manual":
|
||||
return manual_values
|
||||
elif dist_type == "Linear":
|
||||
return Distributions.linear(n_levels, start, start + ts_ap)
|
||||
elif dist_type == "Fibonacci":
|
||||
return Distributions.fibonacci(n_levels, start)
|
||||
elif dist_type == "Logarithmic":
|
||||
return Distributions.logarithmic(n_levels, base, scaling_factor, start)
|
||||
elif dist_type == "Arithmetic":
|
||||
return Distributions.arithmetic(n_levels, start, step)
|
||||
elif dist_type == "Geometric":
|
||||
return Distributions.geometric(n_levels, start, ratio)
|
||||
elif dist_type == "GeoCustom":
|
||||
return [Decimal("0")] + Distributions.geometric(n_levels - 1, start, ratio)
|
||||
|
||||
from utils.st_inputs import normalize, distribution_inputs, get_distribution
|
||||
|
||||
# Initialize the Streamlit page
|
||||
initialize_st_page(title="D-Man Maker V2", icon="🧙♂️", initial_sidebar_state="collapsed")
|
||||
@@ -142,9 +75,9 @@ sell_amount_distributions = normalize(
|
||||
sell_amount_step, sell_amount_ratio, sell_manual_amounts))
|
||||
|
||||
all_orders_amount_normalized = normalize(buy_amount_distributions + sell_amount_distributions)
|
||||
buy_order_amounts_quote = [Decimal(amount * total_amount_quote) for amount in
|
||||
buy_order_amounts_quote = [amount * total_amount_quote for amount in
|
||||
all_orders_amount_normalized[:buy_order_levels]]
|
||||
sell_order_amounts_quote = [Decimal(amount * total_amount_quote) for amount in
|
||||
sell_order_amounts_quote = [amount * total_amount_quote for amount in
|
||||
all_orders_amount_normalized[buy_order_levels:]]
|
||||
|
||||
# Initialize your figure with a dark theme
|
||||
@@ -417,7 +350,7 @@ st.write("---")
|
||||
st.plotly_chart(fig)
|
||||
c1, c2, c3 = st.columns([2, 2, 1])
|
||||
with c1:
|
||||
config_base = st.text_input("Config Base", value=f"{connector}-{trading_pair.split('-')[0]}")
|
||||
config_base = st.text_input("Config Base", value=f"dman_maker_v2-{connector}-{trading_pair.split('-')[0]}")
|
||||
with c2:
|
||||
config_tag = st.text_input("Config Tag", value="1.1")
|
||||
|
||||
@@ -431,8 +364,8 @@ config = {
|
||||
"connector_name": connector,
|
||||
"trading_pair": trading_pair,
|
||||
"total_amount_quote": total_amount_quote,
|
||||
"buy_spreads": [spread / 100 for spread in buy_spread_distributions],
|
||||
"sell_spreads": [spread / 100 for spread in sell_spread_distributions],
|
||||
"buy_spreads": [Decimal(spread / 100) for spread in buy_spread_distributions],
|
||||
"sell_spreads": [Decimal(spread / 100) for spread in sell_spread_distributions],
|
||||
"buy_amounts_pct": buy_order_amounts_quote,
|
||||
"sell_amounts_pct": sell_order_amounts_quote,
|
||||
"executor_refresh_time": executor_refresh_time * 60,
|
||||
|
||||
Reference in New Issue
Block a user