├── CMakeLists.txt
├── compile.sh
├── configs
├── Direct.Bats.ini
├── Direct.Bats.ini~
├── admin_config.xml
├── admin_config.xml~
├── admin_config_server.xml
├── symbol_config_new.xml
├── symbol_config_new.xml~
├── symbol_config_onlyC.xml
├── trading_config_new.xml
└── trading_config_new.xml~
├── connect.sh
├── copylog.sh
├── deploy.sh
├── run_stem.sh
├── scripts
├── file.csv
├── kill_stem.sh
├── line-0
├── line-1
├── liverun.txt
├── liverun.txt~
├── livestats.sh
├── livestatsold.sh
├── livestatssorted.sh
├── log_processing.sh
├── log_processing.sh~
├── order_processing.awk
├── positiontoredis.sh
├── readarray
├── redisfile.csv
├── redistofile.sh
├── run_stem.sh
├── run_stem.sh~
└── run_stem_for_server.sh
└── src
├── CMakeLists.txt
├── CMakeLists.txt~
├── STEMConsole.cpp
├── akela
├── CMakeLists.txt
├── OrderAccount.cpp
├── OrderAccount.h
├── STEMDirectConnection.cpp
├── STEMDirectConnection.h
├── STEMMaddogConnection.cpp
└── STEMMaddogConnection.h
├── avicenna
├── AvicennaInterface.cpp
├── AvicennaInterface.h
└── CMakeLists.txt
├── cli
├── CLI.cpp
├── CLI.h
└── CMakeLists.txt
├── config
├── AdminConfig.h
├── CMakeLists.txt
├── ConfigReader.h
├── SymbolConfig.h
└── TradingConfig.h
├── libs
├── avicenna
│ ├── AvicennaSuperPlus.h
│ ├── Definition.h
│ ├── Output.txt
│ ├── Sample.txt
│ ├── SuperPlusdata.txt
│ └── libAvicennaSuperPlus.so
└── redis
│ ├── anet.c
│ ├── anet.h
│ ├── fmacros.h
│ ├── libredisclient.a
│ └── redisclient.h
├── manager
├── CMakeLists.txt
├── SymbolManager.cpp
├── SymbolManager.h
├── TradeAccountManager.cpp
└── TradeAccountManager.h
├── redis
├── CMakeLists.txt
├── RedisWriter.cpp
└── RedisWriter.h
├── stem1.cpp
├── tests
├── CMakeLists.txt
├── order_sending.cpp
└── position_table.cpp
├── trade
├── AbstractTradeAccount.cpp
├── AbstractTradeAccount.h
├── AvicennaInterface.cpp~
├── AvicennaInterface.h~
├── CMakeLists.txt
├── CMakeLists.txt~
├── LongTradeAccount.cpp
├── LongTradeAccount.h
├── PositionRecordTable.h
├── STEMMaddogConnection.cpp~
├── ShortTradeAccount.cpp
├── ShortTradeAccount.h
├── TradeCase.cpp
├── TradeCase.h
├── TradeInstance.cpp
└── TradeInstance.h
└── utils
├── AsynchronousQueue.cpp
├── AsynchronousQueue.h
├── AsynchronousUnorderedMap.h
├── AsynchronousVector.h
├── CMakeLists.txt
├── ThreadPool.h
├── console.h
├── log.cpp
├── log.h
└── utils.h
/CMakeLists.txt:
--------------------------------------------------------------------------------
1 | CMAKE_MINIMUM_REQUIRED(VERSION 2.8)
2 |
3 |
4 | project(stem3)
5 |
6 | #set(CMAKE_INSTALL_PREFIX ${PROJECT_SOURCE_DIR}/install)
7 | message("-- installation directory ${CMAKE_INSTALL_PREFIX}")
8 |
9 |
10 | add_definitions(-std=c++11)
11 | add_definitions(-DBOOST_LOG_DYN_LINK=1)
12 | add_definitions(-DBOOST_TEST_DYN_LINK)
13 |
14 | set(CMAKE_VERBOSE_MAKEFILE 1)
15 |
16 | include_directories(${PROJECT_SOURCE_DIR}/src/libs/avicenna/)
17 | include_directories(${PROJECT_SOURCE_DIR}/src/libs/redis/)
18 | include_directories($ENV{AKELA_SDK_ROOT}/include/)
19 | include_directories(/home/jamil/workspace/boost_1_57_0/)
20 |
21 | message("-- linking akela library from ... $ENV{AKELA_SDK_ROOT}/lib")
22 | link_directories($ENV{AKELA_SDK_ROOT}/lib)
23 | message("-- linking avicenna library from ... ${PROJECT_SOURCE_DIR}/src/libs/avicenna")
24 | link_directories(${PROJECT_SOURCE_DIR}/src/libs/avicenna)
25 | message("-- linking redis library from ... ${PROJECT_SOURCE_DIR}/src/libs/redis")
26 | link_directories(${PROJECT_SOURCE_DIR}/src/libs/redis)
27 |
28 |
29 | add_subdirectory(src)
30 |
31 | install(DIRECTORY scripts/
32 | DESTINATION scripts
33 | FILES_MATCHING PATTERN "*.sh"
34 | PERMISSIONS OWNER_WRITE OWNER_READ OWNER_EXECUTE
35 | GROUP_WRITE GROUP_READ GROUP_EXECUTE
36 | WORLD_WRITE WORLD_READ WORLD_EXECUTE)
37 | install(DIRECTORY configs/
38 | DESTINATION configs/)
39 |
--------------------------------------------------------------------------------
/compile.sh:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 |
3 | syntax_msg () {
4 | echo "syntax: compile.sh build-directory target-directory";
5 | }
6 |
7 | if [ "$#" -ne 2 ]; then
8 | syntax_msg;
9 | exit 1;
10 | else
11 | echo "build directory "$1" specified";
12 | echo "target directory "$2" specified ";
13 |
14 | if [ -d $2 ]; then
15 | echo "Deleting target directory";
16 | rm -rf $2 && echo "target directory successfully deleted";
17 | fi
18 | fi
19 |
20 | if [ -d $1 ]; then
21 | echo "build directory already exist -- do you want to remove it? ";
22 | read user;
23 |
24 | case "$user" in
25 | yes|y|Y|YES)
26 | rm -rf "$1" && echo "$1 -- deleted successfully";
27 | mkdir "$1" && echo "creating new directory $1";
28 | ;;
29 |
30 | no|n|N|NO)
31 | ;;
32 |
33 | *)
34 | echo "exiting --> incorrect selection -- select yes|no|y|n|YES|NO";
35 | exit 1
36 | ;;
37 | esac
38 | else
39 | mkdir $1
40 | fi
41 |
42 |
43 |
44 | cd $1 && echo "changing directory to $1";
45 | cmake -DCMAKE_CXX_FLAGS=-pg -DCMAKE_INSTALL_PREFIX="../$2" -DCMAKE_BUILD_TYPE=Debug .. && make && make install && cd .. && tar cvzf "$2.tar.gz" $2;
46 |
47 | if [ "$?" -ne 0 ]; then
48 | echo "STEM compilation has failed -- exiting";
49 | exit 1;
50 | fi
51 |
52 |
--------------------------------------------------------------------------------
/configs/Direct.Bats.ini:
--------------------------------------------------------------------------------
1 | [Direct.Bats]
2 | Subject List = #FEED_BATS
3 | Service List = MulticastPitchfh
4 | Router Address = 127.0.0.1
5 | Debug Log = On
6 |
--------------------------------------------------------------------------------
/configs/Direct.Bats.ini~:
--------------------------------------------------------------------------------
1 | [Direct.Bats]
2 | Subject List = #FEED_BATS
3 | Service List = MulticastPitchfh
4 | Router Address = 127.0.0.1
5 |
--------------------------------------------------------------------------------
/configs/admin_config.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 20:30:00
4 | 20:30:00
5 | 20:30:00
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/configs/admin_config.xml~:
--------------------------------------------------------------------------------
1 |
2 |
3 | 13:45:00
4 | 14:45:00
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/configs/admin_config_server.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 20:30:00
4 | 20:30:00
5 | 20:30:00
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/configs/symbol_config_new.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
28 |
29 |
30 |
31 |
--------------------------------------------------------------------------------
/configs/symbol_config_new.xml~:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
24 |
25 |
26 |
27 |
--------------------------------------------------------------------------------
/configs/symbol_config_onlyC.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
24 |
25 |
26 |
27 |
--------------------------------------------------------------------------------
/configs/trading_config_new.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | user1
5 | user2
6 | 1
7 | 1
8 | 1
9 |
10 |
11 | 10
12 | 2
13 | 10.1.20.74
14 | false
15 | AAA
16 | ABB
17 | II
18 | EE
19 | BB
20 |
21 |
22 |
23 | 10
24 | 2
25 | 10.1.20.74
26 | false
27 | AAA
28 | ABB
29 | II
30 | EE
31 | BB
32 |
33 |
34 | 40
35 | 80
36 |
37 |
38 | XBowSIM
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
--------------------------------------------------------------------------------
/configs/trading_config_new.xml~:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | user1
6 | user_high_risk
7 | 1
8 | 1
9 | 1
10 | 10
11 | 2
12 | 10.1.20.74
13 | false
14 | AAA
15 | ABB
16 | II
17 | EE
18 | BB
19 |
20 |
21 | XBowSIM
22 | BAT
23 | ARCA
24 |
25 |
26 |
27 |
28 |
29 |
--------------------------------------------------------------------------------
/connect.sh:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 |
3 | ssh acm@172.25.172.52
4 |
--------------------------------------------------------------------------------
/copylog.sh:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 | if [ ! -d serverlogs ]; then
3 | echo "serverlogs directory doesn't exist -- creating one";
4 | mkdir serverlogs;
5 | fi
6 |
7 | #if [ $# -ne 1 ]; then
8 | # echo "must provide destination file name for serverlogs/{file-name}";
9 | # exit 1;
10 | #fi
11 |
12 |
13 | FN=`date +%Y%m%d-%H`.log
14 |
15 | scp acm@172.25.172.52:~/deploy/scripts/stem.log serverlogs/$FN
16 | if [ $? -eq 0 ]; then
17 | echo "file copied from server successfully";
18 | else
19 | echo "log copy from vpn has failed";
20 | exit 1;
21 | fi
22 |
23 | tar cvzf serverlogs/$1.tar.gz serverlogs/$FN;
24 |
--------------------------------------------------------------------------------
/deploy.sh:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 |
3 | scp deploy.tar.gz acm@172.25.172.52:~
4 |
--------------------------------------------------------------------------------
/run_stem.sh:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 | scripts/positiontoredis.sh -c -a
3 | rm core
4 | ulimit -c unlimited
5 | local/bin/stem 127.0.0.1 0 -s:configs/symbol_config_new.xml -t:configs/trading_config_new.xml -a:configs/admin_config.xml -v:TRACE
6 |
--------------------------------------------------------------------------------
/scripts/file.csv:
--------------------------------------------------------------------------------
1 | EQUITY,,user_high_risk,AA.BA,AA.BA,,,-400,,10.197000
2 | EQUITY,,user1,AA.BA,AA.BA,,,0,,10.174444
3 | kfsfksfj;skfj;askjfd
4 |
--------------------------------------------------------------------------------
/scripts/kill_stem.sh:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 | kill `ps -e|grep "stem"|cut -f1 -d' '`
3 |
--------------------------------------------------------------------------------
/scripts/line-0:
--------------------------------------------------------------------------------
1 | drwxrwxr-x 2 jamil jamil 4.0K دسمبر 28 17:14 .
2 | -rw-rw-r-- 1 jamil jamil 115 ستمبر 19 23:08 file.csv
3 | -rw-rw-r-- 1 jamil jamil 197 دسمبر 28 17:14 line-1
4 | -rwxrwxr-x 1 jamil jamil 3.6K نومبر 30 23:55 livestatssorted.sh
5 | -rwxrw-r-- 1 jamil jamil 1.2K دسمبر 28 16:47 log_processing.sh~
6 | -rw-rw-r-- 1 jamil jamil 0 دسمبر 28 15:20 readarray
7 | -rwxrwxr-x 1 jamil jamil 2.3K اكتوب 26 20:34 redistofile.sh
8 | -rwxr-xr-x 1 jamil jamil 222 نومبر 25 09:08 run_stem.sh
9 |
--------------------------------------------------------------------------------
/scripts/line-1:
--------------------------------------------------------------------------------
1 | total 60K
2 | drwxrwxr-x 15 jamil jamil 4.0K دسمبر 27 21:25 ..
3 | -rw-rw-r-- 1 jamil jamil 49 نومبر 25 08:15 kill_stem.sh
4 | -rwxrwxr-x 1 jamil jamil 2.7K دسمبر 11 19:38 livestats.sh
5 | -rwxrw-r-- 1 jamil jamil 1.2K دسمبر 28 16:48 log_processing.sh
6 | -rwxrwxr-x 1 jamil jamil 2.0K ستمبر 30 19:00 positiontoredis.sh
7 | -rw-rw-r-- 1 jamil jamil 388 ستمبر 20 00:00 redisfile.csv
8 | -rw-r--r-- 1 jamil jamil 187 ستمبر 28 18:52 run_stem_for_server.sh
9 | -rw-r--r-- 1 jamil jamil 176 ستمبر 20 04:03 run_stem.sh~
10 |
--------------------------------------------------------------------------------
/scripts/livestats.sh:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 | trap ctrl_c INT
3 | idtoexit=0
4 | tput civis -- invisible
5 | function ctrl_c() {
6 | # echo "** Trapped CTRL-C"
7 | echo "Exiting ..."
8 | tput cnorm -- normal
9 | kill $idtoexit
10 | exit
11 | }
12 |
13 | positionRecords (){
14 | #echo $1
15 | #echo $2
16 | #clear
17 | tput reset
18 | #positionRecordsNum="$(echo 'LRANGE '$1';'$2' 0 -1' | redis-cli -h $ip -p $port)"
19 | #echo $positionRecordsNum
20 | echo 'average_at_open,open_order_id,open_price,open_size,average_at_close,close_order_id,close_price,close_size,pnl,sign,is_complete'
21 | echo $1
22 | echo 'LRANGE '$1';'$2' 0 -1' | redis-cli -h $ip -p $port
23 | echo ""
24 | echo $3
25 | echo 'LRANGE '$3';'$2' 0 -1' | redis-cli -h $ip -p $port
26 | sleep 4
27 | #for i in {1..71}
28 | #do
29 | #printf "\033[A"
30 | #done
31 | #tput cup 0 0
32 | }
33 |
34 | statsOrders ()
35 | {
36 | rediskeys="$(echo keys ''$user1',*' | redis-cli -h $ip -p $port)" #| wc -l
37 |
38 | # first user
39 | #echo ' '
40 | #echo ' '
41 | echo ' '$user1': '
42 | IFS=' ' read -r -a array <<< "$rediskeys"
43 | #echo 'keys '$user',*' | redis-cli -h $ip -p $port| sed 's/^/get /' | redis-cli -h $ip -p $port
44 | #for i in "${rediskeys[@]}"; do
45 | #echo ''$i' \n'
46 | #done
47 | stringarray=($rediskeys)
48 | for i in "${stringarray[@]}"
49 | do
50 | #echo ''$i' \n'
51 | redisVal="$(echo get ''$i'' | redis-cli -h $ip -p $port)"
52 | #echo ''$i' '$redisVal''
53 | IFS=',' read -r -a splitarray <<< "$redisVal"
54 | if [ -z "${splitarray[4]}" ] && [ -z "${splitarray[7]}" ] && [ "${splitarray[0]}" == "$redissymbol" ]
55 | then
56 | #echo ${splitarray[4]}
57 | echo ' '$redisVal''
58 | #read input
59 | fi
60 | #echo ' '
61 | done
62 | # ......................................
63 |
64 |
65 | #second user
66 | rediskeys2="$(echo keys ''$user2',*' | redis-cli -h $ip -p $port)"
67 | #echo ' '
68 | #echo ' '
69 | echo ' '$user2': '
70 | IFS=' ' read -r -a array2 <<< "$rediskeys2"
71 | stringarray2=($rediskeys2)
72 | for i in "${stringarray2[@]}"
73 | do
74 | redisVal2="$(echo get ''$i'' | redis-cli -h $ip -p $port)"
75 | IFS=',' read -r -a splitarray2 <<< "$redisVal2"
76 | if [ -z "${splitarray2[4]}" ] && [ -z "${splitarray2[7]}" ] && [ "${splitarray2[0]}" == "$redissymbol" ]
77 | then
78 | echo ' '$redisVal2''
79 | fi
80 | done
81 | echo ' '
82 | # ......................................
83 | }
84 |
85 | stats ()
86 | {
87 | #symbols list detection
88 | if [ "$enable_auto_symbol_list" = true ] ; then
89 | #for auto symbol list
90 | keys1="$(echo keys ''$user1':*' | redis-cli -h $ip -p $port)"
91 | keys2="$(echo keys ''$user2':*' | redis-cli -h $ip -p $port)"
92 | #echo 'account 1 keys :: '$keys1''
93 | #echo 'account 2 keys :: '$keys2''
94 | temp1="$(echo $keys1 | sed 's/'$user1'://g')"
95 | temp2="$(echo $keys2 | sed 's/'$user2'://g')"
96 | temp3=''$temp1' '$temp2''
97 | #echo $temp1
98 | #echo $temp2
99 | #echo 'joining list'
100 | #echo $temp3
101 |
102 | #echo 'sorting list'
103 | IFS=' ' read -ra KEYLIST <<< "$temp3"
104 | sorted_unique_ids=$(echo "${KEYLIST[@]}" | tr ' ' '\n' | sort -u | tr '\n' ',')
105 | #echo $sorted_unique_ids
106 | last="$(echo "${sorted_unique_ids: -1}")"
107 | #echo $last
108 | if [ "$last" == "," ]; then
109 | #sorted_unique_ids=${sorted_unique_ids::-1}
110 | size=${#sorted_unique_ids}
111 | size=$((size-1))
112 | #echo ${sorted_unique_ids:0:$size}
113 | symbollist="$(echo ${sorted_unique_ids:0:$size})"
114 | fi
115 | #echo 'symbol list '$symbollist''
116 | #read input_variable
117 | #for auto symbol list
118 | fi
119 | #symbols list detection
120 |
121 | IFS=',' read -ra ADDR <<< "$symbollist"
122 | for i in "${ADDR[@]}"; do
123 | val1="$(echo get ''$user1':'${i}'' | redis-cli -h $ip -p $port)"
124 | #val1=get ''$user1':'${i}'' | redis-cli -h $ip -p $port
125 | val2="$(echo get ''$user2':'${i}'' | redis-cli -h $ip -p $port)"
126 | val3="$(echo LRANGE ''$pair'#'${i}'' -1 -1 | redis-cli -h $ip -p $port)"
127 | IFS=',' read -r -a array <<< "$val1"
128 | IFS=',' read -r -a array2 <<< "$val2"
129 | IFS=',' read -r -a array3 <<< "$val3"
130 | if [ -z "${array[12]}" ]
131 | then
132 | array[12]=0
133 | fi
134 | if [ -z "${array[13]}" ]
135 | then
136 | array[13]=0
137 | fi
138 | if [ -z "${array2[12]}" ]
139 | then
140 | array2[12]=0
141 | fi
142 | if [ -z "${array2[13]}" ]
143 | then
144 | array2[13]=0
145 | fi
146 | if [ -z "${array[14]}" ]
147 | then
148 | array[14]=0
149 | fi
150 | if [ -z "${array2[14]}" ]
151 | then
152 | array2[14]=0
153 | fi
154 | if [ -z "${array[7]}" ]
155 | then
156 | array[7]=0
157 | fi
158 | if [ -z "${array[9]}" ]
159 | then
160 | array[9]=0.0000
161 | fi
162 | if [ -z "${array2[7]}" ]
163 | then
164 | array2[7]=0
165 | fi
166 | if [ -z "${array2[9]}" ]
167 | then
168 | array2[9]=0.0000
169 | fi
170 | if [ "${array3[1]}" == "TRIGGER_STATE_POSITIVE" ]
171 | then
172 | sign="+ve"
173 | elif [ "${array3[1]}" == "TRIGGER_STATE_NEGATIVE" ]
174 | then
175 | sign="-ve"
176 | else
177 | sign=" "
178 | fi
179 | #totallive1=0
180 | #else
181 | totallive1=`expr ${array[12]} + ${array[13]}`
182 | #fi
183 | totallive2=`expr ${array2[12]} + ${array2[13]}`
184 | symbollength=${#i}
185 | if [ $symbollength -eq 2 ]
186 | then
187 | i=$i' '
188 | fi
189 | echo ''$pair'('$user1'-'$user2')::'${i}':'${sign}','${array3[2]}'('${array3[3]}','${array3[4]}','${array3[5]}','${array3[6]}','${array3[7]}') '${array[7]}','${array[9]}','${array[12]}','${array[13]}','$totallive1','${array[14]}' : '${array2[7]}','${array2[9]}','${array2[12]}','${array2[13]}','$totallive2','${array2[14]}' '
190 | if [ "${i}" == "${redissymbol}" ] && [ $1 = true ]
191 | then
192 | statsOrders
193 | fi
194 | done
195 | #date
196 | #echo 2*$i
197 | #i=$((i+1))
198 | IFS=',' read -ra APPR <<< "$symbollist"
199 | for i in "${APPR[@]}"; do
200 | printf "\033[A"
201 |
202 | done
203 | sleep 0.5
204 | #printf "\033[A"
205 | #printf "\033[A"
206 | tput cup 3 0
207 | #read input_variable
208 | } # Function declaration must precede call.
209 |
210 | clear
211 | ip="127.0.0.1"
212 | port=6379
213 | pair=$1
214 | user1=$2
215 | user2=$3
216 | symbollist=$4
217 | enable_auto_symbol_list=true
218 | echo "Pair '$pair'"
219 | echo "Account 1 '$user1'"
220 | echo "Account 2 '$user2'"
221 | symbolcount=0
222 | redissymbol=""
223 |
224 | status="normal"
225 | if [ $# -lt 3 ]; then
226 | echo 'Help'
227 | echo "Usage: $0 PairName Account1 Account2"
228 | echo "To switch to detailed live order mode press S"
229 | echo "Enter the name of the symbol and press enter"
230 | echo "To switch back to normal mode press B"
231 | echo "To switch symbol in detailed live order mode press V"
232 | exit
233 | fi
234 |
235 | while true;
236 | do
237 |
238 |
239 | case $status in
240 | normal)
241 | #echo "in false"
242 |
243 | clear
244 | echo "Pair '$pair'"
245 | echo "Account 1 '$user1'"
246 | echo "Account 2 '$user2'"
247 |
248 | while [ 1 ]
249 | do
250 | stats false
251 | done &
252 |
253 | main=$!
254 | #echo "# main is $main" >&2
255 | idtoexit=$main
256 |
257 | # livinfree's neat dd trick from that other thread vino pointed out
258 | #tput smso
259 | #echo "Press any key to return \c"
260 | #tput rmso
261 | result=""
262 | while [ "$result" != "s" ] && [ "$result" != "p" ];
263 | do
264 | oldstty=`stty -g`
265 | stty -icanon -echo min 1 time 0
266 | result=`dd bs=1 count=1 2>/dev/null`
267 | stty "$oldstty"
268 | #echo $result
269 | done
270 | #/home/akela/Desktop/new.sh $main
271 | kill $main
272 | wait $main 2>/dev/null
273 |
274 |
275 |
276 | if [ "$result" == "s" ]
277 | then
278 | status="symbol"
279 | fi
280 |
281 | if [ "$result" == "p" ]
282 | then
283 | status="positionRecord"
284 | fi
285 | ;;
286 |
287 |
288 |
289 |
290 |
291 | symbol)
292 | #echo "in true"
293 | clear
294 | echo "Enter the symbol:"
295 | read str
296 | redissymbol="$(echo "${str^^}")"
297 | echo 'Symbol read is:'$redissymbol''
298 | clear
299 | echo "Pair '$pair'"
300 | echo "Account 1 '$user1'"
301 | echo "Account 2 '$user2'"
302 |
303 |
304 | while : ; do
305 | stats true
306 | done &
307 |
308 | main2=$!
309 | #echo "# main is $main2" >&2
310 | idtoexit=$main2
311 |
312 | # livinfree's neat dd trick from that other thread vino pointed out
313 | #tput smso
314 | #echo "Press any key to return \c"
315 | #tput rmso
316 | result2=""
317 | while [ "$result2" != "b" ] && [ "$result2" != "r" ];
318 | do
319 | oldstty=`stty -g`
320 | stty -icanon -echo min 1 time 0
321 | result2=`dd bs=1 count=1 2>/dev/null`
322 | stty "$oldstty"
323 | #echo $result2
324 | done
325 |
326 | kill $main2
327 | wait $main2 2>/dev/null
328 |
329 |
330 | if [ "$result2" == "b" ]
331 | then
332 | status="normal"
333 | fi
334 | if [ "$result2" == "r" ]
335 | then
336 | status="symbol"
337 | fi
338 | ;;
339 | orange|tangerine)
340 | echo $'Eeeks! I don\'t like those!\nGo away!'
341 | exit 1
342 | ;;
343 | positionRecord)
344 | clear
345 | #echo "Enter the user:"
346 | #read pos_acc
347 | echo "Enter the symbol:"
348 | read pos_sym
349 | Capitalized_pos_sym="$(echo "${pos_sym^^}")"
350 | while : ; do
351 | positionRecords $user1 $Capitalized_pos_sym $user2
352 | done &
353 |
354 | main3=$!
355 | #echo "# main is $main3" >&2
356 | idtoexit=$main3
357 |
358 | result3=""
359 | while [ "$result3" != "b" ] && [ "$result3" != "r" ];
360 | do
361 | oldstty=`stty -g`
362 | stty -icanon -echo min 1 time 0
363 | result3=`dd bs=1 count=1 2>/dev/null`
364 | stty "$oldstty"
365 | #echo $result
366 | done
367 | #/home/akela/Desktop/new.sh $main3
368 | kill $main3
369 | wait $main3 2>/dev/null
370 | if [ "$result3" == "b" ]
371 | then
372 | status="normal"
373 | fi
374 | if [ "$result3" == "r" ]
375 | then
376 | status="positionRecord"
377 | fi
378 | ;;
379 | *)
380 | echo "Unknown Command?"
381 | esac
382 |
383 | done
384 |
--------------------------------------------------------------------------------
/scripts/livestatsold.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 | clear
3 | tput civis -- invisible
4 |
5 | # trap ctrl-c and call ctrl_c()
6 | trap ctrl_c INT
7 |
8 | function ctrl_c() {
9 | # echo "** Trapped CTRL-C"
10 | echo "Exiting ..."
11 | tput cnorm -- normal
12 | exit
13 | }
14 | ip="127.0.0.1"
15 | port=6379
16 | pair=$1
17 | user1=$2
18 | user2=$3
19 | symbollist=$4
20 | enable_auto_symbol_list=true
21 | echo "Account 1 '$user1'"
22 | echo "Account 2 '$user2'"
23 | symbolcount=0
24 | IFS=',' read -ra ADDR <<< "$symbollist"
25 | for i in "${ADDR[@]}"; do
26 | echo 'symbol '${i}''
27 | symbolcount=$((symbolcount+1))
28 | done
29 | echo 'symbol count '${symbolcount}''
30 |
31 |
32 | while [ 1 ]
33 | do
34 | #symbols list detection
35 | if [ "$enable_auto_symbol_list" = true ] ; then
36 | #for auto symbol list
37 | keys1="$(echo keys ''$user1':*' | redis-cli -h $ip -p $port)"
38 | keys2="$(echo keys ''$user2':*' | redis-cli -h $ip -p $port)"
39 | #echo 'account 1 keys :: '$keys1''
40 | #echo 'account 2 keys :: '$keys2''
41 | temp1="$(echo $keys1 | sed 's/'$user1'://g')"
42 | temp2="$(echo $keys2 | sed 's/'$user2'://g')"
43 | temp3=''$temp1' '$temp2''
44 | #echo $temp1
45 | #echo $temp2
46 | #echo 'joining list'
47 | #echo $temp3
48 |
49 | #echo 'sorting list'
50 | IFS=' ' read -ra KEYLIST <<< "$temp3"
51 | sorted_unique_ids=$(echo "${KEYLIST[@]}" | tr ' ' '\n' | sort -u | tr '\n' ',')
52 | #echo $sorted_unique_ids
53 | last="$(echo "${sorted_unique_ids: -1}")"
54 | #echo $last
55 | if [ "$last" == "," ]; then
56 | #sorted_unique_ids=${sorted_unique_ids::-1}
57 | size=${#sorted_unique_ids}
58 | size=$((size-1))
59 | #echo ${sorted_unique_ids:0:$size}
60 | symbollist="$(echo ${sorted_unique_ids:0:$size})"
61 | fi
62 | #echo 'symbol list '$symbollist''
63 | #read input_variable
64 | #for auto symbol list
65 | fi
66 | #symbols list detection
67 |
68 | IFS=',' read -ra ADDR <<< "$symbollist"
69 | for i in "${ADDR[@]}"; do
70 | val1="$(echo get ''$user1':'${i}'' | redis-cli -h $ip -p $port)"
71 | #val1=get ''$user1':'${i}'' | redis-cli -h $ip -p $port
72 | val2="$(echo get ''$user2':'${i}'' | redis-cli -h $ip -p $port)"
73 | val3="$(echo LRANGE ''$pair'#'${i}'' -1 -1 | redis-cli -h $ip -p $port)"
74 | IFS=',' read -r -a array <<< "$val1"
75 | IFS=',' read -r -a array2 <<< "$val2"
76 | IFS=',' read -r -a array3 <<< "$val3"
77 | if [ -z "${array[12]}" ]
78 | then
79 | array[12]=0
80 | fi
81 | if [ -z "${array[13]}" ]
82 | then
83 | array[13]=0
84 | fi
85 | if [ -z "${array2[12]}" ]
86 | then
87 | array2[12]=0
88 | fi
89 | if [ -z "${array2[13]}" ]
90 | then
91 | array2[13]=0
92 | fi
93 | if [ -z "${array[14]}" ]
94 | then
95 | array[14]=0
96 | fi
97 | if [ -z "${array2[14]}" ]
98 | then
99 | array2[14]=0
100 | fi
101 | if [ -z "${array[7]}" ]
102 | then
103 | array[7]=0
104 | fi
105 | if [ -z "${array[9]}" ]
106 | then
107 | array[9]=0.0000
108 | fi
109 | if [ -z "${array2[7]}" ]
110 | then
111 | array2[7]=0
112 | fi
113 | if [ -z "${array2[9]}" ]
114 | then
115 | array2[9]=0.0000
116 | fi
117 | if [ "${array3[1]}" == "TRIGGER_STATE_POSITIVE" ]
118 | then
119 | sign="+ve"
120 | elif [ "${array3[1]}" == "TRIGGER_STATE_NEGATIVE" ]
121 | then
122 | sign="-ve"
123 | else
124 | sign=" "
125 | fi
126 | #totallive1=0
127 | #else
128 | totallive1=`expr ${array[12]} + ${array[13]}`
129 | #fi
130 | totallive2=`expr ${array2[12]} + ${array2[13]}`
131 | symbollength=${#i}
132 | if [ $symbollength -eq 2 ]
133 | then
134 | i=$i' '
135 | fi
136 | echo ''$pair'('$user1'-'$user2')::'${i}':'${sign}','${array3[2]}' '${array[7]}','${array[9]}','${array[12]}','${array[13]}','$totallive1','${array[14]}' : '${array2[7]}','${array2[9]}','${array2[12]}','${array2[13]}','$totallive2','${array2[14]}' '
137 | done
138 | #date
139 | #echo 2*$i
140 | #i=$((i+1))
141 | IFS=',' read -ra APPR <<< "$symbollist"
142 | for i in "${APPR[@]}"; do
143 | printf "\033[A"
144 |
145 | done
146 | sleep 0.5
147 | #printf "\033[A"
148 | #printf "\033[A"
149 | tput cup 3 0
150 | #read input_variable
151 | done
152 |
153 | tput cnorm -- normal
154 |
--------------------------------------------------------------------------------
/scripts/livestatssorted.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 |
3 | tput civis -- invisible
4 |
5 | # trap ctrl-c and call ctrl_c()
6 | trap ctrl_c INT
7 | trap stp QUIT
8 | enable_output=true
9 | function ctrl_c() {
10 | # echo "** Trapped CTRL-C"
11 | echo ""
12 | tput cnorm -- normal
13 | exit
14 | }
15 |
16 | function stp() {
17 | echo "** Trapped CTRL-"
18 | echo ""
19 | clear
20 | tput cnorm -- normal
21 | #exit
22 | }
23 | indexselect=1
24 |
25 | ip="127.0.0.1"
26 | port=6379
27 | user1=$1
28 | user2=$2
29 | #symbollist=$3
30 | userselect=$3
31 | indexselect=$4
32 |
33 | if [ $indexselect -eq 1 ]; then
34 | indexselect=12
35 | fi
36 |
37 | if [ $indexselect -eq 2 ]; then
38 | indexselect=13
39 | fi
40 |
41 | if [ $indexselect -eq 4 ]; then
42 | indexselect=14
43 | fi
44 |
45 | enable_auto_symbol_list=true
46 | echo "Account 1 '$user1'"
47 | echo "Account 2 '$user2'"
48 | symbolcount=0
49 | IFS=',' read -ra ADDR <<< "$symbollist"
50 | for i in "${ADDR[@]}"; do
51 | echo 'symbol '${i}''
52 | symbolcount=$((symbolcount+1))
53 | done
54 | echo 'symbol count '${symbolcount}''
55 |
56 | while [ 1 ]
57 | do
58 | #symbols list detection
59 |
60 | if [ "$enable_auto_symbol_list" = true ] ; then
61 | #for auto symbol list
62 | keys1="$(echo keys ''$user1':*' | redis-cli -h $ip -p $port)"
63 | keys2="$(echo keys ''$user2':*' | redis-cli -h $ip -p $port)"
64 | #echo 'account 1 keys :: '$keys1''
65 | #echo 'account 2 keys :: '$keys2''
66 | temp1="$(echo $keys1 | sed 's/'$user1'://g')"
67 | temp2="$(echo $keys2 | sed 's/'$user2'://g')"
68 | temp3=''$temp1' '$temp2''
69 | #echo $temp1
70 | #echo $temp2
71 | #echo 'joining list'
72 | #echo $temp3
73 |
74 | #echo 'sorting list'
75 | IFS=' ' read -ra KEYLIST <<< "$temp3"
76 | sorted_unique_ids=$(echo "${KEYLIST[@]}" | tr ' ' '\n' | sort -u | tr '\n' ',')
77 | #echo $sorted_unique_ids
78 | last="$(echo "${sorted_unique_ids: -1}")"
79 | #echo $last
80 | if [ "$last" == "," ]; then
81 | #sorted_unique_ids=${sorted_unique_ids::-1}
82 | size=${#sorted_unique_ids}
83 | size=$((size-1))
84 | #echo ${sorted_unique_ids:0:$size}
85 | symbollist="$(echo ${sorted_unique_ids:0:$size})"
86 | fi
87 | #echo 'symbol list '$symbollist''
88 | #read input_variable
89 | #for auto symbol list
90 | fi
91 | #symbol list detection
92 |
93 |
94 | #added for sorting
95 | IFS=',' read -ra SYM <<< "$symbollist"
96 | declare -A hashmap
97 | for j in "${SYM[@]}"; do
98 | readvalue="$(echo get ''$userselect':'${j}'' | redis-cli -h $ip -p $port)"
99 | IFS=',' read -ra READSTR <<< "$readvalue"
100 | hashmap[${j}]=${READSTR[$indexselect]}
101 |
102 | if [ $indexselect -eq 3 ]; then
103 | hashmap[${j}]=$((${READSTR[12]}+${READSTR[13]}))
104 | fi
105 |
106 | done
107 |
108 |
109 | val="$(for k in "${!hashmap[@]}"
110 | do
111 | echo $k '#' ${hashmap["$k"]}';'
112 | done |
113 | sort -rn -k3)"
114 | #echo $val
115 | some_variable="$( echo "$val" | sed 's/.#.*;//g' )"
116 | #echo $some_variable
117 | symbollist="$( echo "$some_variable" | tr '\n' ',' )"
118 | #echo 'final:'${symbollist}
119 | #read input_variable
120 | #added for sorting
121 | IFS=',' read -ra ADDR <<< "$symbollist"
122 | for i in "${ADDR[@]}"; do
123 | val1="$(echo get ''$user1':'${i}'' | redis-cli -h $ip -p $port)"
124 | #val1=get ''$user1':'${i}'' | redis-cli -h $ip -p $port
125 | val2="$(echo get ''$user2':'${i}'' | redis-cli -h $ip -p $port)"
126 | IFS=',' read -r -a array <<< "$val1"
127 | IFS=',' read -r -a array2 <<< "$val2"
128 | if [ -z "${array[12]}" ]
129 | then
130 | array[12]=0
131 | fi
132 | if [ -z "${array[13]}" ]
133 | then
134 | array[13]=0
135 | fi
136 | if [ -z "${array2[12]}" ]
137 | then
138 | array2[12]=0
139 | fi
140 | if [ -z "${array2[13]}" ]
141 | then
142 | array2[13]=0
143 | fi
144 | if [ -z "${array[14]}" ]
145 | then
146 | array[14]=0
147 | fi
148 | if [ -z "${array2[14]}" ]
149 | then
150 | array2[14]=0
151 | fi
152 | #totallive1=0
153 | #else
154 | totallive1=`expr ${array[12]} + ${array[13]}`
155 | #fi
156 | totallive2=`expr ${array2[12]} + ${array2[13]}`
157 | echo ''$user1'-'$user2' :: '${i}' :'${array[12]}','${array[13]}','$totallive1','${array[14]}' : '${array2[12]}','${array2[13]}','$totallive2','${array2[14]}' '
158 | done
159 | #date
160 | #echo 2*$i
161 | #i=$((i+1))
162 | IFS=',' read -ra APPR <<< "$symbollist"
163 | for i in "${APPR[@]}"; do
164 | printf "\033[A"
165 |
166 | done
167 | sleep 0.5
168 | #printf "\033[A"
169 | #printf "\033[A"
170 | #read input_variable
171 | done
172 |
173 | tput cnorm -- normal
174 |
--------------------------------------------------------------------------------
/scripts/log_processing.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 |
3 |
4 |
5 | echo "Starting log $1 processing -- please wait"
6 |
7 | oddstat(){
8 |
9 | file=$3
10 | grep -E "$1.*OnOrder" $2 > $file
11 | lines=`cut -d" " -f9 $file`
12 |
13 | total=0
14 | canceled=0
15 | changed=0
16 | error=0
17 | executed=0
18 |
19 | for i in $lines; do
20 | case $i in
21 | 0)
22 | total=$(($total+1));
23 | ;;
24 | 3)
25 | executed=$(($executed+1));
26 | ;;
27 | 4)
28 | canceled=$(($canceled+1));
29 | ;;
30 | 16)
31 | changed=$(($changed+1));
32 | ;;
33 | 233|255|245)
34 | error=$(($error+1));
35 | ;;
36 | esac
37 | done
38 |
39 | echo "Order Info($1): Sent: $total Executed: $executed Canceled: $canceled Changed: $changed Error: $error"
40 |
41 | }
42 |
43 | oddexec(){
44 | exec_file=`echo $1|sed 's/file/exec/g'`
45 | cat $1|sed "s/\]\[/ /g" |cut -d" " -f2,9-|sort -k 2 > $exec_file
46 |
47 | orders=( `cat $exec_file|cut -d" " -f2|uniq -c` )
48 |
49 | i="1";
50 | size=${#orders[@]}
51 | #echo $size $exec_file
52 | while [ $i -lt $size ]; do
53 | nrecords=${orders[$i-1]};
54 | id="${orders[$i]}"
55 | order_info=( `grep "$id" $exec_file` )
56 | j="0";
57 |
58 | declare -a order_status
59 | price="${order_info[3]}"
60 | quantity="${order_info[4]}"
61 | acc_type=$2
62 | case "${order_info[5]}" in
63 | 0)
64 | type="BUY"
65 | ;;
66 | 1)
67 | type="SEL"
68 | ;;
69 | 4)
70 | type="SSL"
71 | ;;
72 | *)
73 | type="ERR"
74 | ;;
75 | esac
76 |
77 |
78 | ack="00:00:00.000000"
79 | rec="00:00:00.000000";
80 | exe="00:00:00.000000";
81 | canc="00:00:00.000000";
82 | chan="00:00:00.000000";
83 | err="00:00:00.000000";
84 | othr="00:00:00.000000";
85 | while [ $j -lt $nrecords ]; do
86 | time="${order_info[$(($j*6+0))]}"
87 | status="${order_info[$(($j*6+2))]}"
88 |
89 | case $status in
90 | 10)
91 | ack=$time
92 | ;;
93 | 0)
94 | rec=$time
95 | ;;
96 | 3)
97 | exe=$time
98 | ;;
99 | 4)
100 | canc=$time
101 | ;;
102 | 16)
103 | chan=$time
104 | ;;
105 | 255|245|233)
106 | err=$time
107 | ack=$time
108 | ;;
109 | *)
110 | othr=$time
111 | ;;
112 | esac
113 | j=$(($j+1))
114 | done
115 | echo -e $ack $id $acc_type $price $quantity $type $rec $exe $canc $chan $err
116 | i=$(($i+2))
117 | done
118 |
119 | }
120 |
121 | triginfo(){
122 | #grep "TRIGGER CHANGED" $1|sed "s/\]\[/ /g"|awk '/\,\+\,/ {print $2 " POS"} /,-,/ {print $2 " NEG"}'
123 | #grep "selecting case" $1|sed "s/\]\[/ /g"|cut -d" " -f2
124 | grep "selecting case" $1|sed "s/\]\[/ /g"|awk '/\,\+\,/ {print $2 " POS " $NF} /\,\-\,/ {print $2 " NEG " $NF}'
125 | }
126 |
127 | sfile="/tmp/short-file.log" #temporary file to store short order records
128 | lfile="/tmp/long-file.log" #temporary file to store short order records
129 |
130 | oddstat short $1 $sfile
131 | oddstat long $1 $lfile
132 |
133 | oddexec $sfile short
134 | oddexec $lfile long
135 |
136 | triginfo $1
137 |
--------------------------------------------------------------------------------
/scripts/log_processing.sh~:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 |
3 |
4 |
5 | echo "Starting log $1 processing -- please wait"
6 |
7 | oddstat(){
8 |
9 | file=$3
10 | grep -E "$1.*OnOrder" $2 > $file
11 | lines=`cut -d" " -f9 $file`
12 |
13 | total=0
14 | canceled=0
15 | changed=0
16 | error=0
17 | executed=0
18 |
19 | for i in $lines; do
20 | case $i in
21 | 0)
22 | total=$(($total+1));
23 | ;;
24 | 3)
25 | executed=$(($executed+1));
26 | ;;
27 | 4)
28 | canceled=$(($canceled+1));
29 | ;;
30 | 16)
31 | changed=$(($changed+1));
32 | ;;
33 | 233|255|245)
34 | error=$(($error+1));
35 | ;;
36 | esac
37 | done
38 |
39 | echo "Order Info($1): Sent: $total Executed: $executed Canceled: $canceled Changed: $changed Error: $error"
40 |
41 | }
42 |
43 | oddexec(){
44 | exec_file=`echo $1|sed 's/file/exec/g'`
45 | cat $1|sed "s/\]\[/ /g" |cut -d" " -f2,9-|sort -k 2 > $exec_file
46 |
47 | orders=( `cat $exec_file|cut -d" " -f2|uniq -c` )
48 |
49 | i="1";
50 | size=${#orders[@]}
51 | #echo $size $exec_file
52 | while [ $i -lt $size ]; do
53 | nrecords=${orders[$i-1]};
54 | id="${orders[$i]}"
55 | order_info=( `grep "$id" $exec_file` )
56 | j="0";
57 |
58 | declare -a order_status
59 | price="${order_info[3]}"
60 | quantity="${order_info[4]}"
61 | acc_type=$2
62 | case "${order_info[5]}" in
63 | 0)
64 | type="BUY"
65 | ;;
66 | 1)
67 | type="SEL"
68 | ;;
69 | 4)
70 | type="SSL"
71 | ;;
72 | *)
73 | type="ERR"
74 | ;;
75 | esac
76 |
77 |
78 | ack="00:00:00.000000"
79 | rec="00:00:00.000000";
80 | exe="00:00:00.000000";
81 | canc="00:00:00.000000";
82 | chan="00:00:00.000000";
83 | err="00:00:00.000000";
84 | othr="00:00:00.000000";
85 | while [ $j -lt $nrecords ]; do
86 | time="${order_info[$(($j*6+0))]}"
87 | status="${order_info[$(($j*6+2))]}"
88 |
89 | case $status in
90 | 10)
91 | ack=$time
92 | ;;
93 | 0)
94 | rec=$time
95 | ;;
96 | 3)
97 | exe=$time
98 | ;;
99 | 4)
100 | canc=$time
101 | ;;
102 | 16)
103 | chan=$time
104 | ;;
105 | 255|245|233)
106 | err=$time
107 | ;;
108 | *)
109 | othr=$time
110 | ;;
111 | esac
112 | j=$(($j+1))
113 | done
114 | echo -e $ack $id $acc_type $price $quantity $type $rec $exe $canc $chan $err
115 | i=$(($i+2))
116 | done
117 |
118 | }
119 |
120 | triginfo(){
121 | #grep "TRIGGER CHANGED" $1|sed "s/\]\[/ /g"|awk '/\,\+\,/ {print $2 " POS"} /,-,/ {print $2 " NEG"}'
122 | #grep "selecting case" $1|sed "s/\]\[/ /g"|cut -d" " -f2
123 | grep "selecting case" $1|sed "s/\]\[/ /g"|awk '/\,\+\,/ {print $2 " POS " $NF} /\,\-\,/ {print $2 " NEG " $NF}'
124 | }
125 |
126 | sfile="/tmp/short-file.log" #temporary file to store short order records
127 | lfile="/tmp/long-file.log" #temporary file to store short order records
128 |
129 | oddstat short $1 $sfile
130 | oddstat long $1 $lfile
131 |
132 | oddexec $sfile short
133 | oddexec $lfile long
134 |
135 | triginfo $1
136 |
--------------------------------------------------------------------------------
/scripts/order_processing.awk:
--------------------------------------------------------------------------------
1 | BEGIN {print $1 "\t" $3}
2 |
--------------------------------------------------------------------------------
/scripts/positiontoredis.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 |
3 | if [ $# -eq 0 ]; then
4 | echo "Usage: $0 "
5 | echo "-c [comma seperated list of symbols to clear entries from redis]"
6 | echo "-f [filepath to read values from file to redis]"
7 | exit
8 | fi
9 |
10 | # A POSIX variable
11 | OPTIND=1 # Reset in case getopts has been used previously in the shell.
12 |
13 | # Initialize our own variables:
14 | input_file=""
15 | isclear=0
16 | isall=0
17 | clear_vr=""
18 | ip="127.0.0.1"
19 | port=6379
20 | while getopts "h?c:i:p:f:" opt; do
21 | case "$opt" in
22 | help|\?)
23 | echo "Usage: $0 -c -f -i -p"
24 | echo "-f filepath containing positions"
25 | echo "-c to clear positions of certain symbols from redis eg AAPL,AAB"
26 | echo "-c -a to clear positions of all symbols from redis "
27 | echo "-i ip [optional default 6379]"
28 | echo "-p port [optional default 127.0.0.1]"
29 | exit 0
30 | ;;
31 | c) clear_vr=$OPTARG
32 | isclear=1
33 | ;;
34 | f) input_file=$OPTARG
35 | ;;
36 | a) isall=1
37 | ;;
38 | i) ip=$OPTARG
39 | ;;
40 | p) port=$OPTARG
41 | ;;
42 | esac
43 | done
44 |
45 | shift $((OPTIND-1))
46 |
47 | [ "$1" = "--" ] && shift
48 |
49 | echo "clear=$isclear,clear_vr=$clear_vr, all=$isall, input_file='$input_file' ,ip='$ip',port='$port'"
50 |
51 | if [ "$isclear" = 1 ]; then
52 |
53 | if [ "$clear_vr" = "-a" ]; then
54 | echo "Deleting all positions in redis "
55 | echo 'keys *:*' | redis-cli -h $ip -p $port| sed 's/^/del /' | redis-cli -h $ip -p $port #clears positions
56 | echo 'keys *,*' | redis-cli -h $ip -p $port| sed 's/^/del /' | redis-cli -h $ip -p $port #clears order info
57 | echo 'keys *#*' | redis-cli -h $ip -p $port| sed 's/^/del /' | redis-cli -h $ip -p $port #clears trade case info
58 | else
59 | echo "Deleting symbol list $clear_vr"
60 | IFS=',' read -ra ADDR <<< "$clear_vr"
61 | for i in "${ADDR[@]}"; do
62 | echo 'keys *:'$i'' | redis-cli -h $ip -p $port| sed 's/^/del /' | redis-cli -h $ip -p $port
63 | #echo "$i"
64 | done
65 |
66 | fi
67 | exit
68 | fi
69 |
70 | if [ -z "$input_file" ]
71 | then
72 | echo "input file path is null."
73 | else
74 | #echo "'$input_file' is NOT null."
75 | while IFS= read -r line; do
76 | echo "Reading line : $line"
77 | IFS=', ' read -r -a array <<< "$line"
78 | echo "User : ${array[2]}"
79 | echo "Symbol: ${array[3]}"
80 | c=${array[2]}':'${array[3]}
81 | #echo $c
82 | echo 'set '${c}' '${line}'' | redis-cli -h $ip -p $port
83 | done < "$input_file"
84 | fi
85 |
--------------------------------------------------------------------------------
/scripts/readarray:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mjamilfarooq/tradingapp/2baa792f4ece6dd918a0ef7c74967c36f59ae487/scripts/readarray
--------------------------------------------------------------------------------
/scripts/redisfile.csv:
--------------------------------------------------------------------------------
1 | RecordType,AccountName,SymbolorUnderlier,Root,ExpirationDate,Strike,Quantity,PutorCall,Price
2 | EQUITY,,user1,AA.BA,AA.BA,,,0,,10.181087
3 | EQUITY,,user1,AAPL.BA,AAPL.BA,,,400,,104.857500
4 | EQUITY,,user1,ABX.BA,ABX.BA,,,0,,16.169634
5 | EQUITY,,user_high_risk,AA.BA,AA.BA,,,-400,,10.196000
6 | EQUITY,,user_high_risk,ABX.BA,ABX.BA,,,-400,,16.176250
7 | EQUITY,,user_high_risk,AAPL.BA,AAPL.BA,,,0,,104.848750
8 |
--------------------------------------------------------------------------------
/scripts/redistofile.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 |
3 |
4 | #if [ $# -eq 0 ]; then
5 | #echo 'keys *:*' | redis-cli | sed 's/^/get /' | redis-cli >file.csv
6 | #exit
7 | #fi
8 |
9 | user_list=""
10 | output_file="file.csv"
11 | ip="127.0.0.1"
12 | port=6379
13 |
14 | while getopts "h?f:u:i:p:" opt; do
15 | case "$opt" in
16 | help|\?)
17 | echo "Usage: $0 -f -u -i -p"
18 | echo "-f filepath"
19 | echo "-u userlist e.g ROOT1,ROOT2,ROOT3"
20 | echo "-i ip [optional default 6379]"
21 | echo "-p port [optional default 127.0.0.1]"
22 | exit 0
23 | ;;
24 | u) user_list=$OPTARG
25 | ;;
26 | f) output_file=$OPTARG
27 | ;;
28 | i) ip=$OPTARG
29 | ;;
30 | p) port=$OPTARG
31 | ;;
32 | esac
33 | done
34 |
35 | shift $((OPTIND-1))
36 |
37 | [ "$1" = "--" ] && shift
38 |
39 | echo "output_file=$output_file,user_list=$user_list,ip='$ip',port='$port'"
40 |
41 | echo "Copying following user's positions from redis to file : $user_list"
42 | if [ -z "$user_list" ]
43 | then
44 | echo "user list is null."
45 | echo 'keys *:*' | redis-cli -h $ip -p $port| sed 's/^/get /' | redis-cli -h $ip -p $port
46 | echo 'RecordType,AccountName,SymbolorUnderlier,Root,ExpirationDate,Strike,Quantity,PutorCall,Price'>${output_file}
47 | echo 'keys *:*' | redis-cli -h $ip -p $port| sed 's/^/get /' | redis-cli -h $ip -p $port>>${output_file}
48 | #to discard 11 and 12 collumn of the positions file
49 | cut --complement -f 11-12 -d, ${output_file} > temp.csv
50 | mv temp.csv ${output_file}
51 | else
52 | echo 'RecordType,Reserved,AccountName,SymbolorUnderlier,Root,ExpirationDate,Strike,Quantity,PutorCall,Price'>${output_file}
53 | IFS=',' read -ra ADDR <<< "$user_list"
54 | for i in "${ADDR[@]}"; do
55 | echo 'keys '${i}':*' | redis-cli -h $ip -p $port| sed 's/^/get /' | redis-cli -h $ip -p $port>>${output_file}
56 | echo "Redis data written to file for user '$i'"
57 | done
58 | #to discard 11 and 12 collumn of the positions file
59 | cut --complement -f 11-12 -d, ${output_file} > temp.csv
60 | mv temp.csv ${output_file}
61 | fi
62 |
63 |
64 | #if [ $# -gt 0 ]; then
65 | #filename=$1
66 | #for arg in "$@" ; do
67 | # if [[ "$arg" = "$0" ]] ; then
68 | # echo 'skiping oth\n'
69 | # fi
70 | # if [[ "$arg" = "$1" ]] ; then
71 | # echo 'RecordType,AccountName,SymbolorUnderlier,Root,ExpirationDate,Strike,Quantity,PutorCall,Price'>${filename}
72 | # else
73 | # echo 'keys '${arg}':*' | redis-cli | sed 's/^/get /' | redis-cli >>${filename}
74 | #fi
75 | #done
76 |
77 | #else
78 | #echo 'keys *:*' | redis-cli | sed 's/^/get /' | redis-cli >file.csv
79 | #fi
80 |
--------------------------------------------------------------------------------
/scripts/run_stem.sh:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 | ./positiontoredis.sh -c -a
3 | rm core
4 | ulimit -c unlimited
5 | nohup ../bin/stem 127.0.0.1 0 -s:../configs/symbol_config_new.xml -t:../configs/trading_config_new.xml -a:../configs/admin_config.xml -v:TRACE >/dev/null &
6 |
7 |
--------------------------------------------------------------------------------
/scripts/run_stem.sh~:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 |
3 | rm core
4 | ulimit -c unlimited
5 | ../bin/stem 127.0.0.1 0 -s:../configs/symbol_config_new.xml -t:../config/trading_config_new.xml -a:../config/admin_config.xml -v:TRACE
6 |
7 |
--------------------------------------------------------------------------------
/scripts/run_stem_for_server.sh:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 |
3 | rm core
4 | ulimit -c unlimited
5 | ../bin/stem 127.0.0.1 0 -s:../configs/symbol_config_onlyC.xml -t:../configs/trading_config_new.xml -a:../configs/admin_config_server.xml -v:TRACE
6 |
7 |
--------------------------------------------------------------------------------
/src/CMakeLists.txt:
--------------------------------------------------------------------------------
1 |
2 | add_subdirectory(akela)
3 | add_subdirectory(cli)
4 | add_subdirectory(avicenna)
5 | add_subdirectory(config)
6 | add_subdirectory(manager)
7 | add_subdirectory(trade)
8 | add_subdirectory(utils)
9 | add_subdirectory(redis)
10 | add_subdirectory(tests)
11 |
12 |
13 | add_executable(stem stem1.cpp ${SOURCE} ${AKELA_SOURCES} ${UTILS_SOURCES})
14 | add_executable(stem-cli STEMConsole.cpp)
15 |
16 |
17 | target_link_libraries(stem AvicennaSuperPlus MaddogUtils EdgeLinkx EdgeUtils EdgeDB MaddogConnection ConnectorLinkxTCP boost_atomic boost_log_setup boost_log boost_system pthread rt boost_thread boost_unit_test_framework readline XBowConnection DirectConnection EdgeDB MaddogProcessor ExchangeProcessor libredisclient.a)
18 |
19 |
20 | target_link_libraries(stem-cli boost_atomic boost_log_setup boost_log boost_system pthread rt boost_thread readline )
21 |
22 |
23 | install(TARGETS stem stem-cli
24 | RUNTIME DESTINATION bin)
25 |
--------------------------------------------------------------------------------
/src/CMakeLists.txt~:
--------------------------------------------------------------------------------
1 |
2 | add_subdirectory(akela)
3 | add_subdirectory(cli)
4 | add_subdirectory(avicenna)
5 | add_subdirectory(config)
6 | add_subdirectory(manager)
7 | add_subdirectory(trade)
8 | add_subdirectory(utils)
9 | add_subdirectory(redis)
10 |
11 |
12 | add_executable(stem stem1.cpp ${SOURCE})
13 | add_executable(stem-cli STEMConsole.cpp)
14 |
15 | target_link_libraries(stem AvicennaSuperPlus MaddogUtils EdgeLinkx EdgeUtils MaddogConnection ConnectorLinkxTCP boost_atomic boost_log_setup boost_log boost_system pthread rt boost_thread readline XBowConnection DirectConnection libredisclient.a)
16 |
17 |
18 | target_link_libraries(stem-cli boost_atomic boost_log_setup boost_log boost_system pthread rt boost_thread readline )
19 |
20 |
21 | install(TARGETS stem stem-cli
22 | RUNTIME DESTINATION bin)
23 |
--------------------------------------------------------------------------------
/src/STEMConsole.cpp:
--------------------------------------------------------------------------------
1 | //============================================================================
2 | // Name : STEMConsole.cpp
3 | // Author : Muhammad Jamil Farooq
4 | // Version :
5 | // Copyright : riskapplication.com
6 | // Description : STEM Console Application to talk to STEM
7 |
8 | //============================================================================
9 |
10 |
11 |
12 | #include
13 | #include
14 | #include
15 | #include
16 | #include
17 | #include
18 | #include
19 |
20 |
21 | using namespace std;
22 | using namespace boost::interprocess;
23 |
24 | #define CLI_COMMAND_PROMPT_STRING "stem console>"
25 | #define CLI_MESSAGE_QUEUE_IDENTIFIER "stem-message-queue"
26 |
27 | int main ()
28 | {
29 | try{
30 | //Open a message queue.
31 | message_queue mq (open_only, CLI_MESSAGE_QUEUE_IDENTIFIER);
32 | unsigned int priority;
33 | message_queue::size_type recvd_size;
34 |
35 | //Receive 100 numbers
36 | while(true){
37 |
38 | string buffer = readline(CLI_COMMAND_PROMPT_STRING);
39 |
40 | boost::algorithm::trim(buffer);
41 |
42 |
43 | if ( !buffer.empty() ) {
44 | //place commad in history to be used later
45 | add_history(buffer.c_str());
46 | }
47 |
48 | if ( buffer == "exit" ) return 0;
49 |
50 | mq.send(buffer.c_str(), buffer.size(), 0);
51 | cout<<"sending ... "<(this)->Subscribe(ticker);
16 | if ( ECERR_SUCCESS != status ) {
17 | //log this event
18 | ERROR<<"can't subscribe to symbol ("<tickerList.push_back(ticker);
22 | }
23 | }
24 | }
25 |
26 | void STEMMaddogConnection::Subscribe(std::vector &symList) {
27 | std::for_each(symList.begin(), symList.end(), [this](std::string str){
28 | MarketData::Ticker ticker;
29 | if ( ticker.Parse(str, MarketData::Ticker::TYPE_EQUITY) ) {
30 | int status = static_cast(this)->Subscribe(ticker);
31 | if ( ECERR_SUCCESS != status ) {
32 | //log this event
33 | ERROR<<"can't subscribe to symbol ("<tickerList.push_back(ticker);
37 | }
38 | }
39 | });
40 | }
41 |
42 | void STEMMaddogConnection::Unsubscribe(std::string symbol) {
43 | std::for_each(tickerList.begin(), tickerList.end(),[](MarketData::Ticker ticker){
44 |
45 | });
46 | }
47 |
48 | void STEMMaddogConnection::Unsubscribe() {
49 | std::for_each(tickerList.begin(), tickerList.end(), [this](MarketData::Ticker &ticker){
50 | static_cast(this)->Unsubscribe(ticker);
51 | });
52 | }
53 |
54 | STEMMaddogConnection::STEMMaddogConnection(Linkx::IClient &client):
55 | Maddog::Connection(client),
56 | //member variables
57 | m_bDump(false),
58 | m_bTrades(true),
59 | m_bQuotes(true),
60 | m_bDepth(true),
61 | m_bOrderBook(true) {
62 |
63 | int status = this->Connect("Maddog");
64 | if (ECERR_SUCCESS != status) {
65 | FATAL<<"Maddog::Connect failed rc="< "<(message.priceType)<<" = "<(message.data[0].price), message.data[0].priceType).AsDouble();
102 | trade_signal(message.ticker.ToString(),
103 | price_double);
104 | }
105 | }
106 |
107 | /*=========================================================================================*/
108 |
109 | void STEMMaddogConnection::OnQuote(const Linkx::Address &source, const unsigned serviceId, const void *pSubject, const size_t subjectLength,
110 | const MarketData::Quote &message)
111 | {
112 | if (m_bQuotes) {
113 | //copying quote data in symbol manager
114 | TRACE<<"bid and ask sizes "< = "<<((double)message.bidSize - (double)message.askSize) / ((double)message.bidSize + (double)message.askSize);
116 | quote_signal(message.ticker.ToString(),
117 | message.bidSize,
118 | Utils::Price(static_cast(message.bid), message.priceType).AsDouble(),
119 | message.askSize,
120 | Utils::Price(static_cast(message.ask), message.priceType).AsDouble());
121 | }
122 | }
123 |
124 | /*=========================================================================================*/
125 |
126 | void STEMMaddogConnection::OnQuoteDepth(const Linkx::Address &source, const unsigned serviceId, const void *pSubject,
127 | const size_t subjectLength, const MarketData::Depth &message)
128 | {
129 | // if (m_bDepth) {
130 | // ::fprintf(stdout, "Depth,%d,%lf,%s,%08X,%d,%d\n", message.header.sequence, message.header.timeStamp,
131 | // message.ticker.ToString().c_str(), message.flags, message.priceType, message.levelCount);
132 | // Process(&message, message.header.length);
133 | // }
134 | }
135 |
136 | /*=========================================================================================*/
137 |
138 | void STEMMaddogConnection::OnQuoteDepthList(const Linkx::Address &source, const unsigned serviceId, const void *pSubject,
139 | const size_t subjectLength, const MarketData::DepthList &message)
140 | {
141 | // if (m_bDepth) {
142 | // ::fprintf(stdout, "DepthList,%d,%lf,%s,%08X,%d\n", message.header.sequence, message.header.timeStamp,
143 | // message.ticker.ToString().c_str(), message.flags, message.priceType);
144 | // Process(&message, message.header.length);
145 | // }
146 | }
147 |
148 | /*=========================================================================================*/
149 |
150 | void STEMMaddogConnection::OnRefresh(const Linkx::Address &source, const unsigned serviceId, const void *pSubject,
151 | const size_t subjectLength, const MarketData::Refresh &message)
152 | {
153 | // ::fprintf(stdout, "Refresh,%d,%lf,%s,%08X,%d,%d\n", message.header.sequence, message.header.timeStamp,
154 | // message.ticker.ToString().c_str(), message.flags, message.priceType, message.fieldCount);
155 | // Process(&message, message.header.length);
156 | }
157 |
158 | /*=========================================================================================*/
159 |
160 | void STEMMaddogConnection::OnAlert(const Linkx::Address &source, const unsigned serviceId, const void *pSubject,
161 | const size_t subjectLength, const MarketData::Alert &message)
162 | {
163 | ::fprintf(stdout, "Alert,%d,%lf,%s,%08X,%d\n", message.header.sequence, message.header.timeStamp, message.ticker.ToString().c_str(),
164 | message.flags, message.state);
165 | // Process(&message, message.header.length);
166 | }
167 |
168 | /*=========================================================================================*/
169 |
170 | void STEMMaddogConnection::OnOrder(const Linkx::Address &source, const unsigned serviceId, const void *pSubject,
171 | const size_t subjectLength, const MarketData::Order &message)
172 | {
173 | // if (m_bOrderBook) {
174 | // ::fprintf(stdout, "Order,%d,%lf,%s,%d\n", message.header.sequence, message.header.timeStamp, message.ticker.ToString().c_str(),
175 | // message.priceType);
176 | // Process(&message, message.header.length);
177 | // }
178 | }
179 |
180 | /*=========================================================================================*/
181 |
182 | void STEMMaddogConnection::OnOrderList(const Linkx::Address &source, const unsigned serviceId, const void *pSubject,
183 | const size_t subjectLength, const MarketData::OrderList &message)
184 | {
185 | // if (m_bOrderBook) {
186 | // ::fprintf(stdout, "OrderList,%d,%lf,%s\n", message.header.sequence, message.header.timeStamp, message.ticker.ToString().c_str());
187 | // Process(&message, message.header.length);
188 | // }
189 | }
190 |
191 | /*=========================================================================================*/
192 |
193 | void STEMMaddogConnection::OnCancel(const Linkx::Address &source, const unsigned serviceId, const void *pSubject,
194 | const size_t subjectLength, const MarketData::Cancel &message)
195 | {
196 | // if (m_bOrderBook) {
197 | // ::fprintf(stdout, "Cancel,%d,%lf,%s\n", message.header.sequence, message.header.timeStamp, message.ticker.ToString().c_str());
198 | // Process(&message, message.header.length);
199 | // }
200 | }
201 |
202 | /*=========================================================================================*/
203 |
204 | void STEMMaddogConnection::OnExecution(const Linkx::Address &source, const unsigned serviceId, const void *pSubject,
205 | const size_t subjectLength, const MarketData::Execution &message)
206 | {
207 | // if (m_bTrades || m_bOrderBook) {
208 | // ::fprintf(stdout, "Execution,%d,%lf,%s,%d,%d,%d,%d\n", message.header.sequence, message.header.timeStamp,
209 | // message.ticker.ToString().c_str(), message.priceType, message.price, message.size, message.volume);
210 | // Process(&message, message.header.length);
211 | // }
212 | }
213 |
214 | /*=========================================================================================*/
215 |
216 | void STEMMaddogConnection::OnSettlement(const Linkx::Address &source, const unsigned serviceId, const void *pSubject,
217 | const size_t subjectLength, const MarketData::Settlement &message)
218 | {
219 | // ::fprintf(stdout, "Settlement,%d,%lf,%s,%d\n", message.header.sequence, message.header.timeStamp, message.ticker.ToString().c_str(),
220 | // message.priceType);
221 | // Process(&message, message.header.length);
222 | }
223 |
224 |
--------------------------------------------------------------------------------
/src/akela/STEMMaddogConnection.h:
--------------------------------------------------------------------------------
1 | /*
2 | * STEMMaddogConnection.h
3 | *
4 | * Created on: Apr 26, 2016
5 | * Author: jamil
6 | */
7 |
8 | #ifndef STEMMADDOGCONNECTION_H_
9 | #define STEMMADDOGCONNECTION_H_
10 |
11 | #include
12 | #include
13 | #include
14 | #include
15 |
16 | #include
17 |
18 | #include "../utils/log.h"
19 |
20 | class SymbolManager;
21 |
22 | class STEMMaddogConnection: public Maddog::Connection {
23 | public:
24 | using TradeSlotType = void (const std::string &, double);
25 | using QuoteSlotType = void (const std::string &, uint32_t, double, uint32_t, double);
26 |
27 | boost::signals2::signal trade_signal;
28 | boost::signals2::signal quote_signal;
29 |
30 | STEMMaddogConnection(Linkx::IClient &);
31 | virtual ~STEMMaddogConnection();
32 |
33 |
34 |
35 | void connect(TradeSlotType,
36 | QuoteSlotType);
37 | void Subscribe(std::string sym);
38 | void Subscribe(std::vector &symList);
39 | void Unsubscribe();
40 | void Unsubscribe(std::string);
41 |
42 | protected:
43 | void Process(const void *pUpdate, const size_t updateLength);
44 | virtual void OnTrade(const Linkx::Address &source, const unsigned serviceId, const void *pSubject, const size_t subjectLength,
45 | const MarketData::Trade &trade);
46 | virtual void OnTradeList(const Linkx::Address &source, const unsigned serviceId, const void *pSubject, const size_t subjectLength,
47 | const MarketData::TradeList &tradeList);
48 | virtual void OnQuote(const Linkx::Address &source, const unsigned serviceId, const void *pSubject, const size_t subjectLength,
49 | const MarketData::Quote "e);
50 | virtual void OnQuoteDepth(const Linkx::Address &source, const unsigned serviceId, const void *pSubject, const size_t subjectLength,
51 | const MarketData::Depth &depth);
52 | virtual void OnQuoteDepthList(const Linkx::Address &source, const unsigned serviceId, const void *pSubject, const size_t subjectLength,
53 | const MarketData::DepthList &depthList);
54 | virtual void OnRefresh(const Linkx::Address &source, const unsigned serviceId, const void *pSubject, const size_t subjectLength,
55 | const MarketData::Refresh &refresh);
56 | virtual void OnAlert(const Linkx::Address &source, const unsigned serviceId, const void *pSubject, const size_t subjectLength,
57 | const MarketData::Alert &alert);
58 | virtual void OnOrder(const Linkx::Address &source, const unsigned serviceId, const void *pSubject, const size_t subjectLength,
59 | const MarketData::Order &order);
60 | virtual void OnOrderList(const Linkx::Address &source, const unsigned serviceId, const void *pSubject, const size_t subjectLength,
61 | const MarketData::OrderList &orderList);
62 | virtual void OnCancel(const Linkx::Address &source, const unsigned serviceId, const void *pSubject, const size_t subjectLength,
63 | const MarketData::Cancel &cancel);
64 | virtual void OnExecution(const Linkx::Address &source, const unsigned serviceId, const void *pSubject, const size_t subjectLength,
65 | const MarketData::Execution &execution);
66 | virtual void OnSettlement(const Linkx::Address &source, const unsigned serviceId, const void *pSubject, const size_t subjectLength,
67 | const MarketData::Settlement &settlement);
68 |
69 | private:
70 | STEMMaddogConnection(const STEMMaddogConnection&);
71 | STEMMaddogConnection &operator=(const STEMMaddogConnection&);
72 |
73 | bool m_bDump, m_bTrades, m_bQuotes, m_bDepth, m_bOrderBook;
74 |
75 | std::list tickerList;
76 |
77 | std::unique_ptr sm;
78 | };
79 |
80 | #endif /* STEMMADDOGCONNECTION_H_ */
81 |
--------------------------------------------------------------------------------
/src/avicenna/AvicennaInterface.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | * AvicennaInterface.cpp
3 | *
4 | * Created on: May 12, 2016
5 | * Author: jamil
6 | */
7 |
8 | #include "../avicenna/AvicennaInterface.h"
9 |
10 | #include "../config/TradingConfig.h"
11 |
12 |
13 | AvicennaConnection::AvicennaConnection(const std::string account_id,
14 | const std::string symbol,
15 | const AvicennaConfiguration &config):
16 | account_id(account_id),
17 | symbol(symbol),
18 | price_estimate(-1.00),
19 | price_estimate_3(-1.00),
20 | startup(true),
21 | ms(0) {
22 |
23 | SetIP(const_cast(config.dll_ip.c_str()));
24 | SetVariableConfig(
25 | const_cast(config.dll_str1.c_str()),
26 | const_cast(config.dll_str3.c_str()),
27 | const_cast(config.dll_str4.c_str()),
28 | const_cast(config.dll_str5.c_str())
29 | );
30 |
31 | }
32 |
33 | AvicennaConnection::AvicennaConnection(
34 | const std::string account_id,
35 | const std::string symbol,
36 | const std::string ip,
37 | const std::string str1,
38 | const std::string str2,
39 | const std::string str3,
40 | const std::string str4,
41 | const std::string str5):
42 | account_id(account_id),
43 | symbol(symbol),
44 | price_estimate(-1.00),
45 | price_estimate_3(-1.00),
46 | startup(true),
47 | ms(0) {
48 |
49 | SetIP(const_cast(ip.c_str()));
50 | SetVariableConfig(
51 | const_cast(str1.c_str()),
52 | const_cast(str3.c_str()),
53 | const_cast(str4.c_str()),
54 | const_cast(str5.c_str())
55 | );
56 |
57 | }
58 |
59 | void AvicennaConnection::calculate(double price, double min, double max ) {
60 | // DEBUG< price_estimate_3 ) {
78 | // TRACE<id;
104 |
105 | if ( SymbolConfig::user_symbols_map->find(account_id) == SymbolConfig::user_symbols_map->end() ) {
106 | FATAL<<"exiting AvicennaInterface::timeoutThread for "<find(account_id)->second.get();
111 |
112 | auto timer1 = trade_account->avicenna_configuration[0].dll_timer1;
113 | auto timer2 = trade_account->avicenna_configuration[1].dll_timer1;
114 |
115 |
116 | for (auto itr = symbols_map->begin(); itr != symbols_map->end(); itr++) {
117 | //initialize AvicennaConnection for each symbol
118 | auto symbol = itr->first;
119 |
120 | AvicennaConnectionPair *pair = nullptr;
121 |
122 | pair = new AvicennaConnectionPair{
123 | new AvicennaConnection(
124 | trade_account->id,
125 | symbol,
126 | trade_account->avicenna_configuration[0]
127 | ),
128 | new AvicennaConnection(
129 | trade_account->id,
130 | symbol,
131 | trade_account->avicenna_configuration[1]
132 | )
133 | };
134 |
135 | avicenna_list.emplace(symbol, pair);
136 |
137 | }
138 |
139 |
140 | timeout_thread1 = new std::thread(&AvicennaInterface::timeoutThread, this, timer1, 0);
141 | timeout_thread2 = new std::thread(&AvicennaInterface::timeoutThread, this, timer2, 1);
142 |
143 | }
144 |
145 | void AvicennaInterface::timeoutThread(int timeout, int index) {
146 |
147 | auto symbols_map = SymbolConfig::user_symbols_map->find(account_id)->second.get();
148 | while ( !stop_timeout_thread ) {
149 |
150 | for (auto itr = symbols_map->begin(); itr != symbols_map->end(); itr++) {
151 | auto& symbol = *itr->second.get();
152 |
153 | auto& avicenna_connection = ( 0 == index ) ?
154 | *avicenna_list[symbol.name]->avicenna1:
155 | *avicenna_list[symbol.name]->avicenna2;
156 |
157 | Symbol::reset_interval_callback_type newEstimate = [&avicenna_connection, this, &symbol, index] (
158 | double lat, double min, double max, double ear)->double {
159 | if ( lat > 0 ) {
160 | auto invert = true;
161 | auto val = lat;
162 | while ( avicenna_connection.price_estimate <= 0.0 && avicenna_connection.startup ) {
163 | if ( invert ) {
164 | invert = false;
165 | val += 0.01;
166 | } else {
167 | invert = true;
168 | val -= 0.01;
169 | }
170 | avicenna_connection.calculate(val, min, max);
171 | }
172 |
173 | avicenna_connection.calculate(lat, min, max);
174 | avicenna_connection.startup = false;
175 | auto symbol = avicenna_connection.symbol;
176 | // TRACE<
12 | #include
13 | #include
14 | #include
15 | #include
16 | #include
17 | #include
18 | #include
19 |
20 | //#include "../config/TradingConfig.h"
21 | #include "../config/SymbolConfig.h"
22 | #include "../libs/avicenna/AvicennaSuperPlus.h"
23 |
24 |
25 | class AvicennaConfiguration;
26 | class TradeAccount;
27 |
28 | #define LOG_AVICENNA_INTERFACE " <"<account_id<<"> "
29 | #define LOG_AVICENNA_CONNECTION " <"<account_id<<","< "
30 |
31 | struct AvicennaConnection:public CAvicenna_SuperPlus {
32 | double price_estimate;
33 | double price_estimate_3;
34 |
35 | double ms;
36 |
37 | const std::string account_id;
38 | const std::string symbol;
39 |
40 | bool startup;
41 |
42 | AvicennaConnection(const std::string,
43 | const std::string,
44 | const AvicennaConfiguration &);
45 | AvicennaConnection(
46 | const std::string,
47 | const std::string,
48 | const std::string,
49 | const std::string,
50 | const std::string,
51 | const std::string,
52 | const std::string,
53 | const std::string);
54 |
55 | void calculate(double, double, double);
56 |
57 | };
58 |
59 |
60 | class AvicennaInterface {
61 |
62 | std::string account_id;
63 | std::string symbol;
64 | const TradeAccount *trade_account;
65 |
66 | std::thread *timeout_thread1, *timeout_thread2;
67 | bool stop_timeout_thread;
68 | void timeoutThread(int, int);
69 | void newEstimate(double latest, double min = 0.0, double max = 0.0, double earliest = 0.0);
70 | double output[4];
71 | double price_estimate;
72 |
73 | struct AvicennaConnectionPair {
74 | AvicennaConnection *avicenna1;
75 | AvicennaConnection *avicenna2;
76 | };
77 |
78 |
79 | std::map avicenna_list;
80 |
81 | public:
82 |
83 | AvicennaInterface(const TradeAccount *trade_account);
84 | ~AvicennaInterface();
85 | };
86 |
87 | #endif /* AVICENNAINTERFACE_H_ */
88 |
--------------------------------------------------------------------------------
/src/avicenna/CMakeLists.txt:
--------------------------------------------------------------------------------
1 | set(SOURCE
2 | ${SOURCE}
3 | ${CMAKE_CURRENT_SOURCE_DIR}/AvicennaInterface.cpp
4 | PARENT_SCOPE
5 | )
6 | set(HEADERS
7 | ${HEADERS}
8 | ${CMAKE_CURRENT_SOURCE_DIR}/AvicennaInterface.h
9 | PARENT_SCOPE
10 | )
11 |
--------------------------------------------------------------------------------
/src/cli/CLI.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | * CLI.cpp
3 | *
4 | * Created on: Apr 19, 2016
5 | * Author: jamil
6 | */
7 |
8 | #include "CLI.h"
9 |
10 | CLI *CLI::single = nullptr;
11 | map CLI::callbackLookup;
12 |
13 | CommandCallback::~CommandCallback() {
14 |
15 | }
16 |
17 | CLI::CLI() {
18 |
19 | buffer = new char[CLI_READLINE_BUFFER_SIZE];
20 |
21 | //initiate message queue for IPC
22 | try {
23 | boost::interprocess::message_queue::remove(CLI_MESSAGE_QUEUE_IDENTIFIER);
24 | mq = new boost::interprocess::message_queue (
25 | boost::interprocess::create_only,
26 | CLI_MESSAGE_QUEUE_IDENTIFIER,
27 | CLI_MESSAGE_QUEUE_SIZE,
28 | CLI_READLINE_BUFFER_SIZE
29 | );
30 | } catch ( boost::interprocess::interprocess_exception &e ) {
31 | ERROR<receive(message_buffer, CLI_READLINE_BUFFER_SIZE, message_size, priority);
86 | char *temp = strndup(message_buffer, message_size);
87 | TRACE<
12 | #include