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