Compare commits

..

No commits in common. "2cbc884aae76750a6b9d5eb00ec55388342374f1" and "63b92ccb8c8bc8bf5b68d563e6fea70e4f687400" have entirely different histories.

View File

@ -12,23 +12,18 @@ 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)"
local f_CMDFILE="trade-histories/${f_DATE}-${f_CURRENCY}-${f_ACTION}-BINANCE_CONVERT-TRADE_CMD"
local f_CMDFILE="trade-histories/${f_DATE}-${f_CURRENCY}-BINANCE_CONVERT-TRADE_CMD"
local f_num_converts=$(find trade-histories/*-*-*-BINANCE_CONVERT-TRADE_CMD -type f -mmin 60 | wc -l)
local f_num_converts=$(find trade-histories/*-*-BINANCE_CONVERT-TRADE_CMD -type f -mmin 60 | wc -l)
if [ $f_num_converts -ge 99 ]
then
g_echo_note "Already did 99 or more binance converts last hour."
return 1
fi
# get trade commission for comparison with convert
binance-api-call GET /sapi/v1/asset/tradeFee "&symbol=${f_ASSET}${f_QUANTITY}"
local FEE=$(echo "$(cat $g_tmp/API_CMD_OUT | jq -r .[].takerCommission)*100" | bc -l)
if [ "${f_ACTION}" = "buy" ]
then
# check for enough balance for trade
@ -45,35 +40,20 @@ ${FUNCNAME} $@"
fi
# get quote on buy
binance-api-call POST /sapi/v1/convert/getQuote "&fromAsset=${f_CURRENCY}&toAsset=${f_ASSET}&fromAmount=${f_QUANTITY}&walletType=SPOT&validTime=10s" || return 1
cat ${g_tmp}/API_CMD_OUT >${f_CMDFILE}_QUOTE_OUT
# get convert price
local f_convert_price=$(cat ${f_CMDFILE}_QUOTE_OUT | grep '^{' | jq -r .inverseRatio | head -n1)
echo "binance-api-call POST /sapi/v1/convert/getQuote '&fromAsset=${f_CURRENCY}&toAsset=${f_ASSET}&fromAmount=${f_QUANTITY}&walletType=SPOT&validTime=10s'" >${f_CMDFILE}
fi
if [ "${f_ACTION}" = "sell" ]
then
# get quote on sell
binance-api-call POST /sapi/v1/convert/getQuote "&fromAsset=${f_ASSET}&toAsset=${f_CURRENCY}&fromAmount=${f_QUANTITY}&walletType=SPOT&validTime=10s" || return 1
cat ${g_tmp}/API_CMD_OUT >${f_CMDFILE}_QUOTE_OUT
# 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
echo "binance-api-call POST /sapi/v1/convert/getQuote '&fromAsset=${f_ASSET}&toAsset=${f_CURRENCY}&fromAmount=${f_QUANTITY}&walletType=SPOT&validTime=10s'" >${f_CMDFILE}
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 \"&quoteId=\${f_quoteid}\"
cat ${g_tmp}/API_CMD_OUT >${f_CMDFILE}_OUT
" >${f_CMDFILE}
" >>${f_CMDFILE}
# convert/trade
g_echo_note "Command: $(cat ${f_CMDFILE})"
@ -95,19 +75,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_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)
[ "${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)
local f_COMMISSION="0"
local f_COMMISSIONASSET="${f_CURRENCY}"
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
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
if [ "${f_ACTION}" = "buy" ]
then
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
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
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_convert_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_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