#NEWLINE# def testActiveOrdersAndSharesLong( self ) : #NEWLINE# #INDENT# instrument = 'orcl' #NEWLINE# testCase = self #NEWLINE# class Strategy ( strategy . BacktestingStrategy ) : #NEWLINE# #INDENT# def __init__( self , barFeed , cash ) : #NEWLINE# #INDENT# strategy . BacktestingStrategy . __init__ ( self , barFeed , cash ) #NEWLINE# self . pos = None #NEWLINE# #UNINDENT# def onBars( self , bars ) : #NEWLINE# #INDENT# if ( self . pos is None ) : #NEWLINE# #INDENT# self . pos = self . enterLong ( instrument , 1 , True ) #NEWLINE# testCase . assertEqual ( len ( self . pos . getActiveOrders ( ) ) , 1 ) #NEWLINE# testCase . assertEqual ( self . pos . getShares ( ) , 0 ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if self . pos . isOpen ( ) : #NEWLINE# #INDENT# testCase . assertEqual ( len ( self . pos . getActiveOrders ( ) ) , 0 ) #NEWLINE# testCase . assertEqual ( self . pos . getShares ( ) , 1 ) #NEWLINE# self . pos . exitMarket ( ) #NEWLINE# testCase . assertEqual ( len ( self . pos . getActiveOrders ( ) ) , 1 ) #NEWLINE# testCase . assertEqual ( self . pos . getShares ( ) , 1 ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# testCase . assertEqual ( len ( self . pos . getActiveOrders ( ) ) , 0 ) #NEWLINE# testCase . assertEqual ( self . pos . getShares ( ) , 0 ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# barFeed = load_daily_barfeed ( instrument ) #NEWLINE# strat = Strategy ( barFeed , 1000 ) #NEWLINE# strat . run ( ) #NEWLINE# self . assertNotEqual ( strat . pos , None ) #NEWLINE# self . assertEqual ( strat . pos . isOpen ( ) , False ) #NEWLINE# self . assertEqual ( strat . pos . getPnL ( ) , ( 101.62 - 115.5 ) )