pm-ledger 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.
- pm_ledger-0.1.0/CHANGELOG.md +13 -0
- pm_ledger-0.1.0/LICENSE +21 -0
- pm_ledger-0.1.0/MANIFEST.in +8 -0
- pm_ledger-0.1.0/PKG-INFO +141 -0
- pm_ledger-0.1.0/README.md +116 -0
- pm_ledger-0.1.0/fixtures/Kalshi-Recent-Activity-All.csv +307 -0
- pm_ledger-0.1.0/fixtures/golden/generator_truth.json +20 -0
- pm_ledger-0.1.0/fixtures/golden/js_expected.json +507 -0
- pm_ledger-0.1.0/fixtures/golden/summary_2026.json +277 -0
- pm_ledger-0.1.0/fixtures/journal_sample.json +442 -0
- pm_ledger-0.1.0/fixtures/kalshi_realized_pnl_2026.csv +116 -0
- pm_ledger-0.1.0/fixtures/kalshi_realized_pnl_2026_legacy12.csv +7 -0
- pm_ledger-0.1.0/fixtures/polymarket_us_activities.json +1265 -0
- pm_ledger-0.1.0/js/pm_core.js +495 -0
- pm_ledger-0.1.0/js/test/parser.test.js +96 -0
- pm_ledger-0.1.0/js/test/pm_core.test.js +127 -0
- pm_ledger-0.1.0/pm_ledger/__init__.py +18 -0
- pm_ledger-0.1.0/pm_ledger/__main__.py +4 -0
- pm_ledger-0.1.0/pm_ledger/cli.py +90 -0
- pm_ledger-0.1.0/pm_ledger/export.py +77 -0
- pm_ledger-0.1.0/pm_ledger/fifo.py +123 -0
- pm_ledger-0.1.0/pm_ledger/ledger.py +106 -0
- pm_ledger-0.1.0/pm_ledger/model.py +90 -0
- pm_ledger-0.1.0/pm_ledger/parsers/__init__.py +79 -0
- pm_ledger-0.1.0/pm_ledger/parsers/generic_csv.py +36 -0
- pm_ledger-0.1.0/pm_ledger/parsers/kalshi_activity.py +108 -0
- pm_ledger-0.1.0/pm_ledger/parsers/kalshi_pnl.py +62 -0
- pm_ledger-0.1.0/pm_ledger/parsers/polymarket_us.py +132 -0
- pm_ledger-0.1.0/pm_ledger/summary.py +107 -0
- pm_ledger-0.1.0/pm_ledger/util.py +190 -0
- pm_ledger-0.1.0/pm_ledger.egg-info/PKG-INFO +141 -0
- pm_ledger-0.1.0/pm_ledger.egg-info/SOURCES.txt +46 -0
- pm_ledger-0.1.0/pm_ledger.egg-info/dependency_links.txt +1 -0
- pm_ledger-0.1.0/pm_ledger.egg-info/entry_points.txt +2 -0
- pm_ledger-0.1.0/pm_ledger.egg-info/requires.txt +4 -0
- pm_ledger-0.1.0/pm_ledger.egg-info/top_level.txt +1 -0
- pm_ledger-0.1.0/pyproject.toml +44 -0
- pm_ledger-0.1.0/schema/ledger.schema.json +576 -0
- pm_ledger-0.1.0/setup.cfg +4 -0
- pm_ledger-0.1.0/templates/cashflows.csv +1 -0
- pm_ledger-0.1.0/templates/closed_lots.csv +1 -0
- pm_ledger-0.1.0/templates/journal.csv +1 -0
- pm_ledger-0.1.0/templates/ledger_events.csv +1 -0
- pm_ledger-0.1.0/templates/open_lots.csv +1 -0
- pm_ledger-0.1.0/templates/sheet_lots_9col.csv +1 -0
- pm_ledger-0.1.0/tests/conftest.py +22 -0
- pm_ledger-0.1.0/tests/test_core.py +249 -0
- pm_ledger-0.1.0/tests/test_network_guard.py +31 -0
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to the public `pm_ledger` core are recorded here.
|
|
4
|
+
|
|
5
|
+
## 0.1.0 — 2026-11-20
|
|
6
|
+
|
|
7
|
+
First public snapshot of the MIT-licensed core.
|
|
8
|
+
|
|
9
|
+
- Parsers for Kalshi realized P&L CSV (including the legacy 12-column layout), Kalshi Recent Activity CSV, Polymarket US activities JSON, and a generic ledger-events CSV.
|
|
10
|
+
- Idempotent local ledger store, FIFO lot matching, year summary, and JSON / CSV / sheet exports.
|
|
11
|
+
- JSON Schema (`schema/ledger.schema.json`) and CSV templates under `templates/`.
|
|
12
|
+
- pytest suite with synthetic fixtures, plus a `node --test` runner for a forthcoming JavaScript / Google Apps Script parser port.
|
|
13
|
+
- Privacy posture: local-first, no data collection, no telemetry, no network calls in the core package.
|
pm_ledger-0.1.0/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Margin & Moss
|
|
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.
|
pm_ledger-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: pm-ledger
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Local-first, offline ledger for Kalshi and Polymarket US event-contract trade exports.
|
|
5
|
+
Author-email: Margin & Moss <marginandmoss@mail.grokbot.com>
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
Project-URL: Homepage, https://codeberg.org/marginandmoss/pm-ledger
|
|
8
|
+
Project-URL: Issues, https://codeberg.org/marginandmoss/pm-ledger/issues
|
|
9
|
+
Keywords: ledger,prediction-markets,event-contracts,kalshi,polymarket,fifo
|
|
10
|
+
Classifier: Development Status :: 3 - Alpha
|
|
11
|
+
Classifier: Programming Language :: Python :: 3
|
|
12
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
15
|
+
Classifier: Topic :: Office/Business :: Financial
|
|
16
|
+
Classifier: Intended Audience :: End Users/Desktop
|
|
17
|
+
Classifier: Operating System :: OS Independent
|
|
18
|
+
Requires-Python: >=3.10
|
|
19
|
+
Description-Content-Type: text/markdown
|
|
20
|
+
License-File: LICENSE
|
|
21
|
+
Provides-Extra: dev
|
|
22
|
+
Requires-Dist: pytest>=7; extra == "dev"
|
|
23
|
+
Requires-Dist: jsonschema>=4; extra == "dev"
|
|
24
|
+
Dynamic: license-file
|
|
25
|
+
|
|
26
|
+
# pm_ledger
|
|
27
|
+
|
|
28
|
+
A local-first, offline ledger for Kalshi and Polymarket US event-contract (prediction-market) trade exports.
|
|
29
|
+
|
|
30
|
+
`pm_ledger` is the MIT-licensed core of Margin & Moss's Event-Contract Ledger kit. It reads export files you already have, normalizes them, matches lots, and writes a ledger and summaries on your own computer.
|
|
31
|
+
|
|
32
|
+
**Not affiliated with, endorsed by, or sponsored by Kalshi or Polymarket. Record-keeping tool, not tax, legal, or investment advice.**
|
|
33
|
+
|
|
34
|
+
## What it does
|
|
35
|
+
|
|
36
|
+
- Detects and parses:
|
|
37
|
+
- Kalshi `realized_pnl_*.csv` (current and legacy 12-column layouts)
|
|
38
|
+
- Kalshi `Kalshi-Recent-Activity-*.csv`
|
|
39
|
+
- Polymarket US `/v1/portfolio/activities` JSON
|
|
40
|
+
- A generic `pm_ledger` events CSV
|
|
41
|
+
- Stores events in an idempotent local ledger (re-importing the same file is safe)
|
|
42
|
+
- FIFO-matches fills and settlements into closed and open lots
|
|
43
|
+
- Prefers Kalshi's own realized-P&L lots for a tax year when that official file is present, so activity-derived lots are not double-counted
|
|
44
|
+
- Builds a year summary with descriptive scenario figures only (no filing recommendations)
|
|
45
|
+
- Exports JSON, CSV templates, and a nine-column sheet-friendly CSV
|
|
46
|
+
|
|
47
|
+
Runtime dependencies: Python 3.10+ and the standard library only.
|
|
48
|
+
|
|
49
|
+
A Google Apps Script / JavaScript port of the parser, when present, lives under [`js/`](js/).
|
|
50
|
+
|
|
51
|
+
The commercial Pro kit (a read-only local stdio MCP server, CPA packet export, and Edge Analytics) is **not** part of this repository.
|
|
52
|
+
|
|
53
|
+
## Install
|
|
54
|
+
|
|
55
|
+
```bash
|
|
56
|
+
python3 -m venv .venv
|
|
57
|
+
source .venv/bin/activate
|
|
58
|
+
pip install -e .
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
For tests and JSON Schema validation:
|
|
62
|
+
|
|
63
|
+
```bash
|
|
64
|
+
pip install -e ".[dev]"
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
The CLI entry point is `pm-ledger` (also `python -m pm_ledger`).
|
|
68
|
+
|
|
69
|
+
## Usage
|
|
70
|
+
|
|
71
|
+
```bash
|
|
72
|
+
# Identify an export
|
|
73
|
+
pm-ledger detect Kalshi-Recent-Activity-All.csv
|
|
74
|
+
|
|
75
|
+
# Year summary (JSON or text)
|
|
76
|
+
pm-ledger summarize realized_pnl_2026.csv polymarket_us_activities.json --year 2026
|
|
77
|
+
pm-ledger summarize realized_pnl_2026.csv --year 2026 --json
|
|
78
|
+
|
|
79
|
+
# Idempotent import into a local store (safe to re-run)
|
|
80
|
+
pm-ledger import realized_pnl_2026.csv --store ledger.json
|
|
81
|
+
|
|
82
|
+
# Export a normalized ledger
|
|
83
|
+
pm-ledger export --store ledger.json --format json --out ledger_out.json
|
|
84
|
+
pm-ledger export --store ledger.json --format csv --out ledger_out/
|
|
85
|
+
pm-ledger export polymarket_us_activities.json --format sheet --out polymarket_for_sheet.csv
|
|
86
|
+
|
|
87
|
+
# Open positions
|
|
88
|
+
pm-ledger positions --store ledger.json
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
Python API:
|
|
92
|
+
|
|
93
|
+
```python
|
|
94
|
+
from pm_ledger import Ledger, detect, year_summary
|
|
95
|
+
|
|
96
|
+
ledger = Ledger() # default timezone: US Eastern
|
|
97
|
+
ledger.import_file("Kalshi-Recent-Activity-All.csv")
|
|
98
|
+
ledger.import_file("polymarket_us_activities.json")
|
|
99
|
+
closed, open_lots, warnings = ledger.compute()
|
|
100
|
+
summary = year_summary(closed, open_lots, ledger.cash_events(), 2026)
|
|
101
|
+
ledger.save("ledger.json")
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
CSV templates that match the ledger schema are in [`templates/`](templates/). The JSON Schema (2020-12) is in [`schema/ledger.schema.json`](schema/ledger.schema.json). Synthetic fixtures used by the test suite are in [`fixtures/`](fixtures/).
|
|
105
|
+
|
|
106
|
+
## Privacy
|
|
107
|
+
|
|
108
|
+
This project is local-first and privacy-first.
|
|
109
|
+
|
|
110
|
+
- Your trade data stays on your computer.
|
|
111
|
+
- The package does not collect user data.
|
|
112
|
+
- There is no telemetry, analytics, crash reporting, or phone-home of any kind.
|
|
113
|
+
- The core library and CLI make **no network calls**. They only read files you pass in and write files where you tell them to.
|
|
114
|
+
- There are no accounts, no cloud sync, and no third-party destinations for your ledger.
|
|
115
|
+
|
|
116
|
+
## Disclaimer
|
|
117
|
+
|
|
118
|
+
Not affiliated with, endorsed by, or sponsored by Kalshi or Polymarket. Record-keeping tool, not tax, legal, or investment advice.
|
|
119
|
+
|
|
120
|
+
Kalshi and Polymarket are trademarks of their respective owners. This tool does not place orders, does not recommend trades or tax positions, and is not a substitute for a qualified tax professional.
|
|
121
|
+
|
|
122
|
+
## Development
|
|
123
|
+
|
|
124
|
+
```bash
|
|
125
|
+
# Refresh this tree from the upstream oss-core checkout (never copies pro/)
|
|
126
|
+
./scripts/sync-from-source.sh
|
|
127
|
+
|
|
128
|
+
# Python tests (includes a guard that fails if a test tries to open a network socket)
|
|
129
|
+
pytest
|
|
130
|
+
|
|
131
|
+
# JavaScript / Apps Script parser tests (node --test; skips until the port is present)
|
|
132
|
+
node --test js/test/*.test.js
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
Source: <https://codeberg.org/marginandmoss/pm-ledger>. CI configs are included for Codeberg/Forgejo Actions (`.forgejo/workflows/ci.yml`), GitLab CI (`.gitlab-ci.yml`), and GitHub Actions (`.github/workflows/`). Each runs pytest on Python 3.10–3.12 and the Node test runner. On GitHub, tagging `v*` builds an sdist and wheel and attaches them to a GitHub Release. This repository does not publish to PyPI from CI; see the separate PyPI notes for a manual token upload.
|
|
136
|
+
|
|
137
|
+
## License
|
|
138
|
+
|
|
139
|
+
[MIT](LICENSE). Copyright (c) 2026 Margin & Moss.
|
|
140
|
+
|
|
141
|
+
Schema, templates, parsers, and this documentation are the public core. Do not add commercial Pro sources to this tree.
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
# pm_ledger
|
|
2
|
+
|
|
3
|
+
A local-first, offline ledger for Kalshi and Polymarket US event-contract (prediction-market) trade exports.
|
|
4
|
+
|
|
5
|
+
`pm_ledger` is the MIT-licensed core of Margin & Moss's Event-Contract Ledger kit. It reads export files you already have, normalizes them, matches lots, and writes a ledger and summaries on your own computer.
|
|
6
|
+
|
|
7
|
+
**Not affiliated with, endorsed by, or sponsored by Kalshi or Polymarket. Record-keeping tool, not tax, legal, or investment advice.**
|
|
8
|
+
|
|
9
|
+
## What it does
|
|
10
|
+
|
|
11
|
+
- Detects and parses:
|
|
12
|
+
- Kalshi `realized_pnl_*.csv` (current and legacy 12-column layouts)
|
|
13
|
+
- Kalshi `Kalshi-Recent-Activity-*.csv`
|
|
14
|
+
- Polymarket US `/v1/portfolio/activities` JSON
|
|
15
|
+
- A generic `pm_ledger` events CSV
|
|
16
|
+
- Stores events in an idempotent local ledger (re-importing the same file is safe)
|
|
17
|
+
- FIFO-matches fills and settlements into closed and open lots
|
|
18
|
+
- Prefers Kalshi's own realized-P&L lots for a tax year when that official file is present, so activity-derived lots are not double-counted
|
|
19
|
+
- Builds a year summary with descriptive scenario figures only (no filing recommendations)
|
|
20
|
+
- Exports JSON, CSV templates, and a nine-column sheet-friendly CSV
|
|
21
|
+
|
|
22
|
+
Runtime dependencies: Python 3.10+ and the standard library only.
|
|
23
|
+
|
|
24
|
+
A Google Apps Script / JavaScript port of the parser, when present, lives under [`js/`](js/).
|
|
25
|
+
|
|
26
|
+
The commercial Pro kit (a read-only local stdio MCP server, CPA packet export, and Edge Analytics) is **not** part of this repository.
|
|
27
|
+
|
|
28
|
+
## Install
|
|
29
|
+
|
|
30
|
+
```bash
|
|
31
|
+
python3 -m venv .venv
|
|
32
|
+
source .venv/bin/activate
|
|
33
|
+
pip install -e .
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
For tests and JSON Schema validation:
|
|
37
|
+
|
|
38
|
+
```bash
|
|
39
|
+
pip install -e ".[dev]"
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
The CLI entry point is `pm-ledger` (also `python -m pm_ledger`).
|
|
43
|
+
|
|
44
|
+
## Usage
|
|
45
|
+
|
|
46
|
+
```bash
|
|
47
|
+
# Identify an export
|
|
48
|
+
pm-ledger detect Kalshi-Recent-Activity-All.csv
|
|
49
|
+
|
|
50
|
+
# Year summary (JSON or text)
|
|
51
|
+
pm-ledger summarize realized_pnl_2026.csv polymarket_us_activities.json --year 2026
|
|
52
|
+
pm-ledger summarize realized_pnl_2026.csv --year 2026 --json
|
|
53
|
+
|
|
54
|
+
# Idempotent import into a local store (safe to re-run)
|
|
55
|
+
pm-ledger import realized_pnl_2026.csv --store ledger.json
|
|
56
|
+
|
|
57
|
+
# Export a normalized ledger
|
|
58
|
+
pm-ledger export --store ledger.json --format json --out ledger_out.json
|
|
59
|
+
pm-ledger export --store ledger.json --format csv --out ledger_out/
|
|
60
|
+
pm-ledger export polymarket_us_activities.json --format sheet --out polymarket_for_sheet.csv
|
|
61
|
+
|
|
62
|
+
# Open positions
|
|
63
|
+
pm-ledger positions --store ledger.json
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
Python API:
|
|
67
|
+
|
|
68
|
+
```python
|
|
69
|
+
from pm_ledger import Ledger, detect, year_summary
|
|
70
|
+
|
|
71
|
+
ledger = Ledger() # default timezone: US Eastern
|
|
72
|
+
ledger.import_file("Kalshi-Recent-Activity-All.csv")
|
|
73
|
+
ledger.import_file("polymarket_us_activities.json")
|
|
74
|
+
closed, open_lots, warnings = ledger.compute()
|
|
75
|
+
summary = year_summary(closed, open_lots, ledger.cash_events(), 2026)
|
|
76
|
+
ledger.save("ledger.json")
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
CSV templates that match the ledger schema are in [`templates/`](templates/). The JSON Schema (2020-12) is in [`schema/ledger.schema.json`](schema/ledger.schema.json). Synthetic fixtures used by the test suite are in [`fixtures/`](fixtures/).
|
|
80
|
+
|
|
81
|
+
## Privacy
|
|
82
|
+
|
|
83
|
+
This project is local-first and privacy-first.
|
|
84
|
+
|
|
85
|
+
- Your trade data stays on your computer.
|
|
86
|
+
- The package does not collect user data.
|
|
87
|
+
- There is no telemetry, analytics, crash reporting, or phone-home of any kind.
|
|
88
|
+
- The core library and CLI make **no network calls**. They only read files you pass in and write files where you tell them to.
|
|
89
|
+
- There are no accounts, no cloud sync, and no third-party destinations for your ledger.
|
|
90
|
+
|
|
91
|
+
## Disclaimer
|
|
92
|
+
|
|
93
|
+
Not affiliated with, endorsed by, or sponsored by Kalshi or Polymarket. Record-keeping tool, not tax, legal, or investment advice.
|
|
94
|
+
|
|
95
|
+
Kalshi and Polymarket are trademarks of their respective owners. This tool does not place orders, does not recommend trades or tax positions, and is not a substitute for a qualified tax professional.
|
|
96
|
+
|
|
97
|
+
## Development
|
|
98
|
+
|
|
99
|
+
```bash
|
|
100
|
+
# Refresh this tree from the upstream oss-core checkout (never copies pro/)
|
|
101
|
+
./scripts/sync-from-source.sh
|
|
102
|
+
|
|
103
|
+
# Python tests (includes a guard that fails if a test tries to open a network socket)
|
|
104
|
+
pytest
|
|
105
|
+
|
|
106
|
+
# JavaScript / Apps Script parser tests (node --test; skips until the port is present)
|
|
107
|
+
node --test js/test/*.test.js
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
Source: <https://codeberg.org/marginandmoss/pm-ledger>. CI configs are included for Codeberg/Forgejo Actions (`.forgejo/workflows/ci.yml`), GitLab CI (`.gitlab-ci.yml`), and GitHub Actions (`.github/workflows/`). Each runs pytest on Python 3.10–3.12 and the Node test runner. On GitHub, tagging `v*` builds an sdist and wheel and attaches them to a GitHub Release. This repository does not publish to PyPI from CI; see the separate PyPI notes for a manual token upload.
|
|
111
|
+
|
|
112
|
+
## License
|
|
113
|
+
|
|
114
|
+
[MIT](LICENSE). Copyright (c) 2026 Margin & Moss.
|
|
115
|
+
|
|
116
|
+
Schema, templates, parsers, and this documentation are the public core. Do not add commercial Pro sources to this tree.
|