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
|
#!/bin/sh
#
# Authenticate and grab quotes, read new symbols from stdin.
#
#set -x
#exec 2>/tmp/qm
# If mode is "L2", then get L2 quotes for a single symbol, else
# get real time quotes for a bunch of symbols. Note that quotemedia
# is *NOT* a real streamer. These are just aggragated quotes.
MODE="$1"
read USER
if [ "$USER" = rcfile ]; then
USER=demouser
PW=XXXXXX
HOSTNAME=www.quotemedia.com
PORT=80
while read tag eq val
do
case "$tag" in
username) USER="$val";;
hostname) HOSTNAME="$val";;
password) PW="$val";;
port) PORT="$val";;
esac
done < $HOME/.linuxtrade/quotemedia.com
else
read PW
read HOSTNAME
read PORT
fi
SITE="http://$HOSTNAME:$PORT"
UA="Mozilla/4.78 [en] (X11; U; Linux 2.4.9-13 i686)"
useridpw="$USER|$PW"
TMP="/tmp/qm$$"
TMP2="/tmp/qm$$.2"
#
# Get a session cookie
#
URL1="$SITE/jsp/appletcookie/cookieload.jsp"
URL1="$URL1?cookiename=useridpwd"
umask 077
echo "Set-Cookie: useridpwd=$useridpwd" > $TMP2
curl -A "$UA" -s -o/dev/null -b "$TMP2" -D "$TMP" "$URL1"
rm -f $TMP2
jsessionid=`grep Cookie $TMP |
sed 's/.*JSESSIONID=\([^;]*\);.*/\1/'`
#
# Authenticate user to see if he can get real time quotes
#
URL2="$SITE/dynamic/com.quotemedia.enduser.servlets.Login"
URL2="$URL2?saleId=501"
URL2="$URL2&userName=$USER"
URL2="$URL2&password=$PW"
URL2="$URL2&pageUrl=http://www.quotemedia.com/static/main/corp/"
echo "Set-Cookie: useridpwd=$useridpwd" > $TMP
echo "Set-Cookie: JSESSIONID=$jsessionid" >> $TMP
curl -L -A "$UA" -s -o$TMP2 -b "$TMP" "$URL2"
REALTIME=`cat $TMP2`
cp $TMP2 /tmp/zzz
rm -f $TMP2
#
# Setup to get quotes
#
if [ "$MODE" = L2 ]; then
URL3="$SITE/level2/getSymbolData.do?symbol="
#SUNW,0,5.010,5.010,0.000,0.000,0.000,0.000,0
#30,30,30
#SCHB,5.000,100,0
# 29 more lines of bid, 30 lines of ask
# SALE,TICK,SIZE,DATE,UNK
#5.010,0,4000,06-28-02,1
#5.010,0,400,06-28-02,1
#5.010,1,6400,06-28-02,1
else
URL3="$SITE/dynamic/com.quotemedia.servlet.QTLet"
URL3="$URL3?output=QuoteToStreamer&symbols="
fi
echo "Set-Cookie: JSESSIONID=$jsessionid" > $TMP
case "$REALTIME" in
2*|3*|-2*|-3*)
MARKER="MARKER"
TIMEOUT=1
;;
*)
# There's really no point in polling delayed quotes faster
MARKER="MARKER DELAYED"
TIMEOUT=15
;;
esac
#
# Read the first set of symbols from linuxtrade
#
read SYMS
#
# Loop, checking for new symbol requests and getting new quote
#
while :
do
newsyms=
read -t $TIMEOUT newsyms
if [ "$newsyms" != "" ]; then
SYMS="$newsyms"
fi
curl -A "$UA" -s -b "$TMP" "$URL3$SYMS" 2>/dev/null
if [ "$?" != 0 ]; then
rm -f $TMP
exit 1
fi
if [ "$MODE" = L2 ]; then
echo "$MARKER"
fi
done
|