Skip to content

Commit

Permalink
(feat) make config download
Browse files Browse the repository at this point in the history
  • Loading branch information
cardosofede committed Apr 1, 2024
1 parent 214a763 commit ea4e1d1
Showing 1 changed file with 24 additions and 2 deletions.
26 changes: 24 additions & 2 deletions pages/position_builder/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from plotly.subplots import make_subplots
import plotly.graph_objects as go
from decimal import Decimal
import yaml

from utils.st_utils import initialize_st_page
from hummingbot.smart_components.utils.distributions import Distributions
Expand All @@ -23,6 +24,14 @@ def normalize(values):
return [val / total for val in values]


def convert_to_yaml(spreads, order_amounts):
data = {
'dca_spreads': [float(spread)/100 for spread in spreads],
'dca_amounts': [float(amount) for amount in order_amounts]
}
return yaml.dump(data, default_flow_style=False)


with col_quote:
total_amount_quote = st.number_input("Total amount of quote", value=1000)

Expand Down Expand Up @@ -93,7 +102,19 @@ def get_distribution(dist_type, n_levels, start, base=None, scaling_factor=None,
spread_distribution = get_distribution(spread_dist_type, n_levels, spread_start, spread_base, spread_scaling, spread_step, spread_ratio, manual_spreads)
amount_distribution = normalize(get_distribution(amount_dist_type, n_levels, amount_start, amount_base, amount_scaling, amount_step, amount_ratio, manual_amounts))
order_amounts = [Decimal(amount_dist * total_amount_quote) for amount_dist in amount_distribution]
spreads = [spread - spread_distribution[0] for spread in spread_distribution]
spreads = [Decimal(spread - spread_distribution[0]) for spread in spread_distribution]


# Export Button
if st.button('Export as YAML'):
yaml_data = convert_to_yaml(spreads, order_amounts)
st.download_button(
label="Download YAML",
data=yaml_data,
file_name='config.yaml',
mime='text/yaml'
)

break_even_values = []
take_profit_values = []
for level in range(n_levels):
Expand All @@ -105,10 +126,11 @@ def get_distribution(dist_type, n_levels, start, base=None, scaling_factor=None,

accumulated_amount = [sum(order_amounts[:i+1]) for i in range(len(order_amounts))]


def calculate_unrealized_pnl(spreads, break_even_values, accumulated_amount):
unrealized_pnl = []
for i in range(len(spreads)):
distance = abs(spreads[i] - break_even_values[i])
distance = abs(spreads[i] - break_even_values[i])
pnl = accumulated_amount[i] * distance / 100 # PNL calculation
unrealized_pnl.append(pnl)
return unrealized_pnl
Expand Down

0 comments on commit ea4e1d1

Please sign in to comment.