Example #1
0
    def check_in_process_offers(self):
        in_process_offers = [
            ge_slot for instance in self.runescape_windows
            for ge_slot in instance.list_of_ge_slots
            if ge_slot.current_state is not None
        ]

        for ge_slot in in_process_offers:

            if not ge_slot.image_is_current:
                ge_slot.set_new_image_of_slot()

            elif ge_slot.offer_is_aged:
                print(
                    'Image of {} has not been updated in 30 minutes so we are aborting the offer'
                    .format(ge_slot.item.item_name))
                # TODO: This chaining is bad
                runescape_instance = ge_slot.runescape_instance

                runescape_instance.cancel_offer(ge_slot)
                wait_for(gui.offer_canceled, runescape_instance)
                print(
                    f"Cancelled {ge_slot.item.item_name} since the offer hasn't been updated in a while"
                )
                # then if the item was a buy we handle it

                # if ge_slot.current_state == 'buy':
                #     handle_cancelling_buy(ge_slot.runescape_instance, ge_slot, ge_slot.runescape_instance.items_in_use)
                # elif ge_slot.current_state == 'sell':
                #     handle_cancelling_sell(ge_slot, ge_slot.runescape_instance.items_in_use)
                # we check if any of the item  bought and if so try to sell it
                # we could check the sale history to read the number of items bought and update accordingly
                # then if it was a sell we handle it
                # we would simply retrieve the items and money and update accordingly, then find the new sell price and sell
                break_check = True
    def cancel_offer(self, ge_slot):
        self.open_ge_slot(ge_slot)
        self.select_abort_offer(ge_slot)
        wait_for(gui.offer_canceled, ge_slot.runescape_instance)
        quantity = check_quantity(self.loc_price)  # You bought/sold a qty X
        price_per_item = check_price(self.loc_price)  # For a total price of Y
        total_price = quantity * price_per_item
        self.GEMerch.add_transaction(item=ge_slot.item,
                                     action=ge_slot.item.current_state,
                                     qty=quantity,
                                     price=price_per_item)
        # If this is a buy offer, how much $ did I put into the slot originally?
        # then money += original_offer_amt - (qty_bought * price_per_item)
        # new_qty_to_sell = qty_bought
        # sell items at current sell price or check new buy price
        if ge_slot.item.current_state == 'buy':
            ge_slot.item.qty_in_inventory = quantity
            ge_slot.runescape_instance.money += ge_slot.item.money_in_process - total_price
            ge_slot.item.money_in_process = 0
            ge_slot.item.reset_item_and_slot()
            if quantity > 0:
                ge_slot.item.sell_items(price=ge_slot.item.buy_price)
        # If this is a sell offer, how many items did I originally try to sell?
        # new_qty_to_sell = original_qty_to_sell (quantity in process - quantity
        # then money += price_per_item * qty
        # sell items at original buy price to just unload or check new buy price
        if ge_slot.item.current_state == 'sell':
            ge_slot.runescape_instance.money += quantity * price_per_item
            ge_slot.item.money_in_process = 0
            ge_slot.item.qty_in_inventory += ge_slot.item.qty_in_process - quantity
            ge_slot.item.sell_items(price=ge_slot.item.buy_price)

        self.collect_items()

        ge_slot.item.reset_item_and_slot()
    def collect_items_and_return_price(self, ge_slot):
        self.open_ge_slot(ge_slot)
        price = check_price(self.loc_price)

        if item_in_slot(self.region):
            self.collect_2()

        self.collect_1()
        wait_for(gui.view_all_offers, self)

        return int(price)
Example #4
0
    def sell_items(self, price=None):
        if price is None:
            price = self.sell_price
        self.ge_slot = self.runescape_instance.empty_ge_slot()

        self.runescape_instance.select_sell_bag(self.ge_slot)
        wait_for(gui.sell_offer, self.runescape_instance.region)

        self.runescape_instance.select_inventory_item()
        self.qty_in_process = self.qty_in_inventory
        self.qty_in_inventory = 0

        self.runescape_instance.enter_price(str(price))
        self.runescape_instance.confirm_offer()

        self.current_state('sell')
        print(f'Placed a sell order for {self.qty_in_process} {self.item_name} at {price} each')

        wait_for(gui.view_all_offers, self.runescape_instance.region)
        self.ge_slot.set_new_image_of_slot()
Example #5
0
    def buy_item(self, price, quantity):
        assert price * quantity < self.runescape_instance.money
        self.ge_slot = self.runescape_instance.empty_ge_slot()
        self.ge_slot.item = self

        self.runescape_instance.select_buy_bag(self.ge_slot)
        wait_for(gui.buy_prompt, self.runescape_instance)

        print(f'Buying: {self.item_name} At Price Each: {price}')
        random_typer(str(self.item_name))

        wait_for(self.image, self.runescape_instance)
        move_mouse_to_image_within_region(self.image)
        pyautogui.click()

        self.runescape_instance.enter_price(price)
        self.runescape_instance.enter_quantity(quantity)
        self.runescape_instance.confirm_offer()

        self.qty_in_process = quantity
        self.money_in_process = quantity * price
        self.runescape_instance.update_money(self.runescape_instance.money - self.money_in_process)
        self.set_time_buy_order_placed()
        self._buy_or_sell = 'buy'
        print(f'Placed a buy order for {quantity} {self.item_name} at {price} each')

        wait_for(gui.view_all_offers, self.runescape_instance)
        self.ge_slot.set_new_image_of_slot()
Example #6
0
    def fill_empty_slots(self):
        # TODO: This function does more than one thing
        # IF I have a pickled file I should verify whether its good or not
        empty_slots = []
        for instance in sorted(self.runescape_windows,
                               key=operator.attrgetter('money')):
            for ge_slot in instance.empty_ge_slots():
                empty_slots.append(ge_slot)

        if not empty_slots:
            print('No empty GE slots found or no items available')
            return

        empty_slot = empty_slots[0]

        # If item price_is_outdated() & score < 0 then reset score to 0 and see if its profitable?

        top_item = empty_slot.runescape_instance.best_item_available

        print(f'Top scored item is {top_item.item_name}')
        # Find the current sell price for the item chosen
        wait_for(gui.buy_bag, empty_slot)
        if top_item.price_is_outdated():
            # TODO: Refactor these functions so that they return the price and not set it to the item property
            top_item.find_current_sell_price()
            wait_for(gui.sell_bag, top_item.ge_slot)
            top_item.find_current_buy_price()

            # If this item is profitable, set prices for instant buy and sell

            if top_item.meets_profit_threshold():
                temp = top_item.sell_price
                top_item.set_price_instant_bought_at(top_item.buy_price)
                top_item.set_price_instant_sold_at(temp)

                # If this item has more than 5gp margin then undercut for faster sales
                if top_item.sell_price - top_item.buy_price > 5:
                    top_item.set_price_instant_bought_at(top_item.sell_price -
                                                         1)
                    top_item.set_price_instant_sold_at(top_item.buy_price + 1)

            else:
                print('Item does not meet profitability threshold, returning')
                return

        top_item.score_valid = True
        wait_for(gui.buy_bag, top_item.ge_slot)

        quantity = top_item.optimal_max_quantity
        price = top_item.buy_price
        top_item.buy_item(price=price, quantity=quantity)
Example #7
0
 def find_current_sell_price(self):
     self.ge_slot = self.runescape_instance.empty_ge_slot()
     self.runescape_instance.select_buy_bag(self.ge_slot)
     wait_for(gui.buy_prompt, self.runescape_instance)
     random_typer(str(self.item_name))
     wait_for(self.image, self.runescape_instance.region)
     move_mouse_to_image_within_region(self.image)
     pyautogui.click()
     test_price = 1000
     self.runescape_instance.enter_price(test_price)
     self.runescape_instance.confirm_offer()
     self.runescape_instance.update_money(-test_price)
     wait_for(gui.view_all_offers, self.runescape_instance)
     price_per_item = self.runescape_instance.collect_items_and_return_price(self.ge_slot)
     self.runescape_instance.update_money(test_price-price_per_item)
     wait_for(gui.view_all_offers, self.runescape_instance)
     self.runescape_instance.GEMerch.add_transaction(item=self, qty=1, price=price_per_item, action='Find_Sell')
     self.set_time_of_last_pc()
     self.set_price_instant_sold_at(price_per_item)
     self.reset_item_and_slot()
     print('Current sell price for {} is {} gp'.format(self.item_name, price_per_item))
Example #8
0
 def find_current_buy_price(self):
     self.ge_slot = self.runescape_instance.empty_ge_slot()
     self.runescape_instance.select_sell_bag(self.ge_slot)
     wait_for(gui.sell_offer, self.runescape_instance)
     self.runescape_instance.select_inventory_item()
     price = 1
     self.runescape_instance.enter_price(price)
     self.runescape_instance.confirm_offer()
     wait_for(gui.view_all_offers, self.ge_slot.runescape_instance)
     price = self.runescape_instance.collect_items_and_return_price(self.ge_slot)
     self.runescape_instance.update_money(price)
     wait_for(gui.view_all_offers, self.ge_slot.runescape_instance)
     self.runescape_instance.GEMerch.add_transaction(item=self, qty=1, price=price, action="Find_Buy")
     self.set_time_of_last_pc()
     self.set_price_instant_bought_at(price)
     self.reset_item_and_slot()
     print('Current buy price for {} is {} gp'.format(self.item_name, price))
 def cancel_sell_offer(self, ge_slot):
     self.open_ge_slot(ge_slot)
     self.select_abort_offer(ge_slot)
     wait_for(gui.offer_canceled, ge_slot.runescape_instance)
    def collect_items(self):
        if item_in_slot(self.region):
            self.collect_2()

        self.collect_1()
        wait_for(gui.view_all_offers, self)