Beispiel #1
0
    def _get_partner_inventory(self,
                               partner_steam_id: str,
                               game: GameOptions,
                               merge: bool = True,
                               count: int = 5000) -> dict:
        url = '/'.join([
            SteamUrl.COMMUNITY_URL, 'inventory', partner_steam_id, game.app_id,
            game.context_id
        ])
        params = {'l': 'english', 'count': count}
        response = self._session.get(url, params=params, stream=True)
        self._check_response(response)
        response.raise_for_status()
        response_dict = response.json()
        if not response_dict:
            raise NullInventory()
        if response_dict.get('error'):
            raise ApiException(response_dict['error'])
        if response_dict['success'] != 1:
            raise ApiException('Success value should be 1.')

        if merge:
            return merge_items_with_descriptions_from_inventory(
                response_dict, game)
        return response_dict
Beispiel #2
0
 def buy_item(self,
              market_name: str,
              market_id: str,
              price: int,
              fee: int,
              game: GameOptions,
              currency: Currency = Currency.USD) -> dict:
     data = {
         "sessionid": self._session_id,
         "currency": currency.value,
         "subtotal": price - fee,
         "fee": fee,
         "total": price,
         "quantity": '1'
     }
     headers = {
         'Referer':
         "%s/market/listings/%s/%s" %
         (SteamUrl.COMMUNITY_URL, game.app_id, market_name)
     }
     response = self._session.post(SteamUrl.COMMUNITY_URL +
                                   "/market/buylisting/" + market_id,
                                   data,
                                   headers=headers).json()
     try:
         if response["wallet_info"]["success"] != 1:
             raise ApiException(
                 "There was a problem buying this item. Are you using the right currency? success: %s"
                 % response['wallet_info']['success'])
     except:
         raise ApiException(
             "There was a problem buying this item. Message: %s" %
             response.get("message"))
     return response
Beispiel #3
0
 def create_buy_order(self,
                      market_name: str,
                      price_single_item: str,
                      quantity: int,
                      game: GameOptions,
                      currency: Currency = Currency.USD) -> dict:
     data = {
         "sessionid": self._session_id,
         "currency": currency.value,
         "appid": game.app_id,
         "market_hash_name": market_name,
         "price_total": str(Decimal(price_single_item) * Decimal(quantity)),
         "quantity": quantity
     }
     headers = {
         'Referer':
         "%s/market/listings/%s/%s" %
         (SteamUrl.COMMUNITY_URL, game.app_id, market_name)
     }
     response = self._session.post(SteamUrl.COMMUNITY_URL +
                                   "/market/createbuyorder/",
                                   data,
                                   headers=headers).json()
     if response.get("success") != 1:
         raise ApiException(
             "There was a problem creating the order. Are you using the right currency? success: %s"
             % response.get("success"))
     return response
Beispiel #4
0
 def cancel_sell_order(self, sell_listing_id: str) -> None:
     data = {"sessionid": self._session_id}
     headers = {'Referer': SteamUrl.COMMUNITY_URL + "/market/"}
     url = "%s/market/removelisting/%s" % (SteamUrl.COMMUNITY_URL, sell_listing_id)
     response = self._session.post(url, data=data, headers=headers)
     if response.status_code != 200:
         raise ApiException("There was a problem removing the listing. http code: %s" % response.status_code)
Beispiel #5
0
    def get_my_market_listings(self) -> dict:
        response = self._session.get("%s/market" % SteamUrl.COMMUNITY_URL)
        if response.status_code != 200:
            raise ApiException(
                "There was a problem getting the listings. http code: %s" %
                response.status_code)
        assets_descriptions = json.loads(
            text_between(response.text, "var g_rgAssets = ", ";\r\n"))
        listing_id_to_assets_address = get_listing_id_to_assets_address_from_html(
            response.text)
        listings = get_market_listings_from_html(response.text)
        listings = merge_items_with_descriptions_from_listing(
            listings, listing_id_to_assets_address, assets_descriptions)
        if '<span id="tabContentsMyActiveMarketListings_end">' in response.text:
            n_showing = int(
                text_between(
                    response.text,
                    '<span id="tabContentsMyActiveMarketListings_end">',
                    '</span>'))
            n_total = int(
                text_between(
                    response.text,
                    '<span id="tabContentsMyActiveMarketListings_total">',
                    '</span>'))
            if n_total > n_showing:
                url = "%s/market/mylistings/render/?query=&start=%s&count=%s" % (
                    SteamUrl.COMMUNITY_URL, n_showing, -1)
                response = self._session.get(url)
                if response.status_code != 200:
                    raise ApiException(
                        "There was a problem getting the listings. http code: %s"
                        % response.status_code)
                jresp = response.json()
                listing_id_to_assets_address = get_listing_id_to_assets_address_from_html(
                    jresp.get("hovers"))
                listings_2 = get_market_sell_listings_from_api(
                    jresp.get("results_html"))
                listings_2 = merge_items_with_descriptions_from_listing(
                    listings_2, listing_id_to_assets_address,
                    jresp.get("assets"))
                listings["sell_listings"] = {
                    **listings["sell_listings"],
                    **listings_2["sell_listings"]
                }

        return listings
Beispiel #6
0
 def cancel_buy_order(self, buy_order_id) -> dict:
     data = {
         "sessionid": self._session_id,
         "buy_orderid": buy_order_id
     }
     headers = {"Referer": SteamUrl.COMMUNITY_URL + "/market"}
     response = self._session.post(SteamUrl.COMMUNITY_URL + "/market/cancelbuyorder/", data, headers=headers).json()
     if response.get("success") != 1:
         raise ApiException("There was a problem canceling the order. success: %s" % response.get("success"))
     return response
Beispiel #7
0
 def accept_trade_offer(self, trade_offer_id: str) -> dict:
     trade = self.get_trade_offer(trade_offer_id)
     trade_offer_state = TradeOfferState(trade['response']['offer']['trade_offer_state'])
     if trade_offer_state is not TradeOfferState.Active:
         raise ApiException("Invalid trade offer state: {} ({})".format(trade_offer_state.name,
                                                                        trade_offer_state.value))
     partner = self._fetch_trade_partner_id(trade_offer_id)
     session_id = self._get_session_id()
     accept_url = SteamUrl.COMMUNITY_URL + '/tradeoffer/' + trade_offer_id + '/accept'
     params = {'sessionid': session_id,
               'tradeofferid': trade_offer_id,
               'serverid': '1',
               'partner': partner,
               'captcha': ''}
     headers = {'Referer': self._get_trade_offer_url(trade_offer_id)}
     response = self._session.post(accept_url, data=params, headers=headers).json()
     if response.get('needs_mobile_confirmation', False):
         return self._confirm_transaction(trade_offer_id)
     return response
Beispiel #8
0
 def accept_trade_offer(self, trade_offer_id: str) -> dict:
     trade = self.get_trade_offer(trade_offer_id)
     trade_offer_state = TradeOfferState(trade['response']['offer']['trade_offer_state'])
     if trade_offer_state is not TradeOfferState.Active:
         raise ApiException("Invalid trade offer state: {} ({})".format(trade_offer_state.name,
                                                                        trade_offer_state.value))
     partner = self._fetch_trade_partner_id(trade_offer_id)
     session_id = self._get_session_id()
     accept_url = SteamUrl.COMMUNITY_URL + '/tradeoffer/' + trade_offer_id + '/accept'
     params = {'sessionid': session_id,
               'tradeofferid': trade_offer_id,
               'serverid': '1',
               'partner': partner,
               'captcha': ''}
     headers = {'Referer': self._get_trade_offer_url(trade_offer_id)}
     response = self._session.post(accept_url, data=params, headers=headers)
     status = int(response.status_code)
     if status >= 300 or status < 200:
         return False, {'error_text': response.text, 'status_code': status} 
     response_dict = response.json()
     if response_dict.get('needs_mobile_confirmation'):
         response_dict.update(self._confirm_transaction(response_dict['tradeofferid']))
     return True, response
Beispiel #9
0
 def accept_trade_offer(self, trade_offer_id: str) -> dict:
     trade = self.get_trade_offer(trade_offer_id)
         if trade['trade_offer_state'] is not TradeOfferState.Active:
             raise ApiException("Invalid trade offer state: {}".format(trade['trade_offer_state']))