From 9d309a38d22d26aaff18d81d2085f0e4d281eca7 Mon Sep 17 00:00:00 2001 From: aaron <> Date: Wed, 18 Sep 2024 17:51:12 +0800 Subject: [PATCH] 11 --- discord_sender.py | 14 ++++++-------- monitors/move.py | 5 ++++- requirements.txt | 3 ++- test.py | 35 ++++++++--------------------------- 4 files changed, 20 insertions(+), 37 deletions(-) diff --git a/discord_sender.py b/discord_sender.py index 02e3cfa..a790ceb 100644 --- a/discord_sender.py +++ b/discord_sender.py @@ -1,12 +1,10 @@ -import requests +from discord_webhook import DiscordWebhook, DiscordEmbed +def send_message(url,title,content): + webhook = DiscordWebhook(url) -mUrl = "https://discordapp.com/api/webhooks/1285867836454998077/JNAFUyur_ygOJIh6C4beUAVYMpm1TZf4IEeMn8Q1p0TglO1Hjyiu2LQqiU5AxVovWyiO" + embed = DiscordEmbed(title=title, description=content, color="03b2f8") -def send_message(content): - data = {"content": content} - response = requests.post(mUrl, json=data) + webhook.add_embed(embed) - print(response.status_code) - - print(response.content) \ No newline at end of file + response = webhook.execute() \ No newline at end of file diff --git a/monitors/move.py b/monitors/move.py index b66c7f5..4391915 100644 --- a/monitors/move.py +++ b/monitors/move.py @@ -57,7 +57,10 @@ def stratergy_run(symbol, interval, df, debug): message += f"收盘价: {d1['close']}\r\n" dingding.send_message(message, isAtAll=True) telegram_sender.send_message(setting.chat_id, message) - discord_sender.send_message(message) + + + url = 'https://discordapp.com/api/webhooks/1285867836454998077/JNAFUyur_ygOJIh6C4beUAVYMpm1TZf4IEeMn8Q1p0TglO1Hjyiu2LQqiU5AxVovWyiO' + discord_sender.send_message(url,'信号提醒',message) def run_crypto(interval, debug=False): diff --git a/requirements.txt b/requirements.txt index 7f1619b..69c182f 100644 --- a/requirements.txt +++ b/requirements.txt @@ -5,4 +5,5 @@ pandas requests schedule TA_Lib -tweepy \ No newline at end of file +tweepy +discord_webhook \ No newline at end of file diff --git a/test.py b/test.py index 5650632..a8bbd86 100644 --- a/test.py +++ b/test.py @@ -3,37 +3,18 @@ from monitors import move from datasource import crypto import talib import discord_sender - -# # move.run_crypto('5m') - -# df = crypto.get_klines('PEOPLEUSDT', '5m') +from binance.cm_futures import CMFutures -# ## 计算 ema -# df['ema5'] = talib.EMA(df['close'], timeperiod=5) -# df['ema10'] = talib.EMA(df['close'], timeperiod=10) -# df['ema30'] = talib.EMA(df['close'], timeperiod=30) -# df['ema144'] = talib.EMA(df['close'], timeperiod=144) +client = CMFutures() +data = client.funding_rate('BTCUSD_PERP', limit=1) -# df['shortDiff'] = abs(df['ema5'] - df['ema10']) / df['ema10'] -# df['midDiff'] = abs(df['ema10'] - df['ema30']) / df['ema30'] -# df['longDiff'] = abs(df['ema30'] - df['ema144']) / df['ema144'] +fundingRate = float(data[0]['fundingRate']) * 100 -# df['isLongArrangement'] = ((df['ema5'] > df['ema10']) & (df['ema10'] > df['ema30']) & (df['ema30'] > df['ema144'])) -# df['isShortArrangement'] = ((df['ema5'] < df['ema10']) & (df['ema10'] < df['ema30']) & (df['ema30'] < df['ema144'])) - -# d1 = df.iloc[-1] -# d2 = df.iloc[-2] -# d3 = df.iloc[-3] - -# isBear = d1['isShortArrangement'] == True and d2['isShortArrangement'] == True and d3['isShortArrangement'] == False -# maxDiff = max(d1['shortDiff'], d1['midDiff'], d1['longDiff']) -# minDiff = min(d1['shortDiff'], d1['midDiff'], d1['longDiff']) -# isOffset = maxDiff / minDiff < 3 - -# print(df) -# print(isOffset) +text = f"币种: {data[0]['symbol']}\r\n资金费率: {fundingRate} %" -discord_sender.send_message('https://www.youtube.com/watch?v=_yI5SYTMo0U') +mUrl = "https://discordapp.com/api/webhooks/1285898004641091605/DwIh9yZvrU6TwelVmJr96XBdpFTEEpeFD8GsZpH7rBdwT4UwVyZTrtdmBzS4ae0Ta7PH" + +discord_sender.send_message(mUrl, '消息内容',text)