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_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
|
||||
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_takeprofit=$6
|
||||
local f_params="params={"
|
||||
local f_type
|
||||
|
||||
local f_type f_side_opposite
|
||||
|
||||
### validity checks ###
|
||||
|
||||
@ -39,19 +38,32 @@ function order {
|
||||
[[ $f_symbol =~ /$CURRENCY ]] || return 1
|
||||
|
||||
# check side
|
||||
[ "$f_side" = "long" ] && f_side="buy"
|
||||
[ "$f_side" = "short" ] && f_side="sell"
|
||||
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 =~ ^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
|
||||
|
||||
### validity checks end###
|
||||
### validity checks end ###
|
||||
|
||||
|
||||
# check for swap/margin trades
|
||||
@ -68,7 +80,8 @@ function order {
|
||||
# set leverage
|
||||
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', "
|
||||
|
||||
# calculate amount with leverage
|
||||
@ -102,7 +115,7 @@ function order {
|
||||
fi
|
||||
|
||||
|
||||
# Add stoploos and take profit if available
|
||||
# Add stoploss and take profit if available
|
||||
if [ -n "$f_stoploss" ]
|
||||
then
|
||||
if [[ $f_type = limit ]]
|
||||
@ -122,7 +135,15 @@ function order {
|
||||
fi
|
||||
f_ccxt "print($STOCK_EXCHANGE.priceToPrecision('${f_symbol}', ${f_stoploss}))"
|
||||
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
|
||||
if [ -n "$f_takeprofit" ]
|
||||
then
|
||||
@ -143,7 +164,8 @@ function order {
|
||||
fi
|
||||
f_ccxt "print($STOCK_EXCHANGE.priceToPrecision('${f_symbol}', ${f_takeprofit}))"
|
||||
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
|
||||
|
||||
# end up params syntax with "}"
|
||||
@ -161,6 +183,7 @@ 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
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user