回复
17
查看
1058
收藏
7

0

赠楼

0%

赠楼率

106

蒸汽

1

主题

5

帖子

115

积分
跳转到指定楼层
1
发表于 昨天 11:49 · 北京 | 只看该作者 |倒序浏览 |阅读模式
本文为 其乐用户(UID:212280) 发布的原创文章,转摘前请联系该用户获得许可
因为自己的爬虫需要算社区手续费,所以简单看了一下Steam市场的js文件,关于手续费计算的主要函数为economy_common.js中209行GetItemPriceFromTotal函数。
计算方式有点复杂也不仔细看了,贴出来可用的python代码(请忽略命名规则等)

  1. import math

  2. g_rgWalletInfo = {
  3.     "rwgrsn": -2,
  4.     "success": True,
  5.     "wallet_balance": "14669",
  6.     "wallet_country": "CN",
  7.     "wallet_currency": 23,
  8.     "wallet_currency_increment": "1",
  9.     "wallet_delayed_balance": "356",
  10.     "wallet_fee": "1",
  11.     "wallet_fee_base": "0",
  12.     "wallet_fee_minimum": "7",
  13.     "wallet_fee_percent": "0.05",
  14.     "wallet_market_minimum": "7",
  15.     "wallet_max_balance": "1400000",
  16.     "wallet_publisher_fee_percent_default": "0.10",
  17.     "wallet_state": "",
  18.     "wallet_trade_max_balance": "1260000"
  19. }


  20. def CalculateFee(base_amt, pct, rgWallet):
  21.     if pct > 0:
  22.         return ToValidMarketPrice(math.floor(base_amt * pct), rgWallet)
  23.     return 0


  24. def GetTotalWithFees(base_amt, ppct, spct, rgWallet):
  25.     nBase = ToValidMarketPrice(base_amt, rgWallet)
  26.     nPubFee = CalculateFee(base_amt, ppct, rgWallet)
  27.     nSteamFee = CalculateFee(base_amt, spct, rgWallet)
  28.     return nBase + nPubFee + nSteamFee


  29. def ToValidMarketPrice(nPrice, rgWallet):
  30.     nFloor = int(rgWallet['wallet_market_minimum'])
  31.     nIncrement = int(rgWallet['wallet_currency_increment'])
  32.     if nPrice <= nFloor:
  33.         return nFloor
  34.     if nIncrement > 1:
  35.         dAmount = nPrice / nIncrement
  36.         dSign = -1 if dAmount < 0 else 1
  37.         dAmount = (dSign * math.floor(abs(dAmount) + 0.5)) * nIncrement
  38.         return dAmount
  39.     return nPrice


  40. def GetItemPriceFromTotal(nTotal, rgWallet):
  41.     ppct = float(rgWallet['wallet_publisher_fee_percent_default'])
  42.     spct = float(rgWallet['wallet_fee_percent'])
  43.     nIncrement = int(rgWallet['wallet_currency_increment'])
  44.     nFloor = int(rgWallet['wallet_market_minimum'])
  45.     nInitialGuess = math.floor(nTotal / (1.0 + ppct + spct))
  46.     nMaxBase = nTotal - (2 * nFloor)
  47.     nBase = ToValidMarketPrice(min(nInitialGuess, nMaxBase), rgWallet)
  48.     for i in range(3):
  49.         nCalculated = GetTotalWithFees(nBase, ppct, spct, rgWallet)
  50.         if nCalculated == nTotal:
  51.             return nBase
  52.         if nCalculated < nTotal:
  53.             nBase += nIncrement
  54.         else:
  55.             nBase -= nIncrement
  56.             break
  57.     return max(nFloor, nBase)


  58. if __name__ == '__main__':
  59.     buyer = float(input("买家支付:"))
  60.     receive = GetItemPriceFromTotal(buyer * 100, g_rgWalletInfo) / 100
  61.     print(f"您收款:{receive}")

复制代码


收藏收藏7 分享淘帖 支持支持
回复

使用道具 举报

浏览本版块需要:
1. 初阶会员或更高等级;
2. (点击此处)绑定Steam账号
您需要登录后才可以回帖 登录 | 注册

本版积分规则

欢迎发帖参与讨论 o(*≧▽≦)ツ,请注意
1. 寻求帮助或答案的帖子请发到问题互助版块,悬赏有助于问题解决的速度。发错可能失去在该板块发布主题的权限(了解更多
2. 表达观点可以,也请务必注意语气和用词,以免影响他人浏览,特别是针对其他会员的内容。如觉得违规可使用举报功能 交由管理人员处理,请勿引用对方的内容。
3. 开箱晒物交易中心游戏互鉴福利放送版块请注意额外的置顶版规。
4. 除了提问帖和交易帖以外,不确认发在哪个版块的帖子可以先发在谈天说地

  作为民间站点,自 2004 年起为广大中文 Steam 用户提供技术支持与讨论空间。历经二十余载风雨,如今已发展为国内最大的正版玩家据点。

列表模式 · · 微博 · Bilibili频道 · Steam 群组 · 贴吧 · QQ群 
Keylol 其乐 ©2004-2025 Chinese Steam User Fan Site.
Designed by Lee in Balestier, Powered by Discuz!
推荐使用 ChromeMicrosoft Edge 来浏览本站
广告投放|手机版|广州数趣信息科技有限公司 版权所有|其乐 Keylol ( 粤ICP备17068105号 )
GMT+8, 2025-12-9 01:57
快速回复 返回顶部 返回列表