telegram_get_token_info.py 43 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255
  1. import time
  2. import asyncio
  3. from telethon import TelegramClient, events
  4. from telethon.errors.rpcerrorlist import AuthKeyError
  5. from telethon.sync import TelegramClient as SyncTelegramClient
  6. import json
  7. import datetime
  8. import signal
  9. import sys
  10. import math
  11. import requests
  12. from telethon.tl.types import MessageEntityTextUrl
  13. from apscheduler.schedulers.background import BackgroundScheduler
  14. from telethon.tl.types import PeerUser, PeerChat, PeerChannel
  15. import os
  16. import traceback
  17. import re
  18. from apscheduler.schedulers.asyncio import AsyncIOScheduler
  19. old_print = print
  20. def timestamped_print(*args, **kwargs):
  21. old_print(datetime.datetime.utcnow().replace(
  22. microsecond=0), *args, **kwargs)
  23. print = timestamped_print
  24. print('\n'*5)
  25. def global_exception_hook(exc_type, exc_value, exc_traceback):
  26. print(f"Global exception: {exc_type.__name__} - {exc_value}")
  27. traceback.print_tb(exc_traceback)
  28. raise
  29. def keep_alnum_forgmgn(string):
  30. return re.sub(r'[^a-zA-Z0-9\.\s\+\-]', ' ', string)
  31. def keep_alnum(string):
  32. return re.sub(r'[^a-zA-Z0-9\.\s:+-]', ' ', string)
  33. def term_sig_handler(signum, frame):
  34. # save_obj_unraydium_token()
  35. print(f'catched singal: {signum}')
  36. sys.exit()
  37. def global_exception_hook(exc_type, exc_value, exc_traceback):
  38. print(f"Global exception: {exc_type.__name__} - {exc_value}")
  39. traceback.print_tb(exc_traceback)
  40. raise
  41. int_pattern = r"^\d+$"
  42. api_id_gate = 29760088
  43. api_hash_gate = "7cd2222e0629c770789f9c6cf280d051"
  44. # ID: 6541198030, Name: Fluxbot
  45. api_id_bill = 26338039
  46. api_hash_bill = "09bcd8c34c696df21466303aa13c8913"
  47. GMGN_bot_id = 6344329830
  48. Trojan_on_Solana_Odysseus_id = 6997957200
  49. # Trojan_on_Solana_Achilles_id = 7164284518
  50. feishu_url = 'https://open.feishu.cn/open-apis/bot/v2/hook/a68cffbf-9104-427b-8e25-62dfaf363a47'
  51. utc_plus_8 = datetime.timezone(datetime.timedelta(hours=8))
  52. client_gate = TelegramClient('anon_gate', api_id_gate, api_hash_gate)
  53. client_gate.start()
  54. async def send_tokenaddress_message(GMGN_id , str_tokenaddress):
  55. print(f"enter send_token_address_message str_tokenaddress={str_tokenaddress}")
  56. await client_gate.send_message(GMGN_id, str_tokenaddress)
  57. return
  58. async def send_pairaddress_message(chat_Trojan_on_Solana_Odysseus_id , str_pairaddress):
  59. print(f"enter send_pairaddress_message str_pairaddress={str_pairaddress}")
  60. await client_gate.send_message(chat_Trojan_on_Solana_Odysseus_id, str_pairaddress)
  61. return
  62. # flux 获取dlao swap info 保存进 obj_queueing_pairaddress
  63. # 在一个定时器 的函数中 便利读取 obj_queueing_pairaddress ,对每一个元素进行check 如果可以买卖则进行买卖
  64. def send_token_info_to_feishu(token_info):
  65. print("send_token_info_to_feishu token_info=",token_info)
  66. return
  67. import pathlib
  68. import shutil
  69. set_has_read_file=set()
  70. obj_receive_pair={
  71. # "str_pairaddress":{
  72. # "str_tokenaddress":"",
  73. # "timestamp":0,
  74. # }
  75. }
  76. obj_queueing_pairaddress={}
  77. obj_history_pariaddress={
  78. # "str_pairaddress":{
  79. # "send_feishu_timestamp":0,
  80. # "number_open":0
  81. # "arr_history_timestamp"=[]
  82. # }
  83. }
  84. obj_last_20m_tokens={
  85. # "str_pairaddress":{
  86. # "str_pairaddress":"",
  87. # "timestamp":0,
  88. # "str_tokenaddress":"",
  89. # "number_open": 0,
  90. # "number_holders": 0,
  91. # }
  92. }
  93. import pandas as pd
  94. async def ready_send_feishu_last_20m_tokens_timed():
  95. # 获取最近20分钟在dex出现的token 将其发送给飞书
  96. global obj_last_20m_tokens
  97. arr_str_pairaddress = list(obj_last_20m_tokens.keys())
  98. if len(arr_str_pairaddress)==0:
  99. return
  100. cur_now_timestamp = int(time.time()*1000)
  101. arr_queueing_send_feishu_last_20min = []
  102. for str_pairaddress in arr_str_pairaddress:
  103. if obj_last_20m_tokens[str_pairaddress]["timestamp"] < cur_now_timestamp - 20 * 60 * 1000:
  104. del obj_last_20m_tokens[str_pairaddress]
  105. continue
  106. else:
  107. str_tokenaddress = "unknown"
  108. if obj_receive_pair.get(str_pairaddress) is not None :
  109. str_tokenaddress=obj_receive_pair.get(str_pairaddress)["str_tokenaddress"]
  110. arr_queueing_send_feishu_last_20min.append({
  111. "str_pairaddress":str_pairaddress,
  112. "str_tokenaddress":str_tokenaddress,
  113. "str_number_open":str(obj_last_20m_tokens[str_pairaddress]["number_open"]) ,
  114. "str_number_holders":str(obj_last_20m_tokens[str_pairaddress]["number_holders"] ),
  115. })
  116. if len(arr_queueing_send_feishu_last_20min)==0:
  117. return
  118. send_feishu_last_20m(arr_queueing_send_feishu_last_20min)
  119. return
  120. async def count_recent_tokenaddress_And_send_feishu():
  121. global obj_history_pariaddress
  122. arr_str_pairaddress = list(obj_history_pariaddress.keys())
  123. if len(arr_str_pairaddress)==0:
  124. return
  125. cur_now_timestamp = int(time.time()*1000)
  126. arr_queueing_send_feishu_cout_pairaddress = []
  127. for str_pairaddress in arr_str_pairaddress:
  128. cur_arr_history_timestamp = obj_history_pariaddress[str_pairaddress]["arr_history_timestamp"]
  129. obj_history_pariaddress[str_pairaddress]["arr_history_timestamp"] = [history_timestamp for history_timestamp in cur_arr_history_timestamp if (history_timestamp > cur_now_timestamp - 0.5 *3600*1000 ) ]
  130. if len(obj_history_pariaddress[str_pairaddress]["arr_history_timestamp"])<=1:
  131. continue
  132. obj_history_pariaddress[str_pairaddress]["arr_history_timestamp"].sort()
  133. cur_max_timestamp = max(obj_history_pariaddress[str_pairaddress]["arr_history_timestamp"])
  134. cur_secmax_timestamp = obj_history_pariaddress[str_pairaddress]["arr_history_timestamp"][-2]
  135. # print( f"{str_pairaddress} cur_max_timestamp={cur_max_timestamp} obj_history_pariaddress= ",obj_history_pariaddress[str_pairaddress])
  136. if cur_max_timestamp > obj_history_pariaddress[str_pairaddress]["send_feishu_timestamp"] :
  137. obj_history_pariaddress[str_pairaddress]["send_feishu_timestamp"] = cur_now_timestamp
  138. if cur_secmax_timestamp > cur_now_timestamp - 0.25*3600*1000:
  139. # 上一次 获取到此pair信息是在30分钟内
  140. str_tokenaddress = "unknown"
  141. if obj_receive_pair.get(str_pairaddress) is not None:
  142. str_tokenaddress=obj_receive_pair.get(str_pairaddress)["str_tokenaddress"]
  143. arr_queueing_send_feishu_cout_pairaddress.append({
  144. "str_pairaddress":str_pairaddress,
  145. "counts":str(len(obj_history_pariaddress[str_pairaddress]["arr_history_timestamp"])),
  146. "str_number_open":str( (obj_history_pariaddress[str_pairaddress]["number_open"])),
  147. "str_tokenaddress":str_tokenaddress,
  148. })
  149. # print("arr_queueing_send_feishu_cout_pairaddress=",arr_queueing_send_feishu_cout_pairaddress)
  150. continue
  151. if len(arr_queueing_send_feishu_cout_pairaddress)==0:
  152. return
  153. send_feishu_counts_pairaddress(arr_queueing_send_feishu_cout_pairaddress)
  154. return
  155. def save_pairaddress_2_obj_last_20m_tokens(str_pairaddress):
  156. global obj_last_20m_tokens
  157. if obj_last_20m_tokens.get(str_pairaddress) is None:
  158. obj_last_20m_tokens[str_pairaddress] = {
  159. "str_pairaddress": str_pairaddress ,
  160. "timestamp":0,
  161. "str_tokenaddress":"unknown",
  162. "number_open": 0 ,
  163. "number_holders": 0 ,
  164. }
  165. obj_last_20m_tokens[str_pairaddress]["timestamp"] = (int(time.time()*1000))
  166. return
  167. def save_pairaddress_2_obj_history_pariaddress(str_pairaddress):
  168. global obj_history_pariaddress
  169. if obj_history_pariaddress.get(str_pairaddress) is None:
  170. obj_history_pariaddress[str_pairaddress] = {
  171. "send_feishu_timestamp":0,
  172. "number_open":0,
  173. "arr_history_timestamp":[]
  174. }
  175. obj_history_pariaddress[str_pairaddress]["arr_history_timestamp"].append(int(time.time()*1000))
  176. return
  177. is_handleing_pairaddress_file = False
  178. async def handle_pairaddress_file():
  179. global set_has_read_file,is_handleing_pairaddress_file ,obj_receive_pair ,obj_queueing_pairaddress
  180. if is_handleing_pairaddress_file==True:
  181. return
  182. is_handleing_pairaddress_file = True
  183. arr_csv_file = [f for f in os.listdir(
  184. "/root/Downloads/") if f.endswith(".csv")]
  185. cur_now_timestamp = int(time.time()*1000)
  186. for csv_file in arr_csv_file:
  187. handle_csv_file = csv_file.replace(".csv","")
  188. cur_csv_type = None
  189. if "short" in handle_csv_file:
  190. cur_csv_type = "short"
  191. str_timestamp = handle_csv_file.replace("_short","")
  192. elif "long" in handle_csv_file:
  193. cur_csv_type = "long"
  194. str_timestamp = handle_csv_file.replace("_long","")
  195. else:
  196. os.remove(f"/root/Downloads/{csv_file}")
  197. continue
  198. if not re.match(int_pattern, str_timestamp):
  199. os.remove(f"/root/Downloads/{csv_file}")
  200. continue
  201. csv_file_timestamp = int(str_timestamp)
  202. # 2分钟以前的文件直接删除
  203. if cur_now_timestamp - csv_file_timestamp >= 2 * 60 * 1000:
  204. # os.path.exists(f"/root/Downloads/{csv_file}"):
  205. os.remove(f"/root/Downloads/{csv_file}")
  206. #重新获取当前csv文本
  207. arr_csv_file = [f for f in os.listdir(
  208. "/root/Downloads/") if f.endswith(".csv")]
  209. set_cur_file = set(arr_csv_file)
  210. arr_cur_no_read_file =list (set_cur_file - set_has_read_file)
  211. if len(arr_cur_no_read_file)==0:
  212. is_handleing_pairaddress_file = False
  213. return
  214. df = None
  215. arr_pairaddress =[]
  216. try:
  217. for csv_file in arr_cur_no_read_file:
  218. cur_df = pd.read_csv(f"/root/Downloads/{csv_file}",dtype=object)
  219. df =pd.concat([df,cur_df])
  220. arr_pairaddress = df["pairaddress"].dropna().tolist()
  221. except Exception as e:
  222. print(e)
  223. print("arr_cur_no_read_file=",arr_cur_no_read_file )
  224. is_handleing_pairaddress_file = False
  225. return
  226. if os.path.exists(f"/root/Desktop/gendan/total_df.csv" ):
  227. df.to_csv(f"/root/Desktop/gendan/total_df.csv", mode='a',header =False , index = False )
  228. else:
  229. df.to_csv(f"/root/Desktop/gendan/total_df.csv", index = False )
  230. # for pairaddress in arr_pairaddress:
  231. for idx,str_pairaddress in enumerate(arr_pairaddress):
  232. save_pairaddress_2_obj_history_pariaddress(str_pairaddress)
  233. save_pairaddress_2_obj_last_20m_tokens(str_pairaddress)
  234. if obj_receive_pair.get(str_pairaddress) is None:
  235. obj_receive_pair[str_pairaddress]={
  236. "str_tokenaddress":"unknown",
  237. "timestamp":cur_now_timestamp
  238. }
  239. obj_receive_pair[str_pairaddress]["timestamp"] =cur_now_timestamp
  240. cur_key = cur_now_timestamp
  241. while True:
  242. cur_key = cur_key - (idx+2)*2
  243. if obj_queueing_pairaddress.get(cur_key) is None:
  244. obj_queueing_pairaddress[cur_key] = {
  245. "str_pairaddress":str_pairaddress,
  246. "is_sending":False,
  247. "sending_time":0,
  248. "send_counts":0,
  249. "pair_timestamp" :cur_key,
  250. }
  251. break
  252. else:
  253. continue
  254. elif obj_receive_pair.get(str_pairaddress)["str_tokenaddress"] != "unknown" and cur_now_timestamp - obj_receive_pair.get(str_pairaddress)["timestamp"] >= 4 * 60* 1000:
  255. # 离上次处理过了 4分钟 再处理 重新获取此pair 信息
  256. # 为什么是4 因为 油猴脚本是5分钟重新获取已存在的pair ,为了可以在油猴脚本处理后在处理pair ,要先处理当前py的记录
  257. obj_receive_pair[str_pairaddress]["timestamp"] =cur_now_timestamp
  258. cur_key = cur_now_timestamp
  259. while True:
  260. cur_key = cur_key + (idx+11)*2
  261. if obj_queueing_tokenaddress.get(cur_key) is None:
  262. obj_queueing_tokenaddress[cur_key] = {
  263. "str_tokenaddress": obj_receive_pair[str_pairaddress]["str_tokenaddress"] ,
  264. "str_pairaddress": str_pairaddress,
  265. "is_sending":False,
  266. "sending_time":0,
  267. "send_counts":0,
  268. "token_timestamp" :cur_key,
  269. }
  270. break
  271. else:
  272. continue
  273. continue
  274. else:
  275. continue
  276. set_has_read_file = set(arr_csv_file)
  277. is_handleing_pairaddress_file = False
  278. return
  279. async def handle_obj_queueing_tokenaddress(obj_one_queueing_tokenaddress):
  280. global obj_queueing_tokenaddress
  281. cur_now_timestamp = int(time.time()*1000)
  282. str_tokenaddress = obj_one_queueing_tokenaddress["str_tokenaddress"]
  283. token_timestamp = obj_one_queueing_tokenaddress["token_timestamp"]
  284. if obj_one_queueing_tokenaddress["is_sending"] == True:
  285. if cur_now_timestamp - obj_one_queueing_tokenaddress["sending_time"] >=obj_one_queueing_tokenaddress["send_counts"]* 40*1000:
  286. print(f"token_timestamp={token_timestamp} str_tokenaddress={str_tokenaddress} is_sending_too_long del")
  287. del obj_queueing_tokenaddress[token_timestamp]
  288. else:
  289. print(f"token_timestamp={token_timestamp} str_tokenaddress={str_tokenaddress} is_sending")
  290. return True
  291. obj_one_queueing_tokenaddress["sending_time"] = cur_now_timestamp
  292. obj_one_queueing_tokenaddress["send_counts"]+=1
  293. obj_one_queueing_tokenaddress["is_sending"] = True
  294. await send_tokenaddress_message(GMGN_id=GMGN_bot_id , str_tokenaddress=str_tokenaddress)
  295. return True
  296. async def handle_obj_queueing_pairaddress(obj_one_queueing_pairaddress ):
  297. global obj_queueing_pairaddress , Trojan_on_Solana_Odysseus_id
  298. cur_now_timestamp = int(time.time()*1000)
  299. str_pairaddress = obj_one_queueing_pairaddress["str_pairaddress"]
  300. pair_timestamp = obj_one_queueing_pairaddress["pair_timestamp"]
  301. if obj_one_queueing_pairaddress["is_sending"] == True:
  302. if cur_now_timestamp - obj_one_queueing_pairaddress["sending_time"] >=obj_one_queueing_pairaddress["send_counts"]* 40*1000:
  303. print(f"pair_timestamp={pair_timestamp} str_pairaddress={str_pairaddress} is_sending_too_long del")
  304. del obj_queueing_pairaddress[pair_timestamp]
  305. else:
  306. print(f"pair_timestamp={pair_timestamp} str_pairaddress={str_pairaddress} is_sending")
  307. return True
  308. # print((f"handle_obj_queueing_pairaddress str_pairaddress={str_pairaddress} "))
  309. obj_one_queueing_pairaddress["sending_time"] = cur_now_timestamp
  310. obj_one_queueing_pairaddress["send_counts"]+=1
  311. obj_one_queueing_pairaddress["is_sending"] = True
  312. await send_pairaddress_message(chat_Trojan_on_Solana_Odysseus_id=Trojan_on_Solana_Odysseus_id,str_pairaddress=str_pairaddress)
  313. return True
  314. obj_queueing_send_feishu={
  315. # "feishu_timestamp":{
  316. # "is_sending":False,
  317. # "str_tokenaddress":str_tokenaddress,
  318. # "str_now_price":str_now_price,
  319. # "number_open":number_open,
  320. # "number_liq":number_liq,
  321. # "number_holders":number_holders,
  322. # "number_top_10_holding":number_top_10_holding,
  323. # "last_5m_change":last_5m_change,
  324. # "last_1h_change":last_1h_change,
  325. # "feishu_timestamp":cur_now_timestamp,
  326. # }
  327. }
  328. async def ready_send_feishu(obj_temp_queueing_send_feishu):
  329. global obj_queueing_send_feishu , utc_plus_8
  330. cur_now_timestamp = int(time.time()*1000)
  331. arr_send_feishu_info = []
  332. for obj_one_queueing_send_feishu in obj_temp_queueing_send_feishu.values():
  333. str_tokenaddress = obj_one_queueing_send_feishu["str_tokenaddress"]
  334. feishu_timestamp = obj_one_queueing_send_feishu["feishu_timestamp"]
  335. str_pairaddress = obj_one_queueing_send_feishu["str_pairaddress"]
  336. if obj_one_queueing_send_feishu["is_sending"] == True:
  337. if cur_now_timestamp - obj_one_queueing_send_feishu["sending_time"] >=obj_one_queueing_send_feishu["send_counts"]* 15*1000:
  338. print(f"feishu_timestamp={feishu_timestamp} str_tokenaddress={str_tokenaddress} is_sending_too_long del")
  339. del obj_queueing_send_feishu[feishu_timestamp]
  340. else:
  341. print(f"feishu_timestamp={feishu_timestamp} str_tokenaddress={str_tokenaddress} is_sending")
  342. return True
  343. obj_one_queueing_send_feishu["sending_time"] = cur_now_timestamp
  344. obj_one_queueing_send_feishu["send_counts"]+=1
  345. obj_one_queueing_send_feishu["is_sending"] = True
  346. # 将时间戳转换为datetime对象,并指定时区 ,转换为ISO 8601格式的时间字符串,包含时区信息
  347. str_iso8601_date = datetime.datetime.fromtimestamp(feishu_timestamp/1000, tz=utc_plus_8).isoformat().split('.')[0]
  348. str_now_price = obj_one_queueing_send_feishu["str_now_price"]
  349. str_last_5m_change = str(obj_one_queueing_send_feishu["last_5m_change"])
  350. str_last_1h_change = str(obj_one_queueing_send_feishu["last_1h_change"])
  351. str_number_holders = str(obj_one_queueing_send_feishu["number_holders"])
  352. str_number_open = ""
  353. if obj_one_queueing_send_feishu["number_open"] >24:
  354. str_number_open = str(obj_one_queueing_send_feishu["number_open"]/24) + "d"
  355. else:
  356. str_number_open = str(obj_one_queueing_send_feishu["number_open"]) + "h"
  357. arr_send_feishu_info.append( {
  358. "str_iso8601_date": str_iso8601_date,
  359. "str_tokenaddress":str_tokenaddress,
  360. "str_pairaddress":str_pairaddress,
  361. "str_number_holders":str_number_holders,
  362. "str_last_5m_change":str_last_5m_change,
  363. "str_last_1h_change":str_last_1h_change,
  364. "str_now_price": str_now_price,
  365. "str_number_open":str_number_open,
  366. })
  367. # 发给飞书
  368. send_feishu(
  369. arr_send_feishu_info
  370. )
  371. for obj_one_queueing_send_feishu in obj_temp_queueing_send_feishu.values():
  372. str_tokenaddress = obj_one_queueing_send_feishu["str_tokenaddress"]
  373. feishu_timestamp = obj_one_queueing_send_feishu["feishu_timestamp"]
  374. del obj_queueing_send_feishu[feishu_timestamp]
  375. return
  376. def send_feishu_last_20m(arr_obj_sendmsg):
  377. str_iso8601_date = datetime.datetime.fromtimestamp((time.time()), tz=utc_plus_8).isoformat().split('.')[0]
  378. payload_message = {
  379. "msg_type": "post",
  380. "content": {
  381. "post": {
  382. "zh_cn": {
  383. "title": "LastToken20Min " + str_iso8601_date,
  384. "content": [
  385. ]
  386. }
  387. }
  388. }
  389. }
  390. headers = {
  391. "Content-Type": "application/json; charset=utf-8",
  392. }
  393. content = []
  394. for obj_sendmsg in arr_obj_sendmsg:
  395. content.append([
  396. {
  397. "tag": "text",
  398. 'text': obj_sendmsg['str_pairaddress']
  399. },
  400. {
  401. "tag": "text",
  402. 'text': ' '
  403. } ,
  404. {
  405. "tag": "text",
  406. 'text': "ho:" + obj_sendmsg["str_number_holders"]
  407. },
  408. {
  409. "tag": "text",
  410. 'text': ' '
  411. } ,
  412. {
  413. "tag": "text",
  414. 'text': "op:" + obj_sendmsg["str_number_open"]
  415. },
  416. ])
  417. # content.append([{
  418. # "tag": "text",
  419. # "text":obj_sendmsg["str_tokenaddress"],
  420. # }])
  421. if obj_sendmsg["str_tokenaddress"] == "unknown":
  422. content.append([{
  423. "tag": "a",
  424. "href": "https://dexscreener.com/solana/"+ obj_sendmsg["str_pairaddress"],
  425. "text": "DEX "+ obj_sendmsg["str_pairaddress"][-4:]
  426. }])
  427. else:
  428. content.append([{
  429. "tag": "a",
  430. "href": "https://gmgn.ai/sol/token/" + obj_sendmsg["str_tokenaddress"],
  431. "text": "GMGN " + obj_sendmsg["str_tokenaddress"][-4:]
  432. }])
  433. content.append([{
  434. "tag": "text",
  435. "text": "---------------"
  436. }])
  437. content.append([{
  438. "tag": "at",
  439. "user_id": "all",
  440. "user_name": "allman"
  441. }])
  442. payload_message["content"]["post"]["zh_cn"]["content"] = content
  443. payload_message["content"] = json.dumps(payload_message["content"])
  444. payload_message = json.dumps(payload_message)
  445. response = requests.post(
  446. url=feishu_url, headers=headers, data=payload_message)
  447. # response_json = response.json()
  448. # print("response_json=",response_json)
  449. return
  450. def send_feishu_counts_pairaddress( arr_obj_sendmsg ):
  451. str_iso8601_date = datetime.datetime.fromtimestamp((time.time()), tz=utc_plus_8).isoformat().split('.')[0]
  452. payload_message = {
  453. "msg_type": "post",
  454. "content": {
  455. "post": {
  456. "zh_cn": {
  457. "title": "Count " + str_iso8601_date,
  458. "content": [
  459. ]
  460. }
  461. }
  462. }
  463. }
  464. headers = {
  465. "Content-Type": "application/json; charset=utf-8",
  466. }
  467. content = []
  468. for obj_sendmsg in arr_obj_sendmsg:
  469. content.append([
  470. {
  471. "tag": "text",
  472. 'text': obj_sendmsg['str_pairaddress']
  473. },
  474. {
  475. "tag": "text",
  476. 'text': ' '
  477. } ,
  478. {
  479. "tag": "text",
  480. 'text': 'co:' + obj_sendmsg["counts"]
  481. },
  482. {
  483. "tag": "text",
  484. 'text': ' '
  485. } ,
  486. {
  487. "tag": "text",
  488. 'text': 'op:' + obj_sendmsg["str_number_open"]
  489. },
  490. ])
  491. # content.append([{
  492. # "tag": "text",
  493. # "text":obj_sendmsg["str_tokenaddress"],
  494. # }])
  495. if obj_sendmsg["str_tokenaddress"] == "unknown":
  496. content.append([{
  497. "tag": "a",
  498. "href": "https://dexscreener.com/solana/"+ obj_sendmsg["str_pairaddress"],
  499. "text": "DEX " + obj_sendmsg["str_pairaddress"][-4:]
  500. }])
  501. else:
  502. content.append([{
  503. "tag": "a",
  504. "href": "https://gmgn.ai/sol/token/" + obj_sendmsg["str_tokenaddress"],
  505. "text": "GMGN " + obj_sendmsg["str_tokenaddress"][-4:]
  506. }])
  507. content.append([{
  508. "tag": "text",
  509. "text": "---------------"
  510. }])
  511. content.append([{
  512. "tag": "at",
  513. "user_id": "all",
  514. "user_name": "allman"
  515. }])
  516. payload_message["content"]["post"]["zh_cn"]["content"] = content
  517. payload_message["content"] = json.dumps(payload_message["content"])
  518. payload_message = json.dumps(payload_message)
  519. response = requests.post(
  520. url=feishu_url, headers=headers, data=payload_message)
  521. # response_json = response.json()
  522. # print("response_json=",response_json)
  523. return
  524. def send_feishu(arr_obj_sendmsg):
  525. payload_message = {
  526. "msg_type": "post",
  527. "content": {
  528. "post": {
  529. "zh_cn": {
  530. "title": arr_obj_sendmsg[0]["str_iso8601_date"],
  531. "content": [
  532. ]
  533. }
  534. }
  535. }
  536. }
  537. headers = {
  538. "Content-Type": "application/json; charset=utf-8",
  539. }
  540. content = []
  541. for obj_sendmsg in arr_obj_sendmsg:
  542. content.append([{
  543. "tag": "text",
  544. 'text': obj_sendmsg['str_pairaddress']
  545. }
  546. ])
  547. content.append([{
  548. "tag": "text",
  549. 'text': obj_sendmsg['str_iso8601_date']
  550. } ,
  551. {
  552. "tag": "text",
  553. 'text': ' '
  554. } ,
  555. {
  556. "tag": "text",
  557. 'text': 'op:' + obj_sendmsg['str_number_open']
  558. }
  559. ])
  560. content.append([
  561. {
  562. "tag": "text",
  563. 'text': "price:" + obj_sendmsg['str_now_price']
  564. },
  565. {
  566. "tag": "text",
  567. 'text': ' '
  568. } ,
  569. {
  570. "tag": "text",
  571. 'text': 'ho:' + obj_sendmsg["str_number_holders"]
  572. }
  573. ])
  574. content.append([
  575. {
  576. "tag": "text",
  577. 'text': "5m: " + obj_sendmsg['str_last_5m_change'] + "%"
  578. },
  579. {
  580. "tag": "text",
  581. 'text': ' '
  582. } ,
  583. {
  584. "tag": "text",
  585. 'text': '1h: ' + obj_sendmsg["str_last_1h_change"] + "%"
  586. }
  587. ])
  588. content.append([{
  589. "tag": "a",
  590. "href": "https://gmgn.ai/sol/token/" + obj_sendmsg["str_tokenaddress"],
  591. "text": "GMGN " + obj_sendmsg["str_tokenaddress"][-4:]
  592. }])
  593. content.append([{
  594. "tag": "text",
  595. "text": "*****************"
  596. }])
  597. payload_message["content"]["post"]["zh_cn"]["content"] = content
  598. payload_message["content"] = json.dumps(payload_message["content"])
  599. payload_message = json.dumps(payload_message)
  600. response = requests.post(
  601. url=feishu_url, headers=headers, data=payload_message)
  602. # response_json = response.json()
  603. # print("response_json=",response_json)
  604. return
  605. async def ready_send_feishu_timed():
  606. global obj_queueing_send_feishu
  607. if len(obj_queueing_send_feishu.keys())==0:
  608. return
  609. arr_feishu_timestamp = (list(obj_queueing_send_feishu.keys()))
  610. obj_temp_queueing_send_feishu = {}
  611. for feishu_timestamp in arr_feishu_timestamp:
  612. obj_temp_queueing_send_feishu[feishu_timestamp] = (obj_queueing_send_feishu[feishu_timestamp])
  613. # del obj_queueing_send_feishu[feishu_timestamp]
  614. # obj_one_queueing_send_feishu = obj_queueing_send_feishu[feishu_timestamp]
  615. handle_res = await ready_send_feishu(obj_temp_queueing_send_feishu=obj_temp_queueing_send_feishu )
  616. return
  617. async def handle_obj_queueing_pairaddress_timed():
  618. global obj_queueing_pairaddress
  619. while True:
  620. if len(obj_queueing_pairaddress.keys())==0:
  621. break
  622. pair_timestamp = min(list(obj_queueing_pairaddress.keys()))
  623. obj_one_queueing_pairaddress = obj_queueing_pairaddress[pair_timestamp]
  624. handle_res = await handle_obj_queueing_pairaddress(obj_one_queueing_pairaddress=obj_one_queueing_pairaddress )
  625. if handle_res == True:
  626. break
  627. else:
  628. continue
  629. return
  630. async def handle_obj_queueing_tokenaddress_timed():
  631. global obj_queueing_tokenaddress
  632. while True:
  633. if len(obj_queueing_tokenaddress.keys())==0:
  634. break
  635. token_timestamp = min(list(obj_queueing_tokenaddress.keys()))
  636. obj_one_queueing_tokenaddress = obj_queueing_tokenaddress[token_timestamp]
  637. handle_res = await handle_obj_queueing_tokenaddress(obj_one_queueing_tokenaddress=obj_one_queueing_tokenaddress )
  638. if handle_res == True:
  639. break
  640. else:
  641. continue
  642. return
  643. @client_gate.on(events.NewMessage(chats=[Trojan_on_Solana_Odysseus_id ], incoming=True))
  644. async def handle_incoming_gate_Trojan_NewMessage(event):
  645. global obj_queueing_tokenaddress ,obj_queueing_pairaddress
  646. event_message = event.message
  647. message_text = event.message.message
  648. print("enter handle_incoming_gate_Trojan_NewMessage client_gate.on(events.NewMessage message_text=",message_text)
  649. pair_timestamp = min(list(obj_queueing_pairaddress.keys()))
  650. obj_one_queueing_pairaddress = obj_queueing_pairaddress[pair_timestamp]
  651. str_pairaddress = obj_one_queueing_pairaddress["str_pairaddress"]
  652. if "Share token with your Reflink" not in message_text:
  653. # 不能要 pass
  654. del obj_queueing_pairaddress[pair_timestamp]
  655. return
  656. message_text=keep_alnum(message_text)
  657. arr_message_text = message_text.split("\n")
  658. str_tokenaddress = None
  659. str_tokenaddress=arr_message_text[1].strip()
  660. obj_receive_pair[str_pairaddress]["str_tokenaddress"]=str_tokenaddress
  661. obj_last_20m_tokens[str_pairaddress]["str_tokenaddress"]=str_tokenaddress
  662. obj_tokenaddress_2_pairaddress[str_tokenaddress] = str_pairaddress
  663. if str_pairaddress==str_tokenaddress.lower():
  664. # 没有获取到 str_tokenaddress 直接在send_feishu 赋值
  665. global obj_queueing_send_feishu
  666. cur_now_timestamp = int(time.time()*1000)
  667. cur_key = cur_now_timestamp
  668. while True:
  669. cur_key = cur_key + 2*2
  670. if obj_queueing_tokenaddress.get(cur_key) is None:
  671. obj_queueing_send_feishu[cur_key] = {
  672. "is_sending":False,
  673. "send_counts":0,
  674. "sending_time":0,
  675. "str_pairaddress":str_pairaddress,
  676. "str_tokenaddress":str_tokenaddress,
  677. "str_now_price":"0",
  678. "number_open": 0 ,
  679. "number_liq_usd":"0",
  680. "number_holders":"0",
  681. "number_top_10_holding":"0",
  682. "last_5m_change":"0",
  683. "last_1h_change":"0",
  684. "feishu_timestamp":cur_key,
  685. }
  686. break
  687. else:
  688. continue
  689. del obj_queueing_pairaddress[pair_timestamp]
  690. return
  691. cur_now_timestamp = int(time.time()*1000)
  692. obj_queueing_tokenaddress[cur_now_timestamp]={
  693. "str_tokenaddress":str_tokenaddress,
  694. "str_pairaddress":str_pairaddress,
  695. "is_sending":False,
  696. "sending_time":0,
  697. "send_counts":0,
  698. "token_timestamp" :cur_now_timestamp,
  699. }
  700. del obj_queueing_pairaddress[pair_timestamp]
  701. return
  702. obj_queueing_tokenaddress={
  703. }
  704. obj_tokenaddress_2_pairaddress={
  705. # "str_tokenaddress":"str_pairaddress"
  706. }
  707. @client_gate.on(events.NewMessage(chats=[GMGN_bot_id ], incoming=True))
  708. async def handle_incoming_GMGN_bot_NewMessage(event):
  709. # 【Solana】MAD (MAD)
  710. # $0.0{4}16505 🔴 -2.26% Price Chart (https://gmgn.ai/sol/token/madHpjRn6bd8t78Rsy7NuSuNwWa2HU8ByPobZprHbHv?utm_source=telegram&utm_campaign=tg_cmdbot_hot) | Snipe with Bot (https://t.me/GMGN_sol_bot?start=madHpjRn6bd8t78Rsy7NuSuNwWa2HU8ByPobZprHbHv)
  711. # 📈 5m | 1h | 6h: -0.25% | 0.76% | -3.7%
  712. # 💰 MC: $16.5M
  713. # 💧 Liq: 1,862.71 SOL ($512K 🔥99.98%)
  714. # 💰 Initial LP: 15 SOL (100% supply)
  715. # 👥 Holders: 12326
  716. # 👨‍🍳 Creator: CNBx....FmP (https://solscan.io/account/CNBxpRqrzZZenHU4jT9XXpcxPChtDafTnnrUfSyYFmP8) (2.0708 SOL)
  717. # 🔥 DEV Burnt: --
  718. # 🕒 Open: 43d ago
  719. # 🔥 Smart Buy/Sell: -/-
  720. # 🦅 DEXScreener: Advertised ❌ / Update Social ❌
  721. # 🔔 Audit: NoMint ✅ / Blacklist ✅ / Burnt ✅
  722. # 👥 Top 10 holdings: 6.92%<30% ✅
  723. # 1.65 (https://gmgn.ai/sol/address/ASTyfSima4LLAdDgoFGkgqoKowG1LZFDr9fAQrg7iaJZ) | 0.71 (https://gmgn.ai/sol/address/4SGsfKU4EZT2QUSKgmHxumaEg7TPqw7Ry5N7QE6Ncu8f) | 0.6 (https://gmgn.ai/sol/address/9N115DvPaQ8JBRpNKYEqHb6zpDroMghY3XTgEY9bPYDY) | 0.6 (https://gmgn.ai/sol/address/4hAFR3vWVxsz72GbRtpSgRLgoHSTbrqBB5XtAsoSjxdW) | 0.59 (https://gmgn.ai/sol/address/DzxJZe5fJiLR2yV5x2VRWrczQFcTu5f267HFMBZk1n5k) | 0.57 (https://gmgn.ai/sol/address/Gi7nuWAcJ1EkbXGxdDiopEbT1f4nP1bcotJefWgM9wPf) | 0.57 (https://gmgn.ai/sol/address/Fx4vXtW56dHegfKjEJJnaTX5JtFg1cdzWVxuHQiZqGxM) | 0.57 (https://gmgn.ai/sol/address/2aYpTsDpE1PRAoEPGfcv9Uo66oBHkBkFLPbnQiRkFJqd) | 0.54 (https://gmgn.ai/sol/address/AxLSsHE6iXssJe6MjLbbgecpbwg2jdgHnM7umMsY3QGz) | 0.52 (https://gmgn.ai/sol/address/4xK8gtJ22sNB7JzYhF6MuckECLWaJLpNaSmUU82FPMWm)
  724. # 🐀 Insiders: 2.22%
  725. # 📕 Rug Probability: --
  726. # 📒 Rug history: --
  727. # 🎯 First 70 buyers (Snipers 6):
  728. # 🌑🌑🌑🌑🌑🌗🌑🌑🌑🌕
  729. # 🌑🌕🌑🌑🌑🌕🌕🌑🌑🌑
  730. # 🌗🌑🌑🌑🌕🌑🌑🌑🌕🌑
  731. # 🌕 Hold: 13
  732. # 🌝 Bought more: 0
  733. # 🌗 Sold part: 3
  734. # 🌑 Sold out: 54
  735. # Total Bought: 23.99%
  736. # Current Total Holdings: 0.01%
  737. # Token
  738. # madHpjRn6bd8t78Rsy7NuSuNwWa2HU8ByPobZprHbHv
  739. # Backup BOT: US (https://t.me/US_GMGNBOT?start=madHpjRn6bd8t78Rsy7NuSuNwWa2HU8ByPobZprHbHv) | 01 (https://t.me/GMGN_sol_bot?start=madHpjRn6bd8t78Rsy7NuSuNwWa2HU8ByPobZprHbHv) | 02 (https://t.me/GMGN_sol02_bot?start=madHpjRn6bd8t78Rsy7NuSuNwWa2HU8ByPobZprHbHv) | 03 (https://t.me/GMGN_sol03_bot?start=madHpjRn6bd8t78Rsy7NuSuNwWa2HU8ByPobZprHbHv) | 04 (https://t.me/GMGN_sol04_bot?start=madHpjRn6bd8t78Rsy7NuSuNwWa2HU8ByPobZprHbHv)
  740. # 🐦 Twitter (https://twitter.com/madcoinvip) | 🌏 Website (https://www.madcoin.vip/) | ✈️ Telegram (https://t.me/MadCoinVip)
  741. global obj_queueing_tokenaddress , obj_last_20m_tokens
  742. event_message = event.message
  743. message_text = event.message.message
  744. print("enter handle_incoming_GMGN_bot_NewMessage client_gate.on(events.NewMessage message_text=",message_text)
  745. if len(list(obj_queueing_tokenaddress.keys()))==0:
  746. return
  747. token_timestamp = min(list(obj_queueing_tokenaddress.keys()))
  748. obj_one_queueing_tokenaddress = obj_queueing_tokenaddress[token_timestamp]
  749. str_tokenaddress= obj_one_queueing_tokenaddress["str_tokenaddress"]
  750. str_pairaddress= obj_one_queueing_tokenaddress["str_pairaddress"]
  751. # # 通过 tokenaddress 获取 pairaddress
  752. # str_pairaddress = obj_tokenaddress_2_pairaddress[str_tokenaddress]
  753. message_text=message_text.lower()
  754. message_text=message_text.strip()
  755. # if str_tokenaddress.lower() not in message_text:
  756. # return
  757. str_now_price = None
  758. last_5m_change = None
  759. last_1h_change = None
  760. number_open = 0
  761. number_liq_usd = 0
  762. nomint_flag = False
  763. blacklist_flag = False
  764. burnt_flag = False
  765. number_insiders = 0
  766. number_holders = 0
  767. number_top_10_holding = 0
  768. is_normal = True
  769. arr_total_split_message = re.split('\n+', message_text)
  770. if "pump status: trading on raydium" in message_text:
  771. arr_total_split_message.pop(1)
  772. for idx,split_message in enumerate( arr_total_split_message):
  773. if idx <= 0:
  774. continue
  775. split_message=split_message.lower().strip()
  776. if "$" in split_message and "price chart" in split_message and str_now_price is None:
  777. # 获取当前价格
  778. temp_now_price = split_message.split(" ")[0]
  779. temp_now_price=temp_now_price.replace("$","")
  780. arr_temp_now_price = temp_now_price.split(".")
  781. integer_now_price = arr_temp_now_price[0]
  782. fractional_now_price = arr_temp_now_price[1]
  783. if "{" in fractional_now_price:
  784. fractional_now_price = re.sub(r"[{}]", " ", fractional_now_price)
  785. arr_fractional_now_price = fractional_now_price.split(" ")
  786. fractional_now_price = "0" * (int(arr_fractional_now_price[-2]))+ arr_fractional_now_price[-1]
  787. str_now_price = integer_now_price + "." + fractional_now_price
  788. elif "5m" in split_message :
  789. # 获取最近时间的价格变化
  790. # split_message = re.sub(r"[|%:📈]", "", split_message)
  791. # split_message = re.sub(r"\s+", " ", split_message)
  792. split_message = keep_alnum_forgmgn(split_message)
  793. split_message = re.sub(r"\s+", " ", split_message)
  794. split_message=split_message.strip()
  795. arr_price_change = split_message.split(" ")
  796. if len(arr_price_change)==6:
  797. last_5m_change = (arr_price_change[3])
  798. last_1h_change = (arr_price_change[4])
  799. elif "liq" in split_message:
  800. split_message=split_message.lower()
  801. if "usdc" in split_message or "usdt" in split_message:
  802. # pair 不是sol 是usd pass
  803. is_normal = False
  804. break
  805. split_message=split_message.replace("sol","")
  806. split_message=split_message.replace(",","")
  807. split_message = keep_alnum_forgmgn(split_message)
  808. split_message=split_message.strip()
  809. split_message = re.sub(r"\s+", " ", split_message)
  810. arr_split_message = split_message.split(' ')
  811. # number_liq = float(arr_split_message[1])
  812. split_message_usd = arr_split_message[2]
  813. base_usd = 1
  814. if "m" in split_message_usd:
  815. split_message_usd =split_message_usd.replace("m","")
  816. base_usd = 10**6
  817. elif "k" in split_message_usd:
  818. split_message_usd =split_message_usd.replace("k","")
  819. base_usd = 10**3
  820. elif "b" in split_message_usd:
  821. split_message_usd =split_message_usd.replace("b","")
  822. base_usd = 10**9
  823. number_liq_usd = int(base_usd * float(split_message_usd) )
  824. elif "holders" in split_message:
  825. split_message = keep_alnum_forgmgn(split_message)
  826. split_message=split_message.strip()
  827. split_message = re.sub(r"\s+", " ", split_message)
  828. arr_split_message = split_message.split(' ')
  829. number_holders = int(arr_split_message[1])
  830. elif "open" in split_message:
  831. split_message = keep_alnum_forgmgn(split_message)
  832. split_message=split_message.strip()
  833. split_message = re.sub(r"\s+", " ", split_message)
  834. arr_split_message = split_message.split(' ')
  835. if "d" in arr_split_message[1]:
  836. number_open = int(arr_split_message[1].replace("d","")) *24
  837. elif "h" in arr_split_message[1]:
  838. number_open = int(arr_split_message[1].replace("h",""))
  839. elif "min" in arr_split_message[1]:
  840. number_open = round(int(arr_split_message[1].replace("min","")) / 60 , 2 )
  841. elif "audit" in split_message:
  842. split_message =split_message.replace("✅","yes")
  843. split_message =split_message.replace("❌","no")
  844. split_message =split_message.replace("?","no")
  845. split_message = keep_alnum_forgmgn(split_message)
  846. split_message=split_message.strip()
  847. split_message = re.sub(r"\s+", " ", split_message)
  848. arr_split_message = split_message.split(' ')
  849. nomint_flag = (arr_split_message[2]=="yes")
  850. blacklist_flag = (arr_split_message[4]=="yes")
  851. burnt_flag = (arr_split_message[6]=="yes")
  852. elif "top 10 holdings" in split_message:
  853. split_message = keep_alnum_forgmgn(split_message)
  854. split_message=split_message.replace("--","0")
  855. split_message=split_message.strip()
  856. split_message = re.sub(r"\s+", " ", split_message)
  857. arr_split_message = split_message.split(' ')
  858. number_top_10_holding = float(arr_split_message[3])
  859. elif "insiders" in split_message:
  860. split_message = keep_alnum_forgmgn(split_message)
  861. split_message=split_message.replace("--","0")
  862. split_message=split_message.strip()
  863. split_message = re.sub(r"\s+", " ", split_message)
  864. arr_split_message = split_message.split(' ')
  865. number_insiders = float(arr_split_message[1])
  866. if (nomint_flag and blacklist_flag and burnt_flag ) == False:
  867. is_normal = False
  868. # if number_liq_usd <= 150:
  869. # # 1 sol = 150 $
  870. # # 700sol = 100k $
  871. # is_normal =False
  872. # if number_open <= 24:
  873. # is_normal =False
  874. if number_holders <= 300:
  875. is_normal =False
  876. if number_top_10_holding >= 35:
  877. is_normal =False
  878. if number_insiders >= 20 :
  879. is_normal = False
  880. if is_normal ==False:
  881. print(f"{str_tokenaddress} is unnormal")
  882. obj_queueing_tokenaddress[token_timestamp]["need_remove"] = True
  883. del obj_queueing_tokenaddress[token_timestamp]
  884. if obj_last_20m_tokens.get(str_pairaddress) is not None:
  885. del obj_last_20m_tokens[str_pairaddress]
  886. return
  887. else:
  888. print(f"{str_tokenaddress} is normal")
  889. obj_last_20m_tokens[str_pairaddress]["number_open"] =number_open
  890. obj_last_20m_tokens[str_pairaddress]["number_holders"] =number_holders
  891. obj_history_pariaddress[str_pairaddress]["number_open"] =number_open
  892. global obj_queueing_send_feishu
  893. cur_now_timestamp = int(time.time()*1000)
  894. obj_queueing_send_feishu[cur_now_timestamp] = {
  895. "is_sending":False,
  896. "send_counts":0,
  897. "sending_time":0,
  898. "str_tokenaddress":str_tokenaddress,
  899. "str_pairaddress":str_pairaddress,
  900. "str_now_price":str_now_price,
  901. "number_open":number_open,
  902. "number_liq_usd":number_liq_usd,
  903. "number_holders":number_holders,
  904. "number_top_10_holding":number_top_10_holding,
  905. "last_5m_change":last_5m_change,
  906. "last_1h_change":last_1h_change,
  907. "feishu_timestamp":cur_now_timestamp,
  908. }
  909. obj_queueing_tokenaddress[token_timestamp]["need_remove"] = True
  910. del obj_queueing_tokenaddress[token_timestamp]
  911. return
  912. obj_global_info ={
  913. "timedTasks_idx":0
  914. }
  915. sys.excepthook = global_exception_hook
  916. signal.signal(signal.SIGTERM, term_sig_handler)
  917. signal.signal(signal.SIGINT, term_sig_handler)
  918. print(f"Begin Listening for messages containing in chats ichat names...")
  919. async def timedTasks():
  920. global obj_global_info
  921. obj_global_info["timedTasks_idx"]+=1
  922. cur_timedTasks_idx =obj_global_info["timedTasks_idx"]
  923. if cur_timedTasks_idx <5:
  924. return
  925. if cur_timedTasks_idx%3609 == 0:
  926. obj_global_info["timedTasks_idx"]=10
  927. if cur_timedTasks_idx%3==0:
  928. await handle_pairaddress_file()
  929. if cur_timedTasks_idx%5 == 0:
  930. await handle_obj_queueing_pairaddress_timed()
  931. elif cur_timedTasks_idx%5 == 4:
  932. await handle_obj_queueing_tokenaddress_timed()
  933. if cur_timedTasks_idx%15==0:
  934. # 15s一次飞书
  935. await ready_send_feishu_timed()
  936. elif cur_timedTasks_idx% 61==0:
  937. await count_recent_tokenaddress_And_send_feishu()
  938. elif cur_timedTasks_idx% (1201)==0:
  939. await ready_send_feishu_last_20m_tokens_timed()
  940. return
  941. # scheduler = BackgroundScheduler({'apscheduler.timezone': 'UTC'})
  942. scheduler = AsyncIOScheduler({'apscheduler.timezone': 'UTC'})
  943. scheduler.add_job(timedTasks, "interval", seconds=1)
  944. # scheduler.add_job(func=timedTasks, trigger="cron", seconds=10)
  945. # '*/1 * * * * *'
  946. scheduler.start()
  947. client_gate.run_until_disconnected()
  948. asyncio.get_event_loop().run_forever()
  949. # client_bill.run_until_disconnected()