add maa and fix bug.
This commit is contained in:
parent
dbc0f96e7c
commit
6dbfa2646c
4
bn.py
4
bn.py
@ -3,8 +3,8 @@ from binance.spot import Spot
|
||||
client = Spot()
|
||||
|
||||
# Get klines
|
||||
def klines(symbol, interval):
|
||||
lines = client.klines(symbol,interval)
|
||||
def klines(symbol, interval, limit=1000):
|
||||
lines = client.klines(symbol,interval, limit=limit)
|
||||
return lines
|
||||
|
||||
# Get Symbols
|
||||
|
||||
26
main.py
26
main.py
@ -2,29 +2,21 @@ import schedule
|
||||
import bn
|
||||
import settings
|
||||
import time
|
||||
import strategy.crossover as crossover
|
||||
import strategy.ma_arrangement as maa
|
||||
import strategy.large_trans as lt
|
||||
|
||||
# 获取交易所交易对
|
||||
# symbols = bn.symbols()
|
||||
symbols = bn.symbols()
|
||||
|
||||
# for s in symbols:
|
||||
# 5m
|
||||
# schedule.every(settings.whaleAlert_minutes).minutes.do(lt.strategy_run)
|
||||
for s in symbols:
|
||||
#15m
|
||||
schedule.every(15).minutes.do(maa.strategy_run, symbol=s, interval='15m')
|
||||
|
||||
#1h
|
||||
schedule.every(1).hours.do(maa.strategy_run, symbol=s, interval='1h')
|
||||
|
||||
# 5m
|
||||
# schedule.every(5).minutes.do(crossover.strategy_run, symbol=s, interval='5m')
|
||||
|
||||
# 30m
|
||||
# schedule.every(30).minutes.do(crossover.strategy_run, symbol=s, interval='30m')
|
||||
|
||||
# 1h
|
||||
# schedule.every(1).hours.do(crossover.strategy_run, symbol=s, interval='1h')
|
||||
|
||||
# 4h
|
||||
# schedule.every(4).hours.do(crossover.strategy_run, symbol=s, interval='4h')
|
||||
|
||||
#4h
|
||||
schedule.every(4).hours.do(maa.strategy_run, symbol=s, interval='4h')
|
||||
|
||||
# 监控
|
||||
schedule.every(settings.whaleAlert_minutes).minutes.do(lt.strategy_run)
|
||||
|
||||
@ -1,59 +0,0 @@
|
||||
import talib
|
||||
import numpy as np
|
||||
import bn
|
||||
import tg
|
||||
import settings
|
||||
|
||||
# 检查是否出现多头排列信号
|
||||
def check_bullish_crossover(data):
|
||||
# 提取收盘价
|
||||
close_prices = np.array([float(entry[4]) for entry in data])
|
||||
|
||||
# 计算移动平均线
|
||||
ema7 = talib.EMA(close_prices, timeperiod=7)
|
||||
ema30 = talib.EMA(close_prices, timeperiod=30)
|
||||
ema100 = talib.EMA(close_prices, timeperiod=100)
|
||||
ema200 = talib.EMA(close_prices, timeperiod=200)
|
||||
|
||||
# 判断是否出现多头排列信号
|
||||
# if ema7[-1] > ema30[-1] > ema100[-1] > ema200[-1] and ema7[-2] <= ema30[-2] <= ema100[-2] <= ema200[-2]:
|
||||
if ema7[-1] > ema30[-1] > ema100[-1] and ema7[-2] <= ema30[-2] <= ema100[-2]:
|
||||
return True
|
||||
else:
|
||||
return False
|
||||
|
||||
# 检查是否出现空头排列信号
|
||||
def check_bearish_crossover(data):
|
||||
# 提取收盘价
|
||||
close_prices = np.array([float(entry[4]) for entry in data])
|
||||
|
||||
# 计算移动平均线
|
||||
ema7 = talib.EMA(close_prices, timeperiod=7)
|
||||
ema30 = talib.EMA(close_prices, timeperiod=30)
|
||||
ema100 = talib.EMA(close_prices, timeperiod=100)
|
||||
ema200 = talib.EMA(close_prices, timeperiod=200)
|
||||
|
||||
# 判断是否出现空头排列信号
|
||||
if ema7[-1] < ema30[-1] < ema100[-1] < ema200[-1] >= ema30[-2] >= ema100[-2]:
|
||||
# if ema7[-1] < ema30[-1] < ema100[-1] < ema200[-1] and ema7[-2] >= ema30[-2] >= ema100[-2] >= ema200[-2]:
|
||||
|
||||
return True
|
||||
else:
|
||||
return False
|
||||
|
||||
|
||||
def strategy_run(symbol, interval):
|
||||
# 获取kline数据
|
||||
data = bn.klines(symbol, interval)
|
||||
|
||||
if check_bullish_crossover(data):
|
||||
print('多头排列信号出现!')
|
||||
|
||||
text = f'${symbol} - {interval}\r\n\r\n出现【多头排列】信号'
|
||||
tg.send_message(settings.chat_id, text)
|
||||
|
||||
|
||||
if check_bearish_crossover(data):
|
||||
print("空头排列信号出现!")
|
||||
text = f'${symbol} - {interval}\r\n\r\n出现【空头排列】信号'
|
||||
tg.send_message(settings.chat_id, text)
|
||||
@ -9,6 +9,7 @@ import logging
|
||||
|
||||
|
||||
def strategy_run():
|
||||
try:
|
||||
start_time = datetime.now() - timedelta(minutes=settings.whaleAlert_minutes)
|
||||
start_ts = int(start_time.timestamp())
|
||||
|
||||
@ -19,21 +20,20 @@ def strategy_run():
|
||||
|
||||
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']}"
|
||||
content = f"🚨大额转入提醒🚨\r\n\r\n {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'])
|
||||
tg.send_message(settings.chat_id, resp['message'])
|
||||
except:
|
||||
logging.error(traceback.format_exc())
|
||||
tg.send_message(settings.chat_id, traceback.format_exc())
|
||||
39
strategy/ma_arrangement.py
Normal file
39
strategy/ma_arrangement.py
Normal file
@ -0,0 +1,39 @@
|
||||
import talib
|
||||
import numpy as np
|
||||
import bn
|
||||
import tg
|
||||
import datetime
|
||||
import settings
|
||||
|
||||
|
||||
def check_ma_arrange(data):
|
||||
# 提取收盘价
|
||||
close_prices = np.array([float(entry[4]) for entry in data])
|
||||
|
||||
# 计算移动平均线
|
||||
ema7 = talib.EMA(close_prices, timeperiod=7)
|
||||
ema30 = talib.EMA(close_prices, timeperiod=30)
|
||||
ema100 = talib.EMA(close_prices, timeperiod=100)
|
||||
ema200 = talib.EMA(close_prices, timeperiod=200)
|
||||
|
||||
bullish = ema7[-1] > ema30[-1] > ema100[-1] > ema200[-1]
|
||||
bearish = ema7[-1] < ema30[-1] < ema100[-1] < ema200[-1]
|
||||
|
||||
return bullish, bearish
|
||||
|
||||
|
||||
def strategy_run(symbol, interval):
|
||||
# 获取kline数据
|
||||
data = bn.klines(symbol, interval)
|
||||
|
||||
bullish, bearish = check_ma_arrange(data)
|
||||
|
||||
text=""
|
||||
if bullish:
|
||||
text = f'📶信号预警📶\r\n\r\n品种:【${symbol}】\r\n周期:{interval}\r\n信号:【多头】排列\r\n\r\n{datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")}'
|
||||
if bearish:
|
||||
text = f'📶信号预警📶\r\n\r\n品种:【${symbol}】\r\n周期:{interval}\r\n信号:【空头】排列\r\n\r\n{datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")}'
|
||||
|
||||
if text != "":
|
||||
print(text)
|
||||
tg.send_message(settings.chat_id, text)
|
||||
@ -1,3 +1,8 @@
|
||||
import strategy.large_trans as lt
|
||||
import bn
|
||||
import strategy.ma_arrangement as maa
|
||||
|
||||
lt.strategy_run()
|
||||
# symbols = bn.symbols()
|
||||
|
||||
# for s in symbols:
|
||||
maa.strategy_run('LINKUSDT', '15m')
|
||||
37
test.py
37
test.py
@ -4,39 +4,12 @@ import mplfinance as mpf
|
||||
import datetime as dt
|
||||
import strategy.large_trans as lt
|
||||
|
||||
# def binanceDataFrame(klines):
|
||||
# df = pd.DataFrame(klines.reshape(-1,12),dtype=float, columns = ('Open Time',
|
||||
# 'Open',
|
||||
# 'High',
|
||||
# 'Low',
|
||||
# 'Close',
|
||||
# 'Volume',
|
||||
# 'Close time',
|
||||
# 'Quote asset volume',
|
||||
# 'Number of trades',
|
||||
# 'Taker buy base asset volume',
|
||||
# 'Taker buy quote asset volume',
|
||||
# 'Ignore'))
|
||||
|
||||
# df['Open Time'] = pd.to_datetime(df['Open Time'], unit='ms')
|
||||
klines = bn.klines('BTCUSDT', '1h', limit=10)
|
||||
|
||||
# print(klines[0])
|
||||
|
||||
# return df
|
||||
# print(klines[0][0])
|
||||
dt = dt.datetime.fromtimestamp((klines[-1][0]/1000))
|
||||
|
||||
|
||||
# klines = bn.klines('BTCUSDT', '1h')
|
||||
|
||||
# df = pd.DataFrame(klines,dtype=float)
|
||||
# df.columns = ['Open time', 'Open', 'High', 'Low', 'Close', 'Volume', 'ctime', 'Quote asset volume', 'Number of trades', 'Taker buy base asset volume', 'Taker buy quote asset volume', 'Can be ignored']
|
||||
# df.index = [dt.datetime.fromtimestamp(x/1000.0) for x in df.ctime]
|
||||
# mpf.plot(df, type='line')
|
||||
|
||||
|
||||
# lt.strategy_run()
|
||||
from datetime import datetime, timedelta
|
||||
import time,settings
|
||||
|
||||
last_min = datetime.now() - timedelta(minutes=settings.whaleAlert_minutes)
|
||||
print(last_min)
|
||||
print(time.mktime(last_min.timetuple()))
|
||||
print(last_min.timestamp())
|
||||
print(dt)
|
||||
Loading…
Reference in New Issue
Block a user