|
| 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 |
0 commit comments