mirror of
https://github.com/wassname/catalyst.git
synced 2026-08-12 11:50:11 +08:00
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:
+16
-1
@@ -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):
|
||||
|
||||
Reference in New Issue
Block a user