Skip to content

Instantly share code, notes, and snippets.

@jokereven
Created October 24, 2023 15:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jokereven/811978c931556b9f83120e74a873dc55 to your computer and use it in GitHub Desktop.
Save jokereven/811978c931556b9f83120e74a873dc55 to your computer and use it in GitHub Desktop.
# https://gmgn.ai/defi/quotation/v1/rank/eth/swaps/5m?orderby=swaps&direction=desc
# every 5s to request the url if check is ok, send message to discord or tg.
import datetime
import json
import time
import requests
import schedule
import telebot
# bark
def bark(data):
if TgBotToken != '':
time.sleep(2)
bot.send_message(HotChatID , data, parse_mode='html', disable_web_page_preview=True)
# smart
def smart_bark(data):
if TgBotToken != '':
time.sleep(2)
bot.send_message(SmartChatID, data, parse_mode='html', disable_web_page_preview=True)
# meme
def meme_bark(data):
if TgBotToken != '':
time.sleep(2)
bot.send_message(MemeChatID, data, parse_mode='html', disable_web_page_preview=True)
# meme
def signal_bark(data):
if TgBotToken != '':
time.sleep(2)
bot.send_message(SignalChatID, data, parse_mode='html', disable_web_page_preview=True)
def gmgn_call():
print('call========================')
url = f'https://gmgn.ai/defi/quotation/v1/rank/eth/swaps/5m?orderby=swaps&direction=desc'
session = requests.session()
session.headers = {
'Accept': 'application/json, text/plain, */*',
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/116.0.0.0 Safari/537.36',
'Content-Type': 'application/json',
'Accept-Language': 'zh-CN,zh;q=0.9,en;q=0.8'
}
response = session.get(url)
if response.status_code == 200:
data = response.json()
if data['code'] == 0 and data['msg'] == 'success':
rank = data['data']['rank']
for r in rank:
address = r['address']
symbol = r['symbol']
swaps = r['swaps']
volume = r['volume']
hot_level = r['hot_level']
call_number = r['call_number']
smart_buy_24h = r['smart_buy_24h']
smart_sell_24h = r['smart_sell_24h']
price_change_percent = r['price_change_percent']
pool_creation_timestamp = r['pool_creation_timestamp']
is_honeypot = r['is_honeypot']
is_show_alert = r['is_show_alert']
# 红色绿灯
if is_show_alert:
alert = '🔴'
else:
alert = '🟢'
# 红色绿灯
if is_honeypot == 0:
honeypot = '🟢'
else:
honeypot = '🔴'
# 买卖税率
buy_tax = r.get('buy_tax', 0)
if buy_tax is None:
buy_tax = 0
buy_tax = int(buy_tax * 10000) / 100
sell_tax = r.get('sell_tax', 0)
if sell_tax is None:
sell_tax = 0
sell_tax = int(sell_tax * 10000) / 100
# 池子添加流动性时间
if pool_creation_timestamp is None:
pool_creation_timestamp = int(datetime.datetime.now().timestamp())
else:
pool_creation_timestamp = int(pool_creation_timestamp)
# 将时间戳转换为datetime对象
dt_object = datetime.datetime.fromtimestamp(pool_creation_timestamp)
# 计算时间差
time_diff = datetime.datetime.now() - dt_object
# 30min
thirty_min = datetime.timedelta(seconds=1800)
# 将时间差转换为多久前的格式
if time_diff.days > 0:
time_ago = f"{time_diff.days}天前"
elif time_diff.seconds > 3600:
time_ago = f"{time_diff.seconds // 3600}小时前"
elif time_diff.seconds > 60:
time_ago = f"{time_diff.seconds // 60}分钟前"
else:
time_ago = "刚刚"
# 将多久前的格式插入到字符串中
pool_creation_timestamp = time_ago
# 根据时间差判断是不是三十分钟内的盘
if time_diff < thirty_min:
is_new = '🟢'
else:
is_new = '🔴'
# 热度警告, TODO: 这里感觉得优化一下, 感觉可以根据交易量显示热度
fire = ''
# 根据 swap 和 volume 判断热度, 10 swap 1000 volume 表示一个 🔥 TODO: 可能明天要调一下
fire = '🔥' if swaps > 30 and swaps <= 50 and volume > 10000 else ''
fire = '🔥🔥' if swaps > 50 and swaps <= 100 and volume > 30000 else ''
fire = '🔥🔥🔥' if swaps > 100 and swaps <= 200 and volume > 50000 else ''
fire = '🔥🔥🔥🔥' if swaps > 200 and volume > 200000 else ''
# 聪明钱剩余警告
smart = ''
smart_in = smart_buy_24h - smart_sell_24h
_smart = '🤑' * smart_in if int(smart_in) >= 2 else ''
if smart_buy_24h >= 5:
smart = _smart
if smart_buy_24h > 0 and smart_sell_24h > 0:
smart_ratio = smart_sell_24h / smart_buy_24h * 100
elif smart_buy_24h > 0 and smart_sell_24h == 0:
smart_ratio = 0
else:
smart_ratio = 100
dexscreener_link = f"https://dexscreener.com/ethereum/{address}"
gmgn_link = f'https://gmgn.ai/eth/token/{address}'
# 蜜罐和有警告的项目跳过
# if is_show_alert or is_honeypot != 0:
# continue
# smart buy
# TODO: 聪明钱持仓分析
if smart_buy_24h >= 5:
bark(f"{smart}\nnew : {is_new}\nsmart : buy {smart_buy_24h} sale {smart_sell_24h}\n卖出占比 : {smart_ratio}%\n项目 : {symbol}\n合约 : <code>{address}</code>\n交易量 : {volume}\n交易额 : {swaps}\n买/卖税率 : {buy_tax}% / {sell_tax}%\n价格变化 : {price_change_percent}%\n合约创建时间 : {pool_creation_timestamp}\n热门 : {hot_level}\ncall : {call_number}\n24小时聪明钱包买入 : {smart_buy_24h}\n24小时聪明钱包卖出 : {smart_sell_24h}\n蜜罐 : {honeypot}\n警告 : {alert}\n🔗<a href='{dexscreener_link}'>dexscreener</a> \t | \t 🔗<a href='{gmgn_link}'>gmgn</a>")
if swaps > 30 and volume > 10000:
bark(f"{fire} \nnew : {is_new}\nsmart : buy {smart_buy_24h} sale {smart_sell_24h}\n卖出占比 : {smart_ratio}%\n项目 : {symbol}\n合约 : <code>{address}</code>\n交易量 : {volume}\n交易额 : {swaps}\n买/卖税率 : {buy_tax}% / {sell_tax}%\n价格变化 : {price_change_percent}%\n合约创建时间 : {pool_creation_timestamp}\n热门 : {hot_level}\ncall : {call_number}\n24小时聪明钱包买入 : {smart_buy_24h}\n24小时聪明钱包卖出 : {smart_sell_24h}\n蜜罐 : {honeypot}\n警告 : {alert}\n🔗<a href='{dexscreener_link}'>dexscreener</a> \t | \t 🔗<a href='{gmgn_link}'>gmgn</a>")
# 聪明钱的数目大于等于1, 且时间差小于30分钟, 且没有警告, 且不是蜜罐, 先暂时把警告⚠和蜜罐去除.
if smart_buy_24h >= 1 and time_diff < thirty_min and not is_show_alert and is_honeypot == 0:
# if smart_buy_24h >= 1 and time_diff < thirty_min:
meme_bark(f"{smart} \nnew : {is_new}\nsmart : buy {smart_buy_24h} sale {smart_sell_24h}\n卖出占比 : {smart_ratio}%\n项目 : {symbol}\n合约 : <code>{address}</code>\n交易量 : {volume}\n交易额 : {swaps}\n买/卖税率 : {buy_tax}% / {sell_tax}%\n价格变化 : {price_change_percent}%\n合约创建时间 : {pool_creation_timestamp}\n热门 : {hot_level}\ncall : {call_number}\n24小时聪明钱包买入 : {smart_buy_24h}\n24小时聪明钱包卖出 : {smart_sell_24h}\n蜜罐 : {honeypot}\n警告 : {alert}\n🔗<a href='{dexscreener_link}'>dexscreener</a> \t | \t 🔗<a href='{gmgn_link}'>gmgn</a>")
def gmgn_smart():
print("smart========================")
# Smart Money
# https://gmgn.ai/defi/quotation/v1/smartmoney/eth/rank/token/flow?flow=in&interval=15m
# Fresh Wallet
# https://gmgn.ai/defi/quotation/v1/smartmoney/eth/trade/activity?size=10&tag=&cost=1000&side=buy
# kol/vc
# https://gmgn.ai/defi/quotation/v1/smartmoney/eth/rank/token/flow?flow=in&tag=renowned&interval=15m
url = f'https://gmgn.ai/defi/quotation/v1/smartmoney/eth/rank/token/flow?flow=in&interval=15m'
session = requests.session()
session.headers = {
'Accept': 'application/json, text/plain, */*',
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/116.0.0.0 Safari/537.36',
'Content-Type': 'application/json',
'Accept-Language': 'zh-CN,zh;q=0.9,en;q=0.8'
}
response = session.get(url)
if response.status_code == 200:
data = response.json()
if data['code'] == 0 and data['msg'] == 'success':
rank = data['data']['rank']
for r in rank:
tx_count = r['tx_count']
token = r['token']
address = token['address']
symbol = token['symbol']
is_show_alert = token['is_show_alert']
is_new = token['is_new']
pool_creation_timestamp = token['creation_timestamp']
dexscreener_link = f"https://dexscreener.com/ethereum/{address}"
gmgn_link = f'https://gmgn.ai/eth/token/{address}'
if pool_creation_timestamp is None:
pool_creation_timestamp = int(datetime.datetime.now().timestamp())
else:
pool_creation_timestamp = int(pool_creation_timestamp)
# 将时间戳转换为datetime对象
dt_object = datetime.datetime.fromtimestamp(pool_creation_timestamp)
# 计算时间差
time_diff = datetime.datetime.now() - dt_object
thirty_min = datetime.timedelta(seconds=3600)
# 将时间差转换为多久前的格式
if time_diff.days > 0:
time_ago = f"{time_diff.days}天前"
elif time_diff.seconds > 3600:
time_ago = f"{time_diff.seconds // 3600}小时前"
elif time_diff.seconds > 60:
time_ago = f"{time_diff.seconds // 60}分钟前"
else:
time_ago = "刚刚"
# 将多久前的格式插入到字符串中
pool_creation_timestamp = time_ago
if time_diff < thirty_min:
is_new = '🟢'
else:
is_new = '🔴'
# lamp
if tx_count >= 1 and tx_count <= 2:
light = '🟡' * tx_count
elif tx_count >= 3:
light = '🟢' * tx_count
if is_show_alert:
alert = '🔴'
else:
alert = '🟢'
print(time_diff.seconds, symbol)
smart_bark(f"Alerts:\nnew : {is_new}\n\n{light}\n\n项目 : {symbol}\n合约创建时间 : {pool_creation_timestamp}\n合约 : <code>{address}</code>\n交易次数 : {tx_count}\n警告 : {alert} \n新项目 : {is_new} \n🔗<a href='{dexscreener_link}'>dexscreener</a> \t | \t 🔗<a href='{gmgn_link}'>gmgn</a>")
# 把警告先jie
# if tx_count >= 1 and time_diff < thirty_min and not is_show_alert:
if tx_count >= 1 and time_diff < thirty_min and not is_show_alert:
meme_bark(f"Alerts:\nnew : {is_new}\n\n{light}\n\n项目 : {symbol}\n合约创建时间 : {pool_creation_timestamp}\n合约 : <code>{address}</code>\n交易次数 : {tx_count}\n警告 : {alert} \n新项目 : {is_new} \n🔗<a href='{dexscreener_link}'>dexscreener</a> \t | \t 🔗<a href='{gmgn_link}'>gmgn</a>")
def gmgn_signals():
print("signals========================")
# all signals data
# https://gmgn.ai/defi/quotation/v1/signals?size=10
# only smart money signals data
# https://gmgn.ai/defi/quotation/v1/signals?size=10&signal_type=smart_buy
url = f'https://gmgn.ai/defi/quotation/v1/signals?size=10&signal_type=smart_buy'
session = requests.session()
session.headers = {
'Accept': 'application/json, text/plain, */*',
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/116.0.0.0 Safari/537.36',
'Content-Type': 'application/json',
'Accept-Language': 'zh-CN,zh;q=0.9,en;q=0.8'
}
response = session.get(url)
if response.status_code == 200:
data = response.json()
if data['code'] == 0 and data['msg'] == 'success':
signals = data['data']['signals']
for s in signals:
timestamp = s['timestamp']
if int(time.time()) - timestamp > 300:
continue
token_address = s['token_address']
smart_buy = s['smart_buy']
smart_sell = s['smart_sell']
signal_1h_count = s['signal_1h_count']
# token
token = s['token']
is_honeypot = token['is_honeypot']
symbol = token['symbol']
is_show_alert = token['is_show_alert']
# 红色绿灯
if is_honeypot == 0:
honeypot = '🟢'
else:
honeypot = '🔴'
# tx_count
tx_count = s['tx_count']
if pool_creation_timestamp is None:
pool_creation_timestamp = int(datetime.datetime.now().timestamp())
else:
pool_creation_timestamp = int(pool_creation_timestamp)
dexscreener_link = f"https://dexscreener.com/ethereum/{token_address}"
gmgn_link = f'https://gmgn.ai/eth/token/{token_address}'
signal_bark(f"smart : buy {smart_buy} sale {smart_sell}\nsignal_1h_count : {signal_1h_count}\n项目 : {symbol}\n合约 : <code>{token_address}</code>\n交易次数 : {tx_count}\n警告 : {is_show_alert}\n蜜罐 : {honeypot}\n🔗<a href='{dexscreener_link}'>dexscreener</a> \t | \t 🔗<a href='{gmgn_link}'>gmgn</a>")
if __name__ == '__main__':
file = open('config.json', 'r')
config = json.loads(file.read())
TgBotToken, HotChatID, SmartChatID, MemeChatID, SignalChatID = config['tgbot_token'], config['hot_chat_id'], config['smart_chat_id'], config['meme_chat_id'], config['signal_chat_id']
bot = telebot.TeleBot(TgBotToken)
bot.set_webhook()
# bot.infinity_polling()
schedule.every(10).seconds.do(gmgn_call)
schedule.every(10).seconds.do(gmgn_smart)
schedule.every(10).seconds.do(gmgn_signals)
while True:
schedule.run_pending()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment