conrich2 1.0.0.dev0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (43) hide show
  1. conrich/Common/__init__.py +0 -0
  2. conrich/Common/cipher.py +74 -0
  3. conrich/Common/endpoints.py +49 -0
  4. conrich/Common/errors.py +29 -0
  5. conrich/Common/events.py +117 -0
  6. conrich/Common/framing.py +70 -0
  7. conrich/Common/gate.py +65 -0
  8. conrich/Common/normalize.py +46 -0
  9. conrich/Common/records.py +44 -0
  10. conrich/Common/service.py +110 -0
  11. conrich/Common/signer.py +176 -0
  12. conrich/Common/tagvalue.py +47 -0
  13. conrich/Common/timeutil.py +35 -0
  14. conrich/Common/transport.py +171 -0
  15. conrich/Common/version.py +16 -0
  16. conrich/Futures/Futures_README.md +71 -0
  17. conrich/Futures/__init__.py +12 -0
  18. conrich/Futures/base.py +236 -0
  19. conrich/Futures/constant.py +63 -0
  20. conrich/Futures/fields.py +716 -0
  21. conrich/Futures/foreign_futures.py +53 -0
  22. conrich/Futures/futures.py +74 -0
  23. conrich/Futures/messages.py +97 -0
  24. conrich/Futures/session.py +464 -0
  25. conrich/Quote/__init__.py +15 -0
  26. conrich/Quote/event.py +4 -0
  27. conrich/Quote/quote.py +116 -0
  28. conrich/Quote/server.py +10 -0
  29. conrich/Quote/symbols.py +18 -0
  30. conrich/Stock/__init__.py +10 -0
  31. conrich/Stock/constant.py +48 -0
  32. conrich/Stock/fields.py +147 -0
  33. conrich/Stock/messages.py +179 -0
  34. conrich/Stock/orders.py +104 -0
  35. conrich/Stock/results.py +53 -0
  36. conrich/Stock/session.py +373 -0
  37. conrich/Stock/stock.py +279 -0
  38. conrich/__init__.py +38 -0
  39. conrich2-1.0.0.dev0.dist-info/METADATA +242 -0
  40. conrich2-1.0.0.dev0.dist-info/RECORD +43 -0
  41. conrich2-1.0.0.dev0.dist-info/WHEEL +5 -0
  42. conrich2-1.0.0.dev0.dist-info/licenses/LICENSE +21 -0
  43. conrich2-1.0.0.dev0.dist-info/top_level.txt +1 -0
conrich/__init__.py ADDED
@@ -0,0 +1,38 @@
1
+ # -*- coding: utf-8 -*-
2
+ """
3
+ conrich
4
+ -----------------------------------------------------------
5
+ conrich is an unofficial, pure Python client for the Concord
6
+ securities / futures / options trading API (2025 protocol).
7
+ No .NET, pythonnet, COM or Windows component is needed.
8
+ -----------------------------------------------------------
9
+
10
+ :license: MIT, see LICENSE for more details.
11
+ """
12
+ import logging
13
+ from importlib import import_module
14
+
15
+ __version__ = '1.0.0.dev0'
16
+
17
+ logging.getLogger('conrich').addHandler(logging.NullHandler())
18
+
19
+ from .Common.errors import (CertificateError, ConrichError, OrderError, ProtocolError, # noqa: E402,F401
20
+ TradingDisabledError)
21
+
22
+ # The public classes are imported on first use, so that ``import conrich`` stays light and
23
+ # works while a product package is still being rewritten (design-2025.md section 12).
24
+ _LAZY = {
25
+ 'StockAPI': '.Stock',
26
+ 'FuturesAPI': '.Futures',
27
+ 'ForeignFuturesAPI': '.Futures',
28
+ 'QuoteAPI': '.Quote',
29
+ 'QuoteServer': '.Quote',
30
+ }
31
+
32
+
33
+ def __getattr__(name):
34
+ if name in _LAZY:
35
+ value = getattr(import_module(_LAZY[name], __name__), name)
36
+ globals()[name] = value
37
+ return value
38
+ raise AttributeError(f'module {__name__!r} has no attribute {name!r}')
@@ -0,0 +1,242 @@
1
+ Metadata-Version: 2.4
2
+ Name: conrich2
3
+ Version: 1.0.0.dev0
4
+ Summary: Unofficial pure Python client for the Concords Securities / Futures trading API (not released by Concords).
5
+ Home-page: https://github.com/phymach
6
+ Author: Leo Wu
7
+ Author-email: phymach@gmail.com
8
+ License: MIT
9
+ Keywords: stock,futures,option,TWSE,TPEX,TAIFEX
10
+ Classifier: Development Status :: 4 - Beta
11
+ Classifier: License :: OSI Approved :: MIT License
12
+ Classifier: Intended Audience :: Developers
13
+ Classifier: Programming Language :: Python :: 3.13
14
+ Classifier: Programming Language :: Python :: 3.14
15
+ Classifier: Programming Language :: Python :: 3.15
16
+ Classifier: Operating System :: OS Independent
17
+ Classifier: Topic :: Office/Business :: Financial
18
+ Classifier: Topic :: Software Development :: Libraries
19
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
20
+ Requires-Python: >=3.13
21
+ Description-Content-Type: text/markdown
22
+ License-File: LICENSE
23
+ Requires-Dist: cryptography>=42
24
+ Dynamic: author
25
+ Dynamic: author-email
26
+ Dynamic: classifier
27
+ Dynamic: description
28
+ Dynamic: description-content-type
29
+ Dynamic: home-page
30
+ Dynamic: keywords
31
+ Dynamic: license
32
+ Dynamic: license-file
33
+ Dynamic: requires-dist
34
+ Dynamic: requires-python
35
+ Dynamic: summary
36
+
37
+ # conrich2
38
+
39
+ ![PyPI](https://img.shields.io/pypi/v/conrich2)
40
+ ![PyPI - Python Version](https://img.shields.io/pypi/pyversions/conrich2)
41
+ ![PyPI - Format](https://img.shields.io/pypi/format/conrich2)
42
+ ![PyPI - License](https://img.shields.io/pypi/l/conrich2)
43
+ ![PyPI - Downloads](https://img.shields.io/pypi/dm/conrich2)
44
+ ![contact](https://img.shields.io/badge/contact-康和證券集團-red)
45
+
46
+ > **非官方聲明**:本套件(PyPI 名稱 `conrich2`)為非官方的純 Python 版本,並非康和證券集團發佈。安裝名稱是 `conrich2`,程式裡仍然使用 `import conrich`。
47
+
48
+ 康和綜合證券程式下單API為純 Python 實作(非官方),直接與康和伺服器通訊,不需要 .NET Framework、pythonnet 或任何 DLL,可在 Windows、Linux、macOS 執行,讓使用者可以輕鬆的運用python執行快速下單。
49
+
50
+ >conrich is a securities, futures, option API, which send orders to Concord Securities Group.
51
+ This package is pure Python (unofficial): it talks to the Concord servers directly, with no .NET Framework, pythonnet or vendor DLL, runs on Windows, Linux and macOS, and requires Python 3.13+.
52
+ This is an unofficial release (PyPI name `conrich2`), not published by Concord Securities Group. Install it with `pip install conrich2`; in code you still `import conrich`.
53
+ It is distributed under the MIT license.
54
+
55
+ - [Installation](#installation)
56
+ - [Preinstall](#preinstall)
57
+ - [Binaries](#binaries)
58
+ - [Quick Starts](#quick-starts)
59
+ - [Login](#login)
60
+ - [Place Order](#place-order)
61
+ - [Stock](#stock)
62
+ - [Futures](#futures)
63
+ - [Foreign Futures](#foreign-futures)
64
+ - [Register Event](#register-event)
65
+ - [Quote](#quote)
66
+ - [Reference](#reference)
67
+
68
+
69
+ ## Installation
70
+ ### Preinstall
71
+ >API usage needs application in advance. In order to use this package, please contact us.
72
+
73
+ ### Binaries
74
+
75
+ simply use pip to install (the import name is still `conrich`)
76
+ ```
77
+ pip install conrich2
78
+ ```
79
+
80
+ ## Quick Starts
81
+ ### Login
82
+ ```python
83
+ from conrich import StockAPI
84
+
85
+ agent = StockAPI()
86
+ agent.login("YOUR_PERSON_ID", "YOUR_PASSWORD")
87
+ ```
88
+ ```python
89
+ from conrich import FuturesAPI
90
+
91
+ agent = FuturesAPI()
92
+ agent.login("YOUR_PERSON_ID", "YOUR_PASSWORD")
93
+ ```
94
+ ```python
95
+ from conrich import ForeignFuturesAPI
96
+
97
+ agent = ForeignFuturesAPI()
98
+ agent.login("YOUR_PERSON_ID", "YOUR_PASSWORD")
99
+ ```
100
+
101
+ ## Place Order
102
+ ### Stock
103
+ ```python
104
+ from conrich.Stock import constant
105
+
106
+ result = agent.order(action = constant.Action.NEW_ORDER.value,
107
+ branch_no = '8450',
108
+ account_no = "YOUR_ACCOUNT",
109
+ lot_type = constant.LotType.ROUND_LOT.value,
110
+ order_type = constant.OrderType.ORDINARY.value,
111
+ side = constant.Side.BUY.value,
112
+ day_trade_flag = constant.DayTradeFlag.N.value,
113
+ symbol = '6016',
114
+ quantity = 1,
115
+ price = 10.0,
116
+ price_flag = constant.PriceFlag.FIX.value,
117
+ time_in_force = constant.TimeInForce.ROD.value)
118
+ ```
119
+ ### Futures
120
+ ```python
121
+ from conrich.Futures import constant
122
+
123
+ result = agent.order(action = constant.Action.NEW_ORDER.value,
124
+ branch_no = 'F029000',
125
+ account_no = "YOUR_ACCOUNT",
126
+ market_type = constant.Market.FUTURES.value,
127
+ compound_type = constant.CompoundType.FUTURES_SINGLE.value,
128
+ commodity = 'TXFI0',
129
+ time_in_force = constant.TimeInForce.ROD.value,
130
+ writeoff = constant.WriteOff.AUTO.value,
131
+ order_type = constant.OrderType.LIMIT.value,
132
+ side = constant.Side.BUY.value,
133
+ quantity = 1,
134
+ price = 12000.00)
135
+ ```
136
+ ### Foreign Futures
137
+ ```python
138
+ agent.order(action=constant.Action.NEW_ORDER.value,
139
+ branch_no = 'F029000',
140
+ account_no = "YOUR_ACCOUNT",
141
+ exchange = 'NYM',
142
+ side1 = constant.Side.BUY.value,
143
+ market_type1 = constant.Market.FUTURES.value,
144
+ commodity1 = 'QM',
145
+ commodity_month1 = '202010',
146
+ strike_price1 = 0,
147
+ put_call1 = constant.PutCall.NONE.value,
148
+ side2 = '',
149
+ market_type2 = '',
150
+ commodity2 = '',
151
+ commodity_month2 = '',
152
+ strike_price2 = 0,
153
+ put_call2 = constant.PutCall.NONE.value,
154
+ order_type = constant.ForeignOrderType.LIMIT.value,
155
+ price = 0,
156
+ price_numerator = 0,
157
+ price_denominator = 0,
158
+ stop_price = 42.95,
159
+ stop_price_numerator = 0,
160
+ stop_price_denominator = 0,
161
+ quantity = 1,
162
+ writeoff = constant.Writeoff.OPEN.value)
163
+ ```
164
+
165
+ ## Register Event
166
+ >If you want to catch order or match report, one can define a function and register
167
+
168
+ ### Stock
169
+ ```python
170
+ def OrderReportHandler(result, msg):
171
+ order_result = {'result' : result.ResultType,
172
+ 'status' : result.StatusCode,
173
+ 'desc' : result.CodeDesc,
174
+ 'order_guid' : result.OrderGuid,
175
+ 'net_no' : result.ClOrdID
176
+ }
177
+
178
+ if result.ResultType=='1':
179
+ report = result.ExcReport
180
+ exe_report = {'order_id' : report.OrderID,
181
+ 'orig_net_no' : report.OrigClOrdID,
182
+ 'execute_status' : report.ExecType,
183
+ 'account_no' : report.Account,
184
+ 'symbol' : report.Symbol,
185
+ 'side' : report.Side,
186
+ 'quantity' : report.OrderQty,
187
+ 'price' : report.Price,
188
+ 'strike_quantity' : report.LastQty,
189
+ 'strike_price' : report.LastPx,
190
+ 'transaction_time' : report.TransactTime}
191
+
192
+ agent.OrderReportEvent += OrderReportHandler
193
+ ```
194
+
195
+ ### Futures
196
+ ```python
197
+ def OrderReportHandler(code, msg):
198
+ dict_msg = dict((agent.msg_tag[k], v) for k,v in [tag.split('=') for tag in msg.split('|')])
199
+ print(dict_msg)
200
+
201
+ agent.OnFOrderReport += OrderReportHandler
202
+ ```
203
+
204
+ ## Quote
205
+ Quotes come from the futures gateway (domestic futures and options only), so log in with `FuturesAPI` first.
206
+ `QuoteAPI` polls `FuturesAPI.quote()` in a background thread and fires `OnQuoteUpdate` when a field changes.
207
+ No 康和金好康 or other Windows program needs to be running, and `QuoteServer` (the old COM based quote server)
208
+ is gone: creating it raises `NotImplementedError`, use `QuoteAPI` instead. `code_convert` still works.
209
+
210
+ >The layout of the quote answer is not verified yet: until it is, the topics are the column names
211
+ `col1`, `col2`, ... of the answer row.
212
+
213
+ ```python
214
+ from datetime import datetime
215
+ from conrich import FuturesAPI, QuoteAPI
216
+ from conrich.Quote import code_convert
217
+
218
+ futures = FuturesAPI(pfx_path='YOUR_CERT.pfx', pfx_password='YOUR_PFX_PASSWORD')
219
+ futures.login("YOUR_PERSON_ID", "YOUR_PASSWORD")
220
+
221
+ def on_quote(commodity, topic, value):
222
+ print('[{}][{}] {}'.format(commodity, topic, value))
223
+
224
+ quote = QuoteAPI(futures, interval=1.0) # interval in seconds, 0.5 or more
225
+ quote.OnQuoteUpdate += on_quote
226
+
227
+ topic1 = code_convert(commodity='TXO', commodity_type='P', strike_price=12500, expire_date=datetime(2020, 10, 18), after_hour=True)
228
+ quote.register_topic(topic1, 'col1')
229
+ topic2 = code_convert(commodity='TX', commodity_type='F', strike_price=0, expire_date=datetime(2020, 10, 18), after_hour=False)
230
+ quote.register_topic(topic2, 'col2')
231
+
232
+ quote.start() # or: with QuoteAPI(futures) as quote: ...
233
+ # ...
234
+ quote.stop()
235
+ ```
236
+
237
+ ## Reference
238
+
239
+ [FuturesAPI](./conrich/Futures/README.md)
240
+
241
+ https://www.concords.com.tw/download/20200318_證券API客戶使用元件及文件.zip
242
+ https://www.concordfutures.com.tw/WebSiteUpload//Files/Document/20200728_期貨API.zip
@@ -0,0 +1,43 @@
1
+ conrich/__init__.py,sha256=siul5gfdKjGJVJn1GMN_2CAUERk-Cph_wi9OkpQRFG8,1330
2
+ conrich/Common/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
3
+ conrich/Common/cipher.py,sha256=1KcUpmOYwwwECHvLgltpQcVkYNjaur09uj6YDZcDGNg,2865
4
+ conrich/Common/endpoints.py,sha256=ItfgItGWhDL-QL1OnRvCdgNgFmYo3DMoFDaNGXe-iTg,1600
5
+ conrich/Common/errors.py,sha256=ScxLhFYN3tJooa6RzatRg9ucDphrmyOik0dMWLi-bDs,910
6
+ conrich/Common/events.py,sha256=VgWVtC74XIpp2QTW6L2-Kmh0612E5RBpvuPEekM0nd8,3774
7
+ conrich/Common/framing.py,sha256=JkHOpjGkSc4TiGL3l1PZGf9ag3JsA9rhmJA20Lk0jYc,2543
8
+ conrich/Common/gate.py,sha256=JHvsxI_gdDRRsR_xhqe0DATenyVEhaY4L1vgyZ3rJKY,2615
9
+ conrich/Common/normalize.py,sha256=i5fgVEweZCIkyP7eSTUtLIsJow9S3ys7sSvpro6XR3k,1677
10
+ conrich/Common/records.py,sha256=AbrCbln2iluIv9p_MAcPuEjxgOrR26fS-va0vgwpd9E,1515
11
+ conrich/Common/service.py,sha256=0Jf0kBhmiPpoaKLvzLB-3FQu52WAu096q9I368DpZ_o,4999
12
+ conrich/Common/signer.py,sha256=j_r_6Gm-g44OaOdoozWN2nN11q6Obz2sV9yDVgsOC-4,7755
13
+ conrich/Common/tagvalue.py,sha256=BqFHDP1L_dQvZNuhV6jyEzenp6_QjcNm44Y6_x8z5yo,1816
14
+ conrich/Common/timeutil.py,sha256=leT_Q4VLWIQ75NEugpDSldiVtndxmfje2XdWXYvvK5k,1216
15
+ conrich/Common/transport.py,sha256=6sCnD4_wzkqIrhn08mtdu4BtZNB9n3Ey2YwFjq-_c2E,7442
16
+ conrich/Common/version.py,sha256=9i54yJcfj_ngzPaKTDaNBpQ1RAdQdoaSU_ot_-J09-Y,715
17
+ conrich/Futures/Futures_README.md,sha256=-M3Qt5U9Nl7prTq-CajvkxkVsH6ecw8ql_asTKvEmkg,10606
18
+ conrich/Futures/__init__.py,sha256=nDkBoV0Qu4jX4LFFd7A1AfK3bwDs6_eAaK07WN7OFRw,459
19
+ conrich/Futures/base.py,sha256=LyePSyzyywCQLugv1uFTERygGSvChmrOndBpN4d9ak4,11022
20
+ conrich/Futures/constant.py,sha256=PvnORlZmnUu6Bwc-wUWozhjZT1mCzhCk7RGiQmPlB74,1619
21
+ conrich/Futures/fields.py,sha256=4XquM_oDyRMcIwianrVFFkYMSFgOGCXZHjZjDztdJ0c,34174
22
+ conrich/Futures/foreign_futures.py,sha256=E0MABlj3MeuoA6uZxU_ttRISRf5RvpSi9F4aNyAC_Sk,2291
23
+ conrich/Futures/futures.py,sha256=gQtclOHBFfAbSRDZCYuf2TZhbbyVG94yLnkxotMXZiY,3275
24
+ conrich/Futures/messages.py,sha256=14OjtohSHTa7p8-IBFjuR1yeiS8jwOIqbO-o3lVK3AY,3985
25
+ conrich/Futures/session.py,sha256=gnf3VtK9kCp4RXIHe-7Dacwu35eOJPM_yrhIgx0SC50,21612
26
+ conrich/Quote/__init__.py,sha256=Rv9gUv3JUvArtOY975op2sIbmkG0m2gEjDxknT8SFpc,538
27
+ conrich/Quote/event.py,sha256=OHAPXki1dU9OlElGUpfBCt518UahfXep_KcirCzXkIM,147
28
+ conrich/Quote/quote.py,sha256=jBtdXkd5FPOcl1Pg75AZCZ6nyDHqn-_XE7gfs-2xjp4,4563
29
+ conrich/Quote/server.py,sha256=DPCuOijea6C-wqSduIrTj5qm7sYRVnp1JRdGRLassWA,437
30
+ conrich/Quote/symbols.py,sha256=qnnnEHcWl43KvlXduvHkoGPpMIYWEE045Lzc6_k9i2c,903
31
+ conrich/Stock/__init__.py,sha256=SnKC4OeoNWgT9eE3Okwen0gdLDRNCHBs_F76dR3PNzw,370
32
+ conrich/Stock/constant.py,sha256=FD3gSn8BTRrSwyLH2WrdvWeSSPs-pachV7qlBakdK0o,1258
33
+ conrich/Stock/fields.py,sha256=qxI_94Hp-JXLD4Ootg7--Eayrg2TCNCfHTYR-p2K45k,5424
34
+ conrich/Stock/messages.py,sha256=zW5kE-04Bi-ReLy-uxUQE1Fb1PoKuxGr3Qpj10k01ag,8775
35
+ conrich/Stock/orders.py,sha256=gaMWODQQoqSJVmPFZ19yUG2bR7N8X9Qyg66XsQLkjrw,4461
36
+ conrich/Stock/results.py,sha256=Ttw9CRoYA211jB5GwfV_lsGFDVviIv_VrSRjSJL8RJ0,1964
37
+ conrich/Stock/session.py,sha256=w7UvbUV1gexmkT_zOUxFWqkeIII2wQ0ealTo2lrwP8E,16819
38
+ conrich/Stock/stock.py,sha256=KTIPMATDXf8s5enlhxGmAavVPQWN0dLVy7t0jq9qE5Q,13407
39
+ conrich2-1.0.0.dev0.dist-info/licenses/LICENSE,sha256=RDhbXZ8hwSoeScrBsYzUo9dr2biXB-UtUqkv8A9hHMM,1086
40
+ conrich2-1.0.0.dev0.dist-info/METADATA,sha256=E2HSlShFfyuxBNTBlMx0D_F0SGpbEvZoBspXc0fh2fk,9373
41
+ conrich2-1.0.0.dev0.dist-info/WHEEL,sha256=mOdXR9C3wMVov7cSY8PY-XCzo3SmmWCHvGQr5csJoao,91
42
+ conrich2-1.0.0.dev0.dist-info/top_level.txt,sha256=yACDhDdHhkFy_C_zxwd8DelHI1WdGEtp-1d7F03Qp4s,8
43
+ conrich2-1.0.0.dev0.dist-info/RECORD,,
@@ -0,0 +1,5 @@
1
+ Wheel-Version: 1.0
2
+ Generator: setuptools (84.2.1)
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
5
+
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2020 Concords
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1 @@
1
+ conrich