-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathglobal_parser.py
130 lines (100 loc) · 5.49 KB
/
global_parser.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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
import time
import json
import inspect
import logging
from concurrent.futures.thread import ThreadPoolExecutor
from telebot import TeleBot
import aiogram.utils.markdown as md
from parse import CoinGeckoAPI, ArbitoidAPI
def main():
func_name = inspect.currentframe().f_code.co_name
try:
logger = logging.getLogger("Global_Parser")
logger.setLevel(logging.ERROR)
file_handler = logging.FileHandler('arbitoid.log')
file_handler.setLevel(logging.INFO)
formatter = logging.Formatter('%(asctime)s %(levelname)s: %(message)s', datefmt='%d/%m/%Y %H:%M:%S')
file_handler.setFormatter(formatter)
logger.addHandler(file_handler)
cfg = json.load(open('cfg.json', 'r'))
gecko_api = CoinGeckoAPI(
cfg['CoinGecko']['link'], cfg['CoinGecko']['network_fees'], cfg['CoinGecko']['market_fees'],
cfg['parse']['headers'], {"https": f"http://{cfg['parse']['proxy']['proxy1']}"}, logger
)
tele_bot = TeleBot(cfg['telegram']['bot']['api_token'])
arbitoid = ArbitoidAPI(cfg['FastAPI']['params'], logger)
parser_top_coins(arbitoid, gecko_api, tele_bot, logger)
except Exception as error:
logging.error(f"{func_name}/{error.__class__}||{error.args[0]}")
quit()
def parser_top_coins(arbitoid: ArbitoidAPI, gecko_api: CoinGeckoAPI, tele_bot: TeleBot, logger=None):
func_name = inspect.currentframe().f_code.co_name
try:
loc = gecko_api.gecko_loc(2)
for step in range(0, len(loc), 10):
time.sleep(90)
for coin in loc[step:step + 10]:
with ThreadPoolExecutor() as executor:
executor.submit(announce, arbitoid, gecko_api, tele_bot, coin, logger)
except Exception as error:
logger.error(f"{func_name}/{error.__class__}||{error.args[0]}") if logger else 0
return ''
finally:
logger.info(f"{func_name}") if logger else 0
def announce(arbitoid: ArbitoidAPI, gecko_api: CoinGeckoAPI, tele_bot: TeleBot, coin: str, logger=None):
func_name = inspect.currentframe().f_code.co_name
try:
arb_case = gecko_api.gecko_pairs(coin)
if len(arb_case) == 4:
market_buy, buy_price, link_buy = \
arb_case[0]['market']['name'], arb_case[0]['converted_last']['usd'], arb_case[0]['trade_url']
market_sell, sell_price, link_sell = \
arb_case[1]['market']['name'], arb_case[1]['converted_last']['usd'], arb_case[1]['trade_url']
network, market_fees = arb_case[-1], arb_case[2]
total_profit = arbitoid.profit_between_markets(
market_buy, arbitoid.reform_float(buy_price),
market_sell, arbitoid.reform_float(sell_price),
network[-1], market_fees
)
ready_users = arbitoid.get_ready_users['Response']
for user in ready_users:
if (user['percent'] and total_profit[0] >= user['percent']) or \
(user['percent'] is None and total_profit[0] >= 3.5):
try:
tele_bot.send_message(
user['id'],
md.text(
f"FOUND ARBITRAGE CASE\n"
f"⸻⸻⸻⸻⸻⸻⸻\n\n"
+ md.hitalic("Link to check: ") +
f"https://www.coingecko.com/en/coins/{coin.lower()}#markets" + ' ✅'
+ '\n\n' + "Parameters 📥/📤\n"
+ '├Market to buy: ' + md.hbold(market_buy)
+ '\n├Market link: \n'
+ link_buy[:link_buy.index('?') if '?' in link_buy else len(link_buy)]
+ "\n├Price to buy: " + md.hitalic(buy_price)
+ '\n├\n├Market to sell: ' + md.hbold(market_sell)
+ '\n├Market link: \n'
+ link_sell[:link_sell.index('?') if '?' in link_sell else len(link_sell)]
+ '\n├Price to sell: ' + md.hitalic(sell_price)
+ '\n\nTotal profit 💸' + "\n├Without fees: " + md.hcode(total_profit[0])
+ "\n├Minimal profit: " + md.hcode(total_profit[1])
+ "\n├Maximum profit: " + md.hcode(total_profit[-1])
+ "\nNetwork: " + md.hbold(network[0])
+ "\nFinal result might be lower according to network fees"
+ "\n\nData collected by " + "@Arbitroid_bot",
sep='\n',
),
parse_mode='html',
disable_web_page_preview=True
)
except Exception as error:
logger.warning(f"{func_name}/{error.__class__}||{error.args[0]}") if logger else 0
finally:
logger.info(f"{func_name}") if logger else 0
except Exception as error:
logger.error(f"{func_name}/{error.__class__}||{error.args[0]}") if logger else 0
finally:
logger.info(f"{func_name}") if logger else 0
if __name__ == '__main__':
main()