Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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_dict = self._session.get(url, params=params).json()
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
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
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"]}
else:
for i in range(0, n_total, 100):
url = "%s/market/mylistings/?query=&start=%s&count=%s" % (SteamUrl.COMMUNITY_URL, n_showing + i, 100)
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
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)
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
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