Skip to content

Commit

Permalink
Add calc_market_listing_fee util function.
Browse files Browse the repository at this point in the history
  • Loading branch information
somespecialone committed Jan 4, 2025
1 parent 85ea765 commit eec4bfb
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
5 changes: 2 additions & 3 deletions aiosteampy/mixins/market.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from contextlib import suppress
from typing import overload, Literal, TypeAlias, AsyncIterator, Callable
from datetime import datetime
from math import floor
from re import search as re_search

from aiohttp import ClientResponseError
Expand Down Expand Up @@ -34,7 +33,7 @@
)
from ..helpers import currency_required
from ..exceptions import EResultError, SessionExpired
from ..utils import create_ident_code, buyer_pays_to_receive
from ..utils import create_ident_code, buyer_pays_to_receive, calc_market_listing_fee
from .public import SteamCommunityPublicMixin, T_SHARED_DESCRIPTIONS
from .confirmation import ConfirmationMixin

Expand Down Expand Up @@ -858,7 +857,7 @@ async def buy_market_listing(
if app is None or market_hash_name is None or price is None:
raise ValueError("`app`, `market_hash_name` and `price` arguments must be provided")

fee = fee or ((floor(price * 0.05) or 1) + (floor(price * 0.10) or 1))
fee = fee or calc_market_listing_fee(price)
data = {
"sessionid": self.session_id,
"currency": self.currency.value,
Expand Down
16 changes: 16 additions & 0 deletions aiosteampy/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
"attribute_required",
"make_inspect_url",
"add_cookie_to_session",
"calc_market_listing_fee",
)


Expand Down Expand Up @@ -491,3 +492,18 @@ def add_cookie_to_session(
c[name]["httponly"] = httponly

session.cookie_jar.update_cookies(cookies=c, response_url=url)


def calc_market_listing_fee(price: int, *, wallet_fee=0.05, publisher_fee=0.10, minimal_fee=1) -> int:
"""
Calculate market fee for listing.
Use `get_wallet_info` method of the client to see fees values for specified `Steam` account
:param price: price of market listing
:param wallet_fee:
:param publisher_fee:
:param minimal_fee: minimal fee value
:return: calculated fee of price as integer
"""
return (floor(price * wallet_fee) or minimal_fee) + (floor(price * publisher_fee) or minimal_fee)

0 comments on commit eec4bfb

Please sign in to comment.