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