first commit
This commit is contained in:
commit
4324d8657c
BIN
__pycache__/bn.cpython-310.pyc
Normal file
BIN
__pycache__/bn.cpython-310.pyc
Normal file
Binary file not shown.
BIN
__pycache__/crossover.cpython-310.pyc
Normal file
BIN
__pycache__/crossover.cpython-310.pyc
Normal file
Binary file not shown.
19
bn.py
Normal file
19
bn.py
Normal file
@ -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
|
||||||
48
crossover.py
Normal file
48
crossover.py
Normal file
@ -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("空头排列信号出现!")
|
||||||
140
gitignore
Normal file
140
gitignore
Normal file
@ -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
|
||||||
26
main.py
Normal file
26
main.py
Normal file
@ -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)
|
||||||
Loading…
Reference in New Issue
Block a user