Exemple #1
0
class PaperExecutionService(VirtualExecutionService):
    def __init__(self, username=USERNAME, password=PASSWORD):
        super(PaperExecutionService, self).__init__()
        self.client = API_T()
        self.client.login(username, password)
        self._static = {}

    def get_market_prices(self, market_id):
        if market_id not in self._static:
            static = self.client.get_market(market_id)
            self._static[market_id] = static
        else:
            static = self._static[market_id]
        id_to_name = dict(map(lambda x: (x['selection_id'], extract_horse_name(x['name'])), static['runners']))

        raw = self.client.get_market_prices(market_id)
        prices = raw['runners']
        scheduled_off = dateutil.parser.parse(static['marketTime']).replace(tzinfo=None)
        for px in prices:
            px['market_id'] = market_id
            px['country'] = static['countryISO3']
            px['event'] = static['name']
            px['course'] = ''
            px['scheduled_off'] = scheduled_off
            px['selection'] = id_to_name[px['selection_id']]
        return prices