fixes tp/sl

This commit is contained in:
olli 2024-12-16 17:38:39 +01:00
parent 21125e84e5
commit 76f556b1ad

View File

@ -94,7 +94,7 @@ function order {
# check for swap/margin trades
if [ -n "$LEVERAGE" ] && [[ $f_price != stoploss ]] && [[ $f_price != takeprofit ]]
if [ -n "$LEVERAGE" ]
then
# do some margin things
@ -112,8 +112,11 @@ function order {
f_params="${f_params}'marginMode': '$MARGIN_MODE', "
# calculate amount with leverage
g_calc "${f_amount}*${LEVERAGE}"
f_amount=$g_calc_result
if [[ $f_price != stoploss ]] && [[ $f_price != takeprofit ]]
then
g_calc "${f_amount}*${LEVERAGE}"
f_amount=$g_calc_result
fi
else
# short/sell not possible in spot market
[[ $f_side =~ ^sell$ ]] || return 1
@ -148,7 +151,8 @@ function order {
elif [[ $f_type = "stoploss" ]]
then
f_type="market"
f_params="${f_params}'reduceOnly': True, 'triggerPrice': $f_stoploss, 'triggerDirection': 'down', 'type': '$f_type'"
f_price=$f_stoploss
f_params="${f_params}'reduceOnly': True, 'triggerPrice': $f_stoploss, 'triggerDirection': 'down'"
fi
fi
if [ -n "$f_takeprofit" ]
@ -174,7 +178,8 @@ function order {
if [[ $f_type = "takeprofit" ]]
then
f_type="limit"
f_params="${f_params}'reduceOnly': True, 'triggerPrice': $f_takeprofit, 'triggerDirection': 'up', 'type': '$f_type'"
f_price=$f_takeprofit
f_params="${f_params}'reduceOnly': True, 'triggerPrice': $f_takeprofit, 'triggerDirection': 'up'"
fi
fi
@ -196,7 +201,7 @@ function order {
[[ $f_type = market ]] && local f_order="symbol='${f_symbol}', type='$f_type', amount=${f_amount}, side='${f_side}', ${f_params}"
# takeprofit/stoploss only
[[ $f_price = None ]] && local f_order="symbol='${f_symbol}', type='$f_type', amount=${f_amount}, side='${f_side_opposide}', price='None', ${f_params}"
[[ $f_params =~ reduceOnly ]] && local f_order="symbol='${f_symbol}', type='$f_type', amount=${f_amount}, side='${f_side_opposide}', price=$f_price, ${f_params}"
echo "$f_order" | notify.sh -s "ORDER"
f_ccxt "print($STOCK_EXCHANGE.createOrder(${f_order}))" || return 1