Compare commits
7 Commits
9e918401e7
...
c9da86b94c
Author | SHA1 | Date | |
---|---|---|---|
c9da86b94c | |||
35fc940da5 | |||
4355c14a66 | |||
2f41d7cd19 | |||
2236ac65f7 | |||
8a075d7954 | |||
6807c6c78c |
@ -3,7 +3,7 @@
|
||||
# Webpage URL
|
||||
URL="mydabobot.mydomain"
|
||||
|
||||
# The exchange we use for using the correct API (BINANCE or BITPANDA)
|
||||
# The exchange we use for using the correct API (BINANCE or ONETRADING)
|
||||
STOCK_EXCHANGE="NONE"
|
||||
|
||||
# fee per trade in percentage on exchange (taker and maker added)
|
||||
|
@ -107,10 +107,10 @@ do
|
||||
TOKEN_INFO_CMD="binance_get_token_info"
|
||||
# command for buying/selling a token
|
||||
TRADE_CMD='binance-api-call POST /api/v3/order "&symbol=TOKEN"eOrderQty=QUANTITY&side=ACTION&type=MARKET"'
|
||||
elif [ "${STOCK_EXCHANGE}" = "BITPANDA" ]
|
||||
elif [ "${STOCK_EXCHANGE}" = "ONETRADING" ]
|
||||
then
|
||||
TOKEN_INFO_CMD="bitpanda_get_token_info"
|
||||
TRADE_CMD='bitpanda-api-call POST public/v1/account/orders "--header \"Content-Type: application/json\" --data \"{\\\"instrument_code\\\":\\\"TOKEN\\\",\\\"side\\\":\\\"ACTION\\\",\\\"type\\\":\\\"MARKET\\\",\\\"amount\\\":\\\"QUANTITY\\\"}\""'
|
||||
TOKEN_INFO_CMD="onetrading_get_token_info"
|
||||
TRADE_CMD='onetrading-api-call POST public/v1/account/orders "--header \"Content-Type: application/json\" --data \"{\\\"instrument_code\\\":\\\"TOKEN\\\",\\\"side\\\":\\\"ACTION\\\",\\\"type\\\":\\\"MARKET\\\",\\\"amount\\\":\\\"QUANTITY\\\"}\""'
|
||||
elif [ "${STOCK_EXCHANGE}" = "NONE" ]
|
||||
then
|
||||
## stop here if STOCK_EXCHANGE not present
|
||||
|
@ -1,14 +1,14 @@
|
||||
#!/bin/bash
|
||||
|
||||
function bitpanda-api-call {
|
||||
function onetrading-api-call {
|
||||
g_echo_note "RUNNING FUNCTION ${FUNCNAME} $@"
|
||||
local method=$1
|
||||
local call=$2
|
||||
local params=$3
|
||||
|
||||
if [ -s /dabo/.bitpanda-secrets ]
|
||||
if [ -s /dabo/.onetrading-secrets ]
|
||||
then
|
||||
. /dabo/.bitpanda-secrets
|
||||
. /dabo/.onetrading-secrets
|
||||
else
|
||||
g_echo_error "No secrets file found"
|
||||
return 1
|
||||
@ -17,8 +17,6 @@ function bitpanda-api-call {
|
||||
echo "${call}" | egrep -q "/account/" && local f_token="-H 'Authorization: Bearer ${API_TOKEN}'"
|
||||
echo "curl -s -X ${method} --url https://api.onetrading.com/${call} $f_token -H 'Accept: application/json' ${params}" >${g_tmp}/API_CMD
|
||||
echo "curl -s -X ${method} --url https://api.onetrading.com/${call} -H 'Accept: application/json'" >${g_tmp}/API_CMD_WO_KEY
|
||||
#echo "curl -s -X ${method} --url https://api.exchange.bitpanda.com/${call} $f_token -H 'Accept: application/json' ${params}" >${g_tmp}/API_CMD
|
||||
#echo "curl -s -X ${method} --url https://api.exchange.bitpanda.com/${call} -H 'Accept: application/json'" >${g_tmp}/API_CMD_WO_KEY
|
||||
g_runcmd g_retrycmd sh ${g_tmp}/API_CMD >${g_tmp}/API_CMD_OUT 2>&1
|
||||
|
||||
if egrep -q -i '^{"code":|error' ${g_tmp}/API_CMD_OUT
|
||||
|
@ -1,4 +1,4 @@
|
||||
function bitpanda_get_token_info {
|
||||
function onetrading_get_token_info {
|
||||
|
||||
g_echo_note "RUNNING FUNCTION ${FUNCNAME} $@"
|
||||
|
||||
@ -7,16 +7,16 @@ function bitpanda_get_token_info {
|
||||
f_QUANTITY=$3
|
||||
|
||||
# cleanup cache
|
||||
[ -s BITPANDA_TOKEN_INFO_CMD_OUT ] && find BITPANDA_TOKEN_INFO_CMD_OUT -mmin +60 -or -empty -delete
|
||||
if ! [ -s BITPANDA_TOKEN_INFO_CMD_OUT ]
|
||||
[ -s ONETRADING_TOKEN_INFO_CMD_OUT ] && find ONETRADING_TOKEN_INFO_CMD_OUT -mmin +60 -or -empty -delete
|
||||
if ! [ -s ONETRADING_TOKEN_INFO_CMD_OUT ]
|
||||
then
|
||||
bitpanda-api-call GET public/v1/instruments >BITPANDA_TOKEN_INFO_CMD_OUT
|
||||
cat ${g_tmp}/API_CMD_OUT >BITPANDA_TOKEN_INFO_CMD_OUT
|
||||
onetrading-api-call GET public/v1/instruments >ONETRADING_TOKEN_INFO_CMD_OUT
|
||||
cat ${g_tmp}/API_CMD_OUT >ONETRADING_TOKEN_INFO_CMD_OUT
|
||||
fi
|
||||
|
||||
local f_ASSET_PRECISION=$(cat BITPANDA_TOKEN_INFO_CMD_OUT | jq -r ".[] | select(.state==\"ACTIVE\") | select(.quote.code==\"${f_CURRENCY}\") | select(.base.code==\"${f_ASSET}\") | .amount_precision")
|
||||
local f_CURRENCY_PRECISION=$(cat BITPANDA_TOKEN_INFO_CMD_OUT | jq -r ".[] | select(.state==\"ACTIVE\") | select(.quote.code==\"${f_CURRENCY}\") | select(.base.code==\"${f_ASSET}\") | .quote.precision")
|
||||
local f_ASSET_MINSIZE=$(cat BITPANDA_TOKEN_INFO_CMD_OUT | jq -r ".[] | select(.state==\"ACTIVE\") | select(.quote.code==\"${f_CURRENCY}\") | select(.base.code==\"${f_ASSET}\") | .min_size")
|
||||
local f_ASSET_PRECISION=$(cat ONETRADING_TOKEN_INFO_CMD_OUT | jq -r ".[] | select(.state==\"ACTIVE\") | select(.quote.code==\"${f_CURRENCY}\") | select(.base.code==\"${f_ASSET}\") | .amount_precision")
|
||||
local f_CURRENCY_PRECISION=$(cat ONETRADING_TOKEN_INFO_CMD_OUT | jq -r ".[] | select(.state==\"ACTIVE\") | select(.quote.code==\"${f_CURRENCY}\") | select(.base.code==\"${f_ASSET}\") | .quote.precision")
|
||||
local f_ASSET_MINSIZE=$(cat ONETRADING_TOKEN_INFO_CMD_OUT | jq -r ".[] | select(.state==\"ACTIVE\") | select(.quote.code==\"${f_CURRENCY}\") | select(.base.code==\"${f_ASSET}\") | .min_size")
|
||||
local f_ASSET_PRICE=$(tail -n1 "asset-histories/${f_ASSET}${f_CURRENCY}.history.csv" | cut -d"," -f2)
|
||||
|
||||
if [ -n "$f_QUANTITY" ] && [ -n "$f_ASSET_PRICE" ]
|
||||
|
@ -56,7 +56,7 @@ ${FUNCNAME} $@"
|
||||
# prepare trading command
|
||||
local f_CMDFILE="trade-histories/${f_DATE}-${f_CURRENCY}-TRADE_CMD"
|
||||
[ ${STOCK_EXCHANGE} = "BINANCE" ] && echo "${TRADE_CMD}" | perl -pe "s/ACTION/${f_ACTION}/; s/TOKEN/${f_ASSET}${f_CURRENCY}/; s/QUANTITY/${f_QUANTITY}/" >${f_CMDFILE}
|
||||
[ ${STOCK_EXCHANGE} = "BITPANDA" ] && echo "${TRADE_CMD}" | perl -pe "s/ACTION/${f_ACTION}/; s/TOKEN/${f_ASSET}_${f_CURRENCY}/; s/QUANTITY/${f_ASSET_QUANTITY}/" >${f_CMDFILE}
|
||||
[ ${STOCK_EXCHANGE} = "ONETRADING" ] && echo "${TRADE_CMD}" | perl -pe "s/ACTION/${f_ACTION}/; s/TOKEN/${f_ASSET}_${f_CURRENCY}/; s/QUANTITY/${f_ASSET_QUANTITY}/" >${f_CMDFILE}
|
||||
# trade
|
||||
g_echo_note "Command: $(cat ${f_CMDFILE})"
|
||||
cat ${f_CMDFILE}
|
||||
@ -91,7 +91,7 @@ ${FUNCNAME} $@"
|
||||
|
||||
# Check return and log trade
|
||||
[ ${STOCK_EXCHANGE} = "BINANCE" ] && f_STATUS=$(cat ${f_CMDFILE}_OUT | grep '^{' | jq -r .status)
|
||||
[ ${STOCK_EXCHANGE} = "BITPANDA" ] && f_STATUS=$(cat ${f_CMDFILE}_OUT | grep '^{' | jq -r .order_id)
|
||||
[ ${STOCK_EXCHANGE} = "ONETRADING" ] && f_STATUS=$(cat ${f_CMDFILE}_OUT | grep '^{' | jq -r .order_id)
|
||||
|
||||
local f_trade_info_msg="TRADE - ${f_ACTION} ${f_ASSET}${f_CURRENCY}
|
||||
${f_link}
|
||||
@ -107,14 +107,14 @@ Comment: ${f_COMMENT}"
|
||||
[ ${STOCK_EXCHANGE} = "BINANCE" ] && local f_COMMISSION=$(cat ${f_CMDFILE}_OUT | grep '^{' | jq -r .fills[].commission) | head -n1
|
||||
[ ${STOCK_EXCHANGE} = "BINANCE" ] && local f_COMMISSIONASSET=$(cat ${f_CMDFILE}_OUT | grep '^{' | jq -r .fills[].commissionAsset | head -n1)
|
||||
|
||||
if [ ${STOCK_EXCHANGE} = "BITPANDA" ]
|
||||
if [ ${STOCK_EXCHANGE} = "ONETRADING" ]
|
||||
then
|
||||
sleep 10
|
||||
bitpanda-api-call GET public/v1/account/trades
|
||||
cat ${g_tmp}/API_CMD_OUT >${f_CMDFILE}_OUT_BITPANDA_TRADE
|
||||
local f_PRICE=$(cat ${f_CMDFILE}_OUT_BITPANDA_TRADE | jq -r ".trade_history | .[] | select(.trade.order_id==\"${f_STATUS}\") | .trade.price")
|
||||
local f_COMMISSION=$(cat ${f_CMDFILE}_OUT_BITPANDA_TRADE | jq -r ".trade_history | .[] | select(.trade.order_id==\"${f_STATUS}\") | .fee.fee_amount")
|
||||
local f_COMMISSIONASSET=$(cat ${f_CMDFILE}_OUT_BITPANDA_TRADE | jq -r ".trade_history | .[] | select(.trade.order_id==\"${f_STATUS}\") | .fee.fee_currency")
|
||||
onetrading-api-call GET public/v1/account/trades
|
||||
cat ${g_tmp}/API_CMD_OUT >${f_CMDFILE}_OUT_ONETRADING_TRADE
|
||||
local f_PRICE=$(cat ${f_CMDFILE}_OUT_ONETRADING_TRADE | jq -r ".trade_history | .[] | select(.trade.order_id==\"${f_STATUS}\") | .trade.price")
|
||||
local f_COMMISSION=$(cat ${f_CMDFILE}_OUT_ONETRADING_TRADE | jq -r ".trade_history | .[] | select(.trade.order_id==\"${f_STATUS}\") | .fee.fee_amount")
|
||||
local f_COMMISSIONASSET=$(cat ${f_CMDFILE}_OUT_ONETRADING_TRADE | jq -r ".trade_history | .[] | select(.trade.order_id==\"${f_STATUS}\") | .fee.fee_currency")
|
||||
fi
|
||||
|
||||
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
|
||||
|
@ -11,9 +11,9 @@ function get_assets {
|
||||
binance-api-call GET /api/v3/ticker/price || return 1
|
||||
# parse API output
|
||||
cat ${g_tmp}/API_CMD_OUT | jq -r '.[] | .symbol + "," + .price' | grep "${CURRENCY}," | egrep -v "${TRANSFER_CURRENCY},|,0[\.][0]*$" >${f_filename}_OUT.tmp
|
||||
elif [ ${STOCK_EXCHANGE} = "BITPANDA" ]
|
||||
elif [ ${STOCK_EXCHANGE} = "ONETRADING" ]
|
||||
then
|
||||
bitpanda-api-call GET "public/v1/market-ticker" || return 1
|
||||
onetrading-api-call GET "public/v1/market-ticker" || return 1
|
||||
#cat ${g_tmp}/API_CMD_OUT | jq -r '.[] | select(.state=="ACTIVE") | .instrument_code + "," + .last_price' | sed 's/_//' | grep "${CURRENCY}," | egrep -v "${TRANSFER_CURRENCY},|,0[\.][0]*$" >${f_filename}_OUT.tmp
|
||||
cat ${g_tmp}/API_CMD_OUT | jq -r '.[] | .instrument_code + "," + .last_price' | sed 's/_//' | grep "${CURRENCY}," | egrep -v "${TRANSFER_CURRENCY},|,0[\.][0]*$" >${f_filename}_OUT.tmp
|
||||
elif [ ${STOCK_EXCHANGE} = "NONE" ]
|
||||
|
@ -11,9 +11,9 @@ function get_balances {
|
||||
binance-api-call GET sapi/v1/capital/config/getall || return 1
|
||||
# parse outout
|
||||
cat ${g_tmp}/API_CMD_OUT | jq -r '.[] | .coin + "," + .free' | egrep -v ",0$|,0[\.][0]*$|${TRANSFER_CURRENCY}" | sort >${f_filename}_OUT.tmp_raw
|
||||
elif [ ${STOCK_EXCHANGE} = "BITPANDA" ]
|
||||
elif [ ${STOCK_EXCHANGE} = "ONETRADING" ]
|
||||
then
|
||||
bitpanda-api-call GET public/v1/account/balances || return 1
|
||||
onetrading-api-call GET public/v1/account/balances || return 1
|
||||
cat ${g_tmp}/API_CMD_OUT | jq -r '.balances[] | .currency_code + "," + .available' | egrep -v ",0$|,0[\.][0]*$|${TRANSFER_CURRENCY}" | sort >${f_filename}_OUT.tmp_raw
|
||||
fi
|
||||
|
||||
|
@ -61,7 +61,6 @@ function market_performance {
|
||||
f_eth_forecast=$(echo "scale=2; ${f_eth_forecast}/3" | bc -l | sed -r 's/^(-?)\./\10./')
|
||||
|
||||
# Calculate available market data week changes
|
||||
local f_index_performance_txt=""
|
||||
local f_index_performance_added=0
|
||||
local f_index_performance_csv=""
|
||||
local f_INDEX
|
||||
@ -98,13 +97,11 @@ function market_performance {
|
||||
fi
|
||||
fi
|
||||
# finishing vars
|
||||
f_index_performance_txt="${f_index_performance_txt}${f_INDEX}: ${f_index_performance}%; "
|
||||
f_index_performance_added="$(echo "scale=2; ${f_index_performance_added}+${f_index_performance}" | bc -l | sed -r 's/^(-?)\./\10./')"
|
||||
f_index_performance_csv="${f_index_performance_csv},${f_index_performance}"
|
||||
done
|
||||
|
||||
# calculate US-FED-FEDERAL-FUNDS-RATE-INVERTED
|
||||
local f_economic
|
||||
for f_eco_data in US-FED-FEDERAL-FUNDS-RATE-INVERTED-INDEX
|
||||
do
|
||||
local f_index_performance=$(tail -n 1 asset-histories/${f_eco_data}.history.csv | cut -d, -f2)
|
||||
@ -117,22 +114,19 @@ function market_performance {
|
||||
f_index_performance="-${f_index_performance}"
|
||||
fi
|
||||
fi
|
||||
f_index_performance_txt="${f_index_performance_txt}${f_eco_data}: ${f_index_performance}%; "
|
||||
f_index_performance_added="$(echo "scale=2; ${f_index_performance_added}+${f_index_performance}" | bc -l | sed -r 's/^(-?)\./\10./')"
|
||||
f_index_performance_csv="${f_index_performance_csv},${f_index_performance}"
|
||||
done
|
||||
|
||||
|
||||
# calculate forecast US Unemployment Rate and US Consumer Price Index (CPI)
|
||||
local f_economic
|
||||
for f_eco_data in US-UNEMPLOYMENT-INDEX US-CONSUMER-PRICE-INDEX
|
||||
do
|
||||
local f_current=$(tail -n 1 asset-histories/${f_eco_data}.history.csv | cut -d, -f2)
|
||||
local f_forecast=$(tail -n 1 asset-histories/${f_eco_data}.history.csv | cut -d, -f3)
|
||||
f_index_performance="$(echo "scale=2; ${f_current}-${f_forecast}" | bc -l | sed -r 's/^(-?)\./\10./')"
|
||||
f_index_performance_txt="${f_index_performance_txt}${f_eco_data}: ${f_index_performance}%; "
|
||||
f_index_performance_added="$(echo "scale=2; ${f_index_performance_added}+${f_index_performance}" | bc -l | sed -r 's/^(-?)\./\10./')"
|
||||
f_index_performance_csv="${f_index_performance_csv},${f_index_performance}"
|
||||
#local f_forecast=$(tail -n 1 asset-histories/${f_eco_data}.history.csv | cut -d, -f3)
|
||||
#f_index_performance="$(echo "scale=2; ${f_current}-${f_forecast}" | bc -l | sed -r 's/^(-?)\./\10./')"
|
||||
f_index_performance_added="$(echo "scale=2; ${f_index_performance_added}+${f_current}" | bc -l | sed -r 's/^(-?)\./\10./')"
|
||||
f_index_performance_csv="${f_index_performance_csv},${f_current}"
|
||||
done
|
||||
|
||||
# price performance bitcoin
|
||||
@ -147,9 +141,8 @@ function market_performance {
|
||||
## calculate market performance
|
||||
f_market_performance=$(echo "scale=2; (${f_btc_forecast} + ${f_eth_forecast} + ${f_index_performance_added} + ${f_btc_performance} + ${f_eth_performance} + ${f_top250_marketcap_performance})" | bc -l | sed -r 's/^(-?)\./\10./' | xargs printf "%.2f")
|
||||
local f_date=$(g_date_print)
|
||||
echo "${f_date} Market Performance: ${f_market_performance}%; BTC forecast: ${f_btc_forecast}%; ETH forecast: ${f_eth_forecast}%; ${f_index_performance_txt}BTC: ${f_btc_performance}%; ETH: ${f_eth_performance}%; TOP250 Marketcap: ${f_top250_marketcap_performance}%" >>MARKET_PERFORMANCE
|
||||
local f_indexlistcsv=$(echo "$f_indexlist" | perl -pe 's/\n/,/g; s/ +/,/g; s/,+/,/g')
|
||||
local f_market_csv_headline="date,market performance,btc,eth,btc forecast,eth forecast,top250,${f_indexlistcsv}US-FED-FEDERAL-FUNDS-RATE-INVERTED,US-UNEMPLOYMENT forecast,US-CONSUMER-PRICE forecast"
|
||||
local f_market_csv_headline="date,market performance,btc,eth,btc forecast,eth forecast,top250,${f_indexlistcsv}US-FED-FEDERAL-FUNDS-RATE-INVERTED,US-UNEMPLOYMENT,US-CONSUMER-PRICE"
|
||||
if [ -s MARKET_PERFORMANCE.csv ]
|
||||
then
|
||||
sed -i -e 1c"$f_market_csv_headline" MARKET_PERFORMANCE.csv
|
||||
|
Loading…
Reference in New Issue
Block a user