Merge pull request #91 from quantopian/bug585

change protocol to match new datasources
This commit is contained in:
Scott Sanderson
2012-08-14 09:41:06 -07:00
2 changed files with 18 additions and 3 deletions
+5
View File
@@ -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
+13 -3
View File
@@ -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