<s> """<STR_LIT>""" <EOL> from pyalgotrade import broker <EOL> from pyalgotrade . broker import backtesting <EOL> from pyalgotrade . bitstamp import common <EOL> from pyalgotrade . bitstamp import livebroker <EOL> LiveBroker = livebroker . LiveBroker <EOL> class BacktestingBroker ( backtesting . Broker ) : <EOL> MIN_TRADE_USD = <NUM_LIT:5> <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , cash , barFeed , fee = <NUM_LIT> ) : <EOL> commission = backtesting . TradePercentage ( fee ) <EOL> super ( BacktestingBroker , self ) . __init__ ( cash , barFeed , commission ) <EOL> def getInstrumentTraits ( self , instrument ) : <EOL> return common . BTCTraits ( ) <EOL> def submitOrder ( self , order ) : <EOL> if order . isInitial ( ) : <EOL> order . setAllOrNone ( False ) <EOL> order . setGoodTillCanceled ( True ) <EOL> return super ( BacktestingBroker , self ) . submitOrder ( order ) <EOL> def createMarketOrder ( self , action , instrument , quantity , onClose = False ) : <EOL> raise Exception ( "<STR_LIT>" ) <EOL> def createLimitOrder ( self , action , instrument , limitPrice , quantity ) : <EOL> if instrument != common . btc_symbol : <EOL> raise Exception ( "<STR_LIT>" ) <EOL> if action == broker . Order . Action . BUY_TO_COVER : <EOL> action = broker . Order . Action . BUY <EOL> elif action == broker . Order . Action . SELL_SHORT : <EOL> action = broker . Order . Action . SELL <EOL> if limitPrice * quantity < BacktestingBroker . MIN_TRADE_USD : <EOL> raise Exception ( "<STR_LIT>" % ( BacktestingBroker . MIN_TRADE_USD ) ) <EOL> if action == broker . Order . Action . BUY : <EOL> fee = self . getCommission ( ) . calculate ( None , limitPrice , quantity ) <EOL> cashRequired = limitPrice * quantity + fee <EOL> if cashRequired > self . getCash ( False ) : <EOL> raise Exception ( "<STR_LIT>" ) <EOL> elif action == broker . Order . Action . SELL : <EOL> if quantity > self . getShares ( common . btc_symbol ) : <EOL> raise Exception ( "<STR_LIT>" % ( common . btc_symbol ) ) <EOL> else : <EOL> raise Exception ( "<STR_LIT>" ) <EOL> return super ( BacktestingBroker , self ) . createLimitOrder ( action , instrument , limitPrice , quantity ) <EOL> def createStopOrder ( self , action , instrument , stopPrice , quantity ) : <EOL> raise Exception ( "<STR_LIT>" ) <EOL> def createStopLimitOrder ( self , action , instrument , stopPrice , limitPrice , quantity ) : <EOL> raise Exception ( "<STR_LIT>" ) <EOL> class PaperTradingBroker ( BacktestingBroker ) : <EOL> """<STR_LIT>""" <EOL> pass </s>
