Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 5 additions & 13 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -34,19 +34,11 @@ add_subdirectory( LatencyTest )

install(DIRECTORY ${CMAKE_SOURCE_DIR}/MiscATS/
DESTINATION MiscATS
FILES_MATCHING PATTERN "*.db" PATTERN "*.sh" PATTERN "*.ini" PATTERN "*.cfg")

install(CODE "
file(GLOB_RECURSE SCRIPT_FILES
\"\${CMAKE_INSTALL_PREFIX}/MiscATS/*.sh\")
foreach(script \${SCRIPT_FILES})
execute_process(COMMAND chmod +x \${script})
endforeach()
")

install(FILES FIXGateway/scripts/fixgateway.sh
DataService/scripts/dataservice.sh
MatchingEngine/scripts/matchingengine.sh
FILES_MATCHING PATTERN "*.db" PATTERN "*.py" PATTERN "*.ini" PATTERN "*.cfg" PATTERN "*.json")

install(FILES FIXGateway/scripts/fix_gateway_manager.py
DataService/scripts/data_service_manager.py
MatchingEngine/scripts/matching_engine_manager.py
DESTINATION scripts
PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE
GROUP_READ GROUP_EXECUTE
Expand Down
107 changes: 107 additions & 0 deletions DataService/scripts/data_service_manager.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
#!/usr/bin/env python3

import os
import sys
import time
import subprocess
from pathlib import Path
import psutil

PROGNAME = "DataService"


def get_config_file():
if len(sys.argv) < 3:
print(f"Usage: {sys.argv[0]} [start|stop|check] <config_file>")
sys.exit(1)
return sys.argv[2]


def get_paths(config_file):
basedir = os.environ.get("BASEDIR_ATS", ".")
dats_home = os.environ.get("DATS_HOME")
if not dats_home:
print("DATS_HOME is not set.")
sys.exit(1)

config_path = Path(basedir) / "config" / config_file
log_path = Path(basedir) / "logs" / f"{PROGNAME}.{config_file}.console.log"
binary_path = Path(dats_home) / "bin" / PROGNAME
return binary_path, config_path, log_path, basedir


def source_dats_env():
dats_home = os.environ.get("DATS_HOME")
env_script = Path(dats_home) / "dats_env.sh"
if env_script.exists():
subprocess.call(f"source {env_script}", shell=True, executable="/bin/bash")


def check_process(config_path):
for proc in psutil.process_iter(['pid', 'cmdline']):
try:
cmdline = proc.info['cmdline']
if cmdline and PROGNAME in cmdline[0] and str(config_path) in ' '.join(cmdline):
print(f"{PROGNAME} [{config_path.name}] is running - {proc.pid}")
return proc.pid
except (psutil.NoSuchProcess, psutil.AccessDenied, psutil.ZombieProcess):
continue
print(f"{PROGNAME} [{config_path.name}] is not running")
return None


def start_process(binary_path, config_path, log_path):
print(f"Starting: {PROGNAME} -c {config_path}")
for key in sorted(os.environ):
print(f"{key}={os.environ[key]}")
if check_process(config_path) is None:
with open(log_path, "a") as f:
subprocess.Popen([str(binary_path), "-c", str(config_path)],
stdout=f, stderr=subprocess.STDOUT)
time.sleep(1)
check_process(config_path)


def stop_process(config_path):
cmd_str = f"{PROGNAME} -c {config_path}"
print(f"Stopping: {cmd_str}")
pid = check_process(config_path)
if pid:
os.system(f"pkill -SIGTERM -f \"{cmd_str}\"")
time.sleep(1)

for _ in range(10):
if check_process(config_path) is None:
break
time.sleep(1)
else:
os.system(f"pkill -KILL -U {os.getuid()} -f \"{cmd_str}\"")


def main():
if len(sys.argv) < 3:
print(f"Usage: {sys.argv[0]} [start|stop|check] <config_file>")
sys.exit(1)

command = sys.argv[1].lower()
config_file = get_config_file()

binary_path, config_path, log_path, basedir = get_paths(config_file)
source_dats_env()

if command == "start":
start_process(binary_path, config_path, log_path)
elif command == "stop":
stop_process(config_path)
elif command == "check":
check_process(config_path)
else:
print("Unknown command")
sys.exit(1)

with open(log_path, "a") as f:
f.write(f"{time.strftime('%Y%m%d.%H%M%S')} run-done : pid,{os.getpid()}\n")


if __name__ == "__main__":
main()
2 changes: 2 additions & 0 deletions DataService/src/MarketDataService.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,8 @@ int MarketDataService::service (void)
std::this_thread::sleep_for(std::chrono::duration<long double, std::milli>(1000));
}
};

return 0;
}

bool MarketDataService::populateMarketDataSnapshotFullRefresh( const Instrument& instrument,
Expand Down
3 changes: 2 additions & 1 deletion DataService/src/RefDataService.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,8 @@ void RefDataService::populateUserGroupInstrumentMap()
" m.market_name=im_map.market_name and " \
" im_map.market_name=ugm_map.market_name");

LOG4CXX_INFO(logger, "Populating security list");
LOG4CXX_INFO(logger, "Populating security list : ");
LOG4CXX_INFO(logger, "Query : " + sqliteQuery.getQuery());

m_sqliteConnection->execute(sqliteQuery);

Expand Down
7 changes: 5 additions & 2 deletions DataService/src/SQLiteConnection.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,6 @@ class SQLiteQuery
public:
SQLiteQuery( const std::string& query ) : m_stmt(0), m_query( query )
{

std::cout << query << std::endl;
}

~SQLiteQuery()
Expand Down Expand Up @@ -95,6 +93,11 @@ class SQLiteQuery
{
return m_rows[row][column];
}

std::string getQuery()
{
return m_query;
}

private:
sqlite3_stmt* m_stmt;
Expand Down
98 changes: 98 additions & 0 deletions FIXGateway/scripts/fix_gateway_manager.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
#!/usr/bin/env python3

import os
import sys
import time
import subprocess
from pathlib import Path
import psutil

PROGNAME = "FIXGateway"


def usage():
print(f"Usage: {sys.argv[0]} [start|stop|check] <config_file>")
sys.exit(1)


def get_paths(config_file):
basedir = os.environ.get("BASEDIR_ATS", ".")
dats_home = os.environ.get("DATS_HOME")
if not dats_home:
print("DATS_HOME is not set.")
sys.exit(1)

config_path = Path(basedir) / "config" / config_file
log_path = Path(basedir) / "logs" / f"{PROGNAME}.{config_file}.console.log"
binary_path = Path(dats_home) / "bin" / PROGNAME
return binary_path, config_path, log_path


def check_process(config_path):
for proc in psutil.process_iter(['pid', 'cmdline']):
try:
cmdline = proc.info['cmdline']
if cmdline and PROGNAME in cmdline[0] and str(config_path) in ' '.join(cmdline):
print(f"{PROGNAME} [{config_path.name}] is running - {proc.pid}")
return proc.pid
except (psutil.NoSuchProcess, psutil.AccessDenied, psutil.ZombieProcess):
continue
print(f"{PROGNAME} [{config_path.name}] is not running")
return None


def start_process(binary_path, config_path, log_path):
process_str = f"{PROGNAME} -c {config_path}"
print(f"Starting: {process_str}")
for key in sorted(os.environ):
print(f"{key}={os.environ[key]}")
if check_process(config_path) is None:
with open(log_path, "a") as f:
subprocess.Popen([str(binary_path), "-c", str(config_path)],
stdout=f, stderr=subprocess.STDOUT)
time.sleep(1)
check_process(config_path)


def stop_process(config_path):
process_str = f"{PROGNAME} -c {config_path}"
print(f"Stopping: {process_str}")
pid = check_process(config_path)
if pid:
os.system(f"pkill -SIGTERM -f \"{process_str}\"")
time.sleep(1)

# Try up to 10 seconds to let it exit
for _ in range(10):
if check_process(config_path) is None:
break
time.sleep(1)
else:
os.system(f"pkill -KILL -U {os.getuid()} -f \"{process_str}\"")


def main():
if len(sys.argv) < 3:
usage()

command = sys.argv[1].lower()
config_file = sys.argv[2]

binary_path, config_path, log_path = get_paths(config_file)

if command == "start":
start_process(binary_path, config_path, log_path)
elif command == "stop":
stop_process(config_path)
elif command == "check":
check_process(config_path)
else:
usage()

# Final run log
with open(log_path, "a") as f:
f.write(f"{time.strftime('%Y%m%d.%H%M%S')} run-done : pid,{os.getpid()}\n")


if __name__ == "__main__":
main()
107 changes: 107 additions & 0 deletions MatchingEngine/scripts/matching_engine_manager.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
#!/usr/bin/env python3

import os
import sys
import time
import subprocess
from pathlib import Path
import psutil

PROGNAME = "MatchingEngine"

def get_config_file():
if len(sys.argv) < 3:
print(f"Usage: {sys.argv[0]} [start|stop|check] <config_file>")
sys.exit(1)
return sys.argv[2]


def get_paths(config_file):
basedir = os.environ.get("BASEDIR_ATS", ".")
dats_home = os.environ.get("DATS_HOME")
if not dats_home:
print("DATS_HOME is not set.")
sys.exit(1)

config_path = Path(basedir) / "config" / config_file
log_path = Path(basedir) / "logs" / f"{PROGNAME}.{config_file}.console.log"
binary_path = Path(dats_home) / "bin" / PROGNAME
return binary_path, config_path, log_path, basedir


def source_dats_env():
dats_home = os.environ.get("DATS_HOME")
env_script = Path(dats_home) / "dats_env.sh"
if env_script.exists():
subprocess.call(f"source {env_script}", shell=True, executable="/bin/bash")


def check_process(config_path):
for proc in psutil.process_iter(['pid', 'cmdline']):
try:
cmdline = proc.info['cmdline']
if cmdline and PROGNAME in cmdline[0] and str(config_path) in ' '.join(cmdline):
print(f"{PROGNAME} [{config_path.name}] is running - {proc.pid}")
return proc.pid
except (psutil.NoSuchProcess, psutil.AccessDenied, psutil.ZombieProcess):
continue
print(f"{PROGNAME} [{config_path.name}] is not running")
return None


def start_process(binary_path, config_path, log_path):
print(f"Starting: {PROGNAME} -c {config_path}")
for key in sorted(os.environ):
print(f"{key}={os.environ[key]}")
if check_process(config_path) is None:
with open(log_path, "a") as f:
subprocess.Popen([str(binary_path), "-c", str(config_path)],
stdout=f, stderr=subprocess.STDOUT)
time.sleep(1)
check_process(config_path)


def stop_process(config_path):
cmd_str = f"{PROGNAME} -c {config_path}"
print(f"Stopping: {cmd_str}")
pid = check_process(config_path)
if pid:
os.system(f"pkill -SIGTERM -f \"{cmd_str}\"")
time.sleep(1)

for _ in range(10):
if check_process(config_path) is None:
break
time.sleep(1)
else:
os.system(f"pkill -KILL -U {os.getuid()} -f \"{cmd_str}\"")


def main():
if len(sys.argv) < 3:
print(f"Usage: {sys.argv[0]} [start|stop|check] <config_file>")
sys.exit(1)

command = sys.argv[1].lower()
config_file = get_config_file()

binary_path, config_path, log_path, basedir = get_paths(config_file)

source_dats_env()

if command == "start":
start_process(binary_path, config_path, log_path)
elif command == "stop":
stop_process(config_path)
elif command == "check":
check_process(config_path)
else:
print("Unknown command")
sys.exit(1)

with open(log_path, "a") as f:
f.write(f"{time.strftime('%Y%m%d.%H%M%S')} run-done : pid,{os.getpid()}\n")


if __name__ == "__main__":
main()
2 changes: 1 addition & 1 deletion MatchingEngine/src/Market.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ Market::Market(DataWriterContainerPtr dataWriterContainerPtr,
PriceDepthPublisherQueuePtr&
price_depth_publisher_queue_ptr)
: dataWriterContainerPtr_(dataWriterContainerPtr), _marketName(marketName), _dataServiceName(dataServiceName),
_price_depth_publisher_queue_ptr( price_depth_publisher_queue_ptr )
_price_depth_publisher_queue_ptr( price_depth_publisher_queue_ptr ), _ready_to_trade(false)
{
stats_ptr_ = std::make_shared<OrderBookStatsMap>();
}
Expand Down
Loading