From 4324d8657c5dd90f547d90e3cb1ad0f848c9b486 Mon Sep 17 00:00:00 2001 From: aazhou Date: Wed, 7 Jun 2023 13:37:38 +0800 Subject: [PATCH] first commit --- __pycache__/bn.cpython-310.pyc | Bin 0 -> 588 bytes __pycache__/crossover.cpython-310.pyc | Bin 0 -> 1620 bytes bn.py | 19 ++++ crossover.py | 48 +++++++++ gitignore | 140 ++++++++++++++++++++++++++ main.py | 26 +++++ 6 files changed, 233 insertions(+) create mode 100644 __pycache__/bn.cpython-310.pyc create mode 100644 __pycache__/crossover.cpython-310.pyc create mode 100644 bn.py create mode 100644 crossover.py create mode 100644 gitignore create mode 100644 main.py diff --git a/__pycache__/bn.cpython-310.pyc b/__pycache__/bn.cpython-310.pyc new file mode 100644 index 0000000000000000000000000000000000000000..a8f9be4f826628e8727301fb345f4eb0d6c77186 GIT binary patch literal 588 zcmY*W%}(Pm5T0?|G;~|kD?9;_7II&$Rx54Ky%a8y5K3cHyrfRB4ZBFGSZTTP4(*Xw z@|6>>z=?4x5KJ^*JU<@KH&c&B10XTeJ8^>mPr>*o5g9*8?E!%RffXzK~3N1`XThE3jb~R{`nDMFaZ=1I!Jeu>9+2lCoCJZDW$-m`A zp%?N@>GRqrQVaV>xeFf`O+yAz=OJRgP_{?g@!djLWakbcyGxKDXG7ejkNxAUi_ut3 zV3YRp;aurLm-5Kcj!dB5wa~HeazE4#Q#IiMpL}1|;<}PQXs2Kkf+56gz=!-5?!b1k literal 0 HcmV?d00001 diff --git a/__pycache__/crossover.cpython-310.pyc b/__pycache__/crossover.cpython-310.pyc new file mode 100644 index 0000000000000000000000000000000000000000..a607b7ea9323f8963c863b449b1378e7e0e15c58 GIT binary patch literal 1620 zcmc&!&1(}u6rYcsWQ}RHT0iO+h!=y}L@ju!MNxawUQ$7}NZ9VIHD`wMo0&JWZ{BZS(9@G5P(Gc# zA+IF}d5>gyVL(nm4Tk_Ek<=qrr==FtoLgKn$!`(MkcJe{3Ym~eXcLm=Nyco0B^h%l zHr)az5d-QesNozyM4nMeCA&rH}XA&3Kn3G&8y^shOxV zX%3J&M>Gg0B|{yr8!MPV2ICVxr$nyL6R=sQZ2+|mRTsc!ITOfAR87cKo^-6xGLv5E z8eW)ynuofu9bgJvx@dws1e_rQ;M_xYmE}p3w($y@G!~bbhLsx}a+g5>}J?)02D5zweK)TsT*|O+Q9lBbz{V40GAPj?PR}EHbacbBrhLIDL zDy^V$*Kp_mkUcK!(QOnUN|ziWY z!aIcTP}<)B#z&h*%=}6$Y^Cg4EF#-0PFnoTxs%OAY)Ct@t+e9>p@?MHxjvM^oSA(+eCRaOQ>OYE( ztPmZtj_Al5q7y4bhpZzy@h_rN7;VK7P=^Wwx#~_;8pZ~2ya!-W7p|@Ts0-DLW*ZPT zBJ?3_LfDMZ4=_HewqRc$fGYk)FjpV74VUdg*bU&I3qK2bvY0DIfnctv!((dbtWamO zRBed3q_dO~-+&&BP!bt>W;bw-T*8ZlzVWl45o1-9NbC8N*7H~M_aC+HJpS;u(R%Q@ zb$jmP{TH9#+^p_}`T3WP`KNc+T7|oOY|j0~E^DmHh?q_KaiZiEeK*wNjRm|GNCtQ# z86GFXT6r??ViU$(HEnxp2TZJrY@7}uFGTKCt)Qy@epnD 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