<s> """<STR_LIT>""" <EOL> import numpy as np <EOL> from nose . tools import assert_raises <EOL> from six . moves import range <EOL> from six import itervalues <EOL> from zipline . algorithm import TradingAlgorithm <EOL> from zipline . api import ( <EOL> FixedSlippage , <EOL> order , <EOL> set_slippage , <EOL> record , <EOL> sid , <EOL> ) <EOL> from zipline . errors import UnsupportedOrderParameters <EOL> from zipline . assets import Future , Equity <EOL> from zipline . finance . commission import PerShare <EOL> from zipline . finance . execution import ( <EOL> LimitOrder , <EOL> MarketOrder , <EOL> StopLimitOrder , <EOL> StopOrder , <EOL> ) <EOL> from zipline . finance . controls import AssetDateBounds <EOL> from zipline . utils . math_utils import round_if_near_integer <EOL> class TestAlgorithm ( TradingAlgorithm ) : <EOL> """<STR_LIT>""" <EOL> def initialize ( self , <EOL> sid , <EOL> amount , <EOL> order_count , <EOL> sid_filter = None , <EOL> slippage = None , <EOL> commission = None ) : <EOL> self . count = order_count <EOL> self . asset = self . sid ( sid ) <EOL> self . amount = amount <EOL> self . incr = <NUM_LIT:0> <EOL> if sid_filter : <EOL> self . sid_filter = sid_filter <EOL> else : <EOL> self . sid_filter = [ self . asset . sid ] <EOL> if slippage is not None : <EOL> self . set_slippage ( slippage ) <EOL> if commission is not None : <EOL> self . set_commission ( commission ) <EOL> def handle_data ( self , data ) : <EOL> if self . incr < self . count : <EOL> self . order ( self . asset , self . amount ) <EOL> self . incr += <NUM_LIT:1> <EOL> class HeavyBuyAlgorithm ( TradingAlgorithm ) : <EOL> """<STR_LIT>""" <EOL> def initialize ( self , sid , amount ) : <EOL> self . asset = self . sid ( sid ) <EOL> self . amount = amount <EOL> self . incr = <NUM_LIT:0> <EOL> def handle_data ( self , data ) : <EOL> self . order ( self . asset , self . amount ) <EOL> self . incr += <NUM_LIT:1> <EOL> class NoopAlgorithm ( TradingAlgorithm ) : <EOL> """<STR_LIT>""" <EOL> def initialize ( self ) : <EOL> pass <EOL> def handle_data ( self , data ) : <EOL> pass <EOL> class ExceptionAlgorithm ( TradingAlgorithm ) : <EOL> """<STR_LIT>""" <EOL> def initialize ( self , throw_from , sid ) : <EOL> self . throw_from = throw_from <EOL> self . asset = self . sid ( sid ) <EOL> if self . throw_from == "<STR_LIT>" : <EOL> raise Exception ( "<STR_LIT>" ) <EOL> else : <EOL> pass <EOL> def set_portfolio ( self , portfolio ) : <EOL> if self . throw_from == "<STR_LIT>" : <EOL> raise Exception ( "<STR_LIT>" ) <EOL> else : <EOL> pass <EOL> def handle_data ( self , data ) : <EOL> if self . throw_from == "<STR_LIT>" : <EOL> raise Exception ( "<STR_LIT>" ) <EOL> else : <EOL> pass <EOL> def get_sid_filter ( self ) : <EOL> if self . throw_from == "<STR_LIT>" : <EOL> raise Exception ( "<STR_LIT>" ) <EOL> else : <EOL> return [ self . asset ] <EOL> def set_transact_setter ( self , txn_sim_callable ) : <EOL> pass <EOL> class DivByZeroAlgorithm ( TradingAlgorithm ) : <EOL> def initialize ( self , sid ) : <EOL> self . asset = self . sid ( sid ) <EOL> self . incr = <NUM_LIT:0> <EOL> def handle_data ( self , data ) : <EOL> self . incr += <NUM_LIT:1> <EOL> if self . incr > <NUM_LIT:1> : <EOL> <NUM_LIT:5> / <NUM_LIT:0> <EOL> pass <EOL> class TooMuchProcessingAlgorithm ( TradingAlgorithm ) : <EOL> def initialize ( self , sid ) : <EOL> self . asset = self . sid ( sid ) <EOL> def handle_data ( self , data ) : <EOL> for i in range ( <NUM_LIT> ) : <EOL> self . foo = i <EOL> class TimeoutAlgorithm ( TradingAlgorithm ) : <EOL> def initialize ( self , sid ) : <EOL> self . asset = self . sid ( sid ) <EOL> self . incr = <NUM_LIT:0> <EOL> def handle_data ( self , data ) : <EOL> if self . incr > <NUM_LIT:4> : <EOL> import time <EOL> time . sleep ( <NUM_LIT:100> ) <EOL> pass <EOL> class RecordAlgorithm ( TradingAlgorithm ) : <EOL> def initialize ( self ) : <EOL> self . incr = <NUM_LIT:0> <EOL> def handle_data ( self , data ) : <EOL> self . incr += <NUM_LIT:1> <EOL> self . record ( incr = self . incr ) <EOL> name = '<STR_LIT:name>' <EOL> self . record ( name , self . incr ) <EOL> record ( name , self . incr , '<STR_LIT>' , <NUM_LIT:2> , name3 = self . incr ) <EOL> class TestOrderAlgorithm ( TradingAlgorithm ) : <EOL> def initialize ( self ) : <EOL> self . incr = <NUM_LIT:0> <EOL> def handle_data ( self , data ) : <EOL> if self . incr == <NUM_LIT:0> : <EOL> assert <NUM_LIT:0> not in self . portfolio . positions <EOL> else : <EOL> assert self . portfolio . positions [ <NUM_LIT:0> ] [ '<STR_LIT>' ] == self . incr , "<STR_LIT>" <EOL> assert self . portfolio . positions [ <NUM_LIT:0> ] [ '<STR_LIT>' ] == data . current ( sid ( <NUM_LIT:0> ) , "<STR_LIT>" ) , "<STR_LIT>" <EOL> self . incr += <NUM_LIT:1> <EOL> self . order ( self . sid ( <NUM_LIT:0> ) , <NUM_LIT:1> ) <EOL> class TestOrderInstantAlgorithm ( TradingAlgorithm ) : <EOL> def initialize ( self ) : <EOL> self . incr = <NUM_LIT:0> <EOL> self . last_price = None <EOL> def handle_data ( self , data ) : <EOL> if self . incr == <NUM_LIT:0> : <EOL> assert <NUM_LIT:0> not in self . portfolio . positions <EOL> else : <EOL> assert self . portfolio . positions [ <NUM_LIT:0> ] [ '<STR_LIT>' ] == self . incr , "<STR_LIT>" <EOL> assert self . portfolio . positions [ <NUM_LIT:0> ] [ '<STR_LIT>' ] == self . last_price , "<STR_LIT>" <EOL> self . incr += <NUM_LIT:1> <EOL> self . order_value ( self . sid ( <NUM_LIT:0> ) , data . current ( sid ( <NUM_LIT:0> ) , "<STR_LIT>" ) ) <EOL> self . last_price = data . current ( sid ( <NUM_LIT:0> ) , "<STR_LIT>" ) <EOL> class TestOrderStyleForwardingAlgorithm ( TradingAlgorithm ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , * args , ** kwargs ) : <EOL> self . method_name = kwargs . pop ( '<STR_LIT>' ) <EOL> super ( TestOrderStyleForwardingAlgorithm , self ) . __init__ ( * args , ** kwargs ) <EOL> def initialize ( self ) : <EOL> self . incr = <NUM_LIT:0> <EOL> self . last_price = None <EOL> def handle_data ( self , data ) : <EOL> if self . incr == <NUM_LIT:0> : <EOL> assert len ( self . portfolio . positions . keys ( ) ) == <NUM_LIT:0> <EOL> method_to_check = getattr ( self , self . method_name ) <EOL> method_to_check ( self . sid ( <NUM_LIT> ) , <EOL> data . current ( sid ( <NUM_LIT:0> ) , "<STR_LIT>" ) , <EOL> style = StopLimitOrder ( <NUM_LIT:10> , <NUM_LIT:10> ) ) <EOL> assert len ( self . blotter . open_orders [ self . sid ( <NUM_LIT> ) ] ) == <NUM_LIT:1> <EOL> result = self . blotter . open_orders [ self . sid ( <NUM_LIT> ) ] [ <NUM_LIT:0> ] <EOL> assert result . limit == <NUM_LIT:10> <EOL> assert result . stop == <NUM_LIT:10> <EOL> self . incr += <NUM_LIT:1> <EOL> class TestOrderValueAlgorithm ( TradingAlgorithm ) : <EOL> def initialize ( self ) : <EOL> self . incr = <NUM_LIT:0> <EOL> self . sale_price = None <EOL> def handle_data ( self , data ) : <EOL> if self . incr == <NUM_LIT:0> : <EOL> assert <NUM_LIT:0> not in self . portfolio . positions <EOL> else : <EOL> assert self . portfolio . positions [ <NUM_LIT:0> ] [ '<STR_LIT>' ] == self . incr , "<STR_LIT>" <EOL> assert self . portfolio . positions [ <NUM_LIT:0> ] [ '<STR_LIT>' ] == data . current ( sid ( <NUM_LIT:0> ) , "<STR_LIT>" ) , "<STR_LIT>" <EOL> self . incr += <NUM_LIT:2> <EOL> multiplier = <NUM_LIT> <EOL> if isinstance ( self . sid ( <NUM_LIT:0> ) , Future ) : <EOL> multiplier *= self . sid ( <NUM_LIT:0> ) . multiplier <EOL> self . order_value ( <EOL> self . sid ( <NUM_LIT:0> ) , <EOL> data . current ( sid ( <NUM_LIT:0> ) , "<STR_LIT>" ) * multiplier <EOL> ) <EOL> class TestTargetAlgorithm ( TradingAlgorithm ) : <EOL> def initialize ( self ) : <EOL> self . set_slippage ( FixedSlippage ( ) ) <EOL> self . target_shares = <NUM_LIT:0> <EOL> self . sale_price = None <EOL> def handle_data ( self , data ) : <EOL> if self . target_shares == <NUM_LIT:0> : <EOL> assert <NUM_LIT:0> not in self . portfolio . positions <EOL> else : <EOL> assert self . portfolio . positions [ <NUM_LIT:0> ] [ '<STR_LIT>' ] == self . target_shares , "<STR_LIT>" <EOL> assert self . portfolio . positions [ <NUM_LIT:0> ] [ '<STR_LIT>' ] == data . current ( sid ( <NUM_LIT:0> ) , "<STR_LIT>" ) , "<STR_LIT>" <EOL> self . target_shares = <NUM_LIT:10> <EOL> self . order_target ( self . sid ( <NUM_LIT:0> ) , self . target_shares ) <EOL> class TestOrderPercentAlgorithm ( TradingAlgorithm ) : <EOL> def initialize ( self ) : <EOL> self . set_slippage ( FixedSlippage ( ) ) <EOL> self . target_shares = <NUM_LIT:0> <EOL> self . sale_price = None <EOL> def handle_data ( self , data ) : <EOL> if self . target_shares == <NUM_LIT:0> : <EOL> assert <NUM_LIT:0> not in self . portfolio . positions <EOL> self . order ( self . sid ( <NUM_LIT:0> ) , <NUM_LIT:10> ) <EOL> self . target_shares = <NUM_LIT:10> <EOL> return <EOL> else : <EOL> assert self . portfolio . positions [ <NUM_LIT:0> ] [ '<STR_LIT>' ] == self . target_shares , "<STR_LIT>" <EOL> assert self . portfolio . positions [ <NUM_LIT:0> ] [ '<STR_LIT>' ] == data . current ( sid ( <NUM_LIT:0> ) , "<STR_LIT>" ) , "<STR_LIT>" <EOL> self . order_percent ( self . sid ( <NUM_LIT:0> ) , <NUM_LIT> ) <EOL> if isinstance ( self . sid ( <NUM_LIT:0> ) , Equity ) : <EOL> price = data . current ( sid ( <NUM_LIT:0> ) , "<STR_LIT>" ) <EOL> new_shares = ( <NUM_LIT> * self . portfolio . portfolio_value ) / price <EOL> elif isinstance ( self . sid ( <NUM_LIT:0> ) , Future ) : <EOL> new_shares = ( <NUM_LIT> * self . portfolio . portfolio_value ) / ( data . current ( sid ( <NUM_LIT:0> ) , "<STR_LIT>" ) * <EOL> self . sid ( <NUM_LIT:0> ) . contract_multiplier ) <EOL> new_shares = int ( round_if_near_integer ( new_shares ) ) <EOL> self . target_shares += new_shares <EOL> class TestTargetPercentAlgorithm ( TradingAlgorithm ) : <EOL> def initialize ( self ) : <EOL> self . ordered = False <EOL> self . sale_price = None <EOL> self . set_slippage ( FixedSlippage ( ) ) <EOL> self . set_commission ( PerShare ( <NUM_LIT:0> ) ) <EOL> def handle_data ( self , data ) : <EOL> if not self . ordered : <EOL> assert <NUM_LIT:0> not in self . portfolio . positions <EOL> else : <EOL> target_value = self . portfolio . portfolio_value * <NUM_LIT> <EOL> position_value = self . portfolio . positions [ <NUM_LIT:0> ] [ '<STR_LIT>' ] * self . sale_price <EOL> assert abs ( target_value - position_value ) <= self . sale_price , "<STR_LIT>" <EOL> assert self . portfolio . positions [ <NUM_LIT:0> ] [ '<STR_LIT>' ] == data . current ( sid ( <NUM_LIT:0> ) , "<STR_LIT>" ) , "<STR_LIT>" <EOL> self . sale_price = data . current ( sid ( <NUM_LIT:0> ) , "<STR_LIT>" ) <EOL> self . order_target_percent ( self . sid ( <NUM_LIT:0> ) , <NUM_LIT> ) <EOL> self . ordered = True <EOL> class TestTargetValueAlgorithm ( TradingAlgorithm ) : <EOL> def initialize ( self ) : <EOL> self . set_slippage ( FixedSlippage ( ) ) <EOL> self . target_shares = <NUM_LIT:0> <EOL> self . sale_price = None <EOL> def handle_data ( self , data ) : <EOL> if self . target_shares == <NUM_LIT:0> : <EOL> assert <NUM_LIT:0> not in self . portfolio . positions <EOL> self . order ( self . sid ( <NUM_LIT:0> ) , <NUM_LIT:10> ) <EOL> self . target_shares = <NUM_LIT:10> <EOL> return <EOL> else : <EOL> assert self . portfolio . positions [ <NUM_LIT:0> ] [ '<STR_LIT>' ] == self . target_shares , "<STR_LIT>" <EOL> assert self . portfolio . positions [ <NUM_LIT:0> ] [ '<STR_LIT>' ] == data . current ( sid ( <NUM_LIT:0> ) , "<STR_LIT>" ) , "<STR_LIT>" <EOL> self . order_target_value ( self . sid ( <NUM_LIT:0> ) , <NUM_LIT:20> ) <EOL> self . target_shares = np . round ( <NUM_LIT:20> / data . current ( sid ( <NUM_LIT:0> ) , "<STR_LIT>" ) ) <EOL> if isinstance ( self . sid ( <NUM_LIT:0> ) , Equity ) : <EOL> self . target_shares = np . round ( <NUM_LIT:20> / data . current ( sid ( <NUM_LIT:0> ) , "<STR_LIT>" ) ) <EOL> if isinstance ( self . sid ( <NUM_LIT:0> ) , Future ) : <EOL> self . target_shares = np . round ( <EOL> <NUM_LIT:20> / ( data . current ( sid ( <NUM_LIT:0> ) , "<STR_LIT>" ) * self . sid ( <NUM_LIT:0> ) . multiplier ) ) <EOL> class FutureFlipAlgo ( TestAlgorithm ) : <EOL> def handle_data ( self , data ) : <EOL> if len ( self . portfolio . positions ) > <NUM_LIT:0> : <EOL> if self . portfolio . positions [ self . asset . sid ] [ "<STR_LIT>" ] > <NUM_LIT:0> : <EOL> self . order_target ( self . asset , - self . amount ) <EOL> else : <EOL> self . order_target ( self . asset , <NUM_LIT:0> ) <EOL> else : <EOL> self . order_target ( self . asset , self . amount ) <EOL> class SetMaxLeverageAlgorithm ( TradingAlgorithm ) : <EOL> def initialize ( self , max_leverage = None ) : <EOL> self . set_max_leverage ( max_leverage = max_leverage ) <EOL> class SetMaxPositionSizeAlgorithm ( TradingAlgorithm ) : <EOL> def initialize ( self , asset = None , max_shares = None , max_notional = None ) : <EOL> self . set_slippage ( FixedSlippage ( ) ) <EOL> self . order_count = <NUM_LIT:0> <EOL> self . set_max_position_size ( asset = asset , <EOL> max_shares = max_shares , <EOL> max_notional = max_notional ) <EOL> class SetMaxOrderSizeAlgorithm ( TradingAlgorithm ) : <EOL> def initialize ( self , asset = None , max_shares = None , max_notional = None ) : <EOL> self . order_count = <NUM_LIT:0> <EOL> self . set_max_order_size ( asset = asset , <EOL> max_shares = max_shares , <EOL> max_notional = max_notional ) <EOL> class SetDoNotOrderListAlgorithm ( TradingAlgorithm ) : <EOL> def initialize ( self , sid = None , restricted_list = None ) : <EOL> self . order_count = <NUM_LIT:0> <EOL> self . set_do_not_order_list ( restricted_list ) <EOL> class SetMaxOrderCountAlgorithm ( TradingAlgorithm ) : <EOL> def initialize ( self , count ) : <EOL> self . order_count = <NUM_LIT:0> <EOL> self . set_max_order_count ( count ) <EOL> self . minute_count = <NUM_LIT:0> <EOL> class SetLongOnlyAlgorithm ( TradingAlgorithm ) : <EOL> def initialize ( self ) : <EOL> self . order_count = <NUM_LIT:0> <EOL> self . set_long_only ( ) <EOL> class SetAssetDateBoundsAlgorithm ( TradingAlgorithm ) : <EOL> """<STR_LIT>""" <EOL> def initialize ( self ) : <EOL> self . register_trading_control ( AssetDateBounds ( ) ) <EOL> def handle_data ( algo , data ) : <EOL> algo . order ( algo . sid ( <NUM_LIT:0> ) , <NUM_LIT:1> ) <EOL> class TestRegisterTransformAlgorithm ( TradingAlgorithm ) : <EOL> def initialize ( self , * args , ** kwargs ) : <EOL> self . set_slippage ( FixedSlippage ( ) ) <EOL> def handle_data ( self , data ) : <EOL> pass <EOL> class AmbitiousStopLimitAlgorithm ( TradingAlgorithm ) : <EOL> """<STR_LIT>""" <EOL> def initialize ( self , * args , ** kwargs ) : <EOL> self . asset = self . sid ( kwargs . pop ( '<STR_LIT>' ) ) <EOL> def handle_data ( self , data ) : <EOL> self . order ( self . asset , <NUM_LIT:100> , limit_price = <NUM_LIT:1> ) <EOL> self . order ( self . asset , <NUM_LIT:100> , stop_price = <NUM_LIT> ) <EOL> self . order ( self . asset , <NUM_LIT:100> , limit_price = <NUM_LIT> , stop_price = <NUM_LIT> ) <EOL> self . order ( self . asset , <NUM_LIT:100> , limit_price = <NUM_LIT:1> , stop_price = <NUM_LIT:1> ) <EOL> self . order ( self . asset , - <NUM_LIT:100> , limit_price = <NUM_LIT> ) <EOL> self . order ( self . asset , - <NUM_LIT:100> , stop_price = <NUM_LIT:1> ) <EOL> self . order ( self . asset , - <NUM_LIT:100> , limit_price = <NUM_LIT> , stop_price = <NUM_LIT> ) <EOL> self . order ( self . asset , - <NUM_LIT:100> , limit_price = <NUM_LIT:1> , stop_price = <NUM_LIT:1> ) <EOL> self . order ( self . asset , <NUM_LIT:100> , limit_price = <NUM_LIT> ) <EOL> self . order ( self . asset , - <NUM_LIT:100> , stop_price = <NUM_LIT> ) <EOL> class SetPortfolioAlgorithm ( TradingAlgorithm ) : <EOL> """<STR_LIT>""" <EOL> def initialize ( self , * args , ** kwargs ) : <EOL> pass <EOL> def handle_data ( self , data ) : <EOL> self . portfolio = <NUM_LIT:3> <EOL> class TALIBAlgorithm ( TradingAlgorithm ) : <EOL> """<STR_LIT>""" <EOL> def initialize ( self , * args , ** kwargs ) : <EOL> if '<STR_LIT>' not in kwargs : <EOL> raise KeyError ( '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> elif not isinstance ( kwargs [ '<STR_LIT>' ] , ( list , tuple ) ) : <EOL> self . talib_transforms = ( kwargs [ '<STR_LIT>' ] , ) <EOL> else : <EOL> self . talib_transforms = kwargs [ '<STR_LIT>' ] <EOL> self . talib_results = dict ( ( t , [ ] ) for t in self . talib_transforms ) <EOL> def handle_data ( self , data ) : <EOL> for t in self . talib_transforms : <EOL> result = t . handle_data ( data ) <EOL> if result is None : <EOL> if len ( t . talib_fn . output_names ) == <NUM_LIT:1> : <EOL> result = np . nan <EOL> else : <EOL> result = ( np . nan , ) * len ( t . talib_fn . output_names ) <EOL> self . talib_results [ t ] . append ( result ) <EOL> class EmptyPositionsAlgorithm ( TradingAlgorithm ) : <EOL> """<STR_LIT>""" <EOL> def initialize ( self , sids , * args , ** kwargs ) : <EOL> self . ordered = False <EOL> self . exited = False <EOL> self . sids = sids <EOL> def handle_data ( self , data ) : <EOL> if not self . ordered : <EOL> for s in self . sids : <EOL> self . order ( self . sid ( s ) , <NUM_LIT:1> ) <EOL> self . ordered = True <EOL> if not self . exited : <EOL> amounts = [ pos . amount for pos <EOL> in itervalues ( self . portfolio . positions ) ] <EOL> if ( <EOL> len ( amounts ) > <NUM_LIT:0> and <EOL> all ( [ ( amount == <NUM_LIT:1> ) for amount in amounts ] ) <EOL> ) : <EOL> for stock in self . portfolio . positions : <EOL> self . order ( self . sid ( stock ) , - <NUM_LIT:1> ) <EOL> self . exited = True <EOL> self . record ( num_positions = len ( self . portfolio . positions ) ) <EOL> class InvalidOrderAlgorithm ( TradingAlgorithm ) : <EOL> """<STR_LIT>""" <EOL> def initialize ( self , * args , ** kwargs ) : <EOL> self . asset = self . sid ( kwargs . pop ( '<STR_LIT>' ) [ <NUM_LIT:0> ] ) <EOL> def handle_data ( self , data ) : <EOL> from zipline . api import ( <EOL> order_percent , <EOL> order_target , <EOL> order_target_percent , <EOL> order_target_value , <EOL> order_value , <EOL> ) <EOL> for style in [ MarketOrder ( ) , LimitOrder ( <NUM_LIT:10> ) , <EOL> StopOrder ( <NUM_LIT:10> ) , StopLimitOrder ( <NUM_LIT:10> , <NUM_LIT:10> ) ] : <EOL> with assert_raises ( UnsupportedOrderParameters ) : <EOL> order ( self . asset , <NUM_LIT:10> , limit_price = <NUM_LIT:10> , style = style ) <EOL> with assert_raises ( UnsupportedOrderParameters ) : <EOL> order ( self . asset , <NUM_LIT:10> , stop_price = <NUM_LIT:10> , style = style ) <EOL> with assert_raises ( UnsupportedOrderParameters ) : <EOL> order_value ( self . asset , <NUM_LIT> , limit_price = <NUM_LIT:10> , style = style ) <EOL> with assert_raises ( UnsupportedOrderParameters ) : <EOL> order_value ( self . asset , <NUM_LIT> , stop_price = <NUM_LIT:10> , style = style ) <EOL> with assert_raises ( UnsupportedOrderParameters ) : <EOL> order_percent ( self . asset , <NUM_LIT> , limit_price = <NUM_LIT:10> , style = style ) <EOL> with assert_raises ( UnsupportedOrderParameters ) : <EOL> order_percent ( self . asset , <NUM_LIT> , stop_price = <NUM_LIT:10> , style = style ) <EOL> with assert_raises ( UnsupportedOrderParameters ) : <EOL> order_target ( self . asset , <NUM_LIT:100> , limit_price = <NUM_LIT:10> , style = style ) <EOL> with assert_raises ( UnsupportedOrderParameters ) : <EOL> order_target ( self . asset , <NUM_LIT:100> , stop_price = <NUM_LIT:10> , style = style ) <EOL> with assert_raises ( UnsupportedOrderParameters ) : <EOL> order_target_value ( self . asset , <NUM_LIT:100> , <EOL> limit_price = <NUM_LIT:10> , <EOL> style = style ) <EOL> with assert_raises ( UnsupportedOrderParameters ) : <EOL> order_target_value ( self . asset , <NUM_LIT:100> , <EOL> stop_price = <NUM_LIT:10> , <EOL> style = style ) <EOL> with assert_raises ( UnsupportedOrderParameters ) : <EOL> order_target_percent ( self . asset , <NUM_LIT> , <EOL> limit_price = <NUM_LIT:10> , <EOL> style = style ) <EOL> with assert_raises ( UnsupportedOrderParameters ) : <EOL> order_target_percent ( self . asset , <NUM_LIT> , <EOL> stop_price = <NUM_LIT:10> , <EOL> style = style ) <EOL> def initialize_noop ( context ) : <EOL> pass <EOL> def handle_data_noop ( context , data ) : <EOL> pass <EOL> def initialize_api ( context ) : <EOL> context . incr = <NUM_LIT:0> <EOL> context . sale_price = None <EOL> set_slippage ( FixedSlippage ( ) ) <EOL> def handle_data_api ( context , data ) : <EOL> if context . incr == <NUM_LIT:0> : <EOL> assert <NUM_LIT:0> not in context . portfolio . positions <EOL> else : <EOL> assert context . portfolio . positions [ <NUM_LIT:0> ] [ '<STR_LIT>' ] == context . incr , "<STR_LIT>" <EOL> assert context . portfolio . positions [ <NUM_LIT:0> ] [ '<STR_LIT>' ] == data . current ( sid ( <NUM_LIT:0> ) , "<STR_LIT>" ) , "<STR_LIT>" <EOL> context . incr += <NUM_LIT:1> <EOL> order ( sid ( <NUM_LIT:0> ) , <NUM_LIT:1> ) <EOL> record ( incr = context . incr ) <EOL> noop_algo = """<STR_LIT>""" <EOL> no_handle_data = """<STR_LIT>""" <EOL> api_algo = """<STR_LIT>""" <EOL> api_get_environment_algo = """<STR_LIT>""" <EOL> api_symbol_algo = """<STR_LIT>""" <EOL> call_order_in_init = """<STR_LIT>""" <EOL> access_portfolio_in_init = """<STR_LIT>""" <EOL> access_account_in_init = """<STR_LIT>""" <EOL> call_all_order_methods = """<STR_LIT>""" <EOL> record_variables = """<STR_LIT>""" <EOL> record_float_magic = """<STR_LIT>""" <EOL> call_with_kwargs = """<STR_LIT>""" <EOL> call_without_kwargs = """<STR_LIT>""" <EOL> call_with_bad_kwargs_history = """<STR_LIT>""" <EOL> call_with_bad_kwargs_current = """<STR_LIT>""" <EOL> bad_type_history_assets = """<STR_LIT>""" <EOL> bad_type_history_fields = """<STR_LIT>""" <EOL> bad_type_history_bar_count = """<STR_LIT>""" <EOL> bad_type_history_frequency = """<STR_LIT>""" <EOL> bad_type_current_assets = """<STR_LIT>""" <EOL> bad_type_current_fields = """<STR_LIT>""" <EOL> bad_type_is_stale_assets = """<STR_LIT>""" <EOL> bad_type_can_trade_assets = """<STR_LIT>""" <EOL> bad_type_history_assets_kwarg = """<STR_LIT>""" <EOL> bad_type_history_fields_kwarg = """<STR_LIT>""" <EOL> bad_type_history_bar_count_kwarg = """<STR_LIT>""" <EOL> bad_type_history_frequency_kwarg = """<STR_LIT>""" <EOL> bad_type_current_assets_kwarg = """<STR_LIT>""" <EOL> bad_type_current_fields_kwarg = """<STR_LIT>""" <EOL> bad_type_history_assets_kwarg_list = """<STR_LIT>""" <EOL> call_with_bad_kwargs_get_open_orders = """<STR_LIT>""" <EOL> call_with_good_kwargs_get_open_orders = """<STR_LIT>""" <EOL> call_with_no_kwargs_get_open_orders = """<STR_LIT>""" <EOL> empty_positions = """<STR_LIT>""" <EOL> set_benchmark_algo = """<STR_LIT>""" </s>
