-
Notifications
You must be signed in to change notification settings - Fork 8
/
buy
executable file
·28 lines (23 loc) · 1.14 KB
/
buy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#!/bin/bash
#
# Automatically sets a buy order with miner and dex fees calculated
#
# Usage: ./buy kmd btc 10000 1
# (Tries to buy 1 KMD at a price of 10000 KMD/BTC)
#
# @author webworker01
# @see https://developers.atomicdex.io/basic-docs/atomicdex-api-legacy/buy.html
#
scriptpath="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
source $scriptpath/main
#price - the price in sellcoin the user is willing to pay per one unit of the buycoin coin
#volume - the amount of coins the user is willing to receive of the buycoin coin
if [[ -z $1 ]] || [[ -z $2 ]] || [[ -z $3 ]] || [[ -z $4 ]]; then
echo "Usage: buy <buycoin> <sellcoin> <price=sellcoin/buycoin> <volume (buycoin)>"
exit 0
fi
coin1=${1^^}
coin2=${2^^}
minerfee=$(jq -r .result.amount <<< $(curl -s --url "http://127.0.0.1:7783" --data '{"method":"get_trade_fee","coin":"'${coin2}'","userpass":"'${userpass}'"}'))
volume=$( printf "%.8f" $(bc -l <<< "($4 - $minerfee * 2) * (1 - 1 / 777)") )
jq . <<< $(curl -s --url "http://127.0.0.1:7783" --data '{"method":"buy","base":"'${coin1}'","rel":"'${coin2}'","price":"'${3}'","volume":"'${volume}'","userpass":"'${userpass}'"}')