py-ibkr 0.1.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.
Potentially problematic release.
This version of py-ibkr might be problematic. Click here for more details.
- py_ibkr-0.1.0/.github/workflows/ci.yml +35 -0
- py_ibkr-0.1.0/.github/workflows/publish.yml +33 -0
- py_ibkr-0.1.0/.gitignore +293 -0
- py_ibkr-0.1.0/CHANGELOG.md +13 -0
- py_ibkr-0.1.0/LICENSE +21 -0
- py_ibkr-0.1.0/MANIFEST.in +2 -0
- py_ibkr-0.1.0/PKG-INFO +82 -0
- py_ibkr-0.1.0/README.md +51 -0
- py_ibkr-0.1.0/examples/parse_report.py +41 -0
- py_ibkr-0.1.0/pyproject.toml +53 -0
- py_ibkr-0.1.0/src/py_ibkr/__init__.py +3 -0
- py_ibkr-0.1.0/src/py_ibkr/flex/__init__.py +7 -0
- py_ibkr-0.1.0/src/py_ibkr/flex/enums.py +235 -0
- py_ibkr-0.1.0/src/py_ibkr/flex/models.py +174 -0
- py_ibkr-0.1.0/src/py_ibkr/flex/parser.py +198 -0
- py_ibkr-0.1.0/src/py_ibkr/py.typed +0 -0
- py_ibkr-0.1.0/tests/smoke_test.py +12 -0
- py_ibkr-0.1.0/tests/test_integration.py +45 -0
- py_ibkr-0.1.0/tests/test_models.py +24 -0
- py_ibkr-0.1.0/tests/test_parser_utils.py +43 -0
- py_ibkr-0.1.0/uv.lock +492 -0
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
name: "CI"
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
branches:
|
|
6
|
+
- main
|
|
7
|
+
pull_request:
|
|
8
|
+
|
|
9
|
+
jobs:
|
|
10
|
+
test:
|
|
11
|
+
runs-on: ubuntu-latest
|
|
12
|
+
strategy:
|
|
13
|
+
matrix:
|
|
14
|
+
python-version:
|
|
15
|
+
- "3.10"
|
|
16
|
+
- "3.11"
|
|
17
|
+
- "3.12"
|
|
18
|
+
- "3.13"
|
|
19
|
+
- "3.14"
|
|
20
|
+
fail-fast: false
|
|
21
|
+
steps:
|
|
22
|
+
- name: Checkout
|
|
23
|
+
uses: actions/checkout@v6
|
|
24
|
+
|
|
25
|
+
- name: Install uv
|
|
26
|
+
uses: astral-sh/setup-uv@v5
|
|
27
|
+
|
|
28
|
+
- name: Set up Python ${{ matrix.python-version }}
|
|
29
|
+
run: uv python install ${{ matrix.python-version }}
|
|
30
|
+
|
|
31
|
+
- name: Install dependencies
|
|
32
|
+
run: uv sync --all-extras --dev
|
|
33
|
+
|
|
34
|
+
- name: Run tests
|
|
35
|
+
run: uv run pytest
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
name: "Publish"
|
|
2
|
+
# https://docs.astral.sh/uv/guides/integration/github/#publishing-to-pypi
|
|
3
|
+
|
|
4
|
+
on:
|
|
5
|
+
push:
|
|
6
|
+
tags:
|
|
7
|
+
# Publish on any tag starting with a `v`, e.g., v0.1.0
|
|
8
|
+
- v*
|
|
9
|
+
|
|
10
|
+
jobs:
|
|
11
|
+
run:
|
|
12
|
+
runs-on: ubuntu-latest
|
|
13
|
+
environment:
|
|
14
|
+
name: pypi
|
|
15
|
+
permissions:
|
|
16
|
+
id-token: write
|
|
17
|
+
contents: read
|
|
18
|
+
steps:
|
|
19
|
+
- name: Checkout
|
|
20
|
+
uses: actions/checkout@v6
|
|
21
|
+
- name: Install uv
|
|
22
|
+
uses: astral-sh/setup-uv@v5
|
|
23
|
+
- name: Install Python 3.12
|
|
24
|
+
run: uv python install 3.12
|
|
25
|
+
- name: Build
|
|
26
|
+
run: uv build
|
|
27
|
+
# Check that basic features work and we didn't miss to include crucial files
|
|
28
|
+
- name: Smoke test (wheel)
|
|
29
|
+
run: uv run --isolated --no-project --with dist/*.whl tests/smoke_test.py
|
|
30
|
+
- name: Smoke test (source distribution)
|
|
31
|
+
run: uv run --isolated --no-project --with dist/*.tar.gz tests/smoke_test.py
|
|
32
|
+
- name: Publish
|
|
33
|
+
run: uv publish
|
py_ibkr-0.1.0/.gitignore
ADDED
|
@@ -0,0 +1,293 @@
|
|
|
1
|
+
### VisualStudioCode template
|
|
2
|
+
.vscode/*
|
|
3
|
+
!.vscode/settings.json
|
|
4
|
+
!.vscode/tasks.json
|
|
5
|
+
!.vscode/launch.json
|
|
6
|
+
!.vscode/extensions.json
|
|
7
|
+
!.vscode/*.code-snippets
|
|
8
|
+
|
|
9
|
+
# Local History for Visual Studio Code
|
|
10
|
+
.history/
|
|
11
|
+
|
|
12
|
+
# Built Visual Studio Code Extensions
|
|
13
|
+
*.vsix
|
|
14
|
+
|
|
15
|
+
### JetBrains template
|
|
16
|
+
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio, WebStorm and Rider
|
|
17
|
+
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
|
|
18
|
+
|
|
19
|
+
# User-specific stuff
|
|
20
|
+
.idea/**/workspace.xml
|
|
21
|
+
.idea/**/tasks.xml
|
|
22
|
+
.idea/**/usage.statistics.xml
|
|
23
|
+
.idea/**/dictionaries
|
|
24
|
+
.idea/**/shelf
|
|
25
|
+
|
|
26
|
+
# AWS User-specific
|
|
27
|
+
.idea/**/aws.xml
|
|
28
|
+
|
|
29
|
+
# Generated files
|
|
30
|
+
.idea/**/contentModel.xml
|
|
31
|
+
|
|
32
|
+
# Sensitive or high-churn files
|
|
33
|
+
.idea/**/dataSources/
|
|
34
|
+
.idea/**/dataSources.ids
|
|
35
|
+
.idea/**/dataSources.local.xml
|
|
36
|
+
.idea/**/sqlDataSources.xml
|
|
37
|
+
.idea/**/dynamic.xml
|
|
38
|
+
.idea/**/uiDesigner.xml
|
|
39
|
+
.idea/**/dbnavigator.xml
|
|
40
|
+
|
|
41
|
+
# Gradle
|
|
42
|
+
.idea/**/gradle.xml
|
|
43
|
+
.idea/**/libraries
|
|
44
|
+
|
|
45
|
+
# Gradle and Maven with auto-import
|
|
46
|
+
# When using Gradle or Maven with auto-import, you should exclude module files,
|
|
47
|
+
# since they will be recreated, and may cause churn. Uncomment if using
|
|
48
|
+
# auto-import.
|
|
49
|
+
# .idea/artifacts
|
|
50
|
+
# .idea/compiler.xml
|
|
51
|
+
# .idea/jarRepositories.xml
|
|
52
|
+
# .idea/modules.xml
|
|
53
|
+
# .idea/*.iml
|
|
54
|
+
# .idea/modules
|
|
55
|
+
# *.iml
|
|
56
|
+
# *.ipr
|
|
57
|
+
|
|
58
|
+
# CMake
|
|
59
|
+
cmake-build-*/
|
|
60
|
+
|
|
61
|
+
# Mongo Explorer plugin
|
|
62
|
+
.idea/**/mongoSettings.xml
|
|
63
|
+
|
|
64
|
+
# File-based project format
|
|
65
|
+
*.iws
|
|
66
|
+
|
|
67
|
+
# IntelliJ
|
|
68
|
+
out/
|
|
69
|
+
|
|
70
|
+
# mpeltonen/sbt-idea plugin
|
|
71
|
+
.idea_modules/
|
|
72
|
+
|
|
73
|
+
# JIRA plugin
|
|
74
|
+
atlassian-ide-plugin.xml
|
|
75
|
+
|
|
76
|
+
# Cursive Clojure plugin
|
|
77
|
+
.idea/replstate.xml
|
|
78
|
+
|
|
79
|
+
# SonarLint plugin
|
|
80
|
+
.idea/sonarlint/
|
|
81
|
+
|
|
82
|
+
# Crashlytics plugin (for Android Studio and IntelliJ)
|
|
83
|
+
com_crashlytics_export_strings.xml
|
|
84
|
+
crashlytics.properties
|
|
85
|
+
crashlytics-build.properties
|
|
86
|
+
fabric.properties
|
|
87
|
+
|
|
88
|
+
# Editor-based Rest Client
|
|
89
|
+
.idea/httpRequests
|
|
90
|
+
|
|
91
|
+
# Android studio 3.1+ serialized cache file
|
|
92
|
+
.idea/caches/build_file_checksums.ser
|
|
93
|
+
|
|
94
|
+
### macOS template
|
|
95
|
+
# General
|
|
96
|
+
.DS_Store
|
|
97
|
+
.AppleDouble
|
|
98
|
+
.LSOverride
|
|
99
|
+
|
|
100
|
+
# Icon must end with two \r
|
|
101
|
+
Icon
|
|
102
|
+
|
|
103
|
+
# Thumbnails
|
|
104
|
+
._*
|
|
105
|
+
|
|
106
|
+
# Files that might appear in the root of a volume
|
|
107
|
+
.DocumentRevisions-V100
|
|
108
|
+
.fseventsd
|
|
109
|
+
.Spotlight-V100
|
|
110
|
+
.TemporaryItems
|
|
111
|
+
.Trashes
|
|
112
|
+
.VolumeIcon.icns
|
|
113
|
+
.com.apple.timemachine.donotpresent
|
|
114
|
+
|
|
115
|
+
# Directories potentially created on remote AFP share
|
|
116
|
+
.AppleDB
|
|
117
|
+
.AppleDesktop
|
|
118
|
+
Network Trash Folder
|
|
119
|
+
Temporary Items
|
|
120
|
+
.apdisk
|
|
121
|
+
|
|
122
|
+
### Python template
|
|
123
|
+
# Byte-compiled / optimized / DLL files
|
|
124
|
+
__pycache__/
|
|
125
|
+
*.py[cod]
|
|
126
|
+
*$py.class
|
|
127
|
+
|
|
128
|
+
# C extensions
|
|
129
|
+
*.so
|
|
130
|
+
|
|
131
|
+
# Distribution / packaging
|
|
132
|
+
.Python
|
|
133
|
+
build/
|
|
134
|
+
develop-eggs/
|
|
135
|
+
dist/
|
|
136
|
+
downloads/
|
|
137
|
+
eggs/
|
|
138
|
+
.eggs/
|
|
139
|
+
lib/
|
|
140
|
+
lib64/
|
|
141
|
+
parts/
|
|
142
|
+
sdist/
|
|
143
|
+
var/
|
|
144
|
+
wheels/
|
|
145
|
+
share/python-wheels/
|
|
146
|
+
*.egg-info/
|
|
147
|
+
.installed.cfg
|
|
148
|
+
*.egg
|
|
149
|
+
MANIFEST
|
|
150
|
+
|
|
151
|
+
# PyInstaller
|
|
152
|
+
# Usually these files are written by a python script from a template
|
|
153
|
+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
|
|
154
|
+
*.manifest
|
|
155
|
+
*.spec
|
|
156
|
+
|
|
157
|
+
# Installer logs
|
|
158
|
+
pip-log.txt
|
|
159
|
+
pip-delete-this-directory.txt
|
|
160
|
+
|
|
161
|
+
# Unit test / coverage reports
|
|
162
|
+
htmlcov/
|
|
163
|
+
.tox/
|
|
164
|
+
.nox/
|
|
165
|
+
.coverage
|
|
166
|
+
.coverage.*
|
|
167
|
+
.cache
|
|
168
|
+
nosetests.xml
|
|
169
|
+
coverage.xml
|
|
170
|
+
*.cover
|
|
171
|
+
*.py,cover
|
|
172
|
+
.hypothesis/
|
|
173
|
+
.pytest_cache/
|
|
174
|
+
cover/
|
|
175
|
+
|
|
176
|
+
# Translations
|
|
177
|
+
*.mo
|
|
178
|
+
*.pot
|
|
179
|
+
|
|
180
|
+
# Django stuff:
|
|
181
|
+
*.log
|
|
182
|
+
local_settings.py
|
|
183
|
+
db.sqlite3
|
|
184
|
+
db.sqlite3-journal
|
|
185
|
+
|
|
186
|
+
# Flask stuff:
|
|
187
|
+
instance/
|
|
188
|
+
.webassets-cache
|
|
189
|
+
|
|
190
|
+
# Scrapy stuff:
|
|
191
|
+
.scrapy
|
|
192
|
+
|
|
193
|
+
# Sphinx documentation
|
|
194
|
+
docs/_build/
|
|
195
|
+
|
|
196
|
+
# PyBuilder
|
|
197
|
+
.pybuilder/
|
|
198
|
+
target/
|
|
199
|
+
|
|
200
|
+
# Jupyter Notebook
|
|
201
|
+
.ipynb_checkpoints
|
|
202
|
+
|
|
203
|
+
# IPython
|
|
204
|
+
profile_default/
|
|
205
|
+
ipython_config.py
|
|
206
|
+
|
|
207
|
+
# pyenv
|
|
208
|
+
# For a library or package, you might want to ignore these files since the code is
|
|
209
|
+
# intended to run in multiple environments; otherwise, check them in:
|
|
210
|
+
# .python-version
|
|
211
|
+
|
|
212
|
+
# pipenv
|
|
213
|
+
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
|
|
214
|
+
# However, in case of collaboration, if having platform-specific dependencies or dependencies
|
|
215
|
+
# having no cross-platform support, pipenv may install dependencies that don't work, or not
|
|
216
|
+
# install all needed dependencies.
|
|
217
|
+
#Pipfile.lock
|
|
218
|
+
|
|
219
|
+
# poetry
|
|
220
|
+
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
|
|
221
|
+
# This is especially recommended for binary packages to ensure reproducibility, and is more
|
|
222
|
+
# commonly ignored for libraries.
|
|
223
|
+
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
|
|
224
|
+
#poetry.lock
|
|
225
|
+
|
|
226
|
+
# pdm
|
|
227
|
+
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
|
|
228
|
+
#pdm.lock
|
|
229
|
+
# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
|
|
230
|
+
# in version control.
|
|
231
|
+
# https://pdm.fming.dev/latest/usage/project/#working-with-version-control
|
|
232
|
+
.pdm.toml
|
|
233
|
+
.pdm-python
|
|
234
|
+
.pdm-build/
|
|
235
|
+
|
|
236
|
+
# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
|
|
237
|
+
__pypackages__/
|
|
238
|
+
|
|
239
|
+
# Celery stuff
|
|
240
|
+
celerybeat-schedule
|
|
241
|
+
celerybeat.pid
|
|
242
|
+
|
|
243
|
+
# SageMath parsed files
|
|
244
|
+
*.sage.py
|
|
245
|
+
|
|
246
|
+
# Environments
|
|
247
|
+
.env
|
|
248
|
+
.venv
|
|
249
|
+
env/
|
|
250
|
+
venv/
|
|
251
|
+
ENV/
|
|
252
|
+
env.bak/
|
|
253
|
+
venv.bak/
|
|
254
|
+
|
|
255
|
+
# Spyder project settings
|
|
256
|
+
.spyderproject
|
|
257
|
+
.spyproject
|
|
258
|
+
|
|
259
|
+
# Rope project settings
|
|
260
|
+
.ropeproject
|
|
261
|
+
|
|
262
|
+
# mkdocs documentation
|
|
263
|
+
/site
|
|
264
|
+
|
|
265
|
+
# mypy
|
|
266
|
+
.mypy_cache/
|
|
267
|
+
.dmypy.json
|
|
268
|
+
dmypy.json
|
|
269
|
+
|
|
270
|
+
# Pyre type checker
|
|
271
|
+
.pyre/
|
|
272
|
+
|
|
273
|
+
# pytype static type analyzer
|
|
274
|
+
.pytype/
|
|
275
|
+
|
|
276
|
+
# Cython debug symbols
|
|
277
|
+
cython_debug/
|
|
278
|
+
|
|
279
|
+
# PyCharm
|
|
280
|
+
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
|
|
281
|
+
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
|
|
282
|
+
# and can be added to the global gitignore or merged into this file. For a more nuclear
|
|
283
|
+
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
|
|
284
|
+
#.idea/
|
|
285
|
+
|
|
286
|
+
/.idea/inspectionProfiles/profiles_settings.xml
|
|
287
|
+
/.idea/inspectionProfiles/Project_Default.xml
|
|
288
|
+
/.idea/.gitignore
|
|
289
|
+
/.idea/json_assistant_history.xml
|
|
290
|
+
/.idea/misc.xml
|
|
291
|
+
/.idea/modules.xml
|
|
292
|
+
/.idea/pydantic-ib.iml
|
|
293
|
+
/.idea/vcs.xml
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to this project will be documented in this file.
|
|
4
|
+
|
|
5
|
+
## [0.1.0] - 2026-02-05
|
|
6
|
+
|
|
7
|
+
### Added
|
|
8
|
+
- Initial release of `py-ibkr`.
|
|
9
|
+
- Pydantic models for IBKR Flex Query.
|
|
10
|
+
- Parser for XML Flex Query reports.
|
|
11
|
+
- Support for Trade and CashTransaction models.
|
|
12
|
+
- OSS packaging standards (LICENSE, MANIFEST.in, py.typed).
|
|
13
|
+
- GitHub Actions for CI and PyPI publication.
|
py_ibkr-0.1.0/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Roman Medvedev
|
|
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.
|
py_ibkr-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: py-ibkr
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: A modern, Pydantic-based parser for Interactive Brokers (IBKR) Flex Query reports
|
|
5
|
+
Project-URL: Homepage, https://github.com/romamo/py-ibkr
|
|
6
|
+
Project-URL: Repository, https://github.com/romamo/py-ibkr
|
|
7
|
+
Project-URL: Issues, https://github.com/romamo/py-ibkr/issues
|
|
8
|
+
Author-email: Roman Medvedev <pypi@romavm.dev>
|
|
9
|
+
License: MIT
|
|
10
|
+
License-File: LICENSE
|
|
11
|
+
Keywords: finance,flex-query,ibkr,interactive-brokers,pydantic
|
|
12
|
+
Classifier: Development Status :: 4 - Beta
|
|
13
|
+
Classifier: Intended Audience :: Developers
|
|
14
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
15
|
+
Classifier: Programming Language :: Python :: 3
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
21
|
+
Classifier: Topic :: Office/Business :: Financial :: Investment
|
|
22
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
23
|
+
Requires-Python: >=3.10
|
|
24
|
+
Requires-Dist: pydantic>=2.0
|
|
25
|
+
Provides-Extra: dev
|
|
26
|
+
Requires-Dist: mypy; extra == 'dev'
|
|
27
|
+
Requires-Dist: pytest; extra == 'dev'
|
|
28
|
+
Requires-Dist: ruff; extra == 'dev'
|
|
29
|
+
Requires-Dist: types-python-dateutil; extra == 'dev'
|
|
30
|
+
Description-Content-Type: text/markdown
|
|
31
|
+
|
|
32
|
+
# py-ibkr
|
|
33
|
+
|
|
34
|
+
A modern, Pydantic-based parser for Interactive Brokers (IBKR) Flex Query reports.
|
|
35
|
+
This version replaces the legacy `ibflex` library with strict type checking and improved support for newer IBKR XML fields.
|
|
36
|
+
|
|
37
|
+
## Features
|
|
38
|
+
- **Pydantic Models**: All data is parsed into typed Pydantic models with validation.
|
|
39
|
+
- **Robust Parsing**: Handles "messy" IBKR data (e.g., legacy enums like `Deposits/Withdrawals`, inconsistent date formats).
|
|
40
|
+
- **Forward Compatible**: Designed to handle new fields gracefully.
|
|
41
|
+
|
|
42
|
+
## Installation
|
|
43
|
+
|
|
44
|
+
```bash
|
|
45
|
+
uv pip install py-ibkr
|
|
46
|
+
# or
|
|
47
|
+
pip install py-ibkr
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
## Usage
|
|
51
|
+
|
|
52
|
+
### Parsing a Flex Query File
|
|
53
|
+
|
|
54
|
+
```python
|
|
55
|
+
from py_ibkr import parse, FlexQueryResponse
|
|
56
|
+
|
|
57
|
+
response = parse("path/to/report.xml")
|
|
58
|
+
|
|
59
|
+
print(f"Query Name: {response.queryName}")
|
|
60
|
+
|
|
61
|
+
for statement in response.FlexStatements:
|
|
62
|
+
print(f"Account: {statement.accountId}")
|
|
63
|
+
|
|
64
|
+
# Access Trades
|
|
65
|
+
for trade in statement.Trades:
|
|
66
|
+
print(f"Symbol: {trade.symbol}, Quantity: {trade.quantity}, Price: {trade.tradePrice}")
|
|
67
|
+
|
|
68
|
+
# Access Cash Transactions
|
|
69
|
+
for cash_tx in statement.CashTransactions:
|
|
70
|
+
print(f"Type: {cash_tx.type}, Amount: {cash_tx.amount}")
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
### Models
|
|
74
|
+
|
|
75
|
+
You can import models directly for type hinting:
|
|
76
|
+
|
|
77
|
+
```python
|
|
78
|
+
from py_ibkr import Trade, CashTransaction
|
|
79
|
+
|
|
80
|
+
def process_trade(trade: Trade):
|
|
81
|
+
print(trade.symbol)
|
|
82
|
+
```
|
py_ibkr-0.1.0/README.md
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
# py-ibkr
|
|
2
|
+
|
|
3
|
+
A modern, Pydantic-based parser for Interactive Brokers (IBKR) Flex Query reports.
|
|
4
|
+
This version replaces the legacy `ibflex` library with strict type checking and improved support for newer IBKR XML fields.
|
|
5
|
+
|
|
6
|
+
## Features
|
|
7
|
+
- **Pydantic Models**: All data is parsed into typed Pydantic models with validation.
|
|
8
|
+
- **Robust Parsing**: Handles "messy" IBKR data (e.g., legacy enums like `Deposits/Withdrawals`, inconsistent date formats).
|
|
9
|
+
- **Forward Compatible**: Designed to handle new fields gracefully.
|
|
10
|
+
|
|
11
|
+
## Installation
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
uv pip install py-ibkr
|
|
15
|
+
# or
|
|
16
|
+
pip install py-ibkr
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
## Usage
|
|
20
|
+
|
|
21
|
+
### Parsing a Flex Query File
|
|
22
|
+
|
|
23
|
+
```python
|
|
24
|
+
from py_ibkr import parse, FlexQueryResponse
|
|
25
|
+
|
|
26
|
+
response = parse("path/to/report.xml")
|
|
27
|
+
|
|
28
|
+
print(f"Query Name: {response.queryName}")
|
|
29
|
+
|
|
30
|
+
for statement in response.FlexStatements:
|
|
31
|
+
print(f"Account: {statement.accountId}")
|
|
32
|
+
|
|
33
|
+
# Access Trades
|
|
34
|
+
for trade in statement.Trades:
|
|
35
|
+
print(f"Symbol: {trade.symbol}, Quantity: {trade.quantity}, Price: {trade.tradePrice}")
|
|
36
|
+
|
|
37
|
+
# Access Cash Transactions
|
|
38
|
+
for cash_tx in statement.CashTransactions:
|
|
39
|
+
print(f"Type: {cash_tx.type}, Amount: {cash_tx.amount}")
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
### Models
|
|
43
|
+
|
|
44
|
+
You can import models directly for type hinting:
|
|
45
|
+
|
|
46
|
+
```python
|
|
47
|
+
from py_ibkr import Trade, CashTransaction
|
|
48
|
+
|
|
49
|
+
def process_trade(trade: Trade):
|
|
50
|
+
print(trade.symbol)
|
|
51
|
+
```
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Example script to parse an IBKR Flex Query XML file.
|
|
3
|
+
"""
|
|
4
|
+
|
|
5
|
+
from pathlib import Path
|
|
6
|
+
|
|
7
|
+
from py_ibkr import parse
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
def main():
|
|
11
|
+
# Attempt to locate sample file
|
|
12
|
+
# In a real scenario, provide your own path
|
|
13
|
+
sample_path = Path("path/to/report.xml")
|
|
14
|
+
|
|
15
|
+
if not sample_path.exists():
|
|
16
|
+
print(f"Sample file not found at {sample_path}")
|
|
17
|
+
return
|
|
18
|
+
|
|
19
|
+
print(f"Parsing {sample_path}...")
|
|
20
|
+
try:
|
|
21
|
+
response = parse(str(sample_path))
|
|
22
|
+
print("Successfully parsed.")
|
|
23
|
+
print("-" * 30)
|
|
24
|
+
|
|
25
|
+
for stmt in response.FlexStatements:
|
|
26
|
+
print(f"Account: {stmt.accountId}")
|
|
27
|
+
print(f"Trades Count: {len(stmt.Trades)}")
|
|
28
|
+
print(f"Cash Tx Count: {len(stmt.CashTransactions)}")
|
|
29
|
+
|
|
30
|
+
if stmt.Trades:
|
|
31
|
+
last_trade = stmt.Trades[-1]
|
|
32
|
+
print(
|
|
33
|
+
f"Last Trade: {last_trade.buySell.value} {last_trade.quantity} {last_trade.symbol} @ {last_trade.tradePrice}"
|
|
34
|
+
)
|
|
35
|
+
|
|
36
|
+
except Exception as e:
|
|
37
|
+
print(f"Error parsing file: {e}")
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
if __name__ == "__main__":
|
|
41
|
+
main()
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
[project]
|
|
2
|
+
name = "py-ibkr"
|
|
3
|
+
version = "0.1.0"
|
|
4
|
+
description = "A modern, Pydantic-based parser for Interactive Brokers (IBKR) Flex Query reports"
|
|
5
|
+
readme = "README.md"
|
|
6
|
+
authors = [
|
|
7
|
+
{ name = "Roman Medvedev", email = "pypi@romavm.dev" },
|
|
8
|
+
]
|
|
9
|
+
license = { text = "MIT" }
|
|
10
|
+
requires-python = ">=3.10"
|
|
11
|
+
keywords = ["ibkr", "pydantic", "flex-query", "interactive-brokers", "finance"]
|
|
12
|
+
classifiers = [
|
|
13
|
+
"Development Status :: 4 - Beta",
|
|
14
|
+
"Intended Audience :: Developers",
|
|
15
|
+
"License :: OSI Approved :: MIT License",
|
|
16
|
+
"Programming Language :: Python :: 3",
|
|
17
|
+
"Programming Language :: Python :: 3.10",
|
|
18
|
+
"Programming Language :: Python :: 3.11",
|
|
19
|
+
"Programming Language :: Python :: 3.12",
|
|
20
|
+
"Programming Language :: Python :: 3.13",
|
|
21
|
+
"Programming Language :: Python :: 3.14",
|
|
22
|
+
"Topic :: Software Development :: Libraries :: Python Modules",
|
|
23
|
+
"Topic :: Office/Business :: Financial :: Investment",
|
|
24
|
+
]
|
|
25
|
+
|
|
26
|
+
dependencies = [
|
|
27
|
+
"pydantic>=2.0",
|
|
28
|
+
]
|
|
29
|
+
|
|
30
|
+
[project.optional-dependencies]
|
|
31
|
+
dev = [
|
|
32
|
+
"ruff",
|
|
33
|
+
"mypy",
|
|
34
|
+
"types-python-dateutil",
|
|
35
|
+
"pytest",
|
|
36
|
+
]
|
|
37
|
+
|
|
38
|
+
[project.urls]
|
|
39
|
+
Homepage = "https://github.com/romamo/py-ibkr"
|
|
40
|
+
Repository = "https://github.com/romamo/py-ibkr"
|
|
41
|
+
Issues = "https://github.com/romamo/py-ibkr/issues"
|
|
42
|
+
|
|
43
|
+
[tool.ruff]
|
|
44
|
+
line-length = 100
|
|
45
|
+
target-version = "py310"
|
|
46
|
+
|
|
47
|
+
[tool.ruff.lint]
|
|
48
|
+
select = ["E", "F", "I", "UP", "B"]
|
|
49
|
+
ignore = []
|
|
50
|
+
|
|
51
|
+
[build-system]
|
|
52
|
+
requires = ["hatchling"]
|
|
53
|
+
build-backend = "hatchling.build"
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
from .models import CashTransaction as CashTransaction
|
|
2
|
+
from .models import FlexQueryResponse as FlexQueryResponse
|
|
3
|
+
from .models import FlexStatement as FlexStatement
|
|
4
|
+
from .models import Trade as Trade
|
|
5
|
+
from .parser import parse_xml_file as parse
|
|
6
|
+
|
|
7
|
+
__all__ = ["FlexQueryResponse", "FlexStatement", "Trade", "CashTransaction", "parse"]
|