bitpanda trade fixes, documentation, install/docker fixes

This commit is contained in:
olli 2023-05-09 10:30:03 +02:00
parent 8f3495e497
commit c00e852c0a
10 changed files with 151 additions and 61 deletions

View File

@ -44,6 +44,10 @@ I thought this fits quite well to the cryptotrading world and that's why i chose
# How to use/install # How to use/install
Linux knowledge required! Linux knowledge required!
Needed a running Docker install. Traefik suggested, see
https://gitea.ds9.dedyn.io/olli/debian.ansible.docker
https://gitea.ds9.dedyn.io/olli/debian.ansible.traefik.server
Download: Download:
``` ```
git clone https://gitea.ds9.dedyn.io/olli/dabo.git git clone https://gitea.ds9.dedyn.io/olli/dabo.git
@ -55,13 +59,78 @@ Build container:
docker -l warn compose --ansi never build --progress=plain --pull --no-cache --force-rm docker -l warn compose --ansi never build --progress=plain --pull --no-cache --force-rm
``` ```
Run: Set Rights (UID 10000 for non-root-User in running container):
```
chown -R 10000:10000 dabo data home
```
Edit docker-compose.yml or create docker-compose.override.yml to fit yout needs e.g. domain and network settings or basic auth, e.g. for traefik and letsencrypt:
```
echo '
services:
dabo-bot:
networks:
- YOURNETWORK
dabo-web:
labels:
# DOMAIN
- traefik.http.routers.dabo-YOURINSTANCENAME.rule=Host(`YOURDOMAIN`)
- traefik.http.routers.dabo-YOURINSTANCENAME.entrypoints=https
- traefik.http.routers.dabo-YOURINSTANCENAME.tls=true
# Proxy to service-port
- traefik.http.services.dabo-YOURINSTANCENAME.loadbalancer.server.port=80
- traefik.http.routers.dabo-YOURINSTANCENAME.service=dabo-YOURINSTANCENAME
# cert via letsencrypt
- traefik.http.routers.dabo-YOURINSTANCENAME.tls.certresolver=letsencrypt
# activate secHeaders@file & basic auth
- traefik.http.routers.dabo-YOURINSTANCENAME.middlewares=secHeaders@file,basicauth
# Generate crypted password string with: echo $(htpasswd -nB YOURUSER) | sed -e s/\\$/\\$\\$/g
- traefik.http.middlewares.dabo-YOURINSTANCENAME.basicauth.users=YOURUSER:YOUR-GENERATED-CRYPTED-PASSWORD-STRING
# Traefik network
- traefik.docker.network=traefik
networks:
- traefik
networks:
YOURNETWORK:
driver: bridge
driver_opts:
com.docker.network.bridge.name: YOURBRIDGE
traefik:
external: true
' >docker-compose.override.yml
```
Create Secrets file for your API Key(s)
```
# for Bitpanda
echo 'local API_TOKEN=YOUR_VERY_LOOOOOOONNNNGGGG_API_TOKEN_FROM_BITPANDA' >dabo/.bitpanda-secrets
# or for Binance
echo 'local API_SECRET="YOUR_LONG_API_SECRET_FROM_BINANCE"
local API_KEY="YOUR_LONG_API_KEY_FROM_BINANCE" '>dabo/.binance-secrets
```
Edit your Config
Especially change URL, STOCK_EXCHANGE, FEE, CURRENCY,... to fit your needs.
```
vim dabo/dabo-bot.conf
```
Prepare/Create a stretegy
IMPORTANT!!! THE DEFAULT STRATEGY MAY NOT FIT YOUR NEEDS OR WORK FPR YOU PROPERLY. SO YOU CAN LOOSE ALL YOUR MONEY!!! USE ON YOUR OWN RISK!!!
Run/Restart:
``` ```
docker-compose down # if an old instance is running docker-compose down # if an old instance is running
docker-compose up -d docker-compose up -d
``` ```
Logs: Logs/Output:
``` ```
docker-compose logs -f docker-compose logs -f
``` ```

View File

@ -1,4 +1,7 @@
# Webpage URL
URL="dabo.ds9.dedyn.io"
# The exchange we use for using the correct API (BINANCE or BITPANDA) # The exchange we use for using the correct API (BINANCE or BITPANDA)
STOCK_EXCHANGE="BITPANDA" STOCK_EXCHANGE="BITPANDA"
@ -32,7 +35,7 @@ INVEST="5"
GOOD_MARKET_PERFORMANCE_INDEX="-1" GOOD_MARKET_PERFORMANCE_INDEX="-1"
# Stop all trading and sell everything if the complete balance shrinks under this value in ${CURRENCY} # Stop all trading and sell everything if the complete balance shrinks under this value in ${CURRENCY}
EMERGENCY_STOP="190" EMERGENCY_STOP="90"

View File

@ -59,6 +59,7 @@ do
TRADE_CMD='binance-api-call POST /api/v3/order "&symbol=TOKEN&quoteOrderQty=QUANTITY&side=ACTION&type=MARKET"' TRADE_CMD='binance-api-call POST /api/v3/order "&symbol=TOKEN&quoteOrderQty=QUANTITY&side=ACTION&type=MARKET"'
elif [ ${STOCK_EXCHANGE} = "BITPANDA" ] elif [ ${STOCK_EXCHANGE} = "BITPANDA" ]
then 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\\\"}\""' 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\\\"}\""'
fi fi

View File

@ -68,7 +68,7 @@ cat ${g_tmp}/API_CMD_OUT >${f_CMDFILE}_OUT
local f_trade_info_msg="CONVERT/TRADE - ${f_ACTION} ${f_ASSET}${f_CURRENCY} local f_trade_info_msg="CONVERT/TRADE - ${f_ACTION} ${f_ASSET}${f_CURRENCY}
${f_link} ${f_link}
Complete Overview: https://bot.ds9.dedyn.io/ Complete Overview: https://${URL}/
Comment: ${f_COMMENT}" Comment: ${f_COMMENT}"

View File

@ -0,0 +1,32 @@
function bitpanda_get_token_info {
g_echo_note "RUNNING FUNCTION ${FUNCNAME} $@"
local f_ASSET=$1
local f_CURRENCY=$2
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 ]
then
bitpanda-api-call GET public/v1/instruments >BITPANDA_TOKEN_INFO_CMD_OUT
cat ${g_tmp}/API_CMD_OUT >BITPANDA_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_PRICE=$(tail -n1 "asset-histories/${f_ASSET}${f_CURRENCY}.history.csv" | cut -d"," -f2)
if [ -n "$f_QUANTITY" ] && [ -n "$f_ASSET_PRICE" ]
then
if [ $(echo "${f_ASSET_MINSIZE} < ${f_QUANTITY}" | bc -l) -eq 0 ]
then
f_QUANTITY=$(echo "scale=${f_CURRENCY_PRECISION}; ${f_ASSET_MINSIZE}+1" | bc -l)
fi
f_ASSET_QUANTITY=$(echo "scale=${f_ASSET_PRECISION}; ${f_QUANTITY}/${f_ASSET_PRICE}" | bc -l | sed 's/^\./0./;')
fi
}

View File

@ -14,6 +14,8 @@ function do_trade {
local f_link="https://www.coingecko.com/de/munze/$(egrep -i ^${f_ASSET}, COINGECKO_IDS | cut -d, -f2)" local f_link="https://www.coingecko.com/de/munze/$(egrep -i ^${f_ASSET}, COINGECKO_IDS | cut -d, -f2)"
# get stock exchange specific infos for trade (e.g. f_QUANTITY_LOT_CUT; f_MIN_NOTIONAL, precision and minsize)
${TOKEN_INFO_CMD} ${f_ASSET} ${f_CURRENCY} ${f_QUANTITY}
if [ ${STOCK_EXCHANGE} = "BINANCE" ] if [ ${STOCK_EXCHANGE} = "BINANCE" ]
then then
@ -49,36 +51,41 @@ ${FUNCNAME} $@"
fi fi
fi fi
# prepare trading command # prepare trading command
local f_CMDFILE="trade-histories/${f_DATE}-${f_CURRENCY}-${f_MIN_NOTIONAL}-TRADE_CMD" 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} = "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_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}
# trade # trade
g_echo_note "Command: $(cat ${f_CMDFILE})" g_echo_note "Command: $(cat ${f_CMDFILE})"
cat ${f_CMDFILE}
#g_runcmd g_retrycmd sh ${f_CMDFILE} >${f_CMDFILE}_OUT #g_runcmd g_retrycmd sh ${f_CMDFILE} >${f_CMDFILE}_OUT
. ${f_CMDFILE} . ${f_CMDFILE}
cat ${g_tmp}/API_CMD_OUT >${f_CMDFILE}_OUT cat ${g_tmp}/API_CMD_OUT >${f_CMDFILE}_OUT
g_echo_note "Command Output: $(cat ${f_CMDFILE}_OUT)" g_echo_note "Command Output: $(cat ${f_CMDFILE}_OUT)"
# workaround for "insufficient balance" error. lower quantity in 0.1 steps and try again (for values loosing while selling) # workaround for "insufficient balance" error. lower quantity in 0.1 steps and try again (for values loosing while selling)
if [ "${f_ACTION}" = "sell" ] && grep -q "Account has insufficient balance for requested action." ${f_CMDFILE}_OUT if [ ${STOCK_EXCHANGE} = "BINANCE" ]
then then
g_echo_note "workaround for \"insufficient balance\" error." if [ "${f_ACTION}" = "sell" ] && grep -q "Account has insufficient balance for requested action." ${f_CMDFILE}_OUT
local f_tries=10 then
local f_try=1 g_echo_note "workaround for \"insufficient balance\" error."
until (grep -q "FILLED" ${f_CMDFILE}_OUT) local f_tries=10
do local f_try=1
sleep 1 until (grep -q "FILLED" ${f_CMDFILE}_OUT)
f_QUANTITY=$(echo "$f_QUANTITY-0.1" | bc -l | sed 's/^\./0./;') do
g_echo_note "lower $f_QUANTITY by -0.1" sleep 1
[ ${STOCK_EXCHANGE} = "BINANCE" ] && echo "${TRADE_CMD}" | perl -pe "s/ACTION/${f_ACTION}/; s/TOKEN/${f_ASSET}${f_CURRENCY}/; s/QUANTITY/${f_QUANTITY}/" >${f_CMDFILE} f_QUANTITY=$(echo "$f_QUANTITY-0.1" | bc -l | sed 's/^\./0./;')
[ ${STOCK_EXCHANGE} = "BITPANDA" ] && echo "${TRADE_CMD}" | perl -pe "s/ACTION/${f_ACTION}/; s/TOKEN/${f_ASSET}_${f_CURRENCY}/; s/QUANTITY/${f_QUANTITY}/" >${f_CMDFILE} g_echo_note "lower $f_QUANTITY by -0.1"
#g_runcmd g_retrycmd sh ${f_CMDFILE} >${f_CMDFILE}_OUT echo "${TRADE_CMD}" | perl -pe "s/ACTION/${f_ACTION}/; s/TOKEN/${f_ASSET}${f_CURRENCY}/; s/QUANTITY/${f_QUANTITY}/" >${f_CMDFILE}
. ${f_CMDFILE} #g_runcmd g_retrycmd sh ${f_CMDFILE} >${f_CMDFILE}_OUT
cat ${g_tmp}/API_CMD_OUT >${f_CMDFILE}_OUT . ${f_CMDFILE}
[ ${f_try} -eq ${f_tries} ] && break cat ${g_tmp}/API_CMD_OUT >${f_CMDFILE}_OUT
((f_try=f_try+1)) [ ${f_try} -eq ${f_tries} ] && break
done ((f_try=f_try+1))
done
fi
fi fi
@ -89,7 +96,7 @@ ${FUNCNAME} $@"
local f_trade_info_msg="TRADE - ${f_ACTION} ${f_ASSET}${f_CURRENCY} local f_trade_info_msg="TRADE - ${f_ACTION} ${f_ASSET}${f_CURRENCY}
${f_link} ${f_link}
Complete Overview: https://bot.ds9.dedyn.io/ Complete Overview: https://${URL}/
Comment: ${f_COMMENT}" Comment: ${f_COMMENT}"
@ -100,9 +107,15 @@ 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_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) [ ${STOCK_EXCHANGE} = "BINANCE" ] && local f_COMMISSIONASSET=$(cat ${f_CMDFILE}_OUT | grep '^{' | jq -r .fills[].commissionAsset | head -n1)
[ ${STOCK_EXCHANGE} = "BITPANDA" ] && local f_PRICE=$(cat ${f_CMDFILE}_OUT | grep '^{' | jq -r .price | head -n1) if [ ${STOCK_EXCHANGE} = "BITPANDA" ]
[ ${STOCK_EXCHANGE} = "BITPANDA" ] && local f_COMMISSION=$(echo "scale=2; $f_PRICE/100*${FEE}" | bc -l) then
[ ${STOCK_EXCHANGE} = "BITPANDA" ] && local f_COMMISSIONASSET="EUR" 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")
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 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" ] if [ "${f_ACTION}" = "buy" ]

View File

@ -95,7 +95,7 @@ function get_assets {
. /tmp/parallel . /tmp/parallel
# cleanup trashlines (possibly generated by kill further of this progress) # cleanup trashlines (possibly generated by kill further of this progress)
#sed -i "/[0-9]$(date +%Y)-/d" asset-histories/* sed -i "/[0-9]$(date +%Y)-/d" asset-histories/*
# get MSCI World Index for analysis # get MSCI World Index for analysis
echo "wget -q -O - https://www.boerse.de/realtime-kurse/MSCI-World/XC0009692739 | egrep 'itemprop=\"price\" content=\"[0-9]+\.[0-9]+\"' | cut -d\\\" -f6" >MSCI_WORLD_CMD echo "wget -q -O - https://www.boerse.de/realtime-kurse/MSCI-World/XC0009692739 | egrep 'itemprop=\"price\" content=\"[0-9]+\.[0-9]+\"' | cut -d\\\" -f6" >MSCI_WORLD_CMD

1
dabo/home/.keep Normal file
View File

@ -0,0 +1 @@
needed-dir

1
dabo/htdocs/.keep Normal file
View File

@ -0,0 +1 @@
needed-dir

View File

@ -13,9 +13,6 @@ services:
- ./home:/dabo/home:rw - ./home:/dabo/home:rw
- /usr/local/bin/notify.sh:/usr/local/bin/notify.sh:ro - /usr/local/bin/notify.sh:/usr/local/bin/notify.sh:ro
- /etc/localtime:/etc/localtime:ro - /etc/localtime:/etc/localtime:ro
networks:
- dabo--network
dabo-web: dabo-web:
image: nginx:latest image: nginx:latest
@ -23,31 +20,4 @@ services:
volumes: volumes:
- ./data:/usr/share/nginx/html:ro - ./data:/usr/share/nginx/html:ro
- /etc/localtime:/etc/localtime:ro - /etc/localtime:/etc/localtime:ro
networks:
- traefik
labels:
- traefik.enable=true
# HTTPS
- traefik.http.routers.dabo-web.rule=Host(`dabo.ds9.dedyn.io`)
- traefik.http.routers.dabo-web.entrypoints=https
- traefik.http.routers.dabo-web.tls=true
# Proxy to service-port
- traefik.http.services.dabo-web.loadbalancer.server.port=80
- traefik.http.routers.dabo-web.service=dabo-web
# cert via letsencrypt
- traefik.http.routers.dabo-web.tls.certresolver=letsencrypt
# activate secHeaders@file
- traefik.http.routers.dabo-web.middlewares=secHeaders@file
# Traefik network
- traefik.docker.network=traefik
networks:
dabo--network:
driver: bridge
driver_opts:
com.docker.network.bridge.name: br-dabo
traefik:
external: true