This commit is contained in:
olli 2024-12-15 15:26:03 +01:00
parent 4328807975
commit 6b51e610ff
2 changed files with 22 additions and 12 deletions

View File

@ -24,7 +24,7 @@ function order {
# needed vars # needed vars
local f_symbol=$1 local f_symbol=$1
local f_amount=$2 # amount in $CURRENCY / if crypto_amount:XXX then amount in crypto local f_amount=$2 # amount in $CURRENCY / if asset_amount:XXX then amount in invested asset
local f_side=$3 # buy/sell long/short local f_side=$3 # buy/sell long/short
local f_price=$4 # price for limit order - if "0" do market order - "stoploss" for pure StopLoss Order and "takeprofit" for pure TakeProfit Order local f_price=$4 # price for limit order - if "0" do market order - "stoploss" for pure StopLoss Order and "takeprofit" for pure TakeProfit Order
local f_stoploss=$5 local f_stoploss=$5
@ -56,18 +56,22 @@ function order {
if [[ $f_price = 0 ]] if [[ $f_price = 0 ]]
then then
f_type="market" f_type="market"
#elif [[ $f_price = stoploss ]] || [[ $f_price = takeprofit ]] elif [[ $f_price = stoploss ]]
#then then
# f_price="None" f_type="stoploss"
f_price="None"
elif [[ $f_price = takeprofit ]]
then
f_type="takeprofit"
f_price="None"
else else
f_type="limit" f_type="limit"
fi fi
### validity checks end ### ### validity checks end ###
# check for swap/margin trades # check for swap/margin trades
if [ -n "$LEVERAGE" ] if [ -n "$LEVERAGE" ] && [[ $f_price != stoploss ]] && [[ $f_price != takeprofit ]]
then then
# do some margin things # do some margin things
@ -94,10 +98,10 @@ function order {
# get amount in crypto asset # get amount in crypto asset
if [[ $f_amount =~ ^crypto_amount: ]] if [[ $f_amount =~ ^asset_amount: ]]
then then
# if given in crypto # if given in crypto
f_amount=${f_amount//crypto_amount:} f_amount=${f_amount//asset_amount:}
else else
# on market order use current price # on market order use current price
if [[ $f_type = market ]] if [[ $f_type = market ]]
@ -140,7 +144,7 @@ function order {
then then
f_params="${f_params}'stopLoss': { 'triggerPrice': $f_stoploss, 'type': 'market' }, " f_params="${f_params}'stopLoss': { 'triggerPrice': $f_stoploss, 'type': 'market' }, "
# stoploss (change) for open position # stoploss (change) for open position
elif [[ $f_price = "stoploss" ]] elif [[ $f_type = "stoploss" ]]
then then
f_params="${f_params}'reduceOnly': True, 'triggerPrice': $f_stoploss, 'triggerDirection': 'down', 'type': 'market, '" f_params="${f_params}'reduceOnly': True, 'triggerPrice': $f_stoploss, 'triggerDirection': 'down', 'type': 'market, '"
fi fi
@ -165,7 +169,10 @@ function order {
f_ccxt "print($STOCK_EXCHANGE.priceToPrecision('${f_symbol}', ${f_takeprofit}))" f_ccxt "print($STOCK_EXCHANGE.priceToPrecision('${f_symbol}', ${f_takeprofit}))"
f_takeprofit=$f_ccxt_result f_takeprofit=$f_ccxt_result
[[ $f_type =~ limit|market ]] && f_params="${f_params}'takeProfit': { 'triggerPrice': $f_takeprofit, 'type': 'limit', 'price': $f_takeprofit, }, " [[ $f_type =~ limit|market ]] && f_params="${f_params}'takeProfit': { 'triggerPrice': $f_takeprofit, 'type': 'limit', 'price': $f_takeprofit, }, "
[[ $f_price = "takeprofit" ]] && f_params="${f_params}'stopPx': '$f_takeprofit', " if [[ $f_type = "takeprofit" ]]
then
f_params="${f_params}'reduceOnly': True, 'triggerPrice': $f_takeprofit, 'triggerDirection': 'up', 'type': 'limit, '"
fi
fi fi
# end up params syntax with "}" # end up params syntax with "}"
@ -181,9 +188,12 @@ function order {
fi fi
# do the order # do the order
# market order with or without stoploss/takeprofit
[[ $f_type = limit ]] && local f_order="symbol='${f_symbol}', type='$f_type', price=$f_price, amount=${f_amount}, side='${f_side}', ${f_params}" [[ $f_type = limit ]] && local f_order="symbol='${f_symbol}', type='$f_type', price=$f_price, amount=${f_amount}, side='${f_side}', ${f_params}"
[[ $f_type = market ]] && local f_order="symbol='${f_symbol}', type='$f_type', amount=${f_amount}, side='${f_side}', ${f_params}" [[ $f_type = market ]] && local f_order="symbol='${f_symbol}', type='$f_type', amount=${f_amount}, side='${f_side}', ${f_params}"
[[ $f_type = Stop ]] && local f_order="symbol='${f_symbol}', type='$f_type', amount='0', side='${f_side_opposide}', price='None', ${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}"
echo "$f_order" | notify.sh -s "ORDER" echo "$f_order" | notify.sh -s "ORDER"
f_ccxt "print($STOCK_EXCHANGE.createOrder(${f_order}))" || return 1 f_ccxt "print($STOCK_EXCHANGE.createOrder(${f_order}))" || return 1

View File

@ -44,7 +44,7 @@ do
# create new stoploss # create new stoploss
echo "==== New StopLoss for $asset at $stoploss_price" echo "==== New StopLoss for $asset at $stoploss_price"
order "$symbol" 0 long stoploss "$stoploss_price" order "$symbol" "${p[${asset}_asset_amount]}" long stoploss "$stoploss_price"
fi fi
fi fi