Skip to content

Commit

Permalink
v. 0.1.1 - Added logging functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
Silviu VLASCEANU committed Oct 7, 2013
1 parent ff37153 commit 3dfeb37
Show file tree
Hide file tree
Showing 13 changed files with 59 additions and 12 deletions.
10 changes: 4 additions & 6 deletions agent/DummyAgent.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,17 @@
@author: Silver
'''

from tools.Order import *
from objects.Order import *

class DummyAgent():
def __init__(self, service_locator):
self.services = 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()
Expand All @@ -29,6 +28,5 @@ def process(self, symbol):

self.x += 1


def process_report(self, id):
print "execution!!!!!!!!!!!!"
Binary file modified agent/DummyAgent.pyc
Binary file not shown.
2 changes: 1 addition & 1 deletion injecter/Level1FastInjecter.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Binary file modified injecter/Level1FastInjecter.pyc
Binary file not shown.
6 changes: 3 additions & 3 deletions matching_engine/MatchingEngine.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Binary file modified matching_engine/MatchingEngine.pyc
Binary file not shown.
File renamed without changes.
Binary file added objects/Order.pyc
Binary file not shown.
Empty file added objects/__init__.py
Empty file.
Binary file added objects/__init__.pyc
Binary file not shown.
6 changes: 4 additions & 2 deletions scheduler/Scheduler.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__":
Expand All @@ -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)

Expand All @@ -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")


Expand Down
47 changes: 47 additions & 0 deletions tools/Logger.py
Original file line number Diff line number Diff line change
@@ -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


Binary file added tools/Logger.pyc
Binary file not shown.

0 comments on commit 3dfeb37

Please sign in to comment.