This commit is contained in:
aazhou 2023-06-17 11:55:43 +08:00
parent aa675c084f
commit bd38e34fd7
3 changed files with 30 additions and 22 deletions

13
main.py
View File

@ -6,12 +6,11 @@ import strategy.crossover as crossover
import strategy.large_trans as lt import strategy.large_trans as lt
# 获取交易所交易对 # 获取交易所交易对
symbols = bn.symbols() # symbols = bn.symbols()
# for s in symbols:
for s in symbols:
# 5m # 5m
schedule.every(settings.whaleAlert_minutes).minutes.do(lt.strategy_run) # schedule.every(settings.whaleAlert_minutes).minutes.do(lt.strategy_run)
# 5m # 5m
@ -26,7 +25,11 @@ for s in symbols:
# 4h # 4h
# schedule.every(4).hours.do(crossover.strategy_run, symbol=s, interval='4h') # schedule.every(4).hours.do(crossover.strategy_run, symbol=s, interval='4h')
print(f'监控开始... ChatID: {settings.chat_id}')
# 监控
schedule.every(settings.whaleAlert_minutes).minutes.do(lt.strategy_run)
print(f'Running... ChatID: {settings.chat_id}')
while True: while True:
schedule.run_pending() schedule.run_pending()
time.sleep(1) time.sleep(1)

View File

@ -16,6 +16,6 @@ oklink_api_headers = {
#whaleAlert #whaleAlert
whaleAlert_minutes=2 whaleAlert_minutes=1
whaleAlert_apikey='gPkElMPR8Hpe5LxjKisR4YSFzxRxMLj6' whaleAlert_apikey='gPkElMPR8Hpe5LxjKisR4YSFzxRxMLj6'
whaleAlert_max_limit = os.getenv('TQ_WHALEALERT_MAX_USD_AMOUNT',1000 * 10000) whaleAlert_max_limit = os.getenv('TQ_WHALEALERT_MAX_USD_AMOUNT',1000 * 10000)

View File

@ -7,23 +7,26 @@ import tg
import traceback import traceback
import logging import logging
cursor = '0-0-0'
def strategy_run(): def strategy_run():
# 获取上一分钟的timestamp # 获取上一分钟的timestamp
last_min = datetime.now() - timedelta(minutes=settings.whaleAlert_minutes) last_min = datetime.now() - timedelta(minutes=settings.whaleAlert_minutes)
ts = time.mktime(last_min.timetuple()) ts = time.mktime(last_min.timetuple())
global cursor
url = f'https://api.whale-alert.io/v1/transactions?api_key={settings.whaleAlert_apikey}&start={int(ts)}' 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() resp = requests.get(url).json()
print(resp) print(resp)
if resp['result'] == "success":
cursor = resp['cursor']
try: try:
if 'transactions' in resp: if 'transactions' in resp:
data = resp['transactions'] data = resp['transactions']
for ts in data: for ts in data:
usd = int(ts['amount_usd']) if ts['to']['owner_type'] == 'exchange':
if ts['to']['owner_type'] == 'exchange' and usd > settings.whaleAlert_max_limit:
from_text = 'unknown wallet' from_text = 'unknown wallet'
content = f"🚨 {ts['amount']} #{ts['symbol']} ({ts['amount_usd']} USD) 从 {from_text} 转入 #{ts['to']['owner']}" content = f"🚨 {ts['amount']} #{ts['symbol']} ({ts['amount_usd']} USD) 从 {from_text} 转入 #{ts['to']['owner']}"
@ -32,3 +35,5 @@ def strategy_run():
except Exception as e: except Exception as e:
logging.error(traceback.format_exc()) logging.error(traceback.format_exc())
tg.send_message(settings.chat_id, traceback.format_exc()) tg.send_message(settings.chat_id, traceback.format_exc())
else:
print(resp['message'])