-
-
Notifications
You must be signed in to change notification settings - Fork 79
428 lines (388 loc) · 17.7 KB
/
w9-workflow-download-data.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
# """
# The MIT License (MIT)
# Copyright (c) 2023 pkjmesra
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
# """
name: 9. After-Market Data Gen
on:
workflow_dispatch:
inputs:
name:
description: 'Run Details'
required: false
default: 'After-Market Data Gen'
targetPythonVersion:
description: 'Target Python version: 3.9 , 3.10, 3.11 ?'
required: false
type: string
default: '3.11'
runson:
description: 'Runner OS. e.g: ubuntu-20.04, windows-latest or macos-latest'
required: false
default: 'ubuntu-20.04'
installtalib:
description: 'Is TA-Lib install required? (Y/N). N to skip installing talib.'
required: false
default: 'Y'
skipDownload:
description: 'Skip pkl download for 1y. Leave empty to NOT skip download. Y to skip download'
required: false
default: ''
cleanuphistoricalscans:
description: 'Clean up historical scans? Leave empty to run historical scans. Y to run clean up'
required: false
default: 'N'
scanOptions:
description: 'Scan options for historical scans. cleanuphistoricalscans MUST to be left empty to run historical scans.'
required: false
default: '--reScanForZeroSize --scanDaysInPast 3 -s2 42,0,21,22,29,M,Z -s1 W,N,E,M,Z,S,0,2,3,4,6,7,9,10,13,14,15 -s0 S,T,E,U,Z,F,H,Y,B,G,C,M,D,I,L,P -s3 "0" -s4 "0" --branchname actions-data-download --scans --triggerRemotely -f'
schedule:
- cron: '58 9 * * 0-6'
run-name: ${{ inputs.name || 'After-Market Data Gen'}}
jobs:
Download_Stock_Data:
runs-on: ${{ inputs.runson || 'ubuntu-20.04'}} #ubuntu-20.04 #windows-latest
permissions: write-all
# actions: write
outputs:
should_clean: ${{ inputs.scanOptions }}
steps:
- uses: actions/checkout@v4
with:
ref: actions-data-download
# - name: Take pull from main
# shell: bash
# run: |
# git config user.name github-actions >/dev/null 2>&1
# git config user.email [email protected] >/dev/null 2>&1
# git config remote.origin.fetch '+refs/heads/*:refs/remotes/origin/*' >/dev/null 2>&1
# git remote update >/dev/null 2>&1
# git fetch >/dev/null 2>&1
# git config pull.rebase false >/dev/null 2>&1
# git pull origin main
# git push -v -u origin +actions-data-download >/dev/null 2>&1
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: ${{ inputs.targetPythonVersion || 3.11 }}
- name: Restore Dependencies from Windows Cache
if: startsWith(runner.os, 'Windows')
uses: actions/cache@v4
continue-on-error: true
with:
path: ~\AppData\Local\pip\Cache
key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt') }}
restore-keys: |
${{ runner.os }}-pip-
- name: Load Cache for Linux Dependencies
uses: actions/cache@v4
continue-on-error: true
if: startsWith(runner.os, 'Linux')
with:
path: |
/usr/include/ta-lib
/usr/bin/ta-lib-config
/usr/lib/libta_lib.la
/usr/lib/libta_lib.a
key: ${{ runner.os }}-talib
restore-keys: |
${{ runner.os }}-talib
- name: Install TA-Lib for Windows
if: ${{ inputs.installtalib != 'N' && inputs.skipDownload == '' && startsWith(runner.os, 'Windows') }}
shell: bash
run: |
python3 -m pip install --upgrade pip
cd .github/dependencies/
if [[ "${{ inputs.targetPythonVersion }}" == "" ]] ;then
pip3 install TA_Lib-0.4.29-cp311-cp311-win_amd64.whl
elif [[ "${{ inputs.targetPythonVersion }}" == "3.9" ]] ;then
pip3 install TA_Lib-0.4.19-cp39-cp39-win_amd64.whl
elif [[ "${{ inputs.targetPythonVersion }}" == "3.11" ]] ;then
pip3 install TA_Lib-0.4.29-cp311-cp311-win_amd64.whl
elif [[ "${{ inputs.targetPythonVersion }}" == "3.12" ]] ;then
pip3 install TA_Lib-0.4.29-cp312-cp312-win_amd64.whl
fi
- name: Install TA-Lib for Linux
if: ${{ inputs.installtalib != 'N' && inputs.skipDownload == '' && startsWith(runner.os, 'Linux') }}
run: |
cd .github/dependencies/
pwd
tar -xzf ta-lib-0.4.0-src.tar.gz
cd ta-lib/
./configure --prefix=/usr
make
sudo make install
cd /home/runner/work/PKScreener/PKScreener/
pip3 install ta-lib==0.4.32
- name: Environment setup to get latest EXE
if: ${{ inputs.skipDownload == '' }}
shell: bash
id: releaseurlsetter
run: |
pip3 install requests
python3 .github/workflows/githubutilities.py -d
- name: Download latest executable on Windows
shell: cmd
if: ${{ inputs.skipDownload == '' && startsWith(runner.os, 'Windows' ) }}
env:
exe_path: ${{ steps.releaseurlsetter.outputs.DOWNLOAD_URL }}
run: |
curl -o pkscreenercli.exe -JL %exe_path%
- name: Download latest executable on Ubuntu
shell: bash
if: ${{ inputs.skipDownload == '' && startsWith(runner.os, 'Linux' ) }}
env:
exe_path: ${{ steps.releaseurlsetter.outputs.DOWNLOAD_URL }}
run: |
curl -o /home/runner/work/PKScreener/PKScreener/pkscreenercli.bin -JL $exe_path
chmod +x /home/runner/work/PKScreener/PKScreener/pkscreenercli.bin
- name: Delete stock data
shell: bash
continue-on-error: true
if: ${{ inputs.skipDownload == '' && startsWith(runner.os, 'Linux' ) }}
run: |
rm -rf actions-data-download/*stock_data_*.pkl || true
rm -rf actions-data-download/*DB.pkl || true
- name: Delete results stock data
shell: bash
continue-on-error: true
if: ${{ inputs.skipDownload == '' && startsWith(runner.os, 'Linux' ) }}
run: |
rm -rf results/Data/*stock_data_*.pkl || true
rm -rf results/Data/*DB.pkl || true
- name: Remove deleted file from git
shell: bash
continue-on-error: true
if: ${{ inputs.skipDownload == '' && startsWith(runner.os, 'Linux' ) }}
run: |
git ls-files --deleted -z | xargs -0 git rm
- name: Download 52 week Stock Data on Ubuntu
shell: bash
continue-on-error: true
if: ${{ inputs.skipDownload == '' && startsWith(runner.os, 'Linux' ) }}
run: |
/home/runner/work/PKScreener/PKScreener/pkscreenercli.bin -d -a Y
/home/runner/work/PKScreener/PKScreener/pkscreenercli.bin -d -a Y -i 1m
rm -rf results//Data/*.lck || true
ls -l results/Data
cp results/Data/*.pkl actions-data-download
ls -l actions-data-download
git status
- name: Download 52 week Stock Data on Windows
continue-on-error: true
if: ${{ inputs.skipDownload == '' && startsWith(runner.os, 'Windows' ) }}
shell: cmd
id: downloader
run: |
rmdir /s /q actions-data-download
mkdir actions-data-download
rmdir /s /q results
mkdir results
pkscreenercli.exe -d -a Y
env:
GITHUB_TOKEN : ${{secrets.GITHUB_TOKEN}}
- name: Download Intraday Stock Data on Windows
continue-on-error: true
if: ${{ inputs.skipDownload == '' && startsWith(runner.os, 'Windows' ) }}
shell: cmd
id: intradaydownloader
run: |
pkscreenercli.exe -d -a Y -i 1m
env:
GITHUB_TOKEN : ${{secrets.GITHUB_TOKEN}}
- name: Copy Stock Data Pickles on Windows
continue-on-error: true
if: ${{ inputs.skipDownload == '' && startsWith(runner.os, 'Windows' ) }}
shell: cmd
run: |
copy results\*DB.pkl actions-data-download
copy results\stock_data_*.pkl actions-data-download
- name: Push Pickle Data for stock data
if: ${{ inputs.skipDownload == '' }}
continue-on-error: true
shell: bash
run: |
git config user.name github-actions
git config user.email [email protected]
git config remote.origin.fetch "+refs/heads/*:refs/remotes/origin/*"
git remote update
git fetch
git add actions-data-download/*.pkl --force
git add results/Data/*.pkl --force
git add results/Indices/*.csv --force
git add results/Indices/*.csv -u
git add results/Data/*.pkl -u
git add actions-data-download/*.pkl -u
git commit -m "GitHub-Action-Workflow-Market-Data-Download-(Default-Config)"
git push -v -u origin +actions-data-download
env:
GITHUB_TOKEN : ${{secrets.GITHUB_TOKEN}}
- name: Squash Commits (Python)
if: ${{ inputs.skipDownload == '' }}
shell: bash
continue-on-error: true
run: |
git config user.name github-actions
git config user.email [email protected]
git fetch
python3 .github/workflows/squash.py -b actions-data-download -m "GitHub-Action-Workflow-Market-Data-Download-(Default-Config)"
env:
GITHUB_TOKEN : ${{secrets.GITHUB_TOKEN}}
- name: Install Python Dependencies for clean up
if: ${{ inputs.cleanuphistoricalscans == 'Y' || inputs.skipDownload == '' }}
continue-on-error: true
run: |
pip3 install --upgrade pip
pip3 install -r requirements.txt
pip3 install .
- name: Configure env.dev file
run: |
python3 -c "import os; file = open('.env.dev', 'w'); file.write('CHAT_ID='+os.environ['CHAT_ID_PROD']+'\n'); file.write('TOKEN='+os.environ['TOKEN_DEV']+'\n'); file.write('chat_idADMIN='+os.environ['CHAT_IDADMIN_DEV']+'\n'); file.close()"
python3 -c "import os; file = open('pkscreener/.env.dev', 'w'); file.write('CHAT_ID='+os.environ['CHAT_ID_PROD']+'\n'); file.write('TOKEN='+os.environ['TOKEN_DEV']+'\n'); file.write('chat_idADMIN='+os.environ['CHAT_IDADMIN_DEV']+'\n'); file.close()"
shell: bash
env:
CHAT_ID_PROD : ${{secrets.CHAT_ID_PROD}}
TOKEN_DEV : ${{secrets.TOKEN_DEV}}
CHAT_IDADMIN_DEV : ${{secrets.CHAT_IDADMIN_DEV}}
- name: Trigger miscellaneous tasks that are download-data dependent
if: ${{ inputs.skipDownload == '' }}
shell: bash
continue-on-error: true
run: |
python3 .github/workflows/workflowtriggers.py -f --misc
env:
GITHUB_TOKEN : ${{secrets.GITHUB_TOKEN}}
- name: Clean up old historical scan results
shell: bash
if: ${{ inputs.cleanuphistoricalscans == 'Y' }}
continue-on-error: true
env:
RUNNER : "LOCAL_RUN_SCANNER"
GITHUB_TOKEN : ${{secrets.GITHUB_TOKEN}}
run: |
python3 .github/workflows/workflowtriggers.py -f --cleanuphistoricalscans --scanDaysInPast 450 -s0 S,T,E,U,Z,F,H,Y,G,M,D,I,L -s1 "" -s2 "" -s3 "" -s4 "" --branchname actions-data-download
- name: Setup Python environment for triggers on Ubuntu
shell: bash
if: ${{ inputs.cleanuphistoricalscans != 'Y' && startsWith(runner.os, 'Linux') }}
continue-on-error: true
run: |
cd .github/dependencies/
pwd
tar -xzf ta-lib-0.4.0-src.tar.gz
cd ta-lib/
./configure --prefix=/usr
make
sudo make install
cd /home/runner/work/PKScreener/PKScreener/
python3 -m pip install --upgrade pip
pip3 install -r requirements.txt
pip3 install -r requirements-dev.txt
pip3 install ta-lib==0.4.32
pip3 install .
- name: Setup Python environment for triggers on Windows
continue-on-error: true
if: ${{ inputs.cleanuphistoricalscans != 'Y' && startsWith(runner.os, 'Windows') }}
shell: bash
run: |
cd .github/dependencies/
if [[ "${{ inputs.targetPythonVersion }}" == "" ]] ;then
pip3 install TA_Lib-0.4.29-cp311-cp311-win_amd64.whl
elif [[ "${{ inputs.targetPythonVersion }}" == "3.9" ]] ;then
pip3 install TA_Lib-0.4.19-cp39-cp39-win_amd64.whl
elif [[ "${{ inputs.targetPythonVersion }}" == "3.11" ]] ;then
pip3 install TA_Lib-0.4.29-cp311-cp311-win_amd64.whl
elif [[ "${{ inputs.targetPythonVersion }}" == "3.12" ]] ;then
pip3 install TA_Lib-0.4.29-cp312-cp312-win_amd64.whl
fi
cd ..
cd ..
python3 -m pip install --upgrade pip
pip3 install -r requirements.txt
pip3 install -r requirements-dev.txt
pip3 install .
- name: Run Historical Scan on Ubuntu
shell: bash
continue-on-error: true
env:
RUNNER : "LOCAL_RUN_SCANNER"
GSHEET_SERVICE_ACCOUNT_DEV: ${{secrets.GSHEET_SERVICE_ACCOUNT_DEV}}
GSHEET_VIEWONLY_LINK: ${{secrets.GSHEET_VIEWONLY_LINK}}
GITHUB_TOKEN : ${{secrets.GITHUB_TOKEN}}
if: ${{ inputs.cleanuphistoricalscans != 'Y' && startsWith(runner.os, 'Linux') }}
run: |
python3 .github/workflows/workflowtriggers.py ${{ inputs.scanOptions }}
echo "STAGED_COMMITS=$(git diff --cached --numstat | wc -l)" >> $GITHUB_OUTPUT
id: histRunnnerLinux
- name: Run Historical Scan on Windows
continue-on-error: true
env:
RUNNER : "LOCAL_RUN_SCANNER"
GSHEET_SERVICE_ACCOUNT_DEV: ${{secrets.GSHEET_SERVICE_ACCOUNT_DEV}}
GSHEET_VIEWONLY_LINK: ${{secrets.GSHEET_VIEWONLY_LINK}}
GITHUB_TOKEN : ${{secrets.GITHUB_TOKEN}}
if: ${{ inputs.cleanuphistoricalscans != 'Y' && startsWith(runner.os, 'Windows') }}
shell: cmd
run: |
python3 .github/workflows/workflowtriggers.py ${{ inputs.scanOptions }}
echo "STAGED_COMMITS=$(git diff --cached --numstat | wc -l)" >> $GITHUB_OUTPUT
id: histRunnnerWindows
- name: Push Historical scan Data
shell: bash
if: ${{ inputs.cleanuphistoricalscans != 'Y' && ( steps.histRunnnerLinux.outputs.STAGED_COMMITS != 0 || steps.histRunnnerWindows.outputs.STAGED_COMMITS != 0 ) }}
run: |
git config user.name github-actions
git config user.email [email protected]
git config remote.origin.fetch "+refs/heads/*:refs/remotes/origin/*"
git remote update
git fetch
git add actions-data-scan/*.txt --force
git commit -m "GitHub-Action-Workflow-Market-Data-Scan-Results-(Default-Config)"
git push -v -u origin +actions-data-download
env:
GITHUB_TOKEN : ${{secrets.GITHUB_TOKEN}}
- name: Delete this workflow run
continue-on-error: true
if: ${{ inputs.skipDownload == '' && startsWith(runner.os, 'Linux' ) }}
shell: bash
run: |
gh run list --status success --limit 1000 --json databaseId -q '.[].databaseId' | xargs -IID gh api "repos/$(gh repo view --json nameWithOwner -q .nameWithOwner)/actions/runs/ID" -X DELETE
gh run list --status cancelled --limit 1000 --json databaseId -q '.[].databaseId' | xargs -IID gh api "repos/$(gh repo view --json nameWithOwner -q .nameWithOwner)/actions/runs/ID" -X DELETE
env:
GH_TOKEN : ${{secrets.GITHUB_TOKEN}}
# || '--reScanForZeroSize --scans --local --scanDaysInPast 3 -s2 0,22,29,42,50,M,Z -s0 S,T,E,U,Z,F,H,Y,B,G,C,M,D,I,L,P -s1 W,N,E,M,Z,S,0,2,3,4,6,7,9,10,13,14,15 -s3 "0" -s4 "0" --branchname actions-data-download -f' }}
# Delete_Workflow_Run:
# runs-on: ubuntu-20.04
# needs: [Download_Stock_Data]
# if: ${{ needs.Download_Stock_Data.outputs.should_clean == ''}}
# name: Delete workflow run
# steps:
# - uses: actions/checkout@v4
# with:
# ref: main
# - name: Delete this workflow run
# if: startsWith(runner.os, 'Linux')
# shell: bash
# run: |
# gh run list --status success --limit 100 --json databaseId -q '.[].databaseId' | xargs -IID gh api "repos/$(gh repo view --json nameWithOwner -q .nameWithOwner)/actions/runs/ID" -X DELETE
# gh run list --status cancelled --limit 100 --json databaseId -q '.[].databaseId' | xargs -IID gh api "repos/$(gh repo view --json nameWithOwner -q .nameWithOwner)/actions/runs/ID" -X DELETE
# # for id in $(gh run list --limit 100 --jq ".[] | select (.status == \"success\" ) | .databaseId" --json databaseId,status); do gh run delete $id; done
# # for id in $(gh run list --limit 100 --jq ".[] | select (.status == \"cancelled\" ) | .databaseId" --json databaseId,status); do gh run delete $id; done
# # for id in $(gh run list --limit 100 --jq ".[] | select (.status == \"failure\" ) | .databaseId" --json databaseId,status); do gh run delete $id; done
# # Cancel runs queued or in_progress. See https://cli.github.com/manual/gh_run_list
# # for id in $(gh run list -w "13. Backtest for Generic" --limit 100 --jq ".[] | select (.status == \"queued\" ) | .databaseId" --json databaseId,status); do gh run cancel $id; done
# env:
# GH_TOKEN : ${{secrets.GITHUB_TOKEN}}