50 lines
1.7 KiB
Python
50 lines
1.7 KiB
Python
|
|
import requests
|
|
import setting
|
|
from datetime import datetime, timedelta
|
|
import time
|
|
import telegram_sender
|
|
import traceback
|
|
import logging
|
|
import json
|
|
|
|
def run():
|
|
try:
|
|
start_time = datetime.now() - timedelta(minutes=setting.whaleAlert_minutes)
|
|
start_ts = int(start_time.timestamp())
|
|
|
|
url = f'https://api.whale-alert.io/v1/transactions?api_key={setting.whaleAlert_apikey}&start={start_ts}&min_value={setting.whaleAlert_max_limit}'
|
|
headers = {'Accept': 'application/json'}
|
|
|
|
resp = requests.get(url, headers=headers).text
|
|
# 判断是否为JSON格式
|
|
if json.dumps(resp) == False:
|
|
print(resp)
|
|
return
|
|
|
|
data = json.loads(resp)
|
|
|
|
print(data)
|
|
if data['result'] == "success":
|
|
if 'transactions' in data:
|
|
data = data['transactions']
|
|
|
|
for ts in data:
|
|
if ts['to']['owner_type'] == 'exchange':
|
|
amount = int(ts['amount'])
|
|
amount_usd = int(ts['amount_usd'])
|
|
|
|
amount_format = f'{int(amount_usd):,d}'
|
|
amount_usd_format = f'{int(amount_usd):,d}'
|
|
|
|
|
|
content = f"🚨大额转入提醒🚨\r\n\r\n {amount_format} #{ts['symbol']} ({amount_usd_format} USD) 从 {ts['from']['owner']} 转入 #{ts['to']['owner']}"
|
|
|
|
print(content)
|
|
telegram_sender.send_message(setting.chat_id, content)
|
|
|
|
else:
|
|
print(data)
|
|
telegram_sender.send_message(setting.chat_id, data['message'])
|
|
except:
|
|
logging.error(traceback.format_exc()) |