ENH: Added informative message for calling order in init.

Previously, calling order() in initalize resulted in a weird
stack trace. It now returns a well formulated error that is
readable to the user through the API. Adding a slippage
kwarg to test_algorithm and simfactor was necessary because
slippage can only be called during init. Previously initaliazed
was never set to true and calls to init-only function were sprinkled
around the code in non-init sections. Code changes were to enforce
init-only rules.
This commit is contained in:
Delaney Granizo-Mackenzie
2014-07-08 14:03:53 -04:00
parent 6baabc5975
commit 3521a11ed4
5 changed files with 54 additions and 12 deletions
+16 -1
View File
@@ -29,6 +29,7 @@ import zipline.utils.factory as factory
import zipline.utils.simfactory as simfactory
from zipline.errors import (
OrderDuringInitialize,
RegisterTradingControlPostInit,
TradingControlViolation,
)
@@ -53,6 +54,7 @@ from zipline.test_algorithms import (
api_algo,
api_symbol_algo,
call_all_order_methods,
call_order_in_init,
handle_data_api,
handle_data_noop,
initialize_api,
@@ -585,7 +587,8 @@ def handle_data(context, data):
self._algo_record_float_magic_should_pass('nan')
def test_order_methods(self):
"""Only test that order methods can be called without error.
"""
Only test that order methods can be called without error.
Correct filling of orders is tested in zipline.
"""
test_algo = TradingAlgorithm(
@@ -602,6 +605,18 @@ def handle_data(context, data):
output, _ = drain_zipline(self, zipline)
def test_order_in_init(self):
"""
Test that calling order in initialize
will return an error
"""
with self.assertRaises(OrderDuringInitialize):
test_algo = TradingAlgorithm(
script=call_order_in_init,
sim_params=self.sim_params,
)
set_algo_instance(test_algo)
class TestHistory(TestCase):
def test_history(self):