Guest User

tf2keybuyer

a guest
Jan 9th, 2023
676
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.97 KB | Source Code | 0 0
  1. import requests
  2. import json
  3.  
  4. api_key = ""
  5.  
  6. username = ""
  7. password = ""
  8.  
  9. max_price = 1.50
  10.  
  11. app_id = 440
  12. item_id = 5021
  13.  
  14. def api_request(interface, method, version, **kwargs):
  15. base_url = "https://api.steampowered.com/{}/{}/v{}/".format(interface, method, version)
  16. params = {"key": api_key}
  17. for key, value in kwargs.items():
  18. params[key] = value
  19. response = requests.get(base_url, params=params)
  20. return response.json()
  21.  
  22. def get_lowest_sell_order(app_id, item_id):
  23. market_listings_response = api_request("ISteamEconomy", "GetMarketListings/v1", 1, appid=app_id, item_nameid=item_id)
  24. listings = market_listings_response["listinginfo"]
  25. lowest_sell_order = float("inf")
  26. for listing_id, listing in listings.items():
  27. price = float(listing["converted_price"])
  28. if price < lowest_sell_order:
  29. lowest_sell_order = price
  30. return lowest_sell_order
  31.  
  32. def login():
  33. login_response = api_request("ISteamUserAuth", "AuthenticateUserTicket/v1", 1, username=username, password=password)
  34. if login_response["response"]["result"] == "OK":
  35. return login_response["response"]["params"]["token"]
  36. else:
  37. return None
  38.  
  39. def main():
  40. # Login to Steam
  41. token = login()
  42. if token is None:
  43. print("Error: failed to login to Steam")
  44. return
  45.  
  46. lowest_sell_order = get_lowest_sell_order(app_id, item_id)
  47. if lowest_sell_order == float("inf"):
  48. print("Error: no sell orders found for keys")
  49. return
  50.  
  51.  
  52. if lowest_sell_order <= max_price:
  53. # Make a buy order for the key
  54. buy_response = api_request("ISteamEconomy", "BuyMarketListing/v1", 1, appid=app_id, item_nameid=item_id, price_total=lowest_sell_order, quantity=1, token=token)
  55. if buy_response["response"]["result"] == "OK":
  56. print("Successfully bought key for {}".format(lowest_sell_order))
  57. else:end
  58. else:
  59. print("Error: key is overpriced")
  60.  
Advertisement
Add Comment
Please, Sign In to add comment