compare Trading and Convert price and use the cheaper variant
This commit is contained in:
parent
63b92ccb8c
commit
f2823c7410
@ -12,6 +12,7 @@ function binance_convert {
|
||||
|
||||
local f_DATE=$(date '+%F_%H-%M-%S')
|
||||
local f_ASSET_HIST_FILE="asset-histories/${f_ASSET}${f_CURRENCY}.history.csv"
|
||||
local f_market_price=$(tail -n1 ${f_ASSET_HIST_FILE} | cut -d, -f2)
|
||||
|
||||
local f_link="https://www.coingecko.com/de/munze/$(egrep -i ^${f_ASSET}, COINGECKO_IDS | cut -d, -f2)"
|
||||
|
||||
@ -40,20 +41,32 @@ ${FUNCNAME} $@"
|
||||
fi
|
||||
|
||||
# get quote on buy
|
||||
echo "binance-api-call POST /sapi/v1/convert/getQuote '&fromAsset=${f_CURRENCY}&toAsset=${f_ASSET}&fromAmount=${f_QUANTITY}&walletType=SPOT&validTime=10s'" >${f_CMDFILE}
|
||||
binance-api-call POST /sapi/v1/convert/getQuote "&fromAsset=${f_CURRENCY}&toAsset=${f_ASSET}&fromAmount=${f_QUANTITY}&walletType=SPOT&validTime=10s" >${f_CMDFILE}_QUOTE_OUT || return 1
|
||||
local f_convert_price=$(cat ${f_CMDFILE}_QUOTE_OUT | grep '^{' | jq -r .inverseRatio | head -n1)
|
||||
fi
|
||||
|
||||
if [ "${f_ACTION}" = "sell" ]
|
||||
then
|
||||
# get quote on sell
|
||||
echo "binance-api-call POST /sapi/v1/convert/getQuote '&fromAsset=${f_ASSET}&toAsset=${f_CURRENCY}&fromAmount=${f_QUANTITY}&walletType=SPOT&validTime=10s'" >${f_CMDFILE}
|
||||
binance-api-call POST /sapi/v1/convert/getQuote "&fromAsset=${f_ASSET}&toAsset=${f_CURRENCY}&fromAmount=${f_QUANTITY}&walletType=SPOT&validTime=10s" ${f_CMDFILE}_QUOTE_OUT || return 1
|
||||
# get convert price
|
||||
local f_convert_price=$(cat ${f_CMDFILE}_QUOTE_OUT | grep '^{' | jq -r .ratio | head -n1)
|
||||
fi
|
||||
|
||||
local f_price_diff=$(g_percentage-diff ${f_market_price} ${f_convert_price})
|
||||
if [ $(echo "${f_price_diff} > ${FEE}" | bc -l) -eq 0 ]
|
||||
then
|
||||
local f_note="Price difference between Market Price (${f_market_price}) and Binance Convert Price (${f_convert_price}) is higher then Trading Fee (${f_price_diff} > ${FEE}), so I will better use trade then convert"
|
||||
g_echo_note "$f_note"
|
||||
g_signal-notify "$f_note"
|
||||
return 1
|
||||
fi
|
||||
|
||||
echo "cat ${g_tmp}/API_CMD_OUT >${f_CMDFILE}_QUOTE_OUT
|
||||
local f_quoteid=\$(cat ${g_tmp}/API_CMD_OUT | jq -r '.quoteId')
|
||||
binance-api-call POST /sapi/v1/convert/acceptQuote \""eId=\${f_quoteid}\"
|
||||
cat ${g_tmp}/API_CMD_OUT >${f_CMDFILE}_OUT
|
||||
" >>${f_CMDFILE}
|
||||
" >${f_CMDFILE}
|
||||
|
||||
# convert/trade
|
||||
g_echo_note "Command: $(cat ${f_CMDFILE})"
|
||||
@ -75,19 +88,19 @@ Comment: ${f_COMMENT}"
|
||||
if echo "${f_STATUS}" | egrep -q "PROCESS|ACCEPT_SUCCESS|SUCCESS"
|
||||
then
|
||||
g_echo_note "CONVERT/TRADE SUCCESSFUL!"
|
||||
[ "${f_ACTION}" = "buy" ] && local f_PRICE=$(cat ${f_CMDFILE}_QUOTE_OUT | grep '^{' | jq -r .inverseRatio | head -n1)
|
||||
[ "${f_ACTION}" = "sell" ] && local f_PRICE=$(cat ${f_CMDFILE}_QUOTE_OUT | grep '^{' | jq -r .ratio | head -n1)
|
||||
[ "${f_ACTION}" = "buy" ] && local f_convert_price=$(cat ${f_CMDFILE}_QUOTE_OUT | grep '^{' | jq -r .inverseRatio | head -n1)
|
||||
[ "${f_ACTION}" = "sell" ] && local f_convert_price=$(cat ${f_CMDFILE}_QUOTE_OUT | grep '^{' | jq -r .ratio | head -n1)
|
||||
local f_COMMISSION="0"
|
||||
local f_COMMISSIONASSET="${f_CURRENCY}"
|
||||
echo "${f_DATE},${f_ACTION},${f_CMDFILE}_OUT,${f_QUANTITY} ${f_CURRENCY},${f_PRICE},${f_COMMISSION} ${f_COMMISSIONASSET},${f_COMMENT}" | head -n1 >>trade-histories/${f_ASSET}${f_CURRENCY}.history.csv
|
||||
echo "${f_DATE},${f_ACTION},${f_CMDFILE}_OUT,${f_QUANTITY} ${f_CURRENCY},${f_convert_price},${f_COMMISSION} ${f_COMMISSIONASSET},CONVERT ${f_COMMENT}" | head -n1 >>trade-histories/${f_ASSET}${f_CURRENCY}.history.csv
|
||||
if [ "${f_ACTION}" = "buy" ]
|
||||
then
|
||||
echo "${f_DATE},${f_ACTION},${f_CMDFILE}_OUT,${f_QUANTITY} ${f_CURRENCY},${f_PRICE},${f_COMMISSION} ${f_COMMISSIONASSET},${f_COMMENT}" | head -n1 >>trade-histories/trade-$(date +%F.%T. | sed 's/:/_/g')${f_ASSET}${f_CURRENCY}-open.history.csv
|
||||
echo "${f_DATE},${f_ACTION},${f_CMDFILE}_OUT,${f_QUANTITY} ${f_CURRENCY},${f_convert_price},${f_COMMISSION} ${f_COMMISSIONASSET},CONVERT ${f_COMMENT}" | head -n1 >>trade-histories/trade-$(date +%F.%T. | sed 's/:/_/g')${f_ASSET}${f_CURRENCY}-open.history.csv
|
||||
fi
|
||||
if [ "${f_ACTION}" = "sell" ]
|
||||
then
|
||||
f_tradehistfile="$(ls trade-histories/trade-*${f_ASSET}${f_CURRENCY}-open.history.csv | tail -n1)"
|
||||
echo "${f_DATE},${f_ACTION},${f_CMDFILE}_OUT,${f_QUANTITY_CURRENCY} ${f_CURRENCY},${f_PRICE},${f_COMMISSION} ${f_COMMISSIONASSET},${f_COMMENT}" | head -n1 >>${f_tradehistfile}
|
||||
echo "${f_DATE},${f_ACTION},${f_CMDFILE}_OUT,${f_QUANTITY_CURRENCY} ${f_CURRENCY},${f_convert_price},${f_COMMISSION} ${f_COMMISSIONASSET},${f_COMMENT}" | head -n1 >>${f_tradehistfile}
|
||||
f_tradehistfileclosed=$(echo ${f_tradehistfile} | sed 's/open.history.csv/closed.history.csv/')
|
||||
mv ${f_tradehistfile} ${f_tradehistfileclosed}
|
||||
fi
|
||||
|
Loading…
Reference in New Issue
Block a user