1
This commit is contained in:
parent
736f3bf59b
commit
9e8bb4387c
19
main.py
19
main.py
@ -5,14 +5,7 @@ import telegram_sender,setting
|
||||
import dingding
|
||||
import monitors.move as move
|
||||
|
||||
from monitors import vegas, vegas_cross
|
||||
|
||||
#move
|
||||
# schedule.every().hour.at(":00").do(move.run_crypto, interval = '30m')
|
||||
# schedule.every().hour.at(":30").do(move.run_crypto, interval = '30m')
|
||||
|
||||
# schedule.every().hour.at(":00").do(move.run_crypto, interval = '1h')
|
||||
# schedule.every().hour.at(":00").do(move.run_crypto, interval = '4h')
|
||||
from monitors import vegas, vegas_cross, macd_boll
|
||||
|
||||
#vegas
|
||||
schedule.every().hour.at(":00").do(vegas.run_crypto, interval = '1h')
|
||||
@ -26,7 +19,15 @@ times = ["00:00", "04:00", "08:00", "12:00", "16:00", "20:00"]
|
||||
for t in times:
|
||||
schedule.every().day.at(t).do(vegas_cross.run_crypto, interval = '4h')
|
||||
|
||||
version = 'V1.12'
|
||||
#macd_boll
|
||||
schedule.every().hour.at(":00").do(macd_boll.run_crypto, interval = '15m')
|
||||
schedule.every().hour.at(":15").do(macd_boll.run_crypto, interval = '15m')
|
||||
schedule.every().hour.at(":30").do(macd_boll.run_crypto, interval = '15m')
|
||||
schedule.every().hour.at(":45").do(macd_boll.run_crypto, interval = '15m')
|
||||
|
||||
schedule.every().hour.at(":00").do(macd_boll.run_crypto, interval = '1h')
|
||||
|
||||
version = 'V1.13'
|
||||
print(f'Running... {version}')
|
||||
while True:
|
||||
schedule.run_pending()
|
||||
|
||||
79
monitors/macd_boll.py
Normal file
79
monitors/macd_boll.py
Normal file
@ -0,0 +1,79 @@
|
||||
import talib
|
||||
import numpy as np
|
||||
import time,setting
|
||||
import telegram_sender
|
||||
from datasource import crypto
|
||||
import dingding
|
||||
import discord_sender
|
||||
|
||||
|
||||
# crossover 函数:检测上穿信号
|
||||
def crossover(series1, series2):
|
||||
return (series1 > series2) & (series1.shift(1) <= series2.shift(1))
|
||||
|
||||
# crossunder 函数:检测下穿信号
|
||||
def crossunder(series1, series2):
|
||||
return (series1 < series2) & (series1.shift(1) >= series2.shift(1))
|
||||
|
||||
## 检查信号
|
||||
def stratergy_run(symbol, interval, df, debug):
|
||||
|
||||
macd_fast_length = 12
|
||||
macd_slow_length = 26
|
||||
macd_signal_length = 9
|
||||
bollinger_length = 20
|
||||
bollinger_mult = 2.0
|
||||
|
||||
|
||||
# 计算 MACD
|
||||
macd, macd_signal, macd_hist = talib.MACD(df['close'], fastperiod=macd_fast_length, slowperiod=macd_slow_length, signalperiod=macd_signal_length)
|
||||
|
||||
# 计算布林带
|
||||
upperband, middleband, lowerband = talib.BBANDS(df['close'], timeperiod=bollinger_length, nbdevup=bollinger_mult, nbdevdn=bollinger_mult, matype=0)
|
||||
|
||||
# MACD 上穿和下穿 0 轴的逻辑
|
||||
macd_bullish_cross = (macd.shift(1) <= 0) & (macd > 0) # 上穿0轴
|
||||
macd_bearish_cross = (macd.shift(1) >= 0) & (macd < 0) # 下穿0轴
|
||||
|
||||
|
||||
# 生成交易信号
|
||||
long_condition = macd_bullish_cross & (df['high'] < upperband)
|
||||
short_condition = macd_bearish_cross & (df['low'] > lowerband)
|
||||
|
||||
# 将信号添加到 DataFrame
|
||||
df['Long_Signal'] = long_condition
|
||||
df['Short_Signal'] = short_condition
|
||||
|
||||
latest = df.iloc[-1]
|
||||
|
||||
direction = ""
|
||||
if latest['Short_Signal'] == True:
|
||||
direction = '空'
|
||||
if latest['Long_Signal'] == True:
|
||||
direction = '多'
|
||||
print(df)
|
||||
print(f"【{symbol} - {interval}】 is checked!")
|
||||
if direction != "":
|
||||
message = f"策略:【MACD+BOLL策略】\r\n"
|
||||
message += f"品种: {symbol}\r\n"
|
||||
message += f"周期: {interval}\r\n"
|
||||
message += f"信号: 【{direction}】\r\n"
|
||||
message += f"收盘价: {latest['close']}\r\n"
|
||||
|
||||
if debug == False:
|
||||
url = 'https://discordapp.com/api/webhooks/1286585288986198048/iQ-yr26ViW45GM48ql8rPu70Iumqcmn_XXAmxAcKGeiQBmTQoDPeq-TmlChvIHkw_HJ-'
|
||||
discord_sender.send_message(url,'🦄信号提醒🦄',message)
|
||||
|
||||
print(f"【{symbol} - {interval}】 is singal fired!")
|
||||
else:
|
||||
print(message)
|
||||
|
||||
|
||||
def run_crypto(interval, debug=False):
|
||||
print('Vegas策略运行.')
|
||||
|
||||
for s in setting.symbols:
|
||||
df = crypto.get_klines(s, interval)
|
||||
stratergy_run(s,interval, df, debug)
|
||||
|
||||
time.sleep(1)
|
||||
6
test.py
6
test.py
@ -6,10 +6,12 @@ import discord_sender
|
||||
from binance.cm_futures import CMFutures
|
||||
from monitors import vegas_cross
|
||||
from datasource import crypto
|
||||
from monitors import macd_boll
|
||||
|
||||
macd_boll.run_crypto('1h', debug=True)
|
||||
|
||||
|
||||
|
||||
print(crypto._get_top_coins_by_market_cap(20))
|
||||
# print(crypto._get_top_coins_by_market_cap(20))
|
||||
# vegas_cross.run_crypto('1h')
|
||||
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user