· 5 years ago · May 19, 2020, 05:22 PM
1import requests
2import json
3from time import sleep
4from threading import Thread
5from steampy.client import Asset
6from steampy.utils import GameOptions
7from steampy.client import SteamClient as sc
8
9game = GameOptions.CS
10
11api = '' # Market API
12apikey = '' # Steam api
13login = '' # steam login
14proxy = '' # Format: https://login:password@ip:port
15percent = 0.8 # формат 0.n
16
17url = 'https://market.csgo.com/api/Trades/?key=' + api # <= don't change it!
18steamguard = 'new_mafile.maFile' # <= don't change it!
19i = 2 # <= don't change it!
20avg = 0 # <= don't change it!
21
22
23def offer(assetid, msg, trade_url):
24 if steam_client.is_session_alive():
25 my_items = steam_client.get_my_inventory(game)
26 items = iter(my_items.values())
27 for i in items:
28 if i['id'] == assetid:
29 item = Asset(i['id'], game)
30 return steam_client.make_offer_with_url([item], [], trade_url, msg, True)
31 else:
32 pass
33 else:
34 steam_client.login(login, pswd, steamguard)
35 my_items = steam_client.get_my_inventory(game)
36 items = iter(my_items.values())
37 for i in items:
38 if i['instanceid'] == assetid:
39 item = Asset(i['id'], game)
40 print('СТРОКА 42 ITEM= ' + str(item))
41 return steam_client.make_offer_with_url([item], [], trade_url, msg, True)
42 else:
43 pass
44
45
46def confirm(tradeid):
47 try:
48 steam_client._confirm_transaction(tradeid)
49 except:
50 print("Trade offer was confirmed!")
51
52
53def ChangeFile(fileName, Data):
54 with open(str(fileName), 'w') as file:
55 json.dump(Data, file, indent=4)
56 file.close()
57
58
59def Trades():
60 while i > 1:
61 sleep(2)
62 try:
63 itemdata = requests.post(url).json()
64 if itemdata == []:
65 print('There is nothing on sell! Its time to put something...')
66 else:
67 try:
68 with open('json.json', 'w') as info:
69 json.dump(itemdata, info)
70 assetid = itemdata[0]['ui_asset']
71 if (itemdata[0]['ui_status'] == "1"):
72 pass
73 elif (itemdata[0]['ui_status'] == '2'):
74 tradedata = requests.post("https://market.csgo.com/api/ItemRequest/in/1/?key=" + api).json()
75 msg = tradedata['request']['tradeoffermessage']
76 trade_url = tradedata['request']['tradelink']
77 data = offer(assetid, msg, trade_url)
78 sleep(1)
79 with open('tradedata.json', 'w') as file:
80 json.dump(tradedata, file, indent=4)
81 tradeid = data['tradeofferid']
82 confirm(tradeid)
83 file.close()
84 info.close()
85
86 except TypeError:
87 pass
88 except KeyError:
89 pass
90 else:
91 sleep(10)
92 pass
93 except json.decoder.JSONDecodeError:
94 pass
95 except requests.exceptions.ConnectionError:
96 print('Connection refused! I will try again after 10 seconds')
97 sleep(10)
98 pass
99
100
101def updating():
102 try:
103 i = 2
104 while i > 1: # Обновление ивентаря и включение продаж каждые 3 минуты
105 settingSteamApi()
106 inventUpdate()
107 ping()
108 sleep(160)
109 except json.decoder.JSONDecodeError:
110 sleep(15)
111 pass
112
113
114def ping():
115 try:
116 status = requests.get('https://market.csgo.com/api/v2/ping?key=' + f'{api}')
117 status2 = status.json()
118 if status2['success'] == True:
119 print('Sales was successfuly turned on!')
120 elif status2['success'] == False and status2['message'] == 'too early for pong':
121 pass
122 else:
123 pass
124 except:
125 sleep(5)
126 pass
127
128
129def inventUpdate():
130 try:
131 status = requests.get('https://market.csgo.com/api/v2/update-inventory/?key=' + f'{api}').json()
132 if status['success'] == True:
133 pass
134 elif status['success'] == False:
135 pass
136 except:
137 sleep(5)
138 pass
139
140
141def settingSteamApi():
142 try:
143 requests.get('https://market.csgo.com/api/SetSteamAPIKey/' + apikey + '/?key=' + api).json()
144 except:
145 sleep(5)
146 pass
147
148
149def calc():
150 global history
151 global avg
152 try:
153 for x in history[:40]:
154 avg = avg + x[1]
155 avg = round(avg, 0)
156
157 return avg
158 except:
159 sleep(1)
160 avg = 0
161 calc()
162
163
164def setprices(bestOffer_price, item_price, x, item_name):
165 global avg
166 try:
167 if int(bestOffer_price) > 5000000:
168 requests.get('https://market.csgo.com/api/SetPrice/new_' + x['classid'] + '_' + x[
169 'instanceid'] + '/' + f'{item_price}' + '/?key=' + f'{api}').json()
170 avg = 0
171 print(
172 f'{item_name}' + ' with price ' + f'{int(item_price) / 100}' + ' rub' + ' successfully was added on sale')
173
174 if int(bestOffer_price) > int(item_price):
175 requests.get('https://market.csgo.com/api/SetPrice/new_' + x['classid'] + '_' + x[
176 'instanceid'] + '/' + f'{bestOffer_price}' + '/?key=' + f'{api}').json()
177 print(
178 f'{item_name}' + ' with price ' + f'{int(bestOffer_price) / 100}' + ' rub' + ' successfully was added on sale')
179 avg = 0
180
181 else:
182 requests.get('https://market.csgo.com/api/SetPrice/new_' + x['classid'] + '_' + x[
183 'instanceid'] + '/' + f'{item_price}' + '/?key=' + f'{api}').json()
184 print(f'{item_name}' + ' with price ' + f'{item_price / 100}' + ' rub' + ' successfully was added on sale')
185 avg = 0
186 except:
187 pass
188
189
190def getBestPrice(items_sale):
191 global avg
192 for x in items_sale['items']:
193 try:
194 hashed_name = x['market_hash_name']
195 try:
196 global history
197 history = requests.get(
198 'https://market.csgo.com/api/v2/get-list-items-info?key=' + f'{api}' + '&list_hash_name[]=' + f'{hashed_name}').json()[
199 'data'][hashed_name]['history']
200 except:
201 pass
202 try:
203 item_name = x['market_hash_name']
204 item_price = (calc() / 40) * 100
205 item_price = int(round(item_price, 0))
206
207 bestOffer_status = requests.get(
208 'https://market.csgo.com/api/BestSellOffer/' + x['classid'] + '_' + x[
209 'instanceid'] + '/?key=' + f'{api}').json()['success']
210
211 if bestOffer_status == False:
212 requests.get('https://market.csgo.com/api/SetPrice/new_' + x['classid'] + '_' + x[
213 'instanceid'] + '/' + f'{item_price}' + '/?key=' + f'{api}').json()
214 avg = 0
215
216 if bestOffer_status == True:
217 bestOffer_price = requests.get(
218 'https://market.csgo.com/api/BestSellOffer/' + x['classid'] + '_' + x[
219 'instanceid'] + '/?key=' + f'{api}').json()['best_offer']
220 setprices(bestOffer_price, item_price, x, item_name)
221
222
223 except:
224 avg = 0
225 sleep(1)
226 itemsOnSale()
227 except:
228 avg = 0
229 sleep(1)
230 itemsOnSale()
231
232
233def itemsOnSale():
234 global avg
235 try:
236 status = requests.get('https://market.csgo.com/api/v2/my-inventory/?key=' + f'{api}').json()['success']
237 if status == True:
238 items_sale = requests.get('https://market.csgo.com/api/v2/my-inventory/?key=' + f'{api}').json()
239 if items_sale == []:
240 pass
241
242 else:
243 getBestPrice(items_sale)
244 else:
245 sleep(1)
246 pass
247 except:
248 avg = 0
249 sleep(5)
250 itemsOnSale()
251
252
253def price_offers():
254 global item
255 try:
256 status = requests.get('https://market.csgo.com/api/GetMySellOffers/?key=' + f'{api}').json()['success']
257 if status == True:
258 sleep(1)
259 list_items = requests.get('https://market.csgo.com/api/GetMySellOffers/?key=' + f'{api}').json()['offers']
260 for x in list_items:
261 name = x['i_market_hash_name']
262 start_price = int(x['ui_price']) * 100
263 classid = x['i_classid']
264 instanceid = x['i_instanceid']
265 end_price = int(start_price * 0.97)
266 end_price = round(end_price, 1)
267 userData = json.load((open('C:\\pytest\\position.json')))
268 userData["items"].append({'start_price': f'{start_price}',
269 'end_price': f'{end_price}',
270 'classid': f'{classid}',
271 'instanceid': f'{instanceid}',
272 'name': f'{name}'})
273
274 ChangeFile('C:\\pytest\\position.json', userData)
275 sleep(5)
276 Thread(target=startDump).start()
277
278 else:
279 print('Sales is empty! Time to put up some items..')
280 inventUpdate()
281 sleep(60)
282 price_offers()
283 except:
284 print('Error with getting price offers! I will try again after 5 seconds')
285 sleep(5)
286 price_offers()
287
288
289def startDump():
290 print('Function "price dumping" was successfully turned on! log off')
291 while i > 1:
292 sleep(1)
293 try:
294 ds = json.load((open('C:\\pytest\\position.json')))
295 output_data = [v for v in {inp['name']: inp for inp in ds['items']}.values()]
296 json_str = {"items": output_data}
297 ChangeFile('C:\\pytest\\position.json', json_str)
298 sleep(5)
299 dataFor_dump = json.load((open('C:\\pytest\\position.json')))['items']
300 for x in dataFor_dump:
301 try:
302 classid = x['classid']
303 instanceid = x['instanceid']
304 end_price = x['end_price']
305 start_price = round(int(x['start_price']) * 1.05, 1)
306 bestOffer = requests.get(
307 'https://market.csgo.com/api/BestSellOffer/' + f'{classid}' + '_' + f'{instanceid}' + '/?key=' + f'{api}').json()[
308 'best_offer']
309 if int(start_price) > int(bestOffer) > int(end_price):
310 price = int(bestOffer) - 1
311 requests.get(
312 'https://market.csgo.com/api/MassSetPrice/' + f'{classid}' + '_' + f'{instanceid}' + '/' + f'{price}' + '/?key=' + f'{api}').json()
313 else:
314 pass
315 except:
316 sleep(1)
317 pass
318 except:
319 sleep(5)
320 price_offers()
321
322
323def sumItems():
324 try:
325 items = (requests.get('https://market.csgo.com/api/Trades/?key=' + f'{api}').json())
326 totalPrice = 0
327 for item in items:
328 price = item['ui_price']
329 totalPrice = int(totalPrice) + int(price)
330 balance = requests.get('https://market.csgo.com/api/GetMoney/?key=' + f'{api}').json()['money'] / 100
331 full = str(float(totalPrice * 0.9) + float(balance))
332 print('On sales: ' + str(round(totalPrice * 0.9)) + ' rub')
333 print('Balance: ' + str(round(balance, 1)) + ' rub')
334 return full
335 except:
336 sumItems()
337
338
339def steam_login():
340 global steam_client
341 try:
342 print('Logging to steam account..')
343 steam_client = sc(api)
344 steam_client._session.proxies = {'https': proxy}
345 steam_client.login(login, pswd, steamguard)
346 print('Successfully logged in!')
347 except requests.exceptions.ConnectionError:
348 print('Bad proxy')
349
350
351def del_position():
352 jsonUpd = {"items": []}
353 ChangeFile('C:\\pytest\\position.json', jsonUpd)
354
355
356def new_mafile():
357 global pswd
358 maf_name = login + '.maFile'
359 nameID64 = json.load((open(maf_name)))
360 mafileID64 = nameID64['Session'].get('SteamID')
361 newId64Maf = str(mafileID64) + '.maFile'
362
363 file = open(login + '.txt')
364 log_pass = file.readline()
365 password = str(log_pass).split(':', maxsplit=2)
366 password2 = str(password[2]).split('\n')
367 pswd = (password2[0])
368
369 Mafile = json.load((open(newId64Maf)))
370 steamid = Mafile['Session'].get('SteamID')
371 shared_secret = Mafile.get('shared_secret')
372 identity_secret = Mafile.get('identity_secret')
373 account_name = Mafile.get('account_name')
374 new_mafile = {"steamid": steamid,
375 "shared_secret": shared_secret,
376 "identity_secret": identity_secret,
377 "login": account_name,
378 "password": password2[0]}
379 new_mafile_path = 'new_mafile.maFile'
380 ChangeFile(new_mafile_path, new_mafile)
381
382
383new_mafile()
384bot_action = input(
385 '"0" - Turn on updating' + '\n'
386 + '"1" - Automatically put up tradable items on sale, turn on updating and trades' + '\n'
387 + '"2" - Automatically put up tradable items on sale' + '\n'
388 + '"3" - Turn on auto dump and trades' + '\n'
389 + '"4" - Get your balance' + '\n'
390 + 'Write number: ')
391
392if bot_action == '0':
393 new_mafile()
394 Thread(target=updating).start()
395
396if bot_action == '1':
397 steam_login()
398 del_position()
399 Thread(target=updating).start()
400 Thread(target=Trades).start()
401
402if bot_action == '2':
403 itemsOnSale()
404
405if bot_action == '3':
406 del_position()
407 steam_login()
408 Thread(target=price_offers).start()
409 Thread(target=updating).start()
410 Thread(target=Trades).start()
411
412if bot_action == '4':
413 print('All balance: ' + str(sumItems()) + ' rub')