fix, calculating amount and leverage

This commit is contained in:
olli 2024-10-21 21:08:12 +02:00
parent f69d75b1b7
commit c0a3e85888

View File

@ -54,17 +54,6 @@ function order {
### validity checks end### ### validity checks end###
# get amount in crypto asset
if [[ $f_amount =~ ^crypto_amount: ]]
then
# if given in crypto
f_amount=${f_amount//crypto_amount:}
else
# if given in $CURRENCY
local f_asset=${f_symbol///*}
currency_converter $f_amount $CURRENCY $f_asset || return 1
local f_amount=$f_currency_converter_result
fi
# check for swap/margin trades # check for swap/margin trades
if [ -n "$LEVERAGE" ] if [ -n "$LEVERAGE" ]
@ -83,11 +72,37 @@ function order {
# define margibn mode isolated/cross # define margibn mode isolated/cross
f_params="${f_params}'marginMode': '$MARGIN_MODE', " f_params="${f_params}'marginMode': '$MARGIN_MODE', "
# calculate amount with leverage
g_calc "${f_amount}*${LEVERAGE}"
f_amount=$g_calc_result
else else
# short/sell not possible in spot market # short/sell not possible in spot market
[[ $f_side =~ ^sell$ ]] || return 1 [[ $f_side =~ ^sell$ ]] || return 1
fi fi
# get amount in crypto asset
if [[ $f_amount =~ ^crypto_amount: ]]
then
# if given in crypto
f_amount=${f_amount//crypto_amount:}
else
# on market order use current price
if [[ $f_type = market ]]
then
# if given in $CURRENCY
local f_asset=${f_symbol///*}
currency_converter $f_amount $CURRENCY $f_asset || return 1
f_amount=$f_currency_converter_result
# on limit order use limit price
elif [[ $f_type = limit ]]
then
g_calc "1/${f_price}*${f_amount}"
f_amount=$g_calc_result
fi
fi
# Add stoploos and take profit if available # Add stoploos and take profit if available
if [ -n "$f_stoploss" ] if [ -n "$f_stoploss" ]
then then