Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix realtime unittest #123

Merged
merged 9 commits into from
May 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 22 additions & 5 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ jobs:
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
python-version:
["3.5", "3.6", "3.7", "3.8", "3.9", "3.10", "3.11", "3.12"]
["3.7", "3.12"]
runs-on: ${{ matrix.os }}
name: ${{ matrix.os }} - ${{ github.event_name }}
steps:
Expand All @@ -19,8 +19,25 @@ jobs:
pipenv install --dev
- name: Run tests
run: pipenv run coverage run --source=twstock -m unittest
create-reports:
runs-on: ubuntu-latest
needs: build
strategy:
matrix:
os: [ubuntu-latest]
python-version: ["3.12"]
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Setup
run: |
pip install pipenv
pipenv install --dev
- name: Run tests
run: pipenv run coverage run --source=twstock -m unittest
- name: Create reports
run:
|
pipenv run coveralls
pipenv run codecov
run: |
pipenv run coveralls
pipenv run codecov
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Copyright (c) 2017-2019 Louie Lu
Copyright (c) 2017-2024 Louie Lu

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -109,11 +109,11 @@ ma_p_cont = stock.continuous(ma_p) # 計算五日均價持續天
ma_br = stock.ma_bias_ratio(5, 10) # 計算五日、十日乖離值
```

擷取自 20151 月至今之資料
擷取自 20243 月至今之資料

```python
stock = Stock('2330')
stock.fetch_from(2015, 1)
stock.fetch_from(2024, 3)
```

基本資料之使用
Expand Down
28 changes: 0 additions & 28 deletions appveyor.yml

This file was deleted.

2 changes: 1 addition & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@

# General information about the project.
project = "twstock"
copyright = "2017, Louie Lu"
copyright = "2017-2024, Louie Lu"
author = "Louie Lu"

# The version info for the project you're documenting, acts as replacement for
Expand Down
2 changes: 1 addition & 1 deletion docs/license.rst
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
LICENSE
---------------------

Copyright (c) 2017-2019 Louie Lu
Copyright (c) 2017-2024 Louie Lu

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
11 changes: 10 additions & 1 deletion test/test_mock.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,16 @@ def test_mock_get_stock_info_will_work(self):
def test_mock_get_stock_info_raw_data(self):
self.assertCountEqual(
mock.get_stock_info("2330").keys(),
["msgArray", "userDelay", "rtmessage", "referer", "queryTime", "rtcode"],
[
"msgArray",
"userDelay",
"rtmessage",
"referer",
"queryTime",
"rtcode",
"exKey",
"cachedAlive",
],
)

def test_mock_get_stock_info_msgarray(self):
Expand Down
4 changes: 2 additions & 2 deletions test/test_realtime.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,10 @@ def test_mock_one_stock_id(self):

self.assertTrue(s["success"])
self.assertEqual(s["info"]["code"], "2330")
self.assertEqual(s["realtime"]["latest_trade_price"], "214.50")
self.assertEqual(s["realtime"]["latest_trade_price"], "-")
self.assertEqual(
s["realtime"]["best_bid_price"],
["214.00", "213.50", "213.00", "212.50", "212.00"],
["848.0000", "847.0000", "846.0000", "845.0000", "844.0000"],
)

@unittest.skip("Dont want to fix this, is about the code in realtime")
Expand Down
54 changes: 3 additions & 51 deletions twstock/mock/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,57 +4,9 @@


TSE_2330_TW = [
"""
{"msgArray": [{"ts": "0", "tk0": "2330.tw_tse_20170724_B_9999778918", "tk1":
"2330.tw_tse_20170724_B_9999777950", "tlong": "1500860849000", "f":
"853_1193_972_1209_817_", "ex": "tse", "g": "1221_1530_817_1038_1193_", "d":
"20170724", "it": "12", "b": "214.00_213.50_213.00_212.50_212.00_", "c":
"2330", "mt": "264564", "a": "214.50_215.00_215.50_216.00_216.50_", "n":
"\u53f0\u7a4d\u96fb", "o": "213.50", "l": "213.00", "h": "214.50", "ip": "0",
"i": "24", "w": "193.00", "v": "5094", "u": "235.00", "t": "09:47:29", "s":
"1", "pz": "213.50", "tv": "1", "p": "0", "nf":
"\u53f0\u7063\u7a4d\u9ad4\u96fb\u8def\u88fd\u9020\u80a1\u4efd\u6709\u9650\u516c\u53f8",
"ch": "2330.tw",
"z": "214.50", "y": "214.00", "ps": "1323"}], "userDelay": 5000, "rtmessage":
"OK", "referer": "", "queryTime": {"sysTime": "09:47:30", "sessionLatestTime":
-1, "sysDate": "20170724", "sessionKey": "tse_2330.tw_20170724|",
"sessionFromTime": -1, "stockInfoItem": 2065, "showChart": false,
"sessionStr": "UserSession", "stockInfo": 204322}, "rtcode": "0000"}
""",
"""
{"msgArray": [{"ts": "0", "tk0": "2330.tw_tse_20170724_B_9999766224", "tk1":
"2330.tw_tse_20170724_B_9999765954", "tlong": "1500861105000", "f":
"1059_1079_1014_1229_907_", "ex": "tse", "g": "1455_1598_797_1019_1134_", "d":
"20170724", "it": "12", "b": "214.00_213.50_213.00_212.50_212.00_", "c":
"2330", "mt": "778472", "a": "214.50_215.00_215.50_216.00_216.50_", "n":
"\u53f0\u7a4d\u96fb", "o": "213.50", "l": "213.00", "h": "214.50", "ip": "0",
"i": "24", "w": "193.00", "v": "5217", "u": "235.00", "t": "09:51:45", "s":
"0", "pz": "213.50", "tv": "1", "p": "0", "nf":
"\u53f0\u7063\u7a4d\u9ad4\u96fb\u8def\u88fd\u9020\u80a1\u4efd\u6709\u9650\u516c\u53f8",
"ch": "2330.tw",
"z": "214.50", "y": "214.00", "ps": "1323"}], "userDelay": 5000, "rtmessage":
"OK", "referer": "", "queryTime": {"sysTime": "09:51:48", "sessionLatestTime":
-1, "sysDate": "20170724", "sessionKey": "tse_2330.tw_20170724|",
"sessionFromTime": -1, "stockInfoItem": 2055, "showChart": false,
"sessionStr": "UserSession", "stockInfo": 130895}, "rtcode": "0000"}
""",
"""
{"msgArray": [{"ts": "0", "tk0": "2330.tw_tse_20170724_B_9999760446", "tk1":
"2330.tw_tse_20170724_B_9999759382", "tlong": "1500861243000", "f":
"1034_1028_1009_1253_933_", "ex": "tse", "g": "1466_1625_798_987_1117_", "d":
"20170724", "it": "12", "b": "214.00_213.50_213.00_212.50_212.00_", "c":
"2330", "mt": "962863", "a": "214.50_215.00_215.50_216.00_216.50_", "n":
"\u53f0\u7a4d\u96fb", "o": "213.50", "l": "213.00", "h": "214.50", "ip": "0",
"i": "24", "w": "193.00", "v": "5268", "u": "235.00", "t": "09:54:03", "s":
"0", "pz": "213.50", "tv": "3", "p": "0", "nf":
"\u53f0\u7063\u7a4d\u9ad4\u96fb\u8def\u88fd\u9020\u80a1\u4efd\u6709\u9650\u516c\u53f8",
"ch": "2330.tw",
"z": "214.00", "y": "214.00", "ps": "1323"}], "userDelay": 5000, "rtmessage":
"OK", "referer": "", "queryTime": {"sysTime": "09:54:10", "sessionLatestTime":
-1, "sysDate": "20170724", "sessionKey": "tse_2330.tw_20170724|",
"sessionFromTime": -1, "stockInfoItem": 1602, "showChart": false,
"sessionStr": "UserSession", "stockInfo": 119518}, "rtcode": "0000"}
""",
"""{"msgArray": [{"tv": "-", "ps": "-", "pz": "-", "bp": "0", "a": "849.0000_850.0000_851.0000_852.0000_853.0000_", "b": "848.0000_847.0000_846.0000_845.0000_844.0000_", "c": "2330", "d": "20240516", "ch": "2330.tw", "tlong": "1715827494000", "f": "170_372_260_647_514_", "ip": "0", "g": "6_50_126_107_255_", "mt": "692836", "h": "856.0000", "i": "24", "it": "12", "l": "844.0000", "n": "\\u53f0\\u7a4d\\u96fb", "o": "852.0000", "p": "0", "ex": "tse", "s": "-", "t": "10:44:54", "u": "922.0000", "v": "23350", "w": "756.0000", "nf": "\\u53f0\\u7063\\u7a4d\\u9ad4\\u96fb\\u8def\\u88fd\\u9020\\u80a1\\u4efd\\u6709\\u9650\\u516c\\u53f8", "y": "839.0000", "z": "-", "ts": "0"}], "referer": "", "userDelay": 5000, "rtcode": "0000", "queryTime": {"sysDate": "20240516", "stockInfoItem": 2300, "stockInfo": 1107969, "sessionStr": "UserSession", "sysTime": "10:45:02", "showChart": false, "sessionFromTime": 1715827477731, "sessionLatestTime": 1715827477731}, "rtmessage": "OK", "exKey": "if_tse_2330.tw_zh-tw.null", "cachedAlive": 41360}""",
"""{"msgArray": [{"tv": "-", "ps": "-", "pz": "-", "bp": "0", "a": "848.0000_849.0000_850.0000_851.0000_852.0000_", "b": "847.0000_846.0000_845.0000_844.0000_843.0000_", "c": "2330", "d": "20240516", "ch": "2330.tw", "tlong": "1715827560000", "f": "53_157_370_261_945_", "ip": "0", "g": "42_124_116_271_187_", "mt": "826330", "h": "856.0000", "i": "24", "it": "12", "l": "844.0000", "n": "\\u53f0\\u7a4d\\u96fb", "o": "852.0000", "p": "0", "ex": "tse", "s": "-", "t": "10:46:00", "u": "922.0000", "v": "23384", "w": "756.0000", "nf": "\\u53f0\\u7063\\u7a4d\\u9ad4\\u96fb\\u8def\\u88fd\\u9020\\u80a1\\u4efd\\u6709\\u9650\\u516c\\u53f8", "y": "839.0000", "z": "-", "ts": "0"}], "referer": "", "userDelay": 5000, "rtcode": "0000", "queryTime": {"sysDate": "20240516", "stockInfoItem": 762, "stockInfo": 270448, "sessionStr": "UserSession", "sysTime": "10:46:02", "showChart": false, "sessionFromTime": 1715827446503, "sessionLatestTime": 1715827446503}, "rtmessage": "OK", "exKey": "if_tse_2330.tw_zh-tw.null", "cachedAlive": 17846}""",
"""{"msgArray": [{"tv": "-", "ps": "-", "pz": "-", "bp": "0", "a": "848.0000_849.0000_850.0000_851.0000_852.0000_", "b": "847.0000_846.0000_845.0000_844.0000_843.0000_", "c": "2330", "d": "20240516", "ch": "2330.tw", "tlong": "1715827579000", "f": "64_157_371_261_947_", "ip": "0", "g": "40_124_118_270_185_", "mt": "655374", "h": "856.0000", "i": "24", "it": "12", "l": "844.0000", "n": "\\u53f0\\u7a4d\\u96fb", "o": "852.0000", "p": "0", "ex": "tse", "s": "-", "t": "10:46:19", "u": "922.0000", "v": "23388", "w": "756.0000", "nf": "\\u53f0\\u7063\\u7a4d\\u9ad4\\u96fb\\u8def\\u88fd\\u9020\\u80a1\\u4efd\\u6709\\u9650\\u516c\\u53f8", "y": "839.0000", "z": "-", "ts": "0"}], "referer": "", "userDelay": 5000, "rtcode": "0000", "queryTime": {"sysDate": "20240516", "stockInfoItem": 2216, "stockInfo": 506844, "sessionStr": "UserSession", "sysTime": "10:46:25", "showChart": false, "sessionFromTime": -1, "sessionLatestTime": -1}, "rtmessage": "OK", "exKey": "if_tse_2330.tw_zh-tw.null", "cachedAlive": 21231}""",
]


Expand Down
Loading