def dispatch_message(self, content): try: if 'oid' in content: o = EOffer.from_data(content) self.register_their_offer(o) elif 'pid' in content: self.dispatch_exchange_proposal(content) except Exception as e: # pragma: no cover LOGERROR( "got exception %s " # pragma: no cover "when dispatching a message", e) # pragma: no cover raise # pragma: no cover
def clear_orders(self, ep): self.fire_event('trade_complete', ep) try: if isinstance(ep, MyEProposal): if ep.my_offer: del self.my_offers[ep.my_offer.oid] del self.their_offers[ep.offer.oid] else: del self.my_offers[ep.offer.oid] except Exception as e: # pragma: no cover LOGERROR( "there was an exception " # pragma: no cover "when clearing offers: %s", e) # pragma: no cover self.fire_event('offers_updated', None)
def match_offers(self): if self.has_active_ep(): return for my_offer in self.my_offers.values(): for their_offer in self.their_offers.values(): LOGINFO("matches %s", my_offer.matches(their_offer)) if my_offer.matches(their_offer): success = False try: self.make_exchange_proposal(their_offer, my_offer) success = True except Exception as e: # pragma: no cover LOGERROR( "Exception during " # pragma: no cover "matching offer %s", e) # pragma: no cover raise # pragma: no cover if success: return