Compare commits

..

No commits in common. "b79313d1e426389a01ad367c44e950c0360b91f8" and "f66f1934a137f4cbfc749612a4d63aa35e5dca50" have entirely different histories.

3 changed files with 37 additions and 120 deletions

View File

@ -26,11 +26,12 @@ function order {
local f_symbol=$1
local f_amount=$2 # amount in $CURRENCY / if crypto_amount:XXX then amount in crypto
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
local f_stoploss=$5
local f_takeprofit=$6
local f_params="params={"
local f_type f_side_opposite
local f_type
### validity checks ###
@ -38,27 +39,14 @@ function order {
[[ $f_symbol =~ /$CURRENCY ]] || return 1
# check side
if [ "$f_side" = "long" ] || [ "$f_side" = "buy" ]
then
f_side="buy"
f_pos_side="Long"
f_side_opposide="sell"
fi
if [ "$f_side" = "short" ] || [ "$f_side" = "sell" ]
then
f_side="sell"
f_pos_side="Short"
f_side_opposide="buy"
fi
[ "$f_side" = "long" ] && f_side="buy"
[ "$f_side" = "short" ] && f_side="sell"
[[ $f_side =~ ^buy$|^sell$ ]] || return 1
# check order type limit/market
if [[ $f_price = 0 ]]
if [[ "$f_price" = "0" ]]
then
f_type="market"
#elif [[ $f_price = stoploss ]] || [[ $f_price = takeprofit ]]
#then
# f_price="None"
else
f_type="limit"
fi
@ -80,8 +68,7 @@ function order {
# set leverage
f_ccxt "$STOCK_EXCHANGE.setLeverage($LEVERAGE, '$f_symbol')" || return 1
# define margin mode isolated/cross
#[[ $f_type =~ limit|market ]] &&
# define margibn mode isolated/cross
f_params="${f_params}'marginMode': '$MARGIN_MODE', "
# calculate amount with leverage
@ -115,7 +102,7 @@ function order {
fi
# Add stoploss and take profit if available
# Add stoploos and take profit if available
if [ -n "$f_stoploss" ]
then
if [[ $f_type = limit ]]
@ -135,15 +122,7 @@ function order {
fi
f_ccxt "print($STOCK_EXCHANGE.priceToPrecision('${f_symbol}', ${f_stoploss}))"
f_stoploss=$f_ccxt_result
# market or limit order with stoploss
if [[ $f_type =~ limit|market ]]
then
f_params="${f_params}'stopLoss': { 'triggerPrice': $f_stoploss, 'type': 'market' }, "
# stoploss (change) for open position
elif [[ $f_price = "stoploss" ]]
then
f_params="${f_params}'reduceOnly': True, 'triggerPrice': $f_stoploss, 'triggerDirection': 'down', 'type': 'market, '"
fi
f_params="${f_params}'stopLossPrice': '$f_stoploss', "
fi
if [ -n "$f_takeprofit" ]
then
@ -164,8 +143,7 @@ function order {
fi
f_ccxt "print($STOCK_EXCHANGE.priceToPrecision('${f_symbol}', ${f_takeprofit}))"
f_takeprofit=$f_ccxt_result
[[ $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', "
f_params="${f_params}'takeProfitPrice': '$f_takeprofit', "
fi
# end up params syntax with "}"
@ -183,7 +161,6 @@ function order {
# do the order
[[ $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 = Stop ]] && local f_order="symbol='${f_symbol}', type='$f_type', amount='0', side='${f_side_opposide}', price='None', ${f_params}"
echo "$f_order" | notify.sh -s "ORDER"
f_ccxt "print($STOCK_EXCHANGE.createOrder(${f_order}))" || return 1

View File

@ -41,55 +41,17 @@ function order_cancel {
g_echo_note "No orders for $f_symbol/$f_asset found"
return 0
fi
# for f_order in "${f_get_orders_array[@]}"
# do
# get_order_line_vars "$f_order"
# if [[ $f_symbol = $f_order_symbol ]]
# then
# f_ccxt "print(${STOCK_EXCHANGE}.cancelAllOrders('$f_symbol'))"
# get_orders "$f_symbol"
# get_orders_array
# fi
# done
}
function order_cancel_all {
# Info for log
g_echo_note "RUNNING FUNCTION ${FUNCNAME} $@"
local f_order
get_symbols_ticker
get_orders_array
for f_order in "${f_get_orders_array[@]}"
do
get_order_line_vars "$f_order"
if [[ $f_symbol = $f_order_symbol ]]
then
f_ccxt "print(${STOCK_EXCHANGE}.cancelAllOrders('$f_symbol'))"
get_orders "$f_symbol"
get_orders_array
fi
done
}
function order_cancel_id {
# Info for log
g_echo_note "RUNNING FUNCTION ${FUNCNAME} $@"
local f_symbol=$1
local f_id=$2
local f_order
get_symbols_ticker
get_orders "$f_symbol"
get_orders_array
local f_asset=${f_symbol//:$CURRENCY/}
f_asset=${f_asset//\//}
if grep -q "$f_asset.*$f_id" values-orders
then
f_ccxt "print(${STOCK_EXCHANGE}.cancelOrder(id='${f_id}', symbol='${f_symbol}'))"
get_orders "$f_symbol"
get_orders_array
else
g_echo_note "No orders for $f_symbol/$f_asset with id $f_id found"
return 1
fi
}

View File

@ -13,40 +13,18 @@ get_position_array
# go through trading symbols
for symbol in ${f_symbols_array_trade[@]}
do
asset=${symbol//:$CURRENCY/}
asset=${asset//\//}
# adjust stoploss from percentage profit
from_profit=1
if [ -n "$LEVERAGE" ]
then
g_calc "${from_profit}*${LEVERAGE}"
from_profit=$g_calc_result
fi
# save profit by switching stoploss in profit
if [ -n "${p[${asset}_pnl]}" ] && [[ ${p[${asset}_side]} = long ]]
then
if g_num_is_higher ${p[${asset}_pnl_percentage]} $from_profit
then
# calculate stoploss price with half of current pnl
g_calc "${p[${asset}_current_price]}-((${p[${asset}_current_price]}-${p[${asset}_entry_price]})/2)"
stoploss_price=$g_calc_result
# check for already existing stoploss
if [ -n "${o[${asset}_sl_close_long_id]}" ]
then
# do nothing if current stoploss price is already larger/equal then half of current pnl
g_num_is_higher_equal ${o[${asset}_sl_close_long_stopprice]} $stoploss_price && continue
# cancel existing stoploss order
order_cancel_id "$symbol" "${o[${asset}_sl_close_long_id]}" || continue
fi
# create new stoploss
echo "==== New StopLoss for $asset at $stoploss_price"
order "$symbol" 0 long stoploss "$stoploss_price"
fi
fi
echo "==== XXXXX $symbol"
done
##### WARNING! This strategy is only intended as an example and should not be used with real trades. Please develop your own strategy ######
# if you want to use ist remove the next line with return 0
#return 0
# create stoploss order
#print(exchange.createOrder(symbol='XRP/USDT:USDT', type='Stop', side='sell', amount='0', price='None', params={'posSide': 'Long', 'stopPx':0.5}))
#print(exchange.createOrder(symbol='XRP/USDT:USDT', type='Stop', amount='0', side='sell', price='None', params={'posSide': 'Long', 'stopPx': 0.5}))
# edit stoploss
#print(exchange.editOrder(id='debc0df8-10c7-4cfd-95f7-b4de9cc60332', symbol='XRP/USDT:USDT', type='Stop', side='sell', amount='101', params={'stopLossPrice': 0.48}))