def add_new_product_to_offers(self, new_product): new_offer = Offer.from_product(new_product) new_offer.price += settings['maxPriceMargin'] new_offer.shipping_time = { 'standard': settings['shipping'], 'prime': settings['primeShipping'] } new_offer.prime = True # self.products[new_product.uid] = new_product new_offer.offer_id = self.marketplace_api.add_offer(new_offer).offer_id self.offers[new_product.uid] = new_offer
def create_new_offer(self, offers: List[Offer], product: Product, product_prices_by_uid: dict): offer = Offer.from_product(product) offer.prime = True offer.shipping_time['standard'] = self.settings["shipping"] offer.shipping_time['prime'] = self.settings["primeShipping"] offer.merchant_id = self.merchant_id offer.price = self.calculate_optimal_price(product_prices_by_uid, offer, product.uid, current_offers=offers + [offer]) self.api.add_offer(offer)
def add_new_product_to_offers(self, new_product): new_offer = Offer.from_product(new_product) new_offer.price += settings['maxPriceMargin'] new_offer.shipping_time = { 'standard': settings['shipping'], 'prime': settings['primeShipping'] } new_offer.prime = True self.products[new_product.uid] = new_product try: new_offer.offer_id = self.marketplace_api.add_offer( new_offer).offer_id self.offers[new_product.uid] = new_offer except Exception as e: print('error on adding a new offer:', e)
def post_offer(self, product, price, existing_offer): new_offer = Offer.from_product(product) new_offer.price = price new_offer.shipping_time = { 'standard': settings['shipping'], 'prime': settings['primeShipping'] } new_offer.prime = True try: if existing_offer is None: return self.marketplace_api.add_offer(new_offer) else: self.marketplace_api.restock(existing_offer.offer_id, product.amount, product.signature) return None except Exception as e: print('error on posting an offer:', e)
def add_new_product_to_offers(self, new_product, marketplace_offers): new_offer = Offer.from_product(new_product) new_offer.price = self.calculate_prices(marketplace_offers, new_product.uid, new_product.price, new_product.product_id) new_offer.shipping_time = { 'standard': settings['shipping'], 'prime': settings['primeShipping'] } new_offer.prime = True try: new_offer.offer_id = self.marketplace_api.add_offer( new_offer).offer_id self.products[new_product.uid] = new_product self.offers[new_product.uid] = new_offer except Exception as e: print('error on adding a new offer:', e)
def execute_logic(self): try: offers = self.marketplace_api.get_offers(include_empty_offers=True) except Exception as e: print('error on getting offers from the marketplace:', e) return 1.0 / settings['max_req_per_sec'] own_offers = [ offer for offer in offers if offer.merchant_id == self.merchant_id ] own_offers_by_uid = {offer.uid: offer for offer in own_offers} missing_offers = settings['max_amount_of_offers'] - sum( offer.amount for offer in own_offers) new_products = [] for _ in range(missing_offers): try: prod = self.producer_api.buy_product() new_products.append(prod) except: pass for product in new_products: try: if product.uid in own_offers_by_uid: offer = own_offers_by_uid[product.uid] offer.amount += product.amount offer.signature = product.signature self.marketplace_api.restock(offer.offer_id, amount=product.amount, signature=product.signature) offer.price = self.price_product(product) self.marketplace_api.update_offer(offer) else: offer = Offer.from_product(product) offer.price = self.price_product(product) offer.prime = True offer.shipping_time['standard'] = self.settings['shipping'] offer.shipping_time['prime'] = self.settings[ 'primeShipping'] self.marketplace_api.add_offer(offer) except Exception as e: print('could not handle product:', product, e) return 1.0 / settings['max_req_per_sec']
def execute_logic(self): next_training_session = self.last_learning \ + datetime.timedelta(minutes=self.settings['minutes_between_learnings']) if next_training_session <= datetime.datetime.now(): self.last_learning = datetime.datetime.now() trigger_learning(self.merchant_token, self.merchant_id, settings['kafka_reverse_proxy_url']) request_count = 0 self.models_per_product = self.load_models_from_filesystem() try: offers = self.marketplace_api.get_offers(include_empty_offers=True) except Exception as e: print('error on getting offers:', e) return max(1.0, request_count) / settings['max_req_per_sec'] own_offers = [ offer for offer in offers if offer.merchant_id == self.merchant_id ] own_offers_by_uid = {offer.uid: offer for offer in own_offers} missing_offers = settings['max_amount_of_offers'] - sum( offer.amount for offer in own_offers) new_products = [] for _ in range(missing_offers): try: prod = self.producer_api.buy_product() new_products.append(prod) except: pass products = self.producer_api.get_products() product_prices_by_uid = { product.uid: product.price for product in products } for own_offer in own_offers: if own_offer.amount > 0: own_offer.price = self.price_product(own_offer, product_prices_by_uid, current_offers=offers) try: self.marketplace_api.update_offer(own_offer) request_count += 1 except Exception as e: print('error on updating offer:', e) for product in new_products: try: if product.uid in own_offers_by_uid: offer = own_offers_by_uid[product.uid] offer.amount += product.amount offer.signature = product.signature try: self.marketplace_api.restock( offer.offer_id, amount=product.amount, signature=product.signature) except Exception as e: print('error on restocking an offer:', e) offer.price = self.price_product(product, product_prices_by_uid, current_offers=offers) try: self.marketplace_api.update_offer(offer) request_count += 1 except Exception as e: print('error on updating an offer:', e) else: offer = Offer.from_product(product) offer.prime = True offer.shipping_time['standard'] = self.settings['shipping'] offer.shipping_time['prime'] = self.settings[ 'primeShipping'] offer.merchant_id = self.merchant_id offer.price = self.price_product(product, product_prices_by_uid, current_offers=offers + [offer]) try: self.marketplace_api.add_offer(offer) except Exception as e: print('error on adding an offer to the marketplace:', e) except Exception as e: print('could not handle product:', product, e) return max(1.0, request_count) / settings['max_req_per_sec']