openfund-core 0.0.2__tar.gz

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 (46) hide show
  1. openfund_core-0.0.2/LICENSE +201 -0
  2. openfund_core-0.0.2/PKG-INFO +66 -0
  3. openfund_core-0.0.2/README.md +45 -0
  4. openfund_core-0.0.2/pyproject.toml +53 -0
  5. openfund_core-0.0.2/src/openfund/core/__init__.py +0 -0
  6. openfund_core-0.0.2/src/openfund/core/binance_tools/__init__.py +16 -0
  7. openfund_core-0.0.2/src/openfund/core/binance_tools/binance_tools.py +39 -0
  8. openfund_core-0.0.2/src/openfund/core/binance_tools/continuous_klines.py +147 -0
  9. openfund_core-0.0.2/src/openfund/core/factory.py +37 -0
  10. openfund_core-0.0.2/src/openfund/core/libs/__init__.py +6 -0
  11. openfund_core-0.0.2/src/openfund/core/libs/email_tools.py +56 -0
  12. openfund_core-0.0.2/src/openfund/core/libs/enums.py +507 -0
  13. openfund_core-0.0.2/src/openfund/core/libs/file_tools.py +13 -0
  14. openfund_core-0.0.2/src/openfund/core/libs/log_tools.py +45 -0
  15. openfund_core-0.0.2/src/openfund/core/libs/prepare_env.py +28 -0
  16. openfund_core-0.0.2/src/openfund/core/libs/time.py +14 -0
  17. openfund_core-0.0.2/src/openfund/core/libs/time_tools.py +22 -0
  18. openfund_core-0.0.2/src/openfund/core/openfund_old/__init__.py +0 -0
  19. openfund_core-0.0.2/src/openfund/core/openfund_old/continuous_klines.py +153 -0
  20. openfund_core-0.0.2/src/openfund/core/openfund_old/depth.py +92 -0
  21. openfund_core-0.0.2/src/openfund/core/openfund_old/historical_trades.py +123 -0
  22. openfund_core-0.0.2/src/openfund/core/openfund_old/index_info.py +67 -0
  23. openfund_core-0.0.2/src/openfund/core/openfund_old/index_price_kline.py +118 -0
  24. openfund_core-0.0.2/src/openfund/core/openfund_old/klines.py +95 -0
  25. openfund_core-0.0.2/src/openfund/core/openfund_old/klines_qrr.py +103 -0
  26. openfund_core-0.0.2/src/openfund/core/openfund_old/mark_price.py +121 -0
  27. openfund_core-0.0.2/src/openfund/core/openfund_old/mark_price_klines.py +122 -0
  28. openfund_core-0.0.2/src/openfund/core/openfund_old/ticker_24hr_price_change.py +99 -0
  29. openfund_core-0.0.2/src/openfund/core/pyopenfund.py +32 -0
  30. openfund_core-0.0.2/src/openfund/core/sample/__init__.py +1 -0
  31. openfund_core-0.0.2/src/openfund/core/sample/sample.py +20 -0
  32. openfund_core-0.0.2/src/openfund/core/sycu_exam/__init__.py +1 -0
  33. openfund_core-0.0.2/src/openfund/core/sycu_exam/exam.py +19 -0
  34. openfund_core-0.0.2/src/openfund/core/sycu_exam/random_grade_cplus.py +440 -0
  35. openfund_core-0.0.2/src/openfund/core/sycu_exam/random_grade_web.py +404 -0
  36. openfund_core-0.0.2/tests/__init__.py +0 -0
  37. openfund_core-0.0.2/tests/binance_tools/__init__.py +0 -0
  38. openfund_core-0.0.2/tests/binance_tools/test_binance_tools.py +38 -0
  39. openfund_core-0.0.2/tests/conftest.py +91 -0
  40. openfund_core-0.0.2/tests/fixtures/sample_project/expected_pyproject.toml +30 -0
  41. openfund_core-0.0.2/tests/fixtures/sample_project/expected_pyproject_with_exclude.toml +30 -0
  42. openfund_core-0.0.2/tests/fixtures/sample_project/expected_pyproject_with_latest.toml +30 -0
  43. openfund_core-0.0.2/tests/fixtures/sample_project/expected_pyproject_with_latest_and_pinned.toml +30 -0
  44. openfund_core-0.0.2/tests/fixtures/sample_project/expected_pyproject_with_latest_and_preserve_wildcard.toml +30 -0
  45. openfund_core-0.0.2/tests/fixtures/sample_project/pyproject.toml +30 -0
  46. openfund_core-0.0.2/tests/helpers.py +23 -0
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "{}"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright {yyyy} {name of copyright owner}
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
@@ -0,0 +1,66 @@
1
+ Metadata-Version: 2.1
2
+ Name: openfund-core
3
+ Version: 0.0.2
4
+ Summary:
5
+ Author: yang99love
6
+ Author-email: yang99love@hotmail.com
7
+ Requires-Python: >=3.8,<4.0
8
+ Classifier: Programming Language :: Python :: 3
9
+ Classifier: Programming Language :: Python :: 3.8
10
+ Classifier: Programming Language :: Python :: 3.9
11
+ Classifier: Programming Language :: Python :: 3.10
12
+ Classifier: Programming Language :: Python :: 3.11
13
+ Classifier: Programming Language :: Python :: 3.12
14
+ Classifier: Programming Language :: Python :: 3.13
15
+ Requires-Dist: binance-connector (>=3.9.0,<4.0.0)
16
+ Requires-Dist: binance-futures-connector (>=4.1.0,<5.0.0)
17
+ Requires-Dist: httpretty (>=1.1.4,<2.0.0)
18
+ Requires-Dist: poetry (>=1.8.4,<2.0.0)
19
+ Description-Content-Type: text/markdown
20
+
21
+ # Openfund Core
22
+ [![Poetry](https://img.shields.io/endpoint?url=https://python-poetry.org/badge/v0.json)](https://python-poetry.org/)
23
+ [![PyPI version](https://img.shields.io/pypi/v/poetry-core)](https://pypi.org/project/poetry-core/)
24
+ [![Python Versions](https://img.shields.io/pypi/pyversions/poetry-core)](https://pypi.org/project/poetry-core/)
25
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
26
+ [![](https://github.com/python-poetry/poetry-core/workflows/Tests/badge.svg)](https://github.com/python-poetry/poetry-core/actions?query=workflow%3ATests)
27
+
28
+ A [PEP 517](https://www.python.org/dev/peps/pep-0517/) build backend implementation developed for
29
+ [Poetry](https://github.com/python-poetry/poetry). This project is intended to be a lightweight, fully compliant,
30
+ self-contained package allowing PEP 517-compatible build frontends to build Poetry-managed projects.
31
+
32
+ ## Usage
33
+ In most cases, the usage of this package is transparent to the end-user as it is either used by Poetry itself
34
+ or a PEP 517 frontend (eg: `pip`).
35
+
36
+ In order to enable the use of `openfund-core` as your build backend, the following snippet must be present in your
37
+ project's `pyproject.toml` file.
38
+
39
+ ```toml
40
+ [build-system]
41
+ requires = ["poetry-core"]
42
+ build-backend = "poetry.core.masonry.api"
43
+ ```
44
+
45
+ Once this is present, a PEP 517 frontend like `pip` can build and install your project from source without the need
46
+ for Poetry or any of its dependencies (besides `openfund-core`).
47
+
48
+ ```shell
49
+ # install to current environment
50
+ pip install /path/to/poetry/managed/project
51
+
52
+ # build a wheel package
53
+ pip wheel /path/to/poetry/managed/project
54
+ ```
55
+
56
+ ## Why is this required?
57
+ Prior to the release of version `1.1.0`, Poetry was a project management tool that included a PEP 517
58
+ build backend. This was inefficient and time consuming when a PEP 517 build was required. For example,
59
+ both `pip` and `tox` (with isolated builds) would install Poetry and all dependencies it required. Most of these
60
+ dependencies are not required when the objective is to simply build either a source or binary distribution of your
61
+ project.
62
+
63
+ In order to improve the above situation, `openfund-core` was created. Shared functionality pertaining to PEP 517 build
64
+ backends, including reading `pyproject.toml` and building wheel/sdist, were implemented in this package. This
65
+ makes PEP 517 builds extremely fast for Poetry-managed packages.
66
+
@@ -0,0 +1,45 @@
1
+ # Openfund Core
2
+ [![Poetry](https://img.shields.io/endpoint?url=https://python-poetry.org/badge/v0.json)](https://python-poetry.org/)
3
+ [![PyPI version](https://img.shields.io/pypi/v/poetry-core)](https://pypi.org/project/poetry-core/)
4
+ [![Python Versions](https://img.shields.io/pypi/pyversions/poetry-core)](https://pypi.org/project/poetry-core/)
5
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
6
+ [![](https://github.com/python-poetry/poetry-core/workflows/Tests/badge.svg)](https://github.com/python-poetry/poetry-core/actions?query=workflow%3ATests)
7
+
8
+ A [PEP 517](https://www.python.org/dev/peps/pep-0517/) build backend implementation developed for
9
+ [Poetry](https://github.com/python-poetry/poetry). This project is intended to be a lightweight, fully compliant,
10
+ self-contained package allowing PEP 517-compatible build frontends to build Poetry-managed projects.
11
+
12
+ ## Usage
13
+ In most cases, the usage of this package is transparent to the end-user as it is either used by Poetry itself
14
+ or a PEP 517 frontend (eg: `pip`).
15
+
16
+ In order to enable the use of `openfund-core` as your build backend, the following snippet must be present in your
17
+ project's `pyproject.toml` file.
18
+
19
+ ```toml
20
+ [build-system]
21
+ requires = ["poetry-core"]
22
+ build-backend = "poetry.core.masonry.api"
23
+ ```
24
+
25
+ Once this is present, a PEP 517 frontend like `pip` can build and install your project from source without the need
26
+ for Poetry or any of its dependencies (besides `openfund-core`).
27
+
28
+ ```shell
29
+ # install to current environment
30
+ pip install /path/to/poetry/managed/project
31
+
32
+ # build a wheel package
33
+ pip wheel /path/to/poetry/managed/project
34
+ ```
35
+
36
+ ## Why is this required?
37
+ Prior to the release of version `1.1.0`, Poetry was a project management tool that included a PEP 517
38
+ build backend. This was inefficient and time consuming when a PEP 517 build was required. For example,
39
+ both `pip` and `tox` (with isolated builds) would install Poetry and all dependencies it required. Most of these
40
+ dependencies are not required when the objective is to simply build either a source or binary distribution of your
41
+ project.
42
+
43
+ In order to improve the above situation, `openfund-core` was created. Shared functionality pertaining to PEP 517 build
44
+ backends, including reading `pyproject.toml` and building wheel/sdist, were implemented in this package. This
45
+ makes PEP 517 builds extremely fast for Poetry-managed packages.
@@ -0,0 +1,53 @@
1
+ [tool.poetry]
2
+ name = "openfund-core"
3
+ version = "0.0.2"
4
+ description = ""
5
+ authors = ["yang99love <yang99love@hotmail.com>"]
6
+ readme = "README.md"
7
+ packages = [{include = "openfund", from = "src"}]
8
+ include = [
9
+ { path = "tests", format = "sdist" },
10
+ ]
11
+
12
+ [tool.poetry.dependencies] # main dependency group
13
+ python = "^3.8"
14
+ binance-futures-connector = "^4.1.0"
15
+ binance-connector = "^3.9.0"
16
+ poetry = "^1.8.4"
17
+ httpretty = "^1.1.4"
18
+
19
+ [tool.poetry.group.dev.dependencies]
20
+ pre-commit = ">=2.15.0"
21
+ vendoring = ">=1.0"
22
+
23
+ [tool.poetry.group.test.dependencies]
24
+ binance-futures-connector = "^4.1.0"
25
+ binance-connector = "^3.9.0"
26
+ httpretty = "^1.1.4"
27
+ pytest = ">=7.1.2"
28
+ pytest-cov = ">=3.0.0"
29
+ pytest-mock = ">=3.10"
30
+ build = ">=0.10.0"
31
+ setuptools = ">=60"
32
+ tomli-w = "^1.0.0"
33
+ virtualenv = ">=20.21"
34
+ trove-classifiers = ">=2022.5.19"
35
+
36
+ [tool.pytest.ini_options] # mandatory section name
37
+ addopts = "-vs --no-header --no-summary"
38
+ log_cli = 1
39
+ log_cli_level = "DEBUG"
40
+ log_cli_format = "%(asctime)s.%(msecs)03d - %(filename)s:%(lineno)d - %(funcName)s - %(levelname)s - %(message)s"
41
+ log_cli_datefmt = "%Y-%m-%d-%H:%M:%S"
42
+ testpaths = [
43
+ "tests",
44
+ ]
45
+
46
+ [[tool.poetry.source]]
47
+ name = "mirrors"
48
+ url = "https://pypi.tuna.tsinghua.edu.cn/simple/"
49
+ priority = "primary"
50
+
51
+ [build-system]
52
+ requires = ["poetry-core>=1.0.0"]
53
+ build-backend = "poetry.core.masonry.api"
File without changes
@@ -0,0 +1,16 @@
1
+ # from binance.spot import Spot
2
+
3
+ # client = Spot()
4
+
5
+ # Get server timestamp
6
+ # print(client.time())
7
+ # Get klines of BTCUSDT at 1m interval
8
+ # print(client.klines("BTCUSDT", "1m"))
9
+ # Get last 10 klines of BNBUSDT at 1h interval
10
+ # print(client.klines("BNBUSDT", "1h", limit=10))
11
+
12
+ # API key/secret are required for user data endpoints
13
+ # client = Spot(api_key='<api_key>', api_secret='<api_secret>')
14
+
15
+ # Get account and balance information
16
+ # print(client.account())
@@ -0,0 +1,39 @@
1
+ from __future__ import annotations
2
+
3
+ import logging
4
+ from poetry.utils.authenticator import Authenticator
5
+
6
+ from typing import TYPE_CHECKING
7
+ from binance.spot import Spot as Client
8
+ from openfund.core.pyopenfund import Openfund
9
+
10
+
11
+ tools = "binance"
12
+ logger = logging.getLogger(__name__)
13
+
14
+
15
+ class BinanceTools:
16
+ def __init__(self, openfund: Openfund) -> None:
17
+ logger.debug("######## BinanceTools init ########")
18
+ self._openfund: Openfund = openfund
19
+ self._password_manager = Authenticator(
20
+ self._openfund._poetry.config
21
+ )._password_manager
22
+
23
+ @property
24
+ def api_key(self) -> str:
25
+ return self._password_manager.get_http_auth(tools).get("username")
26
+
27
+ @property
28
+ def apk_secret(self) -> str:
29
+ return self._password_manager.get_http_auth(tools).get("password")
30
+
31
+ def get_time():
32
+ client = Client()
33
+ return client.time()
34
+
35
+ def get_account(self):
36
+ logger.debug("######## BinanceTools.get_account() ########")
37
+ logger.debug("######## BinanceTools api_key=%s ########", self.api_key)
38
+ client = Client(self.api_key, self.apk_secret)
39
+ return client.account()
@@ -0,0 +1,147 @@
1
+ #!/usr/bin/env python
2
+ import csv
3
+ import logging
4
+ import time
5
+
6
+ from datetime import datetime
7
+
8
+ from binance.um_futures import UMFutures
9
+ from binance.um_futures import UMFutures
10
+ from binance.error import ClientError
11
+
12
+ from libs.time_tools import format_timestamp
13
+ from libs.file_tools import create_path
14
+ from libs.prepare_env import get_api_key, get_path
15
+ from libs import enums
16
+
17
+ # 数据路径、日志路径
18
+ data_path, log_path = get_path()
19
+ # client
20
+ um_futures_client = UMFutures()
21
+ # 合同类型
22
+ contractTypes = [type.value for type in enums.ContractType]
23
+ # 币种类型
24
+ # POOL = enums.CUR_SYMBOL_POOL
25
+ POOL = [
26
+ "BTCUSDT_240329",
27
+ "BLURUSDT",
28
+ "DYDXUSDT",
29
+ "ETHBTC",
30
+ "ETHBUSD",
31
+ "ETHUSDT",
32
+ "ETHUSDT_231229",
33
+ "ETHUSDT_240329",
34
+ "GMTBUSD",
35
+ "GMTUSDT",
36
+ "LTCBUSD",
37
+ "LTCUSDT",
38
+ "MATICBUSD",
39
+ "MATICUSDT",
40
+ "SOLBUSD",
41
+ "SOLUSDT",
42
+ ]
43
+ interval = enums.KLINE_INTERVAL_5MINUTE
44
+ limit = 1500
45
+ errorLimit = 100
46
+ sleepSec = 10
47
+
48
+ # 历史截止数据开关
49
+ hisSwitch = 0
50
+ # hisSwitch 打开的情况下,抓取数据截止时间
51
+ hisDateTime = 1653974399999
52
+
53
+ for symbol in POOL:
54
+ fileName = "{}/continuous_klines_{}_{}.log".format(
55
+ log_path, symbol, format_timestamp(datetime.now().timestamp() * 1000)
56
+ )
57
+ # print(fileName)
58
+ logging.basicConfig(
59
+ format="%(asctime)s %(name)s:%(levelname)s:%(message)s",
60
+ datefmt="%Y-%m-%d %H:%M:%S",
61
+ level=logging.INFO,
62
+ filename=fileName,
63
+ )
64
+ logging.info("{} symbol 开始 ++++++++++++++++++++++++++++ ".format(symbol))
65
+ total = 0
66
+ for contractType in contractTypes:
67
+ latestRecords = 1
68
+ records = 0 # 累计记录数
69
+ queryTimes = 0 # 执行次数
70
+ nextEndTime = 0
71
+ errorCount = 0
72
+ params = {"limit": limit}
73
+ while latestRecords != 0: # 循环读取,直到记录为空
74
+ queryTimes = queryTimes + 1
75
+ if nextEndTime != 0:
76
+ params = {"limit": limit, "endTime": nextEndTime}
77
+
78
+ logging.info(
79
+ "1、{}-{} 第{}次开始执行...".format(symbol, contractType, queryTimes)
80
+ )
81
+ listData = []
82
+ try:
83
+ listData = um_futures_client.continuous_klines(
84
+ symbol, contractType, interval, **params
85
+ )
86
+ except KeyError as err:
87
+ print("KeyError:", err)
88
+ logging.error(err)
89
+ break
90
+ except ClientError as error:
91
+ logging.error(
92
+ "Found error. status: {}, error code: {}, error message: {}".format(
93
+ error.status_code, error.error_code, error.error_message
94
+ )
95
+ )
96
+ if error.error_code == -4144 and error.status_code == 400:
97
+ break
98
+ except Exception as e:
99
+ print("Error:", e)
100
+ logging.error(e)
101
+ errorCount = errorCount + 1
102
+ if errorCount > errorLimit:
103
+ break
104
+ else:
105
+ time.sleep(sleepSec)
106
+ continue
107
+
108
+ latestRecords = len(listData)
109
+ records = latestRecords + records
110
+ logging.info("2、{}条写入文件...".format(latestRecords))
111
+
112
+ path = "{}/continuous_klines/{}/{}/".format(data_path, symbol, contractType)
113
+ create_path(path) # 不存在路径进行呢创建
114
+
115
+ with open(
116
+ "{}continuous_klines_{}_{}_{}.csv".format(
117
+ path, symbol, contractType, interval
118
+ ),
119
+ "a",
120
+ newline="",
121
+ ) as file:
122
+ writer = csv.writer(file)
123
+ # 时间戳倒序,插入文件尾部
124
+ writer.writerows(sorted(listData, key=lambda x: x[0], reverse=True))
125
+
126
+ # 拿到最后一条记录后,获取close时间戳,变为下一次截止时间戳
127
+ if latestRecords > 0:
128
+ nextEndTime = (
129
+ listData[0][0] - 1
130
+ ) # -1 不和close时间戳相同,避免重新拉取重复数据
131
+ errorCount = 0
132
+ logging.info(
133
+ "3、下次结束时间 {} {}".format(
134
+ format_timestamp(nextEndTime), nextEndTime
135
+ )
136
+ )
137
+
138
+ if nextEndTime <= hisDateTime and hisSwitch == 1:
139
+ break
140
+ else:
141
+ logging.info("4、结束...")
142
+
143
+ total = total + records
144
+ logging.info("5、{} 抓取数据 {} 条记录...".format(symbol, records))
145
+
146
+ logging.info("6、{} 抓取数据 {} 条记录...".format(symbol, total))
147
+ logging.info("{} symbol --------------------------------- ".format(symbol))
@@ -0,0 +1,37 @@
1
+ from __future__ import annotations
2
+
3
+ import logging
4
+
5
+ from pathlib import Path
6
+ from typing import TYPE_CHECKING
7
+ from poetry.factory import Factory as BaseFactory
8
+ from openfund.core.pyopenfund import Openfund
9
+
10
+ if TYPE_CHECKING:
11
+ from poetry.poetry import Poetry
12
+
13
+
14
+ logger = logging.getLogger(__name__)
15
+
16
+
17
+ class Factory(BaseFactory):
18
+ def __init__(self) -> None:
19
+ super().__init__()
20
+
21
+ def create_poetry(
22
+ self,
23
+ cwd: Path | None = None,
24
+ with_groups: bool = True,
25
+ ) -> Poetry:
26
+ poetry = super().create_poetry(cwd=cwd, with_groups=with_groups)
27
+ return poetry
28
+
29
+ def create_openfund(
30
+ self,
31
+ cwd: Path | None = None,
32
+ with_groups: bool = True,
33
+ ) -> Openfund:
34
+
35
+ poetry = self.create_poetry(cwd=cwd, with_groups=with_groups)
36
+
37
+ return Openfund(poetry)
@@ -0,0 +1,6 @@
1
+ from .email_tools import mail
2
+ from .time_tools import *
3
+ from enums import *
4
+ from .log_tools import Logger
5
+
6
+ from .prepare_env import *
@@ -0,0 +1,56 @@
1
+ #!/usr/bin/env python
2
+ import ssl
3
+ import os
4
+ import sys
5
+ import logging
6
+
7
+ import smtplib
8
+
9
+ from email.mime.text import MIMEText
10
+
11
+ from email.header import Header
12
+ from email.message import EmailMessage
13
+ import time
14
+
15
+ # app = "email_tools"
16
+ # logging.basicConfig(
17
+ # format="%(asctime)s %(name)s:%(levelname)s:%(message)s",
18
+ # datefmt="%Y-%m-%d %H:%M:%S",
19
+ # level=logging.DEBUG,
20
+ # )
21
+
22
+ curPath = os.path.abspath(os.path.dirname(__file__))
23
+ sys.path.append(curPath)
24
+
25
+ from prepare_env import get_mail
26
+
27
+ # logging.info("---- Read config.ini -----")
28
+ (email_address, email_password, email_receiver) = get_mail()
29
+ # logging.info(
30
+ # "---- Read config.ini Finish!----{0}||{1}".format(email_address, email_receiver)
31
+ # )
32
+
33
+
34
+ def mail(topic, content):
35
+ EMAIL_ADDRESS = email_address
36
+ EMAIL_PASSWORD = email_password
37
+ context = ssl.create_default_context()
38
+ sender = EMAIL_ADDRESS
39
+ receiver = email_receiver.split(",")
40
+
41
+ subject = topic
42
+ body = content
43
+ msg = EmailMessage()
44
+ msg["subject"] = subject
45
+ msg["From"] = sender
46
+ msg["To"] = receiver
47
+ msg.set_content(body)
48
+
49
+ with smtplib.SMTP_SSL("smtp.qq.com", 465, context=context) as smtp:
50
+ smtp.login(EMAIL_ADDRESS, EMAIL_PASSWORD)
51
+ smtp.send_message(msg)
52
+ print("---- send_message ----\n{0}".format(msg))
53
+
54
+
55
+ if __name__ == "__main__":
56
+ mail("QRR", "BTCUSDT [2023-12-04 21:44:59 ~ 2023-12-04 21:39:59],QRR=9.4 > 5")