diff --git a/dabo/functions/order.sh b/dabo/functions/order.sh index da4f19f..bfcce34 100644 --- a/dabo/functions/order.sh +++ b/dabo/functions/order.sh @@ -54,20 +54,9 @@ function order { ### 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 - if [ -n "$LEVERAGE" ] + if [ -n "$LEVERAGE" ] then # do some margin things @@ -83,11 +72,37 @@ function order { # define margibn mode isolated/cross f_params="${f_params}'marginMode': '$MARGIN_MODE', " + # calculate amount with leverage + g_calc "${f_amount}*${LEVERAGE}" + f_amount=$g_calc_result else # short/sell not possible in spot market [[ $f_side =~ ^sell$ ]] || return 1 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 if [ -n "$f_stoploss" ] then