Skip to content

Commit 9534767

Browse files
committed
Merge branch 'master' of https://github.com/sngyai/Sequoia into master
2 parents 8940808 + c14ae12 commit 9534767

6 files changed

Lines changed: 104 additions & 7 deletions

File tree

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,5 @@
88
.DS_Store
99
storage/Positions
1010
config.yaml
11+
12+
logs/*

README.md

Lines changed: 75 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,78 @@
77
各策略中的`end_date`参数主要用于回测。
88

99
## 准备工作:
10+
### 环境&依赖管理
11+
推荐使用 Miniconda来进行 Python 环境管理 [Miniconda — conda documentation](https://docs.conda.io/en/latest/miniconda.html)
12+
13+
安装 conda 后,切换到项目专属环境进行配置,例如:
14+
```
15+
conda create -n sequoia39 python=3.9
16+
conda activate sequoia39
17+
```
18+
1019
### 根据不同的平台安装TA-Lib程序
1120

12-
* Mac OS X
21+
* Mac OS X (x86_64)
22+
23+
```
24+
$ brew install ta-lib
25+
# conda 环境下 可直接执行
26+
$ conda install -c conda-forge ta-lib
27+
```
1328
29+
* Mac OS X (arm64)
30+
31+
需要特殊说明的是
32+
M1 芯片的 Mac OS 很多库和依赖都需要基于 arm64 来构建。
33+
所以,这里首先需要确认安装的 homebrew 是 arm 版本,如果之前安装的 homebrew 是 x86 版本,推荐重装 homebrew。
34+
1. 删除老版本 homebrew (如果之前安装的是 x86版本 homebrew,重装前需要删除)
1435
```
15-
$ brew install ta-lib
36+
sudo rm -rf /usr/local/.git
37+
rm -rf ~/Library/Caches/Homebrew
38+
rm -rf /usr/local/Homebrew
39+
```
40+
41+
2. 安装/重装 arm64 版本 homebrew
42+
```
43+
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
44+
```
45+
46+
3. homebrew 初始化
47+
```
48+
vim ~/.zshrc
49+
50+
# 加入到系统环境变量
51+
export PATH=/opt/homebrew/bin:$PATH
52+
53+
source ~/.zshrc
54+
# 确认版本信息
55+
brew config
56+
```
57+
4. 过程中遇到问题的参考解决办法
58+
- [macos - zsh problem: compinit:503: no such file or directory: /usr/local/share/zsh/site-functions/_brew - Stack Overflow](https://stackoverflow.com/questions/65747286/zsh-problem-compinit503-no-such-file-or-directory-usr-local-share-zsh-site)
59+
- [The required file "libmini_racer.dylib" can't be found in mac M1 · Issue #143 · sqreen/PyMiniRacer](https://github.com/sqreen/PyMiniRacer/issues/143)
60+
- [Installing python tables on mac with m1 chip - Stack Overflow](https://stackoverflow.com/questions/65839750/installing-python-tables-on-mac-with-m1-chip)
61+
62+
5. 经过以上步骤后,可以开始继续安装 `ta-lib` 了。 参考
63+
- [TA-Lib · PyPI](https://pypi.org/project/TA-Lib/)
64+
- [说说 talib(ta-lib) 这个技术指标库,各系统怎么最轻松安装 ta-lib - 知乎](https://zhuanlan.zhihu.com/p/546720500)
65+
66+
以下是完整的操作命令示例:
67+
68+
```
69+
# 操作示例
70+
# 1. 创建专属 python 环境
71+
conda create -n sequoia39 python=3.9
72+
conda activate sequoia39
73+
74+
# 2. 安装 ta-lib 库
75+
arch -arm64 brew install ta-lib
76+
export TA_INCLUDE_PATH="$(brew --prefix ta-lib)/include"
77+
export TA_LIBRARY_PATH="$(brew --prefix ta-lib)/lib"
78+
python3.9 -m pip install --no-cache-dir ta-lib
79+
80+
# 3. 验证是否安装成功
81+
python -c "import talib; print(talib.__version__)"
1682
```
1783
1884
* Windows
@@ -35,7 +101,11 @@
35101
```
36102
pip install -r requirements.txt
37103
```
38-
104+
### 更新akshare数据接口
105+
本项目已切换至akshare数据接口,该项目更新频率较高,使用前建议检查接口更新
106+
```
107+
pip install akshare --upgrade
108+
```
39109
### 生成配置文件
40110
41111
```
@@ -46,7 +116,8 @@ cp config.yaml.example config.yaml
46116
```
47117
$ python main.py
48118
```
49-
运行结果查看日志文件[sequoia.log](sequoia.log)
119+
运行结果查看 logs 目录下生成的日志文件 格式为 `logs/sequoia-$YEAR-$MONTH-$DAY-$HOUR-$MINUTE-$SECOND.log`
120+
如:`logs/sequoia-2023-03-03-20-47-56.log`
50121
51122
### 服务器端运行
52123
#### 定时任务

main.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,17 @@
66
import settings
77
import schedule
88
import time
9+
import datetime
910

1011

1112
def job():
1213
if utils.is_weekday():
1314
work_flow.prepare()
1415

1516

16-
logging.basicConfig(format='%(asctime)s %(message)s', filename='sequoia.log')
17+
current_time = datetime.datetime.now().strftime("%Y-%m-%d-%H-%M-%S")
18+
log_filename = 'logs/sequoia-{}.log'.format(current_time)
19+
logging.basicConfig(format='%(asctime)s %(message)s', filename=log_filename)
1720
logging.getLogger().setLevel(logging.INFO)
1821
settings.init()
1922

requirements.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
PyYAML==5.4
2-
requests==2.24.0
2+
requests==2.31.0
33
pandas==1.5.2
44
numpy==1.23.5
55
xlrd==1.2.0
66
TA-Lib==0.4.25
77
tables==3.7.0
8+
# install schedule 可能遇到的问题及 fix 见:https://github.com/sngyai/Sequoia/issues/26
89
schedule==0.6.0
910
wxpusher==2.2.0
1011
pytest==7.2.0

tests/local_test.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# !/usr/bin/env python
2+
# -*-coding:utf-8 -*-
3+
4+
"""
5+
# File : local_test
6+
# Time :2023/3/3 20:40
7+
# Author :qunzhong
8+
# version :python 3.8
9+
# Description:
10+
"""
11+
import datetime
12+
13+
if __name__ == '__main__':
14+
# just for local test
15+
current_time = datetime.datetime.now().strftime("%Y-%m-%d-%H-%M-%S")
16+
log_filename = 'sequoia-{}.log'.format(current_time)
17+
print(log_filename)

tests/test_push.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
from push import strategy
66
from push import statistics
77
import logging
8+
import datetime
89

910

1011
def test_push():
@@ -18,5 +19,7 @@ def test_strategy():
1819
strategy("1")
1920

2021

21-
logging.basicConfig(format='%(asctime)s %(message)s', filename='../sequoia.log')
22+
current_time = datetime.datetime.now().strftime("%Y-%m-%d-%H-%M-%S")
23+
log_filename = 'logs/test-push-{}.log'.format(current_time)
24+
logging.basicConfig(format='%(asctime)s %(message)s', filename=log_filename)
2225
logging.getLogger().setLevel(logging.INFO)

0 commit comments

Comments
 (0)