From 909b412e9bfc04ca69c0dc4e7b8ac20dd12131a5 Mon Sep 17 00:00:00 2001 From: fawce Date: Wed, 28 Jan 2015 22:16:29 -0500 Subject: [PATCH] modified do not order guard to take an iteratble or a container container allows for dynamic restrictions, necessary for a point in time implementation of the restricted list. --- tests/test_algorithm.py | 8 +++++--- zipline/finance/controls.py | 7 ++++++- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/tests/test_algorithm.py b/tests/test_algorithm.py index 403144d2..ab275647 100644 --- a/tests/test_algorithm.py +++ b/tests/test_algorithm.py @@ -958,17 +958,19 @@ class TestTradingControls(TestCase): def test_set_do_not_order_list(self): # set the restricted list to be the sid, and fail. - algo = SetDoNotOrderListAlgorithm(sid=self.sid, + algo = SetDoNotOrderListAlgorithm( + sid=self.sid, restricted_list=[self.sid]) def handle_data(algo, data): algo.order(self.sid, 100) algo.order_count += 1 - + self.check_algo_fails(algo, handle_data, 0) # set the restricted list to exclude the sid, and succeed - algo = SetDoNotOrderListAlgorithm(sid=self.sid, + algo = SetDoNotOrderListAlgorithm( + sid=self.sid, restricted_list=[134, 135, 136]) def handle_data(algo, data): diff --git a/zipline/finance/controls.py b/zipline/finance/controls.py index d02f4fcf..d3d77486 100644 --- a/zipline/finance/controls.py +++ b/zipline/finance/controls.py @@ -106,9 +106,14 @@ class RestrictedListOrder(TradingControl): """ def __init__(self, restricted_list): + """ + restricted list can be an iterable, or + an object that implements __contains__ for dynamic + restrictions. + """ super(RestrictedListOrder, self).__init__() - self.restricted_list = set(restricted_list) + self.restricted_list = restricted_list def validate(self, sid,