update fpr ccxt triggers, stoploss-change
This commit is contained in:
parent
0a6d7264cb
commit
694184a25f
@ -26,12 +26,11 @@ function order {
|
|||||||
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 crypto_amount:XXX then amount in crypto
|
||||||
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
|
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
|
||||||
local f_takeprofit=$6
|
local f_takeprofit=$6
|
||||||
local f_params="params={"
|
local f_params="params={"
|
||||||
local f_type
|
local f_type f_side_opposite
|
||||||
|
|
||||||
|
|
||||||
### validity checks ###
|
### validity checks ###
|
||||||
|
|
||||||
@ -39,14 +38,27 @@ function order {
|
|||||||
[[ $f_symbol =~ /$CURRENCY ]] || return 1
|
[[ $f_symbol =~ /$CURRENCY ]] || return 1
|
||||||
|
|
||||||
# check side
|
# check side
|
||||||
[ "$f_side" = "long" ] && f_side="buy"
|
if [ "$f_side" = "long" ] || [ "$f_side" = "buy" ]
|
||||||
[ "$f_side" = "short" ] && f_side="sell"
|
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 =~ ^buy$|^sell$ ]] || return 1
|
[[ $f_side =~ ^buy$|^sell$ ]] || return 1
|
||||||
|
|
||||||
# check order type limit/market
|
# check order type limit/market
|
||||||
if [[ "$f_price" = "0" ]]
|
if [[ $f_price = 0 ]]
|
||||||
then
|
then
|
||||||
f_type="market"
|
f_type="market"
|
||||||
|
#elif [[ $f_price = stoploss ]] || [[ $f_price = takeprofit ]]
|
||||||
|
#then
|
||||||
|
# f_price="None"
|
||||||
else
|
else
|
||||||
f_type="limit"
|
f_type="limit"
|
||||||
fi
|
fi
|
||||||
@ -68,7 +80,8 @@ function order {
|
|||||||
# set leverage
|
# set leverage
|
||||||
f_ccxt "$STOCK_EXCHANGE.setLeverage($LEVERAGE, '$f_symbol')" || return 1
|
f_ccxt "$STOCK_EXCHANGE.setLeverage($LEVERAGE, '$f_symbol')" || return 1
|
||||||
|
|
||||||
# define margibn mode isolated/cross
|
# define margin mode isolated/cross
|
||||||
|
#[[ $f_type =~ limit|market ]] &&
|
||||||
f_params="${f_params}'marginMode': '$MARGIN_MODE', "
|
f_params="${f_params}'marginMode': '$MARGIN_MODE', "
|
||||||
|
|
||||||
# calculate amount with leverage
|
# calculate amount with leverage
|
||||||
@ -102,7 +115,7 @@ function order {
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
||||||
# Add stoploos and take profit if available
|
# Add stoploss and take profit if available
|
||||||
if [ -n "$f_stoploss" ]
|
if [ -n "$f_stoploss" ]
|
||||||
then
|
then
|
||||||
if [[ $f_type = limit ]]
|
if [[ $f_type = limit ]]
|
||||||
@ -122,7 +135,15 @@ function order {
|
|||||||
fi
|
fi
|
||||||
f_ccxt "print($STOCK_EXCHANGE.priceToPrecision('${f_symbol}', ${f_stoploss}))"
|
f_ccxt "print($STOCK_EXCHANGE.priceToPrecision('${f_symbol}', ${f_stoploss}))"
|
||||||
f_stoploss=$f_ccxt_result
|
f_stoploss=$f_ccxt_result
|
||||||
f_params="${f_params}'stopLossPrice': '$f_stoploss', "
|
# 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
|
||||||
fi
|
fi
|
||||||
if [ -n "$f_takeprofit" ]
|
if [ -n "$f_takeprofit" ]
|
||||||
then
|
then
|
||||||
@ -143,7 +164,8 @@ function order {
|
|||||||
fi
|
fi
|
||||||
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_params="${f_params}'takeProfitPrice': '$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', "
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# end up params syntax with "}"
|
# end up params syntax with "}"
|
||||||
@ -161,6 +183,7 @@ function order {
|
|||||||
# do the 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 = 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}"
|
||||||
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
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user