File: moneyam.helper

package info (click to toggle)
linuxtrade 3.65-8
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 3,100 kB
  • ctags: 1,978
  • sloc: ansic: 30,168; sh: 4,922; perl: 566; makefile: 126
file content (141 lines) | stat: -rwxr-xr-x 2,762 bytes parent folder | download | duplicates (2)
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
#!/bin/sh
#
#	Authenticate and grab quotes, read new symbols from stdin.
#
echo "$*" > /tmp/ggg

# If mode is "L2", then get L2 quotes for a single symbol, else
# get real time quotes for a bunch of symbols.
MODE="$1"
jsessionid=

if [ "$MODE" = Daily ]; then
    USER=rcfile
    SYM="$2"
else
    read USER
fi

case "$USER" in
rcfile)
	USER=demouser
	PW=XXXXXX
	while read tag eq val
	do
		case "$tag" in
		username)	USER="$val";;
		password)	PW="$val";;
		esac
	done < $HOME/.linuxtrade/moneyam.com
	;;
jsessionid)
	read jsessionid
	;;
*)
	read PW
	;;
esac

SITE="http://$HOSTNAME:$PORT"
UA="Mozilla/4.78 [en] (X11; U; Linux 2.4.9-13 i686)"

#
#	Get a session cookie
#
if [ "$jsessionid" = "" ]; then
    URL="https://www.moneyam.com/action/user/processLogin"
    jsessionid=`curl -A "$UA" -s \
	    -D- \
	    -d action=login \
	    -d username=$USER \
	    -d password=$PW \
	    -d saveDetails=on \
	    -o/dev/null $URL \
	    | sed -n 's/Set-Cookie: JSESSIONID=\([^;]*\).*/\1/p'`
    echo "_J$jsessionid"
fi

#
#	Setup to get quotes
#
case "$MODE" in
L2)
	# Demo symbols are: RYB PTY
	URL="http://level2.moneyam.com/data.dat"
	URL="$URL?Class=L2&linuxtrade=$USER&JSESSIONID=$jsessionid"
	;;
Chart)
	URL="http://streamer.moneyam.com/data.dat"
	URL="$URL?Class=Chart&chartType=Intraday&keyCodes=VOD"
	URL="$URL&startDate=2003-06-26&endDate=2003-06-26"
	URL="$URL&JSESSIONID=$jsessionid"
	curl -A "$UA" -s "$URL" 2>/dev/null
	exit
	;;
Daily)
	URL="http://streamer.moneyam.com/data.dat"
	URL="$URL?Class=Chart&chartType=Historical&keyCodes=$SYM"
	# URL="$URL&startDate=2003-06-01&endDate=2003-06-26"
	URL="$URL&startDate=$3&endDate=$4"
	URL="$URL&JSESSIONID=$jsessionid"
	curl -A "$UA" -s "$URL" 2>/dev/null
	exit
	;;
*)
	URL="http://streamer.moneyam.com/data.dat"
	URL="$URL?Class=Stock&JSESSIONID=$jsessionid"
	;;
esac

cleanup() {
    if [ $PID -gt 1 ]; then
	kill $PID 2>/dev/null
    fi
}

#
#	Use our private version of curl unless curl version 7.10.6 or
#	newer is installed.
#
case `curl --version` in
curl\ [0-6].*)		CURL=linuxtrade-curl;;
curl\ 7.[0-9].*)	CURL=linuxtrade-curl;;
curl\ 7.10.[1-5]\ *)	CURL=linuxtrade-curl;;
curl\ *)		CURL=curl;;
*)			CURL=linuxtrade-curl;;
esac

#
# Loop, checking for new symbol requests and getting quotes
#
PID=0
trap cleanup 0
while :
do
	read SYMS

	if [ $PID -gt 1 ]; then
	    kill $PID 2>/dev/null; PID=0
	    echo "_MARKER"
	fi

	if [ "$SYMS" = "" ]; then
	    exit
	fi

	if [ "$MODE" = L2 ]; then
	    # For debugging
	    # cat /home/rick/proj/lt2/xxxvod.l2
	    # cat /home/rick/proj/lt2/xxxryb.l2
	    :
	fi

	# Temporary hack: use private copy of curl where the -N option
	# is not broken.
	$CURL -N -A "$UA" -s "$URL&keyCodes=$SYMS" 2>/dev/null &
	PID=$!

	if [ "$?" != 0 ]; then
	    exit 1
	fi
done