project-x-py 0.2.0__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 (35) hide show
  1. project_x_py-0.2.0/.gitignore +283 -0
  2. project_x_py-0.2.0/CHANGELOG.md +162 -0
  3. project_x_py-0.2.0/LICENSE +21 -0
  4. project_x_py-0.2.0/PKG-INFO +676 -0
  5. project_x_py-0.2.0/README.md +603 -0
  6. project_x_py-0.2.0/docs/Makefile +39 -0
  7. project_x_py-0.2.0/docs/README.md +168 -0
  8. project_x_py-0.2.0/docs/_static/custom.css +113 -0
  9. project_x_py-0.2.0/docs/api/client.rst +52 -0
  10. project_x_py-0.2.0/docs/api/data.rst +96 -0
  11. project_x_py-0.2.0/docs/api/models.rst +120 -0
  12. project_x_py-0.2.0/docs/api/trading.rst +76 -0
  13. project_x_py-0.2.0/docs/api/utilities.rst +61 -0
  14. project_x_py-0.2.0/docs/authentication.rst +277 -0
  15. project_x_py-0.2.0/docs/conf.py +198 -0
  16. project_x_py-0.2.0/docs/configuration.rst +400 -0
  17. project_x_py-0.2.0/docs/index.rst +143 -0
  18. project_x_py-0.2.0/docs/installation.rst +161 -0
  19. project_x_py-0.2.0/docs/make.bat +35 -0
  20. project_x_py-0.2.0/docs/quickstart.rst +243 -0
  21. project_x_py-0.2.0/pyproject.toml +275 -0
  22. project_x_py-0.2.0/src/project_x_py/__init__.py +550 -0
  23. project_x_py-0.2.0/src/project_x_py/client.py +1241 -0
  24. project_x_py-0.2.0/src/project_x_py/config.py +338 -0
  25. project_x_py-0.2.0/src/project_x_py/exceptions.py +63 -0
  26. project_x_py-0.2.0/src/project_x_py/models.py +275 -0
  27. project_x_py-0.2.0/src/project_x_py/order_manager.py +1186 -0
  28. project_x_py-0.2.0/src/project_x_py/orderbook.py +2071 -0
  29. project_x_py-0.2.0/src/project_x_py/position_manager.py +1140 -0
  30. project_x_py-0.2.0/src/project_x_py/py.typed +0 -0
  31. project_x_py-0.2.0/src/project_x_py/realtime.py +1128 -0
  32. project_x_py-0.2.0/src/project_x_py/realtime_data_manager.py +1003 -0
  33. project_x_py-0.2.0/src/project_x_py/utils.py +1890 -0
  34. project_x_py-0.2.0/tests/__init__.py +6 -0
  35. project_x_py-0.2.0/tests/test_client.py +213 -0
@@ -0,0 +1,283 @@
1
+ # Byte-compiled / optimized / DLL files
2
+ __pycache__/
3
+ *.py[cod]
4
+ *$py.class
5
+
6
+ # C extensions
7
+ *.so
8
+
9
+ # Distribution / packaging
10
+ .Python
11
+ build/
12
+ develop-eggs/
13
+ dist/
14
+ downloads/
15
+ eggs/
16
+ .eggs/
17
+ lib/
18
+ lib64/
19
+ parts/
20
+ sdist/
21
+ var/
22
+ wheels/
23
+ share/python-wheels/
24
+ *.egg-info/
25
+ .installed.cfg
26
+ *.egg
27
+ MANIFEST
28
+
29
+ # PyInstaller
30
+ # Usually these files are written by a python script from a template
31
+ # before PyInstaller builds the exe, so as to inject date/other infos into it.
32
+ *.manifest
33
+ *.spec
34
+
35
+ # Installer logs
36
+ pip-log.txt
37
+ pip-delete-this-directory.txt
38
+
39
+ # Unit test / coverage reports
40
+ htmlcov/
41
+ .tox/
42
+ .nox/
43
+ .coverage
44
+ .coverage.*
45
+ .cache
46
+ nosetests.xml
47
+ coverage.xml
48
+ *.cover
49
+ *.py,cover
50
+ .hypothesis/
51
+ .pytest_cache/
52
+ cover/
53
+
54
+ # Translations
55
+ *.mo
56
+ *.pot
57
+
58
+ # Django stuff:
59
+ *.log
60
+ local_settings.py
61
+ db.sqlite3
62
+ db.sqlite3-journal
63
+
64
+ # Flask stuff:
65
+ instance/
66
+ .webassets-cache
67
+
68
+ # Scrapy stuff:
69
+ .scrapy
70
+
71
+ # Sphinx documentation
72
+ docs/_build/
73
+
74
+ # PyBuilder
75
+ .pybuilder/
76
+ target/
77
+
78
+ # Jupyter Notebook
79
+ .ipynb_checkpoints
80
+
81
+ # IPython
82
+ profile_default/
83
+ ipython_config.py
84
+
85
+ # pyenv
86
+ # For a library or package, you might want to ignore these files since the code is
87
+ # intended to run in multiple environments; otherwise, check them in:
88
+ # .python-version
89
+
90
+ # pipenv
91
+ # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
92
+ # However, in case of collaboration, if having platform-specific dependencies or dependencies
93
+ # having no cross-platform support, pipenv may install dependencies that don't work, or not
94
+ # install all needed dependencies.
95
+ #Pipfile.lock
96
+
97
+ # poetry
98
+ # Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
99
+ # This is especially recommended for binary packages to ensure reproducibility, and is more
100
+ # commonly ignored for libraries.
101
+ # https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
102
+ #poetry.lock
103
+
104
+ # pdm
105
+ # Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
106
+ #pdm.lock
107
+ # pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
108
+ # in version control.
109
+ # https://pdm.fming.dev/#use-with-ide
110
+ .pdm.toml
111
+
112
+ # PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
113
+ __pypackages__/
114
+
115
+ # Celery stuff
116
+ celerybeat-schedule
117
+ celerybeat.pid
118
+
119
+ # SageMath parsed files
120
+ *.sage.py
121
+
122
+ # Environments
123
+ .env
124
+ .venv
125
+ env/
126
+ venv/
127
+ ENV/
128
+ env.bak/
129
+ venv.bak/
130
+
131
+ # Spyder project settings
132
+ .spyderproject
133
+ .spyproject
134
+
135
+ # Rope project settings
136
+ .ropeproject
137
+
138
+ # mkdocs documentation
139
+ /site
140
+
141
+ # mypy
142
+ .mypy_cache/
143
+ .dmypy.json
144
+ dmypy.json
145
+
146
+ # Pyre type checker
147
+ .pyre/
148
+
149
+ # pytype static type analyzer
150
+ .pytype/
151
+
152
+ # Cython debug symbols
153
+ cython_debug/
154
+
155
+ # PyCharm
156
+ # JetBrains specific template is maintained in a separate JetBrains.gitignore that can
157
+ # be added to the global gitignore or merged into this file. For a more nuclear
158
+ # option (not recommended) you can uncomment the following to ignore the entire idea folder.
159
+ #.idea/
160
+
161
+ # VS Code
162
+ .vscode/
163
+ *.code-workspace
164
+
165
+ # Sublime Text
166
+ *.sublime-project
167
+ *.sublime-workspace
168
+
169
+ # Vim
170
+ *.swp
171
+ *.swo
172
+ *~
173
+
174
+ # Emacs
175
+ *~
176
+ \#*\#
177
+ /.emacs.desktop
178
+ /.emacs.desktop.lock
179
+ *.elc
180
+ auto-save-list
181
+ tramp
182
+ .\#*
183
+
184
+ # macOS
185
+ .DS_Store
186
+ .AppleDouble
187
+ .LSOverride
188
+ Icon
189
+ ._*
190
+ .DocumentRevisions-V100
191
+ .fseventsd
192
+ .Spotlight-V100
193
+ .TemporaryItems
194
+ .Trashes
195
+ .VolumeIcon.icns
196
+ .com.apple.timemachine.donotpresent
197
+ .AppleDB
198
+ .AppleDesktop
199
+ Network Trash Folder
200
+ Temporary Items
201
+ .apdisk
202
+
203
+ # Windows
204
+ Thumbs.db
205
+ Thumbs.db:encryptable
206
+ ehthumbs.db
207
+ ehthumbs_vista.db
208
+ *.tmp
209
+ *.temp
210
+ Desktop.ini
211
+ $RECYCLE.BIN/
212
+ *.cab
213
+ *.msi
214
+ *.msix
215
+ *.msm
216
+ *.msp
217
+ *.lnk
218
+
219
+ # Linux
220
+ *~
221
+ .fuse_hidden*
222
+ .directory
223
+ .Trash-*
224
+ .nfs*
225
+
226
+ # Project-specific
227
+ config.json
228
+ *.key
229
+ *.pem
230
+ *.crt
231
+ *.p12
232
+ *.jks
233
+ secrets/
234
+ private/
235
+
236
+ # Trading/Financial data
237
+ data/
238
+ logs/
239
+ backups/
240
+ *.csv
241
+ *.xlsx
242
+ *.db
243
+
244
+ # Temporary files
245
+ tmp/
246
+ temp/
247
+ scratch/
248
+
249
+ # IDE and editor files
250
+ .idea/
251
+ *.iml
252
+ .project
253
+ .pydevproject
254
+ .settings/
255
+ .classpath
256
+
257
+ # Backup files
258
+ *.bak
259
+ *.backup
260
+ *.orig
261
+ *.save
262
+
263
+ # Compiled documentation
264
+ docs/build/
265
+ docs/_build/
266
+ docs/dist/
267
+
268
+ # Local configuration files
269
+ local_config.py
270
+ local_settings.py
271
+ .local/
272
+
273
+ # API keys and secrets (project-specific patterns)
274
+ *api_key*
275
+ *secret*
276
+ *password*
277
+ *token*
278
+ .env.local
279
+ .env.development
280
+ .env.test
281
+ .env.production
282
+ .env
283
+ test.py
@@ -0,0 +1,162 @@
1
+ # Changelog
2
+
3
+ All notable changes to the ProjectX Python client will be documented in this file.
4
+
5
+ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6
+ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
+
8
+ ## [0.2.0] - 2025-01-28
9
+
10
+ ### Added
11
+ - **Modular Architecture**: Split large monolithic file into logical modules
12
+ - `client.py` - Main ProjectX client class
13
+ - `models.py` - Data models and configuration
14
+ - `exceptions.py` - Custom exception hierarchy
15
+ - `utils.py` - Utility functions and helpers
16
+ - `config.py` - Configuration management
17
+ - **Enhanced Error Handling**: Comprehensive exception hierarchy with specific error types
18
+ - `ProjectXAuthenticationError` for auth failures
19
+ - `ProjectXServerError` for 5xx errors
20
+ - `ProjectXRateLimitError` for rate limiting
21
+ - `ProjectXConnectionError` for network issues
22
+ - `ProjectXDataError` for data validation errors
23
+ - **Configuration Management**:
24
+ - Environment variable support with `PROJECTX_*` prefix
25
+ - JSON configuration file support
26
+ - Default configuration with overrides
27
+ - Configuration validation and templates
28
+ - **Professional Package Structure**:
29
+ - Proper `pyproject.toml` with optional dependencies
30
+ - Comprehensive README with examples
31
+ - MIT license
32
+ - Test framework setup with pytest
33
+ - Development tools configuration (ruff, mypy, black)
34
+ - **Enhanced API Design**:
35
+ - Factory methods: `ProjectX.from_env()`, `ProjectX.from_config_file()`
36
+ - Improved type hints throughout
37
+ - Better documentation and examples
38
+ - Consistent error handling patterns
39
+ - **Utility Functions**:
40
+ - `setup_logging()` for consistent logging
41
+ - `get_env_var()` for environment variable handling
42
+ - `format_price()` and `format_volume()` for display
43
+ - `is_market_hours()` for market timing
44
+ - `RateLimiter` class for API rate limiting
45
+
46
+ ### Changed
47
+ - **Breaking**: Restructured package imports - use `from project_x_py import ProjectX` instead of importing from `__init__.py`
48
+ - **Breaking**: Configuration now uses `ProjectXConfig` dataclass instead of hardcoded values
49
+ - **Improved**: Better error messages with specific exception types
50
+ - **Enhanced**: Client initialization with lazy authentication
51
+ - **Updated**: Package metadata and PyPI classifiers
52
+
53
+ ### Improved
54
+ - **Documentation**: Comprehensive README with installation, usage, and examples
55
+ - **Code Quality**: Improved type hints, docstrings, and code organization
56
+ - **Testing**: Basic test framework with pytest fixtures and mocks
57
+ - **Development**: Better development workflow with linting and formatting tools
58
+
59
+ ### Dependencies
60
+ - **Core**: `polars>=1.31.0`, `pytz>=2025.2`, `requests>=2.32.4`
61
+ - **Optional Realtime**: `signalrcore>=0.9.5`, `websocket-client>=1.0.0`
62
+ - **Development**: `pytest`, `ruff`, `mypy`, `black`, `isort`
63
+
64
+ ## [0.1.0] - 2025-01-01
65
+
66
+ ### Added
67
+ - Initial release with basic trading functionality
68
+ - ProjectX Gateway API client
69
+ - Real-time data management via WebSocket
70
+ - Order placement, modification, and cancellation
71
+ - Position and trade management
72
+ - Historical market data retrieval
73
+ - Multi-timeframe data synchronization
74
+
75
+ ### Features
76
+ - Authentication with TopStepX API
77
+ - Account management
78
+ - Instrument search and contract details
79
+ - OHLCV historical data with polars DataFrames
80
+ - Real-time market data streams
81
+ - Level 2 market depth data
82
+ - Comprehensive logging
83
+
84
+ ---
85
+
86
+ ## Release Notes
87
+
88
+ ### Upgrading to v0.2.0
89
+
90
+ If you're upgrading from v0.1.0, please note the following breaking changes:
91
+
92
+ 1. **Import Changes**:
93
+ ```python
94
+ # Old (v0.1.0)
95
+ from project_x_py import ProjectX
96
+
97
+ # New (v0.2.0) - same import, but underlying structure changed
98
+ from project_x_py import ProjectX # Still works
99
+ ```
100
+
101
+ 2. **Environment Variables**:
102
+ ```bash
103
+ # Required (same as before)
104
+ export PROJECT_X_API_KEY="your_api_key"
105
+ export PROJECT_X_USERNAME="your_username"
106
+
107
+ # New optional configuration variables
108
+ export PROJECTX_API_URL="https://api.topstepx.com/api"
109
+ export PROJECTX_TIMEOUT_SECONDS="30"
110
+ export PROJECTX_RETRY_ATTEMPTS="3"
111
+ ```
112
+
113
+ 3. **Client Initialization**:
114
+ ```python
115
+ # Recommended new approach
116
+ client = ProjectX.from_env() # Uses environment variables
117
+
118
+ # Or with explicit credentials (same as before)
119
+ client = ProjectX(username="user", api_key="key")
120
+
121
+ # Or with custom configuration
122
+ config = ProjectXConfig(timeout_seconds=60)
123
+ client = ProjectX.from_env(config=config)
124
+ ```
125
+
126
+ 4. **Error Handling**:
127
+ ```python
128
+ # New specific exception types
129
+ try:
130
+ client = ProjectX.from_env()
131
+ account = client.get_account_info()
132
+ except ProjectXAuthenticationError:
133
+ print("Authentication failed")
134
+ except ProjectXServerError:
135
+ print("Server error")
136
+ except ProjectXError:
137
+ print("General ProjectX error")
138
+ ```
139
+
140
+ ### Migration Guide
141
+
142
+ 1. **Update imports**: No changes needed - existing imports still work
143
+ 2. **Update error handling**: Consider using specific exception types
144
+ 3. **Use new factory methods**: `ProjectX.from_env()` is now recommended
145
+ 4. **Optional**: Set up configuration file for advanced settings
146
+ 5. **Optional**: Use new utility functions for logging and formatting
147
+
148
+ ### New Installation Options
149
+
150
+ ```bash
151
+ # Basic installation (same as before)
152
+ pip install project-x-py
153
+
154
+ # With real-time features
155
+ pip install project-x-py[realtime]
156
+
157
+ # With development tools
158
+ pip install project-x-py[dev]
159
+
160
+ # Everything
161
+ pip install project-x-py[all]
162
+ ```
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Jeff West
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.