[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"skill:01M77RWAE6C5HSYNHEHE5J7H7J":3,"skill-same:01M77RWAE6C5HSYNHEHE5J7H7J":56},{"skillNo":4,"name":5,"nameZh":6,"description":7,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":16,"categories":17,"keywords":18,"publishedAt":19,"linkOnly":20,"markdownContent":21,"markdownBody":22,"frontMatter":23,"refName":33,"commitSha":34,"skillDirectory":35,"forksCount":36,"repositoryHtmlUrl":37,"repositoryHomepageUrl":38,"ownerHtmlUrl":39,"ownerBlogUrl":6,"ownerDescription":40,"updatedAt":41,"install":42,"resources":55},"01M77RWAE6C5HSYNHEHE5J7H7J","Position Tracker Self-Healing State Management",null,"Keep track of positions across any exchange, broker, or external system. Detect orphans, prevent leaks. Self-healing state reconciliation for any stateful bot.","Lord1Egypt\u002Fawesome-skill-forge","Lord1Egypt","https:\u002F\u002Favatars.githubusercontent.com\u002Fu\u002F99746359?v=4","01M7592YDNT0XK9WJ0T2MQVPDN","Mohamed Mounir Ali AL Keshita","01M75GRFNHC8VZNWEB8DKDE433",3,"MIT","https:\u002F\u002Fgithub.com\u002FLord1Egypt\u002Fawesome-skill-forge\u002Fblob\u002Fmaster\u002Fcommunity\u002Fclawhub\u002Fp\u002Fposition-tracker\u002FSKILL.md",[],[],"2026-11-15 14:19:17",false,"﻿---\nname: \"Position Tracker Self-Healing State Management\"\ndescription: \"Keep track of positions across any exchange, broker, or external system. Detect orphans, prevent leaks. Self-healing state reconciliation for any stateful bot.\"\nauthor: \"@TheShadowRose\"\nversion: \"1.0.0\"\ntags: [\"state-management\", \"tracking\", \"orphan-detection\", \"reconciliation\", \"bot\", \"python\"]\nlicense: \"MIT\"\n---\n\n# Position Tracker Self-Healing State Management\n\nKeep track of positions across any exchange, broker, or external system. Detect orphans, prevent leaks. Self-healing state reconciliation for any stateful bot.\n\n---\n\n## Keep track of positions across ANY exchange, broker, or external system. Detect orphans. Prevent leaks.\n\n[![License: MIT](https:\u002F\u002Fimg.shields.io\u002Fbadge\u002FLicense-MIT-yellow.svg)](.\u002FLICENSE)\n[![Python: 3.8+](https:\u002F\u002Fimg.shields.io\u002Fbadge\u002FPython-3.8%2B-blue)]()\n\n**Position Tracker is a generalized state machine for tracking positions with self-healing reconciliation against external APIs.**\n\nOriginally built for high-frequency crypto trading, now generalized for **any** domain where you need to track external positions that can become orphaned or phantom.\n\n---\n\n## The Problem\n\nYou're tracking positions across an external system (exchange, broker, cloud provider, API service). Your local state says you have 3 active positions. The external API says you have 5.\n\n**Which is correct?**\n\nWithout reconciliation, you get:\n- **Orphans** — positions exist on the exchange but not in your state (leak money\u002Fresources)\n- **Phantoms** — positions exist in your state but not on the exchange (trigger unnecessary actions)\n- **Drift** — state becomes increasingly inconsistent over time\n\n**Manual fixes don't scale.** You need self-healing reconciliation.\n\n---\n\n## The Solution\n\nPosition Tracker implements:\n\n### 1. **State Machine** (Position Lifecycle)\nTrack positions through their full lifecycle:\n```\nWATCHING → IN → EXITED → cleanup\n```\n\nEach state has:\n- Entry\u002Fexit conditions\n- Transition logic\n- Timeout handling\n- Cleanup rules\n\n### 2. **Orphan Detection**\nDetect positions that exist externally but not in your local state:\n- Poll external API for all positions\n- Compare against local state\n- Flag discrepancies above dust threshold\n- Self-heal via automatic reconciliation\n\n### 3. **Phantom Cleanup**\nRemove local state entries that don't correspond to external reality:\n- Detect missing external positions\n- Verify before cleanup (avoid race conditions)\n- Log cleanup actions for audit trail\n\n### 4. **Dust Filtering**\nIgnore sub-threshold positions to prevent noise:\n- Set minimum value threshold\n- Skip positions below threshold (rewards, rounding errors, etc.)\n- Configurable per use case\n\n### 5. **Reconciliation**\nPeriodic health checks against external API:\n- Detect state drift\n- Flag inconsistencies\n- Auto-correct when safe\n- Alert when manual intervention needed\n\n---\n\n## Quick Start (3 Steps)\n\n### 1. Install\n```bash\npip install position-tracker\n# OR copy position_tracker.py to your project\n```\n\n### 2. Implement API Adapter\n```python\nfrom position_tracker import PositionTracker, ExternalAPIAdapter\n\nclass MyBrokerAdapter(ExternalAPIAdapter):\n    def get_all_positions(self):\n        \"\"\"Fetch all positions from your broker\u002Fexchange.\"\"\"\n        # Return list of {\"id\": str, \"value\": float, \"metadata\": dict}\n        return self.broker_client.get_positions()\n    \n    def close_position(self, position_id):\n        \"\"\"Close a position on the broker\u002Fexchange.\"\"\"\n        return self.broker_client.close(position_id)\n```\n\n### 3. Track Positions\n```python\ntracker = PositionTracker(\n    api_adapter=MyBrokerAdapter(),\n    min_position_value=5.0,  # Ignore positions \u003C $5\n    max_positions=10,         # Safety cap\n)\n\n# Track a new position\ntracker.track(\"AAPL-123\", metadata={\"entry_price\": 150.00})\n\n# Update state\ntracker.update(\"AAPL-123\", action=\"ENTER\", value=1000.0)\n\n# Check for orphans (self-healing)\norphans = tracker.detect_orphans()\nif orphans:\n    tracker.cleanup_orphans(orphans)\n\n# Reconcile against external API\ntracker.reconcile()\n```\n\n**Time to integrate: 20-30 minutes.**\n\n---\n\n## Use Cases\n\n### Crypto\u002FStock Trading\nTrack open positions across exchanges. Detect orphaned trades that weren't recorded locally. Prevent position leaks that cost money.\n\n### Cloud Resource Management\nTrack active cloud instances (AWS EC2, GCP VMs, etc.). Detect orphaned instances that are still billing but not tracked. Auto-cleanup to save costs.\n\n### API Service Quotas\nTrack active API sessions, subscriptions, or quota allocations. Detect orphaned sessions that consume quota. Cleanup to free resources.\n\n### Database Connection Pools\nTrack open database connections. Detect orphaned connections that weren't properly closed. Prevent connection leaks.\n\n### Subscription Management\nTrack active subscriptions across services. Detect orphans (subscriptions you forgot about). Cancel to save money.\n\n**Any domain where external state can diverge from local tracking benefits from this.**\n\n---\n\n## Architecture\n\n### State Machine\n```\nWATCHING:  Position detected, not yet entered\n    ↓ (action=ENTER)\nIN:        Active position being tracked\n    ↓ (action=EXIT)\nEXITED:    Position closed, pending cleanup\n    ↓ (timeout)\n(deleted)  Cleaned up after timeout\n```\n\n### Orphan Detection Flow\n```\n1. Fetch all positions from external API\n2. Compare against local state\n3. Flag positions in API but not in state (orphans)\n4. Filter by min_position_value (ignore dust)\n5. Log orphans for review\n6. (Optional) Auto-cleanup via API adapter\n```\n\n### Reconciliation Flow\n```\n1. Periodic poll (e.g., every 5 minutes)\n2. Get local IN positions\n3. Verify each exists in external API\n4. Flag phantoms (local but not external)\n5. Flag orphans (external but not local)\n6. Auto-correct or alert based on config\n```\n\n---\n\n## Configuration\n\n### Basic Config\n```python\ntracker = PositionTracker(\n    api_adapter=adapter,\n    state_dir=\".\u002Fstate\",              # Where to persist state\n    min_position_value=5.0,           # Dust threshold ($5)\n    max_positions=10,                 # Safety cap\n    skip_cleanup_seconds=3600,        # Clean up SKIPPED after 1h\n    exited_cleanup_seconds=1800,      # Clean up EXITED after 30m\n)\n```\n\n### Advanced Config\n```python\ntracker = PositionTracker(\n    # ... basic config ...\n    enable_auto_reconcile=True,       # Auto-fix orphans\u002Fphantoms\n    reconcile_interval=300,           # Reconcile every 5 min\n    log_file=\".\u002Flogs\u002Ftracker.log\",    # Logging\n    alert_callback=my_alert_func,     # Custom alerting\n)\n```\n\nSee [config_example.json](.\u002Fconfig_example.json) for full options.\n\n---\n\n## API Reference\n\n### Core Methods\n\n#### `track(position_id, metadata=None)`\nStart tracking a new position.\n\n**Args:**\n- `position_id` (str): Unique identifier\n- `metadata` (dict, optional): Additional data to store\n\n**Returns:** PositionState object\n\n---\n\n#### `update(position_id, action, value=0.0)`\nUpdate position state based on action.\n\n**Args:**\n- `position_id` (str): Position to update\n- `action` (str): One of `ENTER`, `EXIT`, `HOLD`, `MONITOR`, `SKIP`\n- `value` (float): Current position value\n\n**Returns:** Updated PositionState object\n\n---\n\n#### `detect_orphans()`\nDetect positions on external API that aren't in local state.\n\n**Returns:** List of orphan position dicts `[{\"id\": str, \"value\": float, ...}]`\n\n---\n\n#### `cleanup_orphans(orphans, auto_close=False)`\nHandle orphaned positions.\n\n**Args:**\n- `orphans` (list): List from `detect_orphans()`\n- `auto_close` (bool): If True, close orphans via API adapter\n\n**Returns:** List of cleaned up position IDs\n\n---\n\n#### `reconcile()`\nReconcile local state against external API.\n\n**Returns:** Reconciliation report dict with `orphans`, `phantoms`, `corrected`\n\n---\n\n### State Machine Actions\n\n- **`ENTER`** — Enter a position (WATCHING → IN)\n- **`EXIT`** — Exit a position (IN → EXITED)\n- **`HOLD`** — Hold current position (stay in IN)\n- **`MONITOR`** — Continue monitoring (stay in WATCHING)\n- **`SKIP`** — Skip this position (WATCHING → SKIPPED)\n\n---\n\n## Error Handling\n\n### Orphan Detection\n```python\ntry:\n    orphans = tracker.detect_orphans()\nexcept ExternalAPIError as e:\n    logger.error(f\"API unreachable: {e}\")\n    # Fall back to local state only\n```\n\n### Reconciliation Failure\n```python\nreport = tracker.reconcile()\nif report[\"errors\"]:\n    logger.warning(f\"Reconciliation errors: {report['errors']}\")\n    # Manual intervention needed\n```\n\n### Position Not Found\n```python\nstate = tracker.get(\"unknown-id\")\nif state is None:\n    logger.info(\"Position not tracked\")\n```\n\n---\n\n## Testing\n\n### Unit Tests\n```bash\npytest tests\u002Ftest_position_tracker.py\n```\n\n### Integration Test (Mock API)\n```python\nfrom position_tracker import PositionTracker, MockAPIAdapter\n\nadapter = MockAPIAdapter()\nadapter.add_position(\"test-1\", value=100.0)\n\ntracker = PositionTracker(adapter)\ntracker.track(\"test-1\")\ntracker.update(\"test-1\", \"ENTER\", value=100.0)\n\n# Simulate orphan\nadapter.add_position(\"test-2\", value=200.0)\norphans = tracker.detect_orphans()\nassert len(orphans) == 1\nassert orphans[0][\"id\"] == \"test-2\"\n```\n\n---\n\n## Limitations\n\nSee [LIMITATIONS.md](.\u002FLIMITATIONS.md) for details, including:\n- API rate limits and polling frequency\n- Race conditions during reconciliation\n- Dust threshold calibration\n- State persistence guarantees\n\n---\n\n## Performance\n\n### Memory\n- ~1KB per tracked position\n- 1000 positions ≈ 1MB memory\n- State file grows linearly with position count\n\n### CPU\n- Reconciliation: O(N) where N = position count\n- Typical: \u003C10ms for 100 positions\n\n### I\u002FO\n- State saves: atomic writes with fsync\n- API polls: configurable interval (default 300s)\n\n---\n\n## Troubleshooting\n\n### Problem: Orphans detected every reconciliation cycle\n**Cause:** Dust threshold too high, filtering out real positions  \n**Fix:** Lower `min_position_value` to match your use case\n\n---\n\n### Problem: State file grows unbounded\n**Cause:** Old EXITED positions not cleaning up  \n**Fix:** Check `exited_cleanup_seconds` config, ensure timeouts are working\n\n---\n\n### Problem: API adapter errors\n**Cause:** External API unreachable or credentials invalid  \n**Fix:** Implement retry logic in your adapter, add error handling\n\n---\n\n## Migration Guide\n\n### From Manual Tracking\n1. Export current positions to JSON\n2. Initialize tracker with `state_file=your_export.json`\n3. Run `reconcile()` to validate\n4. Switch to tracker for all position updates\n\n### From Custom State Machine\n1. Map your states to tracker states (WATCHING\u002FIN\u002FEXITED)\n2. Implement API adapter for your external system\n3. Run parallel for 1-2 days (log differences)\n4. Cut over once validated\n\n---\n\n## Contributing\n\nPosition Tracker is **open source** and **community-maintained**.\n\n### Report Issues\n- Bugs, edge cases, performance problems\n- Integration confusion (docs unclear)\n- Feature requests\n\n### Submit Improvements\n- Additional API adapter examples\n- Performance optimizations\n- Test coverage improvements\n\n**Contribution guidelines:** Open an issue or PR on GitHub. We review everything.\n\n---\n\n## Philosophy: Why Open Source?\n\nPosition Tracker solves a **universal infrastructure problem** — tracking external state reliably. Hoarding the solution helps no one.\n\nThis is a **goodwill project** to:\n1. Prove the **vibe coding methodology** (build adaptive systems by feel, not CS theory)\n2. Build reputation for future paid Shadow Rose products\n3. Improve through community testing and feedback\n\n---\n\n## Support & Community\n\n### Get Help\n- 📖 **Documentation:** You're reading it\n- 💬 **Discord:** https:\u002F\u002Fdiscord.com\u002Finvite\u002Fclawd (OpenClaw community)\n- 🐦 **Twitter:** https:\u002F\u002Fx.com\u002FTheShadowyRose\n- 🐛 **Issues:** [GitHub link]\n\n### Support Development\nPosition Tracker is free, but if it saved you time:\n\n☕ **Ko-fi:** https:\u002F\u002Fko-fi.com\u002Ftheshadowrose\n\nDonations support ongoing testing, docs, and new features.\n\n---\n\n## License\n\nMIT License — use freely, credit appreciated.\n\nCopyright © 2026 Shadow Rose\n\nSee [LICENSE](.\u002FLICENSE) for details.\n\n---\n\n## What's Next?\n\n### Planned Features\n- **Redis backend** — Distributed state across multiple processes\n- **WebSocket support** — Real-time reconciliation instead of polling\n- **Advanced alerting** — Slack, PagerDuty, email integrations\n- **Dashboard** — Web UI for monitoring positions\n\n**Want to work on these?** Open an issue or reach out on Discord.\n\n---\n\n## Credits\n\n**Created by:** Shadow Rose  \n**Extracted from:** Production trading bot (proven in live trading)  \n**Philosophy:** Vibe coding — infrastructure that heals itself  \n**License:** MIT\n\nBuilt on lessons learned from a real orphan catastrophe — dozens of positions leaked, manual cleanup required. Never again.\n\n---\n\n## Final Thought\n\nExternal state will diverge from local state. That's not a bug, it's reality.\n\nThe question is: **does your system detect and heal the divergence automatically, or do you find out when the bill arrives?**\n\nPosition Tracker ensures you find out **before** the bill arrives.\n\nShip it. Break it. Tell us what you find.\n\n— Shadow Rose  \nFebruary 2026\n\n---\n\n☕ Support: https:\u002F\u002Fko-fi.com\u002Ftheshadowrose  \n🐦 Follow: https:\u002F\u002Fx.com\u002FTheShadowyRose  \n💬 Community: https:\u002F\u002Fdiscord.com\u002Finvite\u002Fclawd\n\n\n---\n\n## ⚠️ Disclaimer\n\nThis software is provided \"AS IS\", without warranty of any kind, express or implied.\n\n**USE AT YOUR OWN RISK.**\n\n- The author(s) are NOT liable for any damages, losses, or consequences arising from \n  the use or misuse of this software — including but not limited to financial loss, \n  data loss, security breaches, business interruption, or any indirect\u002Fconsequential damages.\n- This software does NOT constitute financial, legal, trading, or professional advice.\n- Users are solely responsible for evaluating whether this software is suitable for \n  their use case, environment, and risk tolerance.\n- No guarantee is made regarding accuracy, reliability, completeness, or fitness \n  for any particular purpose.\n- The author(s) are not responsible for how third parties use, modify, or distribute \n  this software after purchase.\n\nBy downloading, installing, or using this software, you acknowledge that you have read \nthis disclaimer and agree to use the software entirely at your own risk.\n\n\n**TRADING DISCLAIMER:** This software is a tool, not a trading system. It does not \nmake trading decisions for you and does not guarantee profits. Trading cryptocurrency, \nstocks, or any financial instrument carries significant risk of loss. You can lose \nsome or all of your investment. Past performance of any system or methodology is not \nindicative of future results. Never trade with money you cannot afford to lose. \nConsult a qualified financial advisor before making investment decisions.\n---\n\n## Support & Links\n\n| | |\n|---|---|\n| 🐛 **Bug Reports** | TheShadowyRose@proton.me |\n| ☕ **Ko-fi** | [ko-fi.com\u002Ftheshadowrose](https:\u002F\u002Fko-fi.com\u002Ftheshadowrose) |\n| 🛒 **Gumroad** | [shadowyrose.gumroad.com](https:\u002F\u002Fshadowyrose.gumroad.com) |\n| 🐦 **Twitter** | [@TheShadowyRose](https:\u002F\u002Ftwitter.com\u002FTheShadowyRose) |\n| 🐙 **GitHub** | [github.com\u002FTheShadowRose](https:\u002F\u002Fgithub.com\u002FTheShadowRose) |\n| 🧠 **PromptBase** | [promptbase.com\u002Fprofile\u002Fshadowrose](https:\u002F\u002Fpromptbase.com\u002Fprofile\u002Fshadowrose) |\n\n*Built with [OpenClaw](https:\u002F\u002Fgithub.com\u002Fopenclaw\u002Fopenclaw) — thank you for making this possible.*\n\n---\n\n🛠️ **Need something custom?** Custom OpenClaw agents & skills starting at $500. If you can describe it, I can build it. → [Hire me on Fiverr](https:\u002F\u002Fwww.fiverr.com\u002Fs\u002FjjmlZ0v)","# Position Tracker Self-Healing State Management\n\nKeep track of positions across any exchange, broker, or external system. Detect orphans, prevent leaks. Self-healing state reconciliation for any stateful bot.\n\n---\n\n## Keep track of positions across ANY exchange, broker, or external system. Detect orphans. Prevent leaks.\n\n[![License: MIT](https:\u002F\u002Fimg.shields.io\u002Fbadge\u002FLicense-MIT-yellow.svg)](.\u002FLICENSE)\n[![Python: 3.8+](https:\u002F\u002Fimg.shields.io\u002Fbadge\u002FPython-3.8%2B-blue)]()\n\n**Position Tracker is a generalized state machine for tracking positions with self-healing reconciliation against external APIs.**\n\nOriginally built for high-frequency crypto trading, now generalized for **any** domain where you need to track external positions that can become orphaned or phantom.\n\n---\n\n## The Problem\n\nYou're tracking positions across an external system (exchange, broker, cloud provider, API service). Your local state says you have 3 active positions. The external API says you have 5.\n\n**Which is correct?**\n\nWithout reconciliation, you get:\n- **Orphans** — positions exist on the exchange but not in your state (leak money\u002Fresources)\n- **Phantoms** — positions exist in your state but not on the exchange (trigger unnecessary actions)\n- **Drift** — state becomes increasingly inconsistent over time\n\n**Manual fixes don't scale.** You need self-healing reconciliation.\n\n---\n\n## The Solution\n\nPosition Tracker implements:\n\n### 1. **State Machine** (Position Lifecycle)\nTrack positions through their full lifecycle:\n```\nWATCHING → IN → EXITED → cleanup\n```\n\nEach state has:\n- Entry\u002Fexit conditions\n- Transition logic\n- Timeout handling\n- Cleanup rules\n\n### 2. **Orphan Detection**\nDetect positions that exist externally but not in your local state:\n- Poll external API for all positions\n- Compare against local state\n- Flag discrepancies above dust threshold\n- Self-heal via automatic reconciliation\n\n### 3. **Phantom Cleanup**\nRemove local state entries that don't correspond to external reality:\n- Detect missing external positions\n- Verify before cleanup (avoid race conditions)\n- Log cleanup actions for audit trail\n\n### 4. **Dust Filtering**\nIgnore sub-threshold positions to prevent noise:\n- Set minimum value threshold\n- Skip positions below threshold (rewards, rounding errors, etc.)\n- Configurable per use case\n\n### 5. **Reconciliation**\nPeriodic health checks against external API:\n- Detect state drift\n- Flag inconsistencies\n- Auto-correct when safe\n- Alert when manual intervention needed\n\n---\n\n## Quick Start (3 Steps)\n\n### 1. Install\n```bash\npip install position-tracker\n# OR copy position_tracker.py to your project\n```\n\n### 2. Implement API Adapter\n```python\nfrom position_tracker import PositionTracker, ExternalAPIAdapter\n\nclass MyBrokerAdapter(ExternalAPIAdapter):\n    def get_all_positions(self):\n        \"\"\"Fetch all positions from your broker\u002Fexchange.\"\"\"\n        # Return list of {\"id\": str, \"value\": float, \"metadata\": dict}\n        return self.broker_client.get_positions()\n    \n    def close_position(self, position_id):\n        \"\"\"Close a position on the broker\u002Fexchange.\"\"\"\n        return self.broker_client.close(position_id)\n```\n\n### 3. Track Positions\n```python\ntracker = PositionTracker(\n    api_adapter=MyBrokerAdapter(),\n    min_position_value=5.0,  # Ignore positions \u003C $5\n    max_positions=10,         # Safety cap\n)\n\n# Track a new position\ntracker.track(\"AAPL-123\", metadata={\"entry_price\": 150.00})\n\n# Update state\ntracker.update(\"AAPL-123\", action=\"ENTER\", value=1000.0)\n\n# Check for orphans (self-healing)\norphans = tracker.detect_orphans()\nif orphans:\n    tracker.cleanup_orphans(orphans)\n\n# Reconcile against external API\ntracker.reconcile()\n```\n\n**Time to integrate: 20-30 minutes.**\n\n---\n\n## Use Cases\n\n### Crypto\u002FStock Trading\nTrack open positions across exchanges. Detect orphaned trades that weren't recorded locally. Prevent position leaks that cost money.\n\n### Cloud Resource Management\nTrack active cloud instances (AWS EC2, GCP VMs, etc.). Detect orphaned instances that are still billing but not tracked. Auto-cleanup to save costs.\n\n### API Service Quotas\nTrack active API sessions, subscriptions, or quota allocations. Detect orphaned sessions that consume quota. Cleanup to free resources.\n\n### Database Connection Pools\nTrack open database connections. Detect orphaned connections that weren't properly closed. Prevent connection leaks.\n\n### Subscription Management\nTrack active subscriptions across services. Detect orphans (subscriptions you forgot about). Cancel to save money.\n\n**Any domain where external state can diverge from local tracking benefits from this.**\n\n---\n\n## Architecture\n\n### State Machine\n```\nWATCHING:  Position detected, not yet entered\n    ↓ (action=ENTER)\nIN:        Active position being tracked\n    ↓ (action=EXIT)\nEXITED:    Position closed, pending cleanup\n    ↓ (timeout)\n(deleted)  Cleaned up after timeout\n```\n\n### Orphan Detection Flow\n```\n1. Fetch all positions from external API\n2. Compare against local state\n3. Flag positions in API but not in state (orphans)\n4. Filter by min_position_value (ignore dust)\n5. Log orphans for review\n6. (Optional) Auto-cleanup via API adapter\n```\n\n### Reconciliation Flow\n```\n1. Periodic poll (e.g., every 5 minutes)\n2. Get local IN positions\n3. Verify each exists in external API\n4. Flag phantoms (local but not external)\n5. Flag orphans (external but not local)\n6. Auto-correct or alert based on config\n```\n\n---\n\n## Configuration\n\n### Basic Config\n```python\ntracker = PositionTracker(\n    api_adapter=adapter,\n    state_dir=\".\u002Fstate\",              # Where to persist state\n    min_position_value=5.0,           # Dust threshold ($5)\n    max_positions=10,                 # Safety cap\n    skip_cleanup_seconds=3600,        # Clean up SKIPPED after 1h\n    exited_cleanup_seconds=1800,      # Clean up EXITED after 30m\n)\n```\n\n### Advanced Config\n```python\ntracker = PositionTracker(\n    # ... basic config ...\n    enable_auto_reconcile=True,       # Auto-fix orphans\u002Fphantoms\n    reconcile_interval=300,           # Reconcile every 5 min\n    log_file=\".\u002Flogs\u002Ftracker.log\",    # Logging\n    alert_callback=my_alert_func,     # Custom alerting\n)\n```\n\nSee [config_example.json](.\u002Fconfig_example.json) for full options.\n\n---\n\n## API Reference\n\n### Core Methods\n\n#### `track(position_id, metadata=None)`\nStart tracking a new position.\n\n**Args:**\n- `position_id` (str): Unique identifier\n- `metadata` (dict, optional): Additional data to store\n\n**Returns:** PositionState object\n\n---\n\n#### `update(position_id, action, value=0.0)`\nUpdate position state based on action.\n\n**Args:**\n- `position_id` (str): Position to update\n- `action` (str): One of `ENTER`, `EXIT`, `HOLD`, `MONITOR`, `SKIP`\n- `value` (float): Current position value\n\n**Returns:** Updated PositionState object\n\n---\n\n#### `detect_orphans()`\nDetect positions on external API that aren't in local state.\n\n**Returns:** List of orphan position dicts `[{\"id\": str, \"value\": float, ...}]`\n\n---\n\n#### `cleanup_orphans(orphans, auto_close=False)`\nHandle orphaned positions.\n\n**Args:**\n- `orphans` (list): List from `detect_orphans()`\n- `auto_close` (bool): If True, close orphans via API adapter\n\n**Returns:** List of cleaned up position IDs\n\n---\n\n#### `reconcile()`\nReconcile local state against external API.\n\n**Returns:** Reconciliation report dict with `orphans`, `phantoms`, `corrected`\n\n---\n\n### State Machine Actions\n\n- **`ENTER`** — Enter a position (WATCHING → IN)\n- **`EXIT`** — Exit a position (IN → EXITED)\n- **`HOLD`** — Hold current position (stay in IN)\n- **`MONITOR`** — Continue monitoring (stay in WATCHING)\n- **`SKIP`** — Skip this position (WATCHING → SKIPPED)\n\n---\n\n## Error Handling\n\n### Orphan Detection\n```python\ntry:\n    orphans = tracker.detect_orphans()\nexcept ExternalAPIError as e:\n    logger.error(f\"API unreachable: {e}\")\n    # Fall back to local state only\n```\n\n### Reconciliation Failure\n```python\nreport = tracker.reconcile()\nif report[\"errors\"]:\n    logger.warning(f\"Reconciliation errors: {report['errors']}\")\n    # Manual intervention needed\n```\n\n### Position Not Found\n```python\nstate = tracker.get(\"unknown-id\")\nif state is None:\n    logger.info(\"Position not tracked\")\n```\n\n---\n\n## Testing\n\n### Unit Tests\n```bash\npytest tests\u002Ftest_position_tracker.py\n```\n\n### Integration Test (Mock API)\n```python\nfrom position_tracker import PositionTracker, MockAPIAdapter\n\nadapter = MockAPIAdapter()\nadapter.add_position(\"test-1\", value=100.0)\n\ntracker = PositionTracker(adapter)\ntracker.track(\"test-1\")\ntracker.update(\"test-1\", \"ENTER\", value=100.0)\n\n# Simulate orphan\nadapter.add_position(\"test-2\", value=200.0)\norphans = tracker.detect_orphans()\nassert len(orphans) == 1\nassert orphans[0][\"id\"] == \"test-2\"\n```\n\n---\n\n## Limitations\n\nSee [LIMITATIONS.md](.\u002FLIMITATIONS.md) for details, including:\n- API rate limits and polling frequency\n- Race conditions during reconciliation\n- Dust threshold calibration\n- State persistence guarantees\n\n---\n\n## Performance\n\n### Memory\n- ~1KB per tracked position\n- 1000 positions ≈ 1MB memory\n- State file grows linearly with position count\n\n### CPU\n- Reconciliation: O(N) where N = position count\n- Typical: \u003C10ms for 100 positions\n\n### I\u002FO\n- State saves: atomic writes with fsync\n- API polls: configurable interval (default 300s)\n\n---\n\n## Troubleshooting\n\n### Problem: Orphans detected every reconciliation cycle\n**Cause:** Dust threshold too high, filtering out real positions  \n**Fix:** Lower `min_position_value` to match your use case\n\n---\n\n### Problem: State file grows unbounded\n**Cause:** Old EXITED positions not cleaning up  \n**Fix:** Check `exited_cleanup_seconds` config, ensure timeouts are working\n\n---\n\n### Problem: API adapter errors\n**Cause:** External API unreachable or credentials invalid  \n**Fix:** Implement retry logic in your adapter, add error handling\n\n---\n\n## Migration Guide\n\n### From Manual Tracking\n1. Export current positions to JSON\n2. Initialize tracker with `state_file=your_export.json`\n3. Run `reconcile()` to validate\n4. Switch to tracker for all position updates\n\n### From Custom State Machine\n1. Map your states to tracker states (WATCHING\u002FIN\u002FEXITED)\n2. Implement API adapter for your external system\n3. Run parallel for 1-2 days (log differences)\n4. Cut over once validated\n\n---\n\n## Contributing\n\nPosition Tracker is **open source** and **community-maintained**.\n\n### Report Issues\n- Bugs, edge cases, performance problems\n- Integration confusion (docs unclear)\n- Feature requests\n\n### Submit Improvements\n- Additional API adapter examples\n- Performance optimizations\n- Test coverage improvements\n\n**Contribution guidelines:** Open an issue or PR on GitHub. We review everything.\n\n---\n\n## Philosophy: Why Open Source?\n\nPosition Tracker solves a **universal infrastructure problem** — tracking external state reliably. Hoarding the solution helps no one.\n\nThis is a **goodwill project** to:\n1. Prove the **vibe coding methodology** (build adaptive systems by feel, not CS theory)\n2. Build reputation for future paid Shadow Rose products\n3. Improve through community testing and feedback\n\n---\n\n## Support & Community\n\n### Get Help\n- 📖 **Documentation:** You're reading it\n- 💬 **Discord:** https:\u002F\u002Fdiscord.com\u002Finvite\u002Fclawd (OpenClaw community)\n- 🐦 **Twitter:** https:\u002F\u002Fx.com\u002FTheShadowyRose\n- 🐛 **Issues:** [GitHub link]\n\n### Support Development\nPosition Tracker is free, but if it saved you time:\n\n☕ **Ko-fi:** https:\u002F\u002Fko-fi.com\u002Ftheshadowrose\n\nDonations support ongoing testing, docs, and new features.\n\n---\n\n## License\n\nMIT License — use freely, credit appreciated.\n\nCopyright © 2026 Shadow Rose\n\nSee [LICENSE](.\u002FLICENSE) for details.\n\n---\n\n## What's Next?\n\n### Planned Features\n- **Redis backend** — Distributed state across multiple processes\n- **WebSocket support** — Real-time reconciliation instead of polling\n- **Advanced alerting** — Slack, PagerDuty, email integrations\n- **Dashboard** — Web UI for monitoring positions\n\n**Want to work on these?** Open an issue or reach out on Discord.\n\n---\n\n## Credits\n\n**Created by:** Shadow Rose  \n**Extracted from:** Production trading bot (proven in live trading)  \n**Philosophy:** Vibe coding — infrastructure that heals itself  \n**License:** MIT\n\nBuilt on lessons learned from a real orphan catastrophe — dozens of positions leaked, manual cleanup required. Never again.\n\n---\n\n## Final Thought\n\nExternal state will diverge from local state. That's not a bug, it's reality.\n\nThe question is: **does your system detect and heal the divergence automatically, or do you find out when the bill arrives?**\n\nPosition Tracker ensures you find out **before** the bill arrives.\n\nShip it. Break it. Tell us what you find.\n\n— Shadow Rose  \nFebruary 2026\n\n---\n\n☕ Support: https:\u002F\u002Fko-fi.com\u002Ftheshadowrose  \n🐦 Follow: https:\u002F\u002Fx.com\u002FTheShadowyRose  \n💬 Community: https:\u002F\u002Fdiscord.com\u002Finvite\u002Fclawd\n\n\n---\n\n## ⚠️ Disclaimer\n\nThis software is provided \"AS IS\", without warranty of any kind, express or implied.\n\n**USE AT YOUR OWN RISK.**\n\n- The author(s) are NOT liable for any damages, losses, or consequences arising from \n  the use or misuse of this software — including but not limited to financial loss, \n  data loss, security breaches, business interruption, or any indirect\u002Fconsequential damages.\n- This software does NOT constitute financial, legal, trading, or professional advice.\n- Users are solely responsible for evaluating whether this software is suitable for \n  their use case, environment, and risk tolerance.\n- No guarantee is made regarding accuracy, reliability, completeness, or fitness \n  for any particular purpose.\n- The author(s) are not responsible for how third parties use, modify, or distribute \n  this software after purchase.\n\nBy downloading, installing, or using this software, you acknowledge that you have read \nthis disclaimer and agree to use the software entirely at your own risk.\n\n\n**TRADING DISCLAIMER:** This software is a tool, not a trading system. It does not \nmake trading decisions for you and does not guarantee profits. Trading cryptocurrency, \nstocks, or any financial instrument carries significant risk of loss. You can lose \nsome or all of your investment. Past performance of any system or methodology is not \nindicative of future results. Never trade with money you cannot afford to lose. \nConsult a qualified financial advisor before making investment decisions.\n---\n\n## Support & Links\n\n| | |\n|---|---|\n| 🐛 **Bug Reports** | TheShadowyRose@proton.me |\n| ☕ **Ko-fi** | [ko-fi.com\u002Ftheshadowrose](https:\u002F\u002Fko-fi.com\u002Ftheshadowrose) |\n| 🛒 **Gumroad** | [shadowyrose.gumroad.com](https:\u002F\u002Fshadowyrose.gumroad.com) |\n| 🐦 **Twitter** | [@TheShadowyRose](https:\u002F\u002Ftwitter.com\u002FTheShadowyRose) |\n| 🐙 **GitHub** | [github.com\u002FTheShadowRose](https:\u002F\u002Fgithub.com\u002FTheShadowRose) |\n| 🧠 **PromptBase** | [promptbase.com\u002Fprofile\u002Fshadowrose](https:\u002F\u002Fpromptbase.com\u002Fprofile\u002Fshadowrose) |\n\n*Built with [OpenClaw](https:\u002F\u002Fgithub.com\u002Fopenclaw\u002Fopenclaw) — thank you for making this possible.*\n\n---\n\n🛠️ **Need something custom?** Custom OpenClaw agents & skills starting at $500. If you can describe it, I can build it. → [Hire me on Fiverr](https:\u002F\u002Fwww.fiverr.com\u002Fs\u002FjjmlZ0v)",{"name":5,"tags":24,"author":31,"license":15,"version":32,"description":7},[25,26,27,28,29,30],"state-management","tracking","orphan-detection","reconciliation","bot","python","@TheShadowRose","1.0.0","master","4aa004da461d820f4ea5499e58eb8d196cf99016","community\u002Fclawhub\u002Fp\u002Fposition-tracker",0,"https:\u002F\u002Fgithub.com\u002FLord1Egypt\u002Fawesome-skill-forge","https:\u002F\u002Fskill-explorer-rho.vercel.app","https:\u002F\u002Fgithub.com\u002FLord1Egypt","Unbreakable. Unstoppable. Unmatched⚡.\r\n Speaker of machine tongues 🤖  | World-builder of decentralized dreams 🌐 | Defender of the digital realm🛡️.","2026-06-10 08:21:01",{"source":8,"skillName":5,"commands":43,"prompt":53,"zipAvailable":54},[44,47,50],{"tool":45,"command":46},"npx","npx skills add Lord1Egypt\u002Fawesome-skill-forge --skill \"Position Tracker Self-Healing State Management\"",{"tool":48,"command":49},"bunx","bunx skills add Lord1Egypt\u002Fawesome-skill-forge --skill \"Position Tracker Self-Healing State Management\"",{"tool":51,"command":52},"pnpm","pnpm dlx skills add Lord1Egypt\u002Fawesome-skill-forge --skill \"Position Tracker Self-Healing State Management\"","安装技能，技能地址：https:\u002F\u002Fgithub.com\u002FLord1Egypt\u002Fawesome-skill-forge\u002Fblob\u002Fmaster\u002Fcommunity\u002Fclawhub\u002Fp\u002Fposition-tracker\u002FSKILL.md",true,[],[57,64,71,78,85,92],{"skillNo":58,"name":59,"nameZh":6,"description":60,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":61,"categories":62,"keywords":63,"publishedAt":19},"01M785WKJB99G3STR1NF9NRTJW","youtube-content","YouTube transcripts to summaries, threads, blogs.","https:\u002F\u002Fgithub.com\u002FLord1Egypt\u002Fawesome-skill-forge\u002Fblob\u002Fmaster\u002Fskills\u002Fyoutube-content\u002FSKILL.md",[],[],{"skillNo":65,"name":66,"nameZh":6,"description":67,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":68,"categories":69,"keywords":70,"publishedAt":19},"01M785WEFHB0G2S9YA6EPR3H0E","xurl","X\u002FTwitter via xurl CLI: post, search, DM, media, v2 API.","https:\u002F\u002Fgithub.com\u002FLord1Egypt\u002Fawesome-skill-forge\u002Fblob\u002Fmaster\u002Fskills\u002Fxurl\u002FSKILL.md",[],[],{"skillNo":72,"name":73,"nameZh":6,"description":74,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":75,"categories":76,"keywords":77,"publishedAt":19},"01M785W98EDN4EFJXJPMQEHCRC","touchdesigner-mcp","Control a running TouchDesigner instance via twozero MCP — create operators, set parameters, wire connections, execute Python, build real-time visuals. 36 native tools.","https:\u002F\u002Fgithub.com\u002FLord1Egypt\u002Fawesome-skill-forge\u002Fblob\u002Fmaster\u002Fskills\u002Ftouchdesigner-mcp\u002FSKILL.md",[],[],{"skillNo":79,"name":80,"nameZh":6,"description":81,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":82,"categories":83,"keywords":84,"publishedAt":19},"01M785W5S9FP3QBH2V191E025P","test-driven-development","TDD: enforce RED-GREEN-REFACTOR, tests before code.","https:\u002F\u002Fgithub.com\u002FLord1Egypt\u002Fawesome-skill-forge\u002Fblob\u002Fmaster\u002Fskills\u002Ftest-driven-development\u002FSKILL.md",[],[],{"skillNo":86,"name":87,"nameZh":6,"description":88,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":89,"categories":90,"keywords":91,"publishedAt":19},"01M785W2AS08NSSH9YATCV6FJB","teams-meeting-pipeline","Operate the Teams meeting summary pipeline via Hermes CLI — summarize meetings, inspect pipeline status, replay jobs, manage Microsoft Graph subscriptions.","https:\u002F\u002Fgithub.com\u002FLord1Egypt\u002Fawesome-skill-forge\u002Fblob\u002Fmaster\u002Fskills\u002Fteams-meeting-pipeline\u002FSKILL.md",[],[],{"skillNo":93,"name":94,"nameZh":6,"description":95,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":96,"categories":97,"keywords":98,"publishedAt":19},"01M785VXKW4T34BTP1SCHW1R7F","systematic-debugging","4-phase root cause debugging: understand bugs before fixing.","https:\u002F\u002Fgithub.com\u002FLord1Egypt\u002Fawesome-skill-forge\u002Fblob\u002Fmaster\u002Fskills\u002Fsystematic-debugging\u002FSKILL.md",[],[]]