39 lines
1.4 KiB
Python
39 lines
1.4 KiB
Python
|
|
import requests
|
|
import settings
|
|
from datetime import datetime, timedelta
|
|
import time
|
|
import tg
|
|
import traceback
|
|
import logging
|
|
|
|
cursor = '0-0-0'
|
|
|
|
def strategy_run():
|
|
# 获取上一分钟的timestamp
|
|
last_min = datetime.now() - timedelta(minutes=settings.whaleAlert_minutes)
|
|
ts = time.mktime(last_min.timetuple())
|
|
global cursor
|
|
cursor_query = f"&cursor={cursor}" if cursor != '0-0-0' else ""
|
|
url = f'https://api.whale-alert.io/v1/transactions?api_key={settings.whaleAlert_apikey}&start={int(ts)}&min_value={settings.whaleAlert_max_limit}' + cursor_query
|
|
print(f'Request url: {url}')
|
|
resp = requests.get(url).json()
|
|
print(resp)
|
|
if resp['result'] == "success":
|
|
cursor = resp['cursor']
|
|
try:
|
|
if 'transactions' in resp:
|
|
data = resp['transactions']
|
|
|
|
for ts in data:
|
|
if ts['to']['owner_type'] == 'exchange':
|
|
from_text = 'unknown wallet'
|
|
content = f"🚨 {ts['amount']} #{ts['symbol']} ({ts['amount_usd']} USD) 从 {from_text} 转入 #{ts['to']['owner']}"
|
|
|
|
print(content)
|
|
tg.send_message(settings.chat_id, content)
|
|
except Exception as e:
|
|
logging.error(traceback.format_exc())
|
|
tg.send_message(settings.chat_id, traceback.format_exc())
|
|
else:
|
|
print(resp['message']) |