diff --git a/agent/DummyAgent.py b/agent/DummyAgent.py index cf43f94..718fa4b 100644 --- a/agent/DummyAgent.py +++ b/agent/DummyAgent.py @@ -4,7 +4,7 @@ @author: Silver ''' -from tools.Order import * +from objects.Order import * class DummyAgent(): def __init__(self, service_locator): @@ -12,10 +12,9 @@ def __init__(self, service_locator): self.x = 0 def process(self, symbol): - print "Received Market Data Event on symbol %s" % symbol - data = self.services.bus.get_market_data() - print data - print "BID: %d, ASK: %d, PRICE: %d, SIZE: %d" % (data[symbol]["bid"], data[symbol]["ask"], data[symbol]["price"], data[symbol]["size"]) + self.services.logger.info("Received Market Data Event on symbol %s" % symbol) + data = self.services.bus.get_market_data() + self.services.logger.info("BID: %d, ASK: %d, PRICE: %d, SIZE: %d" % (data[symbol]["bid"], data[symbol]["ask"], data[symbol]["price"], data[symbol]["size"])) if self.x == 0: o = Order() @@ -29,6 +28,5 @@ def process(self, symbol): self.x += 1 - def process_report(self, id): print "execution!!!!!!!!!!!!" \ No newline at end of file diff --git a/agent/DummyAgent.pyc b/agent/DummyAgent.pyc index ddda3c3..e387252 100644 Binary files a/agent/DummyAgent.pyc and b/agent/DummyAgent.pyc differ diff --git a/injecter/Level1FastInjecter.py b/injecter/Level1FastInjecter.py index 4431413..e5b9d7a 100644 --- a/injecter/Level1FastInjecter.py +++ b/injecter/Level1FastInjecter.py @@ -17,7 +17,7 @@ def main_loop(self, parameter): data = pd.read_csv(self.filename, sep = ';') for i in range(len(data)): row = data.ix[i] - logging.info(1, "injecting row: %s" % row) + self.services.logger.info("injecting row: %s" % row) self.services.bus.inject_snapshot(self.symbol, row) self.services.events['SnapshotInject'].emit(self.symbol) diff --git a/injecter/Level1FastInjecter.pyc b/injecter/Level1FastInjecter.pyc index e46e990..5c07ff9 100644 Binary files a/injecter/Level1FastInjecter.pyc and b/injecter/Level1FastInjecter.pyc differ diff --git a/matching_engine/MatchingEngine.py b/matching_engine/MatchingEngine.py index 4e15305..6e8190c 100644 --- a/matching_engine/MatchingEngine.py +++ b/matching_engine/MatchingEngine.py @@ -15,11 +15,11 @@ def inject_snapshot(self, symbol, snapshot): def inject_update(self, symbol, update): pass - def inject_new_order(self, symbol, id, order): + def on_new_order(self, symbol, id, order): pass - def inject_modify_order(self, symbol, id, order): + def on_modify_order(self, symbol, id, order): pass - def inject_cancel_order(self, symbol, id): + def on_cancel_order(self, symbol, id): pass \ No newline at end of file diff --git a/matching_engine/MatchingEngine.pyc b/matching_engine/MatchingEngine.pyc index a52eb12..40cd31d 100644 Binary files a/matching_engine/MatchingEngine.pyc and b/matching_engine/MatchingEngine.pyc differ diff --git a/tools/Order.py b/objects/Order.py similarity index 100% rename from tools/Order.py rename to objects/Order.py diff --git a/objects/Order.pyc b/objects/Order.pyc new file mode 100644 index 0000000..31ea95d Binary files /dev/null and b/objects/Order.pyc differ diff --git a/objects/__init__.py b/objects/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/objects/__init__.pyc b/objects/__init__.pyc new file mode 100644 index 0000000..a471190 Binary files /dev/null and b/objects/__init__.pyc differ diff --git a/scheduler/Scheduler.py b/scheduler/Scheduler.py index 504dbbc..ef5e438 100644 --- a/scheduler/Scheduler.py +++ b/scheduler/Scheduler.py @@ -11,8 +11,8 @@ from bus.Bus import Bus from agent.DummyAgent import DummyAgent from events.signals import Events -from tools.Order import * -import logging +from tools.Logger import * +from objects.Order import * if __name__ == "__main__": @@ -23,6 +23,7 @@ services.injecter = Level1FastInjecter(services, "G:/st_sim/simulator/input_files/data.csv") services.events = Events services.order_dispatcher = OrderDispatcher(services) + services.logger = get_logger() dummy = DummyAgent(services) @@ -39,6 +40,7 @@ # connect the injecter to the scheduler events Events['Start'].connect(services.injecter.main_loop) + services.logger.info("starting the simulation") services.events["Start"].emit("simulation") diff --git a/tools/Logger.py b/tools/Logger.py new file mode 100644 index 0000000..beaf8ce --- /dev/null +++ b/tools/Logger.py @@ -0,0 +1,47 @@ +''' +Created on Oct 7, 2013 + +@author: Silver +''' + +import logging, sys + + +class LowerLevelFilter(logging.Filter): + def __init__(self, passlevel, reject): + self.passlevel = passlevel + self.reject = reject + + def filter(self, record): + """ + this filter helps push messages below a certain level to stdout while leaving the rest to stderr + """ + if self.reject: + return (record.levelno > self.passlevel) + else: + return (record.levelno <= self.passlevel) + +def get_logger(): + # create logger + #logging.basicConfig(format = '%(asctime)s %(levelname)s %(module)s:%(lineno)d >> %(message)s') + formatter = logging.Formatter('%(asctime)s\t%(levelname)s\t%(module)s:%(lineno)d\t%(message)s') + root_logger = logging.getLogger() + root_logger.setLevel(logging.DEBUG) + root_logger.handlers = [] + + j = logging.StreamHandler(sys.stderr) + j.setLevel(logging.DEBUG) + j.addFilter(LowerLevelFilter(logging.INFO, True)) + j.setFormatter(formatter) + + h = logging.StreamHandler(sys.stdout) + h.setLevel(logging.DEBUG) + h.addFilter(LowerLevelFilter(logging.INFO, False)) + h.setFormatter(formatter) + + root_logger.addHandler(h) + root_logger.addHandler(j) + + return root_logger + + diff --git a/tools/Logger.pyc b/tools/Logger.pyc new file mode 100644 index 0000000..384c8e1 Binary files /dev/null and b/tools/Logger.pyc differ