Skip to content

Commit 10094cd

Browse files
dsameandrewshvv
authored andcommitted
utils: general: add /bin directory with set of shell scripts mirroring httpAccess rpc
1 parent a34a16d commit 10094cd

File tree

6 files changed

+159
-0
lines changed

6 files changed

+159
-0
lines changed

bin/accesshttp

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
#!/bin/bash
2+
3+
echo @=$@
4+
5+
if [ x$1 = x--help -o x$1 = x-h ];then
6+
echo "With params calls http access service"
7+
echo " $0 METHOD [comma separated params]"
8+
echo "Without params adds the highlevel functions to the environment"
9+
echo " $0"
10+
echo "Exported functions are:"
11+
echo " rpc METHOD [comma separated params]"
12+
echo " balance_update user_id asset deposit | withdraw op_id amount"
13+
echo " order_put_market user_id 1(sell)|2(buy) amount taker_fee_rate [source]"
14+
exit 0
15+
fi
16+
17+
shdir=`dirname ${0}`
18+
19+
if [ -z $HTTP_URL ];then
20+
. ${shdir}/config.sh
21+
HTTP_URL="http://$( accesshttp_bind )"
22+
fi
23+
24+
function rpc () {
25+
method=$1
26+
shift
27+
if [ ! -z $DEBUG ];then
28+
echo "{\"method\":\"${method}\",\"params\":[$1],\"id\":${RANDOM}}"
29+
fi
30+
curl -i -H 'Accept: application/json' \
31+
-X POST \
32+
-d "{\"method\":\"${method}\",\"params\":[$1],\"id\":${RANDOM}}" \
33+
$HTTP_URL
34+
RESULT=$?
35+
echo
36+
return $RESULT
37+
}
38+
39+
function balance.query () {
40+
if [ $# -lt 1 ]; then
41+
echo "bad arguments: $@"
42+
echo 'usage: user_id'
43+
return 1
44+
fi
45+
rpc balance.query $1
46+
}
47+
48+
# user_id
49+
# asset
50+
# deposit | withdraw
51+
# op_id
52+
# amount
53+
function balance.update () {
54+
rpc balance.update "$1,\"$2\",\"$3\",$4,\"$5\",{}"
55+
}
56+
57+
function order.put_market () {
58+
if [ $# -lt 5 ]; then
59+
echo "bad arguments: $@"
60+
echo 'usage: user_id market 1(sell)|2(buy) amount taker_fee_rate [source]'
61+
return 1
62+
fi
63+
source=$6
64+
test $source || source="shell command"
65+
rpc order.put_market "$1,\"$2\",$3,\"$4\",\"$5\",\"$source\""
66+
}
67+
68+
function order.put_market () {
69+
if [ $# -lt 5 ]; then
70+
echo "bad arguments: $@"
71+
echo 'usage: user_id market 1(sell)|2(buy) amount taker_fee_rate [source]'
72+
return 1
73+
fi
74+
source=$6
75+
test $source || source="shell command"
76+
rpc order.put_market "$1,\"$2\",$3,\"$4\",\"$5\",\"$source\""
77+
}
78+
79+
function market.status () {
80+
if [ $# -lt 2 ]; then
81+
echo "bad arguments: $@"
82+
echo 'usage: market period'
83+
return 1
84+
fi
85+
rpc "market.status" "\"$1\",$2"
86+
}
87+
88+
# if [ $# -gt 0 ];then
89+
# rpc $@
90+
# fi

bin/balance.query

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#!/bin/bash
2+
shdir=`dirname ${0}`
3+
. ${shdir}/accesshttp
4+
5+
balance.query $@

bin/balance.update

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#!/bin/bash
2+
if [ $# -eq 0 -o x$1 = x--help -o x$1 = x-h ];then
3+
echo "$0 user_id asset deposit | withdraw op_id amount"
4+
exit 0
5+
fi
6+
7+
shdir=`dirname ${0}`
8+
. ${shdir}/accesshttp
9+
10+
balance.update $@

bin/config.sh

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
#!/bin/bash
2+
# Exports functions parsing the services configs
3+
4+
# Internal utils
5+
servicesdir="`dirname ${0}`/.."
6+
7+
function get () {
8+
filter=$1
9+
service=$2
10+
config="${servicesdir}/$service/config.json"
11+
ret=`jq "$filter[0]" < $config`
12+
test -z $ret || test $ret = null && $ret=''
13+
if [ -z $ret ]; then
14+
ret=`jq $filter[0] < $config`
15+
test -z ret && return 1
16+
fi
17+
echo $ret
18+
}
19+
20+
function trim_quotes () {
21+
echo $1|sed -e's/^"//'|sed -e's/"$//'
22+
}
23+
24+
function trim_port() {
25+
echo $1|sed -e's/^[^@]*@//'
26+
}
27+
28+
function trim_quotes_port() {
29+
echo $1|sed -e's/^"//'|sed -e's/"$//'|sed -e's/^[^@]*@//'
30+
}
31+
32+
# Exported functions
33+
function accesshttp_bind () {
34+
if [ -z $REMOTE ]; then
35+
# get .svr.bind accesshttp
36+
ip=$( get .svr.bind accesshttp )
37+
# echo "ip=$ip"
38+
trim_quotes_port $ip
39+
else
40+
echo $REMOTE
41+
fi
42+
}

bin/market.status

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#!/bin/bash
2+
3+
shdir=`dirname ${0}`
4+
. ${shdir}/accesshttp
5+
6+
market.status $@

bin/order.put_market

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#!/bin/bash
2+
3+
shdir=`dirname ${0}`
4+
. ${shdir}/accesshttp
5+
6+
order.put_market $@

0 commit comments

Comments
 (0)