anybroker 0.1.1__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 (58) hide show
  1. anybroker-0.1.1/.github/workflows/ci.yml +63 -0
  2. anybroker-0.1.1/.gitignore +16 -0
  3. anybroker-0.1.1/CHANGELOG.md +37 -0
  4. anybroker-0.1.1/CONTRIBUTING.md +56 -0
  5. anybroker-0.1.1/LICENSE +21 -0
  6. anybroker-0.1.1/PKG-INFO +180 -0
  7. anybroker-0.1.1/README.md +112 -0
  8. anybroker-0.1.1/docs/api-reference.md +150 -0
  9. anybroker-0.1.1/docs/comparisons.md +46 -0
  10. anybroker-0.1.1/docs/getting-started.md +145 -0
  11. anybroker-0.1.1/docs/launch-drafts.md +54 -0
  12. anybroker-0.1.1/docs/positioning.md +86 -0
  13. anybroker-0.1.1/docs/pypi-release.md +23 -0
  14. anybroker-0.1.1/docs/start-here.md +88 -0
  15. anybroker-0.1.1/docs/superpowers/plans/2026-12-02-public-onboarding.md +21 -0
  16. anybroker-0.1.1/docs/validation.md +66 -0
  17. anybroker-0.1.1/examples/demo.py +148 -0
  18. anybroker-0.1.1/examples/offline_strategy.py +58 -0
  19. anybroker-0.1.1/pyproject.toml +98 -0
  20. anybroker-0.1.1/src/anybroker/__init__.py +54 -0
  21. anybroker-0.1.1/src/anybroker/codes.py +117 -0
  22. anybroker-0.1.1/src/anybroker/enums.py +56 -0
  23. anybroker-0.1.1/src/anybroker/errors.py +150 -0
  24. anybroker-0.1.1/src/anybroker/models.py +137 -0
  25. anybroker-0.1.1/src/anybroker/py.typed +0 -0
  26. anybroker-0.1.1/src/anybroker/registry.py +104 -0
  27. anybroker-0.1.1/src/anybroker/spec.py +185 -0
  28. anybroker-0.1.1/src/anybroker/venue.py +523 -0
  29. anybroker-0.1.1/src/anybroker/venues/__init__.py +27 -0
  30. anybroker-0.1.1/src/anybroker/venues/alpaca.py +530 -0
  31. anybroker-0.1.1/src/anybroker/venues/ccxt_venue.py +372 -0
  32. anybroker-0.1.1/src/anybroker/venues/ibkr.py +846 -0
  33. anybroker-0.1.1/src/anybroker/venues/tradovate.py +509 -0
  34. anybroker-0.1.1/src/anybroker/webhook/__init__.py +38 -0
  35. anybroker-0.1.1/src/anybroker/webhook/__main__.py +146 -0
  36. anybroker-0.1.1/src/anybroker/webhook/alert.py +334 -0
  37. anybroker-0.1.1/src/anybroker/webhook/config.py +359 -0
  38. anybroker-0.1.1/src/anybroker/webhook/journal.py +168 -0
  39. anybroker-0.1.1/src/anybroker/webhook/router.py +309 -0
  40. anybroker-0.1.1/src/anybroker/webhook/server.py +579 -0
  41. anybroker-0.1.1/tests/conftest.py +4 -0
  42. anybroker-0.1.1/tests/fakes.py +203 -0
  43. anybroker-0.1.1/tests/test_alpaca.py +666 -0
  44. anybroker-0.1.1/tests/test_ccxt_venue.py +215 -0
  45. anybroker-0.1.1/tests/test_enums.py +24 -0
  46. anybroker-0.1.1/tests/test_examples.py +300 -0
  47. anybroker-0.1.1/tests/test_ibkr.py +363 -0
  48. anybroker-0.1.1/tests/test_ibkr_resilience.py +284 -0
  49. anybroker-0.1.1/tests/test_idempotency.py +276 -0
  50. anybroker-0.1.1/tests/test_interface.py +69 -0
  51. anybroker-0.1.1/tests/test_registry.py +167 -0
  52. anybroker-0.1.1/tests/test_review_findings.py +619 -0
  53. anybroker-0.1.1/tests/test_spec.py +111 -0
  54. anybroker-0.1.1/tests/test_tradovate.py +532 -0
  55. anybroker-0.1.1/tests/test_tradovate_transport.py +65 -0
  56. anybroker-0.1.1/tests/test_trailing.py +128 -0
  57. anybroker-0.1.1/tests/test_venue.py +19 -0
  58. anybroker-0.1.1/tests/test_webhook.py +1792 -0
@@ -0,0 +1,63 @@
1
+ name: ci
2
+
3
+ on:
4
+ push:
5
+ branches: [main]
6
+ pull_request:
7
+ workflow_dispatch:
8
+
9
+ concurrency:
10
+ group: ci-${{ github.ref }}
11
+ cancel-in-progress: true
12
+
13
+ jobs:
14
+ test:
15
+ name: tests (py${{ matrix.python }})
16
+ runs-on: ubuntu-latest
17
+ strategy:
18
+ fail-fast: false
19
+ matrix:
20
+ python: ["3.10", "3.11", "3.12", "3.13"]
21
+ steps:
22
+ - uses: actions/checkout@v4
23
+ - uses: actions/setup-python@v5
24
+ with:
25
+ python-version: ${{ matrix.python }}
26
+ - run: python -m pip install --upgrade pip
27
+ - run: pip install -e ".[dev]"
28
+ - run: pytest -q
29
+
30
+ types:
31
+ name: mypy
32
+ runs-on: ubuntu-latest
33
+ steps:
34
+ - uses: actions/checkout@v4
35
+ - uses: actions/setup-python@v5
36
+ with:
37
+ python-version: "3.12"
38
+ - run: pip install mypy
39
+ - run: mypy src --ignore-missing-imports
40
+
41
+ lint:
42
+ name: ruff
43
+ runs-on: ubuntu-latest
44
+ steps:
45
+ - uses: actions/checkout@v4
46
+ - uses: actions/setup-python@v5
47
+ with:
48
+ python-version: "3.12"
49
+ - run: pip install ruff
50
+ - run: ruff check .
51
+ - run: ruff format --check .
52
+
53
+ build:
54
+ name: package builds and is valid
55
+ runs-on: ubuntu-latest
56
+ steps:
57
+ - uses: actions/checkout@v4
58
+ - uses: actions/setup-python@v5
59
+ with:
60
+ python-version: "3.12"
61
+ - run: pip install build twine
62
+ - run: python -m build
63
+ - run: twine check dist/*
@@ -0,0 +1,16 @@
1
+ __pycache__/
2
+ *.py[cod]
3
+ *.egg-info/
4
+ build/
5
+ dist/
6
+ .pytest_cache/
7
+ .venv/
8
+ venv/
9
+ .coverage
10
+ htmlcov/
11
+ .DS_Store
12
+ # never commit credentials or cached tokens
13
+ *_key
14
+ *.key
15
+ token-*.json
16
+ .env
@@ -0,0 +1,37 @@
1
+ # Changelog
2
+
3
+ ## 0.1.1 — 2026-12-02
4
+
5
+ - First PyPI release with free-project onboarding, offline examples and versioned documentation.
6
+ - Includes reviewed uncertain-write handling and whole-contract validation.
7
+ - Depend on tradovate-client 0.2.1 from PyPI instead of a Git URL.
8
+
9
+ ## Unreleased — execution correctness and public onboarding
10
+
11
+ - Update the pinned Tradovate client to include uncertain-write handling and futures quantity validation fixes.
12
+ - Add real-client adapter regression tests proving uncertain submissions block a second send and fractional contracts never reach the transport.
13
+ - Attribute the maintainer's reported live/paper usage separately from automated and release-specific verification.
14
+ - Add offline order previews and a synthetic strategy with next-sample assumed fills.
15
+ - Add explicit Tradovate demo-account read, submit and cancel commands; no live switch.
16
+ - Filter working orders by the selected account in the new examples.
17
+ - Reorganize the README around a first run and retain advanced material in docs/api-reference.md.
18
+ - Document validation limits, troubleshooting, tradeoffs and developer-preview announcement drafts.
19
+
20
+
21
+ ## 0.1.0 — 2026-11-27
22
+
23
+ - Python API for IBKR, Tradovate, Alpaca, and CCXT venues.
24
+ - Orders, brackets, cancellation, modification, positions, accounts, and quotes,
25
+ subject to each venue's capabilities.
26
+ - Submission deduplication and tracking of unresolved writes.
27
+ - IBKR reconnection, bracket recovery, and optional submission-state persistence.
28
+ - TradingView webhook server, JSON/text alerts, shared-secret authentication,
29
+ and SQLite journaling, available through `anyhook`.
30
+ - Tradovate bulk cancellation resolves the account before sending requests and
31
+ filters working orders by account. Bulk cancellation and liquidation check
32
+ broker rejection responses and stop on the first failure.
33
+ - Tradovate dependency pinned to a commit; included in `[all]` and `[dev]`.
34
+
35
+ This release is a GitHub prerelease. Tests use simulated brokers and SDK request
36
+ models; they do not establish broker acceptance or execution in paper or live
37
+ accounts. Bulk operations are sequential and cannot roll back earlier requests.
@@ -0,0 +1,56 @@
1
+ # Contributing
2
+
3
+ Thanks for looking.
4
+
5
+ ## Running the tests
6
+
7
+ ```sh
8
+ python -m pip install -e ".[dev]"
9
+ pytest -q
10
+ ```
11
+
12
+ The suite needs **no network, no credentials and no broker account**. Every
13
+ venue is exercised against a fake. If a test ever needs a live connection to
14
+ pass, it is the wrong test.
15
+
16
+ ## What CI checks
17
+
18
+ Four jobs, all of which must be green:
19
+
20
+ | job | what it does |
21
+ | --- | --- |
22
+ | `test` | the suite on Python 3.10 through 3.13 |
23
+ | `types` | `mypy src` — the package ships `py.typed`, so the annotations are a promise |
24
+ | `lint` | `ruff check` and `ruff format --check` |
25
+ | `build` | the wheel builds and `twine check` passes |
26
+
27
+ ## House rules
28
+
29
+ **Nothing invents a number.** No default stop distance, no default target, no
30
+ assumed tick size, no made-up threshold. If a value is not supplied by the
31
+ caller or published by the venue, the code asks or raises. This is a broker
32
+ client, not a strategy.
33
+
34
+ **Every enum value is traceable to the venue's own documentation.** When you
35
+ add one, say in a comment where it came from, and add it to the test that
36
+ asserts the whole set. A vendor changing a value should surface as a failing
37
+ test, not a rejected order.
38
+
39
+ **Failures raise.** No function returns a dictionary with an error key in it.
40
+ That mistake places orders.
41
+
42
+ **A write is never retried blindly.** A timeout on an order is not a
43
+ rejection — the order may already be working. Retries are allowed only when
44
+ the failure proves nothing was sent, and otherwise the caller gets an error
45
+ marked ambiguous so it knows to read state before writing again.
46
+
47
+ **Paper and live are different objects, not a flag.** If a venue has no paper
48
+ environment, say so in its capabilities and raise when one is asked for.
49
+
50
+ ## Adding a venue
51
+
52
+ 1. Subclass `Venue`, declare `Capabilities` honestly, and translate
53
+ `OrderSpec` at your own edge.
54
+ 2. Refuse what the venue cannot do rather than substituting something near it.
55
+ 3. Write a fake client in `tests/` and assert the exact payload your venue
56
+ sends. No network.
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 QuantQJ
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,180 @@
1
+ Metadata-Version: 2.5
2
+ Name: anybroker
3
+ Version: 0.1.1
4
+ Summary: Python interface for orders, positions, accounts, and TradingView webhooks across IBKR, Tradovate, Alpaca, and CCXT.
5
+ Project-URL: Homepage, https://github.com/QuantQJ/anybroker
6
+ Project-URL: Source, https://github.com/QuantQJ/anybroker/tree/v0.1.1
7
+ Project-URL: Documentation, https://github.com/QuantQJ/anybroker/blob/v0.1.1/docs/start-here.md
8
+ Project-URL: Changelog, https://github.com/QuantQJ/anybroker/blob/v0.1.1/CHANGELOG.md
9
+ Project-URL: Issues, https://github.com/QuantQJ/anybroker/issues
10
+ Author: QuantQJ
11
+ License: MIT License
12
+
13
+ Copyright (c) 2026 QuantQJ
14
+
15
+ Permission is hereby granted, free of charge, to any person obtaining a copy
16
+ of this software and associated documentation files (the "Software"), to deal
17
+ in the Software without restriction, including without limitation the rights
18
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
19
+ copies of the Software, and to permit persons to whom the Software is
20
+ furnished to do so, subject to the following conditions:
21
+
22
+ The above copyright notice and this permission notice shall be included in all
23
+ copies or substantial portions of the Software.
24
+
25
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
26
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
27
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
28
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
29
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
30
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
31
+ SOFTWARE.
32
+ License-File: LICENSE
33
+ Keywords: broker,ccxt,futures,ibkr,orders,trading,tradovate
34
+ Classifier: Development Status :: 3 - Alpha
35
+ Classifier: Intended Audience :: Developers
36
+ Classifier: Intended Audience :: Financial and Insurance Industry
37
+ Classifier: License :: OSI Approved :: MIT License
38
+ Classifier: Programming Language :: Python :: 3
39
+ Classifier: Programming Language :: Python :: 3 :: Only
40
+ Classifier: Programming Language :: Python :: 3.10
41
+ Classifier: Programming Language :: Python :: 3.11
42
+ Classifier: Programming Language :: Python :: 3.12
43
+ Classifier: Programming Language :: Python :: 3.13
44
+ Classifier: Topic :: Office/Business :: Financial :: Investment
45
+ Requires-Python: >=3.10
46
+ Provides-Extra: all
47
+ Requires-Dist: alpaca-py>=0.33; extra == 'all'
48
+ Requires-Dist: ccxt>=4.4.0; extra == 'all'
49
+ Requires-Dist: ib-insync>=0.9.86; extra == 'all'
50
+ Requires-Dist: tradovate-client==0.2.1; extra == 'all'
51
+ Provides-Extra: alpaca
52
+ Requires-Dist: alpaca-py>=0.33; extra == 'alpaca'
53
+ Provides-Extra: crypto
54
+ Requires-Dist: ccxt>=4.4.0; extra == 'crypto'
55
+ Provides-Extra: dev
56
+ Requires-Dist: alpaca-py>=0.33; extra == 'dev'
57
+ Requires-Dist: ccxt>=4.4.0; extra == 'dev'
58
+ Requires-Dist: ib-insync>=0.9.86; extra == 'dev'
59
+ Requires-Dist: mypy>=1.8; extra == 'dev'
60
+ Requires-Dist: pytest>=7.4; extra == 'dev'
61
+ Requires-Dist: ruff>=0.6; extra == 'dev'
62
+ Requires-Dist: tradovate-client==0.2.1; extra == 'dev'
63
+ Provides-Extra: ibkr
64
+ Requires-Dist: ib-insync>=0.9.86; extra == 'ibkr'
65
+ Provides-Extra: tradovate
66
+ Requires-Dist: tradovate-client==0.2.1; extra == 'tradovate'
67
+ Description-Content-Type: text/markdown
68
+
69
+ # anybroker
70
+
71
+ Use one Python order interface across Tradovate, IBKR, Alpaca and CCXT venues.
72
+
73
+ **Developer preview.** Start offline, then validate in your own broker demo account.
74
+ The examples are educational. This is execution infrastructure; no profitable strategy,
75
+ production-readiness certification, or performance advantage is established here.
76
+
77
+ **Free and open source (MIT).** Use, modify and share the library under its license.
78
+ There is no library subscription or paid setup requirement. Your broker may charge
79
+ for API access, market data and trading.
80
+
81
+ New to the project? [Start here](https://github.com/QuantQJ/anybroker/blob/v0.1.1/docs/start-here.md) explains which library to choose,
82
+ what to run first and what each example actually does.
83
+
84
+ ## Who this helps
85
+
86
+ Python developers building their own trading tools who want to spend less time on
87
+ broker integration. You still choose the strategy, data source, account permissions,
88
+ and operating limits.
89
+
90
+ - Reuse `OrderSpec`, position and account interfaces across supported adapters.
91
+ - Ask each adapter which order features it supports before using them.
92
+ - Route TradingView alerts through the included `anyhook` command.
93
+ - Surface duplicate and unresolved submissions so the application can reconcile them.
94
+
95
+ Choose [tradovate-client](https://github.com/QuantQJ/tradovate-client) when you only need Tradovate and want its full REST and streaming API.
96
+
97
+ ## Install the library
98
+
99
+ ```sh
100
+ python -m pip install "anybroker[tradovate]==0.1.1"
101
+ # Other venue extras: ibkr, alpaca, crypto, all
102
+ ```
103
+
104
+ The package installs the library. To run the repository examples, follow the clone
105
+ walkthrough below, which selects the matching release tag.
106
+
107
+ ## First run: no account or credentials
108
+
109
+ Requires Git and Python 3.10–3.13. Python 3.12 is the documented walkthrough environment.
110
+ Run these commands from a terminal:
111
+
112
+ ```sh
113
+ git clone --branch v0.1.1 https://github.com/QuantQJ/anybroker.git
114
+ cd anybroker
115
+ python3 -m venv .venv
116
+ source .venv/bin/activate
117
+ python -m pip install -e .
118
+ python examples/demo.py preview
119
+ python examples/offline_strategy.py
120
+ ```
121
+
122
+ Windows: create the environment with `py -3.12 -m venv .venv`, then activate it with
123
+ `.venv\Scripts\Activate.ps1` in PowerShell. Subsequent `python` commands are the same.
124
+
125
+ `preview` prints JSON with `"mode": "offline"`, `"submitted": false`, and an order
126
+ for the invented symbol `SYNTHETIC`. It does not authenticate or contact a broker.
127
+ The strategy demo processes five invented prices: an assumed buy at 102, an assumed
128
+ sell at 98, and a final position of zero. This deliberately unprofitable sequence
129
+ shows signal → order → assumed fill → position transitions, without a returns claim.
130
+
131
+ ## Next: read a demo account, then try one demo order
132
+
133
+ Follow the [step-by-step guide](https://github.com/QuantQJ/anybroker/blob/v0.1.1/docs/getting-started.md) for credentials, required
134
+ API access, expected output, account selection, an explicit one-contract demo limit
135
+ order, cancellation, and troubleshooting. All supplied broker commands are fixed to
136
+ Tradovate demo/paper. They have no live switch.
137
+
138
+ A demo limit order can fill immediately. Exiting a script does not cancel a working
139
+ order or close a position. Cancellation requests are not proof that an order did not fill.
140
+
141
+ ## What is verified
142
+
143
+ The automated suite uses simulated broker responses. New examples cover offline
144
+ operation, invalid inputs, explicit submission confirmation, account filtering and
145
+ synthetic strategy transitions. **The maintainer reports live and paper trading with the brokers and crypto
146
+ exchanges used in these projects. These automated checks do not independently
147
+ verify that history or every adapter/order type.** See [validation status](https://github.com/QuantQJ/anybroker/blob/v0.1.1/docs/validation.md)
148
+ for the exact evidence and the remaining broker-demo procedure.
149
+
150
+ Broker features differ. No unified market-data streaming, no Tradier or TradeStation adapter. The submission registry is in memory by default; a restart can lose deduplication state. The Tradovate dependency is pinned to the reviewed client release 0.2.1; this adapter does not expose the standalone client's full streaming API.
151
+
152
+ ## Guides and reference
153
+
154
+ - [Getting started and troubleshooting](https://github.com/QuantQJ/anybroker/blob/v0.1.1/docs/getting-started.md)
155
+ - [Comparison with alternatives](https://github.com/QuantQJ/anybroker/blob/v0.1.1/docs/comparisons.md)
156
+ - [Detailed API reference](https://github.com/QuantQJ/anybroker/blob/v0.1.1/docs/api-reference.md)
157
+ - [Evidence and broker-demo validation](https://github.com/QuantQJ/anybroker/blob/v0.1.1/docs/validation.md)
158
+ - [Who should use this, tradeoffs and alternatives](https://github.com/QuantQJ/anybroker/blob/v0.1.1/docs/positioning.md)
159
+ - [Contributing](https://github.com/QuantQJ/anybroker/blob/v0.1.1/CONTRIBUTING.md) · [Changelog](https://github.com/QuantQJ/anybroker/blob/v0.1.1/CHANGELOG.md)
160
+
161
+ ## Development
162
+
163
+ ```sh
164
+ python -m pip install -e ".[dev]"
165
+ pytest -q
166
+ ruff check .
167
+ ruff format --check .
168
+ mypy src --ignore-missing-imports
169
+ ```
170
+
171
+ For reproducibility, use a reviewed release tag or commit rather than tracking `main`
172
+ in a deployed application. The clone walkthrough uses the versioned source and examples.
173
+
174
+ ## License and support
175
+
176
+ MIT. Not affiliated with any broker or exchange. Report reproducible software issues
177
+ through [GitHub Issues](https://github.com/QuantQJ/anybroker/issues), including your version,
178
+ Python version, environment and a redacted traceback. Never include passwords, API
179
+ secrets, access tokens or account-identifying logs. Account access and rejected trading
180
+ permissions need the broker's support. No support response time is promised.
@@ -0,0 +1,112 @@
1
+ # anybroker
2
+
3
+ Use one Python order interface across Tradovate, IBKR, Alpaca and CCXT venues.
4
+
5
+ **Developer preview.** Start offline, then validate in your own broker demo account.
6
+ The examples are educational. This is execution infrastructure; no profitable strategy,
7
+ production-readiness certification, or performance advantage is established here.
8
+
9
+ **Free and open source (MIT).** Use, modify and share the library under its license.
10
+ There is no library subscription or paid setup requirement. Your broker may charge
11
+ for API access, market data and trading.
12
+
13
+ New to the project? [Start here](https://github.com/QuantQJ/anybroker/blob/v0.1.1/docs/start-here.md) explains which library to choose,
14
+ what to run first and what each example actually does.
15
+
16
+ ## Who this helps
17
+
18
+ Python developers building their own trading tools who want to spend less time on
19
+ broker integration. You still choose the strategy, data source, account permissions,
20
+ and operating limits.
21
+
22
+ - Reuse `OrderSpec`, position and account interfaces across supported adapters.
23
+ - Ask each adapter which order features it supports before using them.
24
+ - Route TradingView alerts through the included `anyhook` command.
25
+ - Surface duplicate and unresolved submissions so the application can reconcile them.
26
+
27
+ Choose [tradovate-client](https://github.com/QuantQJ/tradovate-client) when you only need Tradovate and want its full REST and streaming API.
28
+
29
+ ## Install the library
30
+
31
+ ```sh
32
+ python -m pip install "anybroker[tradovate]==0.1.1"
33
+ # Other venue extras: ibkr, alpaca, crypto, all
34
+ ```
35
+
36
+ The package installs the library. To run the repository examples, follow the clone
37
+ walkthrough below, which selects the matching release tag.
38
+
39
+ ## First run: no account or credentials
40
+
41
+ Requires Git and Python 3.10–3.13. Python 3.12 is the documented walkthrough environment.
42
+ Run these commands from a terminal:
43
+
44
+ ```sh
45
+ git clone --branch v0.1.1 https://github.com/QuantQJ/anybroker.git
46
+ cd anybroker
47
+ python3 -m venv .venv
48
+ source .venv/bin/activate
49
+ python -m pip install -e .
50
+ python examples/demo.py preview
51
+ python examples/offline_strategy.py
52
+ ```
53
+
54
+ Windows: create the environment with `py -3.12 -m venv .venv`, then activate it with
55
+ `.venv\Scripts\Activate.ps1` in PowerShell. Subsequent `python` commands are the same.
56
+
57
+ `preview` prints JSON with `"mode": "offline"`, `"submitted": false`, and an order
58
+ for the invented symbol `SYNTHETIC`. It does not authenticate or contact a broker.
59
+ The strategy demo processes five invented prices: an assumed buy at 102, an assumed
60
+ sell at 98, and a final position of zero. This deliberately unprofitable sequence
61
+ shows signal → order → assumed fill → position transitions, without a returns claim.
62
+
63
+ ## Next: read a demo account, then try one demo order
64
+
65
+ Follow the [step-by-step guide](https://github.com/QuantQJ/anybroker/blob/v0.1.1/docs/getting-started.md) for credentials, required
66
+ API access, expected output, account selection, an explicit one-contract demo limit
67
+ order, cancellation, and troubleshooting. All supplied broker commands are fixed to
68
+ Tradovate demo/paper. They have no live switch.
69
+
70
+ A demo limit order can fill immediately. Exiting a script does not cancel a working
71
+ order or close a position. Cancellation requests are not proof that an order did not fill.
72
+
73
+ ## What is verified
74
+
75
+ The automated suite uses simulated broker responses. New examples cover offline
76
+ operation, invalid inputs, explicit submission confirmation, account filtering and
77
+ synthetic strategy transitions. **The maintainer reports live and paper trading with the brokers and crypto
78
+ exchanges used in these projects. These automated checks do not independently
79
+ verify that history or every adapter/order type.** See [validation status](https://github.com/QuantQJ/anybroker/blob/v0.1.1/docs/validation.md)
80
+ for the exact evidence and the remaining broker-demo procedure.
81
+
82
+ Broker features differ. No unified market-data streaming, no Tradier or TradeStation adapter. The submission registry is in memory by default; a restart can lose deduplication state. The Tradovate dependency is pinned to the reviewed client release 0.2.1; this adapter does not expose the standalone client's full streaming API.
83
+
84
+ ## Guides and reference
85
+
86
+ - [Getting started and troubleshooting](https://github.com/QuantQJ/anybroker/blob/v0.1.1/docs/getting-started.md)
87
+ - [Comparison with alternatives](https://github.com/QuantQJ/anybroker/blob/v0.1.1/docs/comparisons.md)
88
+ - [Detailed API reference](https://github.com/QuantQJ/anybroker/blob/v0.1.1/docs/api-reference.md)
89
+ - [Evidence and broker-demo validation](https://github.com/QuantQJ/anybroker/blob/v0.1.1/docs/validation.md)
90
+ - [Who should use this, tradeoffs and alternatives](https://github.com/QuantQJ/anybroker/blob/v0.1.1/docs/positioning.md)
91
+ - [Contributing](https://github.com/QuantQJ/anybroker/blob/v0.1.1/CONTRIBUTING.md) · [Changelog](https://github.com/QuantQJ/anybroker/blob/v0.1.1/CHANGELOG.md)
92
+
93
+ ## Development
94
+
95
+ ```sh
96
+ python -m pip install -e ".[dev]"
97
+ pytest -q
98
+ ruff check .
99
+ ruff format --check .
100
+ mypy src --ignore-missing-imports
101
+ ```
102
+
103
+ For reproducibility, use a reviewed release tag or commit rather than tracking `main`
104
+ in a deployed application. The clone walkthrough uses the versioned source and examples.
105
+
106
+ ## License and support
107
+
108
+ MIT. Not affiliated with any broker or exchange. Report reproducible software issues
109
+ through [GitHub Issues](https://github.com/QuantQJ/anybroker/issues), including your version,
110
+ Python version, environment and a redacted traceback. Never include passwords, API
111
+ secrets, access tokens or account-identifying logs. Account access and rejected trading
112
+ permissions need the broker's support. No support response time is promised.
@@ -0,0 +1,150 @@
1
+ # anybroker API reference
2
+
3
+ Python interface for orders, positions, accounts, and TradingView webhooks across
4
+ IBKR, Tradovate, Alpaca, and CCXT venues.
5
+
6
+ ## Install
7
+
8
+ Python 3.10–3.13. Install the SDK for the venue you use:
9
+
10
+ ```sh
11
+ pip install "anybroker[ibkr]==0.1.1"
12
+ pip install "anybroker[tradovate]==0.1.1"
13
+ pip install "anybroker[alpaca]==0.1.1"
14
+ pip install "anybroker[crypto]==0.1.1"
15
+ # All venue SDKs:
16
+ pip install "anybroker[all]==0.1.1"
17
+ ```
18
+
19
+ The Tradovate extra installs `tradovate-client` from a pinned PyPI release.
20
+ `ib_insync` depends on `eventkit`, which does not import under Python 3.14.
21
+
22
+ ## Read an account
23
+
24
+ With IB Gateway running and API access enabled:
25
+
26
+ ```python
27
+ from anybroker import Env, open_venue
28
+
29
+ with open_venue("ibkr", Env.PAPER, client_id=7788, port=4002) as broker:
30
+ print(broker.get_account())
31
+ print(broker.list_positions())
32
+ print(broker.working_orders())
33
+ ```
34
+
35
+ IBKR requires a `client_id` and `port`. Use a client ID that other sessions are
36
+ not using. Gateway defaults are 4002 for paper and 4001 for live; TWS defaults
37
+ are 7497 and 7496. Check your gateway configuration and account selection.
38
+
39
+ Other venue constructors:
40
+
41
+ ```python
42
+ tradovate = open_venue(
43
+ "tradovate", Env.PAPER, credential_path="/secure/key.json", account="DEMO1234"
44
+ )
45
+ alpaca = open_venue("alpaca", Env.PAPER, api_key="...", secret_key="...")
46
+ exchange = open_venue("krakenfutures", Env.PAPER, api_key="...", secret="...")
47
+ ```
48
+
49
+ `Env` is required. A CCXT venue without sandbox support raises
50
+ `UnsupportedError` when asked for `Env.PAPER`.
51
+
52
+ ## Orders
53
+
54
+ These calls submit orders when used with a connected broker:
55
+
56
+ ```python
57
+ from anybroker import OrderSpec, OrderType, Side, TimeInForce
58
+
59
+ spec = OrderSpec(
60
+ "AAPL",
61
+ Side.BUY,
62
+ 1,
63
+ OrderType.LIMIT,
64
+ limit_price=200.0,
65
+ time_in_force=TimeInForce.DAY,
66
+ client_order_id="example-entry-001",
67
+ )
68
+ order = broker.place(spec)
69
+ broker.cancel(order.id)
70
+ ```
71
+
72
+ The API includes `market`, `limit`, `stop`, `stop_limit`, `trailing_stop`,
73
+ `modify`, `cancel_all`, `flatten`, and `flatten_all`. Add `take_profit` and
74
+ `stop_loss` to an `OrderSpec` for a bracket. Symbols, quantities, and prices must
75
+ match the broker's requirements. Tradovate futures quantities are whole contracts.
76
+
77
+ Check `broker.capabilities` for order types, brackets, modification, and paper
78
+ support. CCXT capabilities come from the exchange's `has` table. Broker
79
+ acceptance also depends on the instrument, account permissions, and market rules.
80
+
81
+ ## Venues
82
+
83
+ | Venue | Driver | Connection |
84
+ | --- | --- | --- |
85
+ | `ibkr` | `ib_insync` | TWS or IB Gateway |
86
+ | `tradovate` | `tradovate-client` | Tradovate REST API |
87
+ | `alpaca` | `alpaca-py` | Alpaca trading API |
88
+ | CCXT exchange ID | `ccxt` | Exchange API |
89
+
90
+ `available()` reports installed drivers. CCXT also has an Interactive Brokers
91
+ integration; anybroker's `ibkr` adapter uses the TWS/Gateway socket API.
92
+
93
+ ## Duplicate submissions and recovery
94
+
95
+ `place()` tracks submissions using `client_order_id`, or a fingerprint of the
96
+ order when no ID is provided. Repeating a working order returns its known order;
97
+ repeating a finished order raises `DuplicateOrderError`. An ambiguous submission
98
+ raises and leaves the key unresolved until `resolve()` or `forget()` is called.
99
+ Check broker state before resolving it. Duplicate lookup may return cached state
100
+ when the broker cannot be reached.
101
+
102
+ `extra` fields are excluded from the fingerprint. Assign different
103
+ `client_order_id` values when those fields change the intended order. The default
104
+ registry is in memory; restarting a process loses that registry. IBKR supports
105
+ `state_path` for persistence and restores submissions as unresolved.
106
+
107
+ IBKR's `resync()` recovers bracket relationships from open orders;
108
+ `unprotected_positions()` reports positions without a working stop. These
109
+ checks report observed broker state and cannot guarantee future execution.
110
+
111
+ Tradovate bulk operations select an account before writing and check each
112
+ response for rejection. They stop at the first error. Earlier cancellations or
113
+ liquidations may already have succeeded; bulk operations are not transactions.
114
+
115
+ ## TradingView webhooks
116
+
117
+ ```sh
118
+ anyhook secret
119
+ ANYHOOK_SECRET=... ANYHOOK_VENUE=tradovate ANYHOOK_ENV=paper anyhook serve
120
+ ```
121
+
122
+ Configure the venue's credentials and account for the server process. Send JSON
123
+ or text such as `buy 1 ABCZ6` to `/alert/<secret>`. The server authenticates the
124
+ shared secret, queues execution, and records events in SQLite. It uses the same
125
+ venue API and submission registry. Journaling is not a guarantee of durable
126
+ execution or deduplication across restarts.
127
+
128
+ ## Release status and tests
129
+
130
+ `v0.1.0` is a GitHub prerelease. Tests exercise simulated broker responses and SDK
131
+ request models. The maintainer reports live and paper trading with brokers and
132
+ crypto exchanges used in these projects. Exact coverage and versions have not
133
+ been recorded here; see [validation status](validation.md) for the distinction
134
+ between that usage and the automated checks. Passing tests do not establish
135
+ that the library is bug-free.
136
+
137
+ ```sh
138
+ pip install -e ".[dev]"
139
+ pytest -q
140
+ ruff check .
141
+ ruff format --check .
142
+ mypy src --ignore-missing-imports
143
+ ```
144
+
145
+ CI runs tests on Python 3.10–3.13, lint, type checking, and package builds.
146
+ Tradier, TradeStation, and market-data streaming are not implemented.
147
+
148
+ ## Licence
149
+
150
+ MIT. Not affiliated with any broker or exchange.