forked from gallaam/binance_nft_bot-1
-
Notifications
You must be signed in to change notification settings - Fork 0
/
box.py
95 lines (75 loc) · 2.91 KB
/
box.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
import json
from abc import abstractmethod
from collections import defaultdict
from datetime import datetime
from typing import Optional, Union
import requests
from handlers import event_is_not_over
from schemas import Body
from settings import headers
class BaseBox:
def __init__(self):
self._box_info: str = 'https://www.binance.com/bapi/nft/v1/friendly/nft/mystery-box/detail?productId='
self._box_list = 'https://www.binance.com/bapi/nft/v1/public/nft/mystery-box/list?page=1&size=15'
def get_list_boxes(self) -> dict:
return requests.get(self._box_list).json()['data']
def get_avalible_boxes(self) -> dict:
avalible_boxes = defaultdict(dict)
boxes = self.get_list_boxes()
box_num = 0
for box in boxes:
product_id = box['productId']
response = requests.get(self._box_info + product_id, headers=headers).json()['data']
status = box['status']
name = box['name']
selling_delay = response['secondMarketSellingDelay']
limit_amount = response['limitPerTime']
if event_is_not_over(status):
box_num += 1
avalible_boxes[str(box_num)] = {
'name': name,
'product_id': product_id,
'selling_delay': selling_delay,
'limit_amount': limit_amount
}
return avalible_boxes
@staticmethod
def log_info_boxes(avalible_boxes: dict) -> None:
for box_num, value in avalible_boxes.items():
print(f'{box_num}. {value["name"]}\n Selling delay on market: {value["selling_delay"]} hours\n')
class Box(BaseBox):
def __init__(
self,
amount: int=0,
product_id: Optional[Union[str, int]]='',
):
super().__init__()
self._box_buy: str = 'https://www.binance.com/bapi/nft/v1/private/nft/mystery-box/purchase'
self._product_id = product_id
self._amount = amount
self._headers: dict = headers
self._body: Body = {
'productId': product_id,
'number': amount
}
@property
@abstractmethod
def _get_box_info(self) -> dict():
return requests.get(self._box_info + str(self._product_id)).json()['data']
@property
@abstractmethod
def _get_start_sale_time(self) -> datetime:
start_sale = self._get_box_info['startTime']
start_sale_time = datetime.fromtimestamp(start_sale/1000)
return start_sale_time
@abstractmethod
def _buy_box(self, proxy: str, captcha: str) -> json:
# resolve invisible recaptcha V3
self._headers['x-nft-checkbot-token'] = captcha
response = requests.post(
self._box_buy, headers=self._headers,
data=json.dumps(self._body),
proxies={'http': f'http://{proxy}/'}
)
print(response.json())
return response