diff --git a/zipline/gens/utils.py b/zipline/gens/utils.py index 1ac85df6..b8ee6ac4 100644 --- a/zipline/gens/utils.py +++ b/zipline/gens/utils.py @@ -67,12 +67,17 @@ def hash_args(*args, **kwargs): return hasher.hexdigest() def create_trade(sid, price, amount, datetime, source_id = "test_factory"): + row = ndict({ 'source_id' : source_id, 'type' : DATASOURCE_TYPE.TRADE, 'sid' : sid, 'dt' : datetime, 'price' : price, + 'close' : price, + 'open' : price, + 'low' : price * .95, + 'high' : price * 1.05, 'volume' : amount }) return row diff --git a/zipline/protocol.py b/zipline/protocol.py index 19ee8c80..a2cf50c3 100644 --- a/zipline/protocol.py +++ b/zipline/protocol.py @@ -132,6 +132,7 @@ from utils.date_utils import EPOCH, UN_EPOCH, epoch_now # ----------------------- PRODUCTION_PREFIXES = ['PERF', 'RISK', 'EXCEPTION','CANCEL','DONE', 'LOG'] +PRICE_FIELDS = ['price', 'open', 'close', 'high', 'low'] INVALID_CONTROL_FRAME = FrameExceptionFactory('CONTROL') @@ -428,21 +429,26 @@ def TRADE_FRAME(event): assert isinstance(event, ndict) assert event.type == DATASOURCE_TYPE.TRADE assert isinstance(event.sid, int) - assert isinstance(event.price, numbers.Real) + for field in PRICE_FIELDS: + assert isinstance(event[field], numbers.Real) assert isinstance(event.volume, numbers.Integral) PACK_DATE(event) return msgpack.dumps(tuple([ event.sid, event.price, + event.open, + event.close, + event.high, + event.low, event.volume, event.dt, - event.type, + event.type ])) def TRADE_UNFRAME(msg): try: packed = msgpack.loads(msg) - sid, price, volume, dt, source_type = packed + sid, price, open, close, high, low, volume, dt, source_type = packed assert isinstance(sid, int) assert isinstance(price, numbers.Real) @@ -450,6 +456,10 @@ def TRADE_UNFRAME(msg): rval = ndict({ 'sid' : sid, 'price' : price, + 'open' : open, + 'close' : close, + 'high' : high, + 'low' : low, 'volume' : volume, 'dt' : dt, 'type' : source_type