<s> import datetime <EOL> from decimal import Decimal <EOL> import queue <EOL> from abc import ABCMeta , abstractmethod <EOL> from qstrader . event . event import FillEvent , OrderEvent <EOL> class ExecutionHandler ( object ) : <EOL> """<STR_LIT>""" <EOL> __metaclass__ = ABCMeta <EOL> @ abstractmethod <EOL> def execute_order ( self , event ) : <EOL> """<STR_LIT>""" <EOL> raise NotImplementedError ( "<STR_LIT>" ) <EOL> class IBSimulatedExecutionHandler ( ExecutionHandler ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , events_queue , price_handler ) : <EOL> """<STR_LIT>""" <EOL> self . events_queue = events_queue <EOL> self . price_handler = price_handler <EOL> def calculate_ib_commission ( self ) : <EOL> """<STR_LIT>""" <EOL> return Decimal ( "<STR_LIT>" ) <EOL> def execute_order ( self , event ) : <EOL> """<STR_LIT>""" <EOL> if event . type == '<STR_LIT>' : <EOL> timestamp = datetime . datetime . utcnow ( ) <EOL> ticker = event . ticker <EOL> action = event . action <EOL> quantity = event . quantity <EOL> bid , ask = self . price_handler . get_best_bid_ask ( ticker ) <EOL> if event . action == "<STR_LIT>" : <EOL> fill_price = Decimal ( str ( ask ) ) <EOL> else : <EOL> fill_price = Decimal ( str ( bid ) ) <EOL> exchange = "<STR_LIT>" <EOL> commission = self . calculate_ib_commission ( ) <EOL> fill_event = FillEvent ( <EOL> timestamp , ticker , <EOL> action , quantity , <EOL> exchange , fill_price , <EOL> commission <EOL> ) <EOL> self . events_queue . put ( fill_event ) </s>
