place orders
This commit is contained in:
parent
c7c8ea9b7f
commit
ec7b7a9d8f
68
dabo/functions/order.sh
Normal file
68
dabo/functions/order.sh
Normal file
@ -0,0 +1,68 @@
|
|||||||
|
function order {
|
||||||
|
# Info for log
|
||||||
|
g_echo_note "RUNNING FUNCTION ${FUNCNAME} $@"
|
||||||
|
|
||||||
|
# needed vars
|
||||||
|
local f_symbol=$1
|
||||||
|
local f_quote_currency_amount=$2 # amount in $CURRENCY
|
||||||
|
local f_side=$3 # buy/sell long/short
|
||||||
|
local f_price=$4 # price for liomit order - if not given do market order
|
||||||
|
local f_params f_type
|
||||||
|
|
||||||
|
|
||||||
|
### validity checks ###
|
||||||
|
|
||||||
|
# check symbol XXX/$CURRENCY[:$CURRENCY]
|
||||||
|
[[ $f_symbol =~ /$CURRENCY ]] || return 1
|
||||||
|
|
||||||
|
# check amount
|
||||||
|
g_num_valid_number "$f_quote_currency_amount" || return 1
|
||||||
|
|
||||||
|
# check side
|
||||||
|
[ "$f_side" = "long" ] && f_side="buy"
|
||||||
|
[ "$f_side" = "short" ] && f_side="sell"
|
||||||
|
[[ $f_side =~ ^buy$|^sell$ ]] || return 1
|
||||||
|
|
||||||
|
# check order type limit/market
|
||||||
|
if [ -z "$f_price" ]
|
||||||
|
then
|
||||||
|
f_type="market"
|
||||||
|
f_price=0
|
||||||
|
else
|
||||||
|
f_type="limit"
|
||||||
|
fi
|
||||||
|
|
||||||
|
### validity checks end###
|
||||||
|
|
||||||
|
|
||||||
|
# get amount in krypto asset
|
||||||
|
local f_asset=${f_symbol///*}
|
||||||
|
currency_converter $f_quote_currency_amount $CURRENCY $f_asset || return 1
|
||||||
|
local f_amount=$f_currency_converter_result
|
||||||
|
|
||||||
|
# check for swap/margin trades
|
||||||
|
if [ -n "$LEVERAGE" ]
|
||||||
|
then
|
||||||
|
# do some margin things
|
||||||
|
|
||||||
|
# check for CCXT swap symbol :$CURRENCY
|
||||||
|
[[ $f_symbol =~ : ]] || f_symbol="$f_symbol:$CURRENCY"
|
||||||
|
|
||||||
|
# set position mode
|
||||||
|
f_ccxt "$STOCK_EXCHANGE.setPositionMode(hedged=False, symbol='$f_symbol')" || return 1
|
||||||
|
|
||||||
|
# set leverage
|
||||||
|
f_ccxt "$STOCK_EXCHANGE.setLeverage($LEVERAGE, '$f_symbol')" || return 1
|
||||||
|
|
||||||
|
# define margibn mode isolated/cross
|
||||||
|
f_params="params={'marginMode': '$MARGIN_MODE'}"
|
||||||
|
else
|
||||||
|
# short/sell not possible in spot market
|
||||||
|
[[ $f_side =~ ^sell$ ]] || return 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# do the order
|
||||||
|
f_ccxt "print($STOCK_EXCHANGE.createOrder(symbol='${f_symbol}', type='$f_type', price=$f_price, amount='${f_amount}', side='${f_side}', ${f_params}))" || return 1
|
||||||
|
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user