(feat) add directional components

This commit is contained in:
cardosofede
2024-05-20 17:58:49 -05:00
parent cce2078487
commit 9ee08c5c16
5 changed files with 82 additions and 2 deletions

View File

@@ -20,5 +20,5 @@ CERTIFIED_STRATEGIES = ["xemm", "cross exchange market making", "pmm", "pure mar
AUTH_SYSTEM_ENABLED = False
BACKEND_API_HOST = os.getenv("BACKEND_API_HOST", "localhost")
BACKEND_API_HOST = os.getenv("BACKEND_API_HOST", "127.0.0.1")
BACKEND_API_PORT = os.getenv("BACKEND_API_PORT", 8000)

View File

@@ -0,0 +1,34 @@
import streamlit as st
def get_directional_trading_general_inputs():
with st.expander("General Settings", expanded=True):
c1, c2, c3, c4, c5, c6, c7 = st.columns(7)
with c1:
connector_name = st.text_input("Connector", value="binance_perpetual",
help="Enter the name of the exchange to trade on (e.g., binance_perpetual).")
candles_connector_name = st.text_input("Candles Connector", value="binance_perpetual",
help="Enter the name of the exchange to get candles from (e.g., binance_perpetual).")
with c2:
trading_pair = st.text_input("Trading Pair", value="WLD-USDT",
help="Enter the trading pair to trade on (e.g., WLD-USDT).")
candles_trading_pair = st.text_input("Candles Trading Pair", value="WLD-USDT",
help="Enter the trading pair to get candles for (e.g., WLD-USDT).")
with c3:
leverage = st.number_input("Leverage", value=20,
help="Set the leverage to use for trading (e.g., 20 for 20x leverage). Set it to 1 for spot trading.")
interval = st.selectbox("Candles Interval", ("1m", "5m", "15m", "1h", "4h", "1d"), index=3,
help="Enter the interval for candles (e.g., 1m).")
with c4:
total_amount_quote = st.number_input("Total amount of quote", value=1000,
help="Enter the total amount in quote asset to use for trading (e.g., 1000).")
with c5:
max_executors_per_side = st.number_input("Max Executors Per Side", value=5,
help="Enter the maximum number of executors per side (e.g., 5).")
with c6:
cooldown_time = st.number_input("Cooldown Time (minutes)", value=60,
help="Specify the cooldown time in minutes (e.g., 60).") * 60
with c7:
position_mode = st.selectbox("Position Mode", ("HEDGE", "ONEWAY"), index=0,
help="Enter the position mode (HEDGE/ONEWAY).")
return connector_name, trading_pair, leverage, total_amount_quote, max_executors_per_side, cooldown_time, position_mode, candles_connector_name, candles_trading_pair, interval

View File

@@ -0,0 +1,21 @@
import pandas_ta as ta # noqa: F401
import plotly.graph_objects as go
from frontend.visualization import theme
def get_bbands_traces(candles, bb_length, bb_std):
tech_colors = theme.get_color_scheme()
candles.ta.bbands(length=bb_length, std=bb_std, append=True)
bb_lower = f'BBL_{bb_length}_{bb_std}'
bb_middle = f'BBM_{bb_length}_{bb_std}'
bb_upper = f'BBU_{bb_length}_{bb_std}'
traces = [
go.Scatter(x=candles.index, y=candles[bb_upper], line=dict(color=tech_colors['upper_band']),
name='Upper Band'),
go.Scatter(x=candles.index, y=candles[bb_middle], line=dict(color=tech_colors['middle_band']),
name='Middle Band'),
go.Scatter(x=candles.index, y=candles[bb_lower], line=dict(color=tech_colors['lower_band']),
name='Lower Band'),
]
return traces

View File

@@ -0,0 +1,22 @@
from frontend.visualization import theme
import plotly.graph_objects as go
import pandas_ta as ta # noqa: F401
def add_bbands_with_threshold(fig, candles, bb_length, bb_std, bb_long_threshold, bb_short_threshold, row=1, col=1):
tech_colors = theme.get_color_scheme()
# Add Bollinger Bands
candles.ta.bbands(length=bb_length, std=bb_std, append=True)
# Generate conditions
buy_signals = candles[candles[f"BBP_{bb_length}_{bb_std}"] < bb_long_threshold]
sell_signals = candles[candles[f"BBP_{bb_length}_{bb_std}"] > bb_short_threshold]
# Signals plot
fig.add_trace(go.Scatter(x=buy_signals.index, y=buy_signals['close'], mode='markers',
marker=dict(color=tech_colors['buy_signal'], size=10, symbol='triangle-up'),
name='Buy Signal'), row=row, col=col)
fig.add_trace(go.Scatter(x=sell_signals.index, y=sell_signals['close'], mode='markers',
marker=dict(color=tech_colors['sell_signal'], size=10, symbol='triangle-down'),
name='Sell Signal'), row=row, col=col)
return fig

View File

@@ -0,0 +1,3 @@
def add_traces_to_fig(fig, traces, row=1, col=1):
for trace in traces:
fig.add_trace(trace, row=row, col=col)