commit 4324d8657c5dd90f547d90e3cb1ad0f848c9b486 Author: aazhou Date: Wed Jun 7 13:37:38 2023 +0800 first commit diff --git a/__pycache__/bn.cpython-310.pyc b/__pycache__/bn.cpython-310.pyc new file mode 100644 index 0000000..a8f9be4 Binary files /dev/null and b/__pycache__/bn.cpython-310.pyc differ diff --git a/__pycache__/crossover.cpython-310.pyc b/__pycache__/crossover.cpython-310.pyc new file mode 100644 index 0000000..a607b7e Binary files /dev/null and b/__pycache__/crossover.cpython-310.pyc differ diff --git a/bn.py b/bn.py new file mode 100644 index 0000000..a001ea2 --- /dev/null +++ b/bn.py @@ -0,0 +1,19 @@ +from binance.spot import Spot + +client = Spot() + + +# Get klines +def klines(symbol, interval, limit=300): + return client.klines(symbol,interval,limit=limit) + +# Get Symbols +def symbols(): + info = client.exchange_info() + + symbols = [] + for s in info['symbols']: + if s['symbol'].endswith('USDT'): + symbols.append(s['symbol']) + + return symbols diff --git a/crossover.py b/crossover.py new file mode 100644 index 0000000..986b030 --- /dev/null +++ b/crossover.py @@ -0,0 +1,48 @@ +import talib +import numpy as np +import bn + +# 检查是否出现多头排列信号 +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]: + 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] 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('多头排列信号出现!') + + if check_bearish_crossover(data): + print("空头排列信号出现!") diff --git a/gitignore b/gitignore new file mode 100644 index 0000000..d403580 --- /dev/null +++ b/gitignore @@ -0,0 +1,140 @@ +# Byte-compiled / optimized / DLL files +__pycache__/ +*.py[cod] +*$py.class + +# C extensions +*.so + +# Distribution / packaging +.Python +build/ +develop-eggs/ +dist/ +downloads/ +eggs/ +.eggs/ +lib/ +lib64/ +parts/ +sdist/ +var/ +wheels/ +share/python-wheels/ +*.egg-info/ +.installed.cfg +*.egg +MANIFEST + +# PyInstaller +# Usually these files are written by a python script from a template +# before PyInstaller builds the exe, so as to inject date/other infos into it. +*.manifest +*.spec + +# Installer logs +pip-log.txt +pip-delete-this-directory.txt + +# Unit test / coverage reports +htmlcov/ +.tox/ +.nox/ +.coverage +.coverage.* +.cache +nosetests.xml +coverage.xml +*.cover +*.py,cover +.hypothesis/ +.pytest_cache/ +cover/ + +# Translations +*.mo +*.pot + +# Django stuff: +*.log +local_settings.py +db.sqlite3 +db.sqlite3-journal + +# Flask stuff: +instance/ +.webassets-cache + +# Scrapy stuff: +.scrapy + +# Sphinx documentation +docs/_build/ + +# PyBuilder +.pybuilder/ +target/ + +# Jupyter Notebook +.ipynb_checkpoints + +# IPython +profile_default/ +ipython_config.py + +# pyenv +# For a library or package, you might want to ignore these files since the code is +# intended to run in multiple environments; otherwise, check them in: +# .python-version + +# pipenv +# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. +# However, in case of collaboration, if having platform-specific dependencies or dependencies +# having no cross-platform support, pipenv may install dependencies that don't work, or not +# install all needed dependencies. +#Pipfile.lock + +# PEP 582; used by e.g. github.com/David-OConnor/pyflow +__pypackages__/ + +# Celery stuff +celerybeat-schedule +celerybeat.pid + +# SageMath parsed files +*.sage.py + +# Environments +.env +.venv +env/ +venv/ +ENV/ +env.bak/ +venv.bak/ + +# Spyder project settings +.spyderproject +.spyproject + +# Rope project settings +.ropeproject + +# mkdocs documentation +/site + +# mypy +.mypy_cache/ +.dmypy.json +dmypy.json + +# Pyre type checker +.pyre/ + +# pytype static type analyzer +.pytype/ + +# Cython debug symbols +cython_debug/ + +# End of https://mrkandreev.name/snippets/gitignore-generator/#Python \ No newline at end of file diff --git a/main.py b/main.py new file mode 100644 index 0000000..4a37515 --- /dev/null +++ b/main.py @@ -0,0 +1,26 @@ +import schedule +import bn +import time +import crossover + +# 获取交易所交易对 +symbols = bn.symbols() + + +for s in symbols: + # 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') + +print('监控开始...') +while True: + schedule.run_pending() + time.sleep(1) \ No newline at end of file