#NEWLINE# def testRanOutOfCash( self ) : #NEWLINE# #INDENT# class Strategy ( TestStrategy ) : #NEWLINE# #INDENT# def __init__( self , feed , brk ) : #NEWLINE# #INDENT# TestStrategy . __init__ ( self , feed , brk ) #NEWLINE# self . errors = 0 #NEWLINE# #UNINDENT# def onBars( self , bars ) : #NEWLINE# #INDENT# try : #NEWLINE# #INDENT# self . limitOrder ( 'BTC' , 100 , 0.1 ) #NEWLINE# #UNINDENT# except Exception : #NEWLINE# #INDENT# self . errors += 1 #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# barFeed = TestingLiveTradeFeed ( ) #NEWLINE# barFeed . addTrade ( datetime . datetime ( 2000 , 1 , 1 ) , 1 , 100 , 10 ) #NEWLINE# barFeed . addTrade ( datetime . datetime ( 2000 , 1 , 2 ) , 1 , 100 , 10 ) #NEWLINE# barFeed . addTrade ( datetime . datetime ( 2000 , 1 , 3 ) , 1 , 100 , 10 ) #NEWLINE# brk = broker . PaperTradingBroker ( 10.025 , barFeed ) #NEWLINE# strat = Strategy ( brk , brk ) #NEWLINE# strat . run ( ) #NEWLINE# self . assertEquals ( strat . errors , 2 ) #NEWLINE# self . assertEquals ( brk . getShares ( 'BTC' ) , 0.1 ) #NEWLINE# self . assertEquals ( brk . getCash ( ) , 0 )