شعار Capital Preservation Mode For Degraded Conditions

Capital Preservation Mode For Degraded Conditions

المجتمع
HimanshuJ16
capital-preservation-mode-for-degraded-conditions

استخدمه عندما يحتاج نظام يعمل مباشرةً إلى آلية مستقلة عن الاستراتيجية تمنع الأوامر الجديدة إذا تجاوز التراجع أو معدل إرسال الأوامر أو أخطاء منصة التداول المتتالية أو تقادم بيانات السوق حدًا معينًا. تمنع هذه الآلية الأوامر الجديدة؛ أما إلغاء الأوامر القائمة فهو مهمة مفتاح الإيقاف الطارئ.

Add to TypingMind

نظرة عامة

الناشرHimanshuJ16
المستودعAlgo-Trading-Skills
اسم المهارةcapital-preservation-mode-for-degraded-conditions
النجوم
50
التفريعات
7
الملفات المرفقة
5
الترخيصApache-2.0
الروابط
  • تعليمات بصيغة Markdown

    ملف SKILL.md يُحمّله النموذج عند الحاجة، فلا يستهلك توكنات إلا عندما يَرِد طلب ذو صلة فعلًا.

  • تعمل مع أي نموذج لغوي كبير

    مهارات الذكاء الاصطناعي مكتوبة بصيغة Markdown وليست شيفرة خاصة بمزوّد معيّن، لذا تعمل مع GPT أو Claude أو Gemini أو Grok أو نموذج محلي.

  • الملفات المرفقة: 5

    نصوص برمجية وقوالب ومراجع يمكن للنموذج قراءتها أثناء عمله. الملفات للقراءة فقط ولا تُنفّذ أبدًا.

  • مفتوحة المصدر

    نشرها HimanshuJ16 على GitHub. اطّلع على المصدر قبل تثبيتها.

التثبيت

ثبّت مهارة الذكاء الاصطناعي Capital Preservation Mode For Degraded Conditions في TypingMind لاستخدامها مع أي نموذج لغوي كبير، أو أضفها إلى وكيل ذكاء اصطناعي آخر يقرأ SKILL.md.

1

التثبيت في TypingMind

يُثبّت TypingMind المهارة مباشرةً من مجلدها على GitHub — فيقرأ SKILL.md، ويجمع ملفات الموارد في حزمة، ويحفظ النتيجة محليًا.

  1. افتح التطبيق وانتقل إلى «الإضافات» ثم «المهارات».
  2. اختر «تثبيت من GitHub».
  3. الصق رابط مجلد المهارة الموضّح أدناه وأكّد التثبيت.
    https://github.com/HimanshuJ16/Algo-Trading-Skills/tree/main/skills/capital-preservation-mode-for-degraded-conditions
  4. فعّل المهارة في كل محادثة تريد إتاحتها فيها.
الإضافات ← المهارات ← إضافة مهارة ← من رابط GitHub، ثم الصق رابط المجلد واضغط على «متابعة».
2

التثبيت في وكيل ذكاء اصطناعي آخر

يمكن لأي وكيل ذكاء اصطناعي يقرأ تنسيق Agent Skills استخدام هذه المهارة — انسخ المجلد إلى مجلد المهارات الخاص بذلك الوكيل.

Claude Code — .claude/skills
git clone --depth 1 https://github.com/HimanshuJ16/Algo-Trading-Skills.git /tmp/Algo-Trading-Skills
mkdir -p .claude/skills
cp -r /tmp/Algo-Trading-Skills/skills/capital-preservation-mode-for-degraded-conditions .claude/skills/capital-preservation-mode-for-degraded-conditions
أعد تشغيل Claude Code بعد النسخ ليتعرّف على المهارة الجديدة.

استخدمها في TypingMind

فعّل Capital Preservation Mode For Degraded Conditions في أي محادثة على TypingMind وسيتولى النموذج الباقي. تتضمن مطالبة النظام اسمها ووصفها، وبمجرد ورود طلب ذي صلة، يُحمّل النموذج التعليمات الكاملة تلقائيًا — فلا تحتاج إلى استدعائها يدويًا، ولا تستهلك أي توكنات حتى تُستخدم فعليًا.

يُحمّل النموذج مهارة Capital Preservation Mode For Degraded Conditions تلقائيًا بمجرد ورود طلب ذي صلة بها.

تعمل مع أي نموذج ذكاء اصطناعي

مهارات الذكاء الاصطناعي هي تعليمات بصيغة Markdown وليست شيفرة خاصة بمزوّد معيّن، لذا لا ترتبط Capital Preservation Mode For Degraded Conditions بالنموذج الذي كُتبت له. ثبّتها مرة واحدة في TypingMind واستخدمها مع GPT-5 أو Claude أو Gemini أو Grok أو DeepSeek أو Mistral أو Llama أو نموذج محلي تشغّله بنفسك — كل ذلك باستخدام مفاتيح API الخاصة بك.

  • تُحمَّل عند الحاجة فقط

    تتضمن مطالبة النظام الاسم والوصف فقط. وتُجلب التعليمات عند أول طلب ذي صلة، لذا لا تستهلك تعليمات المهارة أي توكنات ما دامت المهارة غير مستخدمة.

  • بدّل النماذج أثناء المحادثة

    لأن المهارة تعليمات وليست شيفرة، فإن تغيير النموذج لا يعطّلها — فالنموذج التالي يقرأ ملف SKILL.md نفسه.

تعليمات المهارة

هذا هو محتوى SKILL.md الذي يُحمّله النموذج. اقرأه قبل التثبيت — فالمهارة عبارة عن تعليمات سيتبعها نموذجك.

When to Use

Use this skill to build the last line of defence for a live algorithmic trading system: an observer that sits between strategy logic and the execution gateway and refuses to pass new orders once a hard limit is breached. It enforces four independent controls — peak-to-trough drawdown of session P&L, order submission rate over a rolling window, consecutive broker/venue errors, and staleness of the P&L feed the drawdown control depends on — and it does not auto-recover from a limit breach.

Reach for it when: capital is real, the strategy is capable of looping, and nobody is watching the screen continuously.

When NOT to Use

  • As your only MiFID II RTS 6 control. Article 12 kill functionality requires the ability to cancel unexecuted orders across every venue you are connected to. This engine blocks new submissions; it does not cancel resting orders or flatten positions. Wire its on_halt callback to whatever does, and treat that wiring as the compliance artefact.
  • As a substitute for per-order pre-trade checks. Price collars, maximum order value and maximum order volume (RTS 6 Article 15(1)(a)–(c)) are per-order checks this engine does not perform — it never sees order contents. Use sec-rule-15c3-5-risk-controls-us and kill-switch-and-drawdown-circuit-breakers alongside it.
  • Across processes. The engine is thread-safe within one process and holds state in memory. Two order-routing processes each running their own engine enforce two independent budgets, not one shared budget. Run a single gateway process, or promote the counters to shared storage.
  • As a strategy-level stop-loss. Sizing and per-trade stops belong in the strategy; this is the layer that must keep working when the strategy does not.

Prerequisites

  • A chokepoint through which every order submission passes, so the check cannot be bypassed by a code path that forgets to call it.
  • A mark-to-market source producing cumulative session realized and unrealized P&L, independent of the strategy's own bookkeeping.
  • A reset secret provisioned out of band, in CAPITAL_PRESERVATION_RESET_TOKEN or an injected ResetAuthorizer. There is no default: an engine deployed without one cannot be reset at all, which is the intended failure direction.
  • Durable storage for snapshot() if the system can restart while halted.

Workflow

  1. Configure limits. Instantiate PreservationLimits. Every field is a placeholder calibrated by you, not a standard: set max_daily_drawdown_usd from the desk's risk tolerance, max_orders_per_minute from measured peak operating rate (the reference workflow suggests ~2x peak), max_consecutive_errors from the venue's normal reject rate. Set max_pnl_staleness_seconds unless another layer guarantees P&L freshness — leaving it None means a dead mark-to-market feed silently disarms the drawdown control. Invalid limits (zero, negative, NaN) raise at construction rather than failing open at runtime.
  2. Restore before trading. On start-up, load the last persisted snapshot() and call restore(). A process that restarts mid-halt must come back HALTED; an unreadable snapshot restores as HALTED rather than ACTIVE.
  3. Gate every submission. Call check_order_allowed() exactly once immediately before routing each order. It consumes one slot of the rate budget as a side effect — calling it speculatively, or twice for one order, inflates the measured rate and can trip a halt that cannot be undone without human action.
  4. Distinguish the two failure states before reacting. False from the gate means one of two different things, and conflating them produces the wrong operational response:
    • EngineState.DEGRADED_WARNING — a risk input is untrustworthy (stale or non-finite P&L). Recoverable; the engine clears itself on the next valid update_pnl. Do not page the head of trading; fix the feed.
    • EngineState.HALTED — a risk limit was breached. Terminal. Page a human, run the cancel-all, and expect no automatic recovery.
  5. Feed the inputs. Call update_pnl(realized, unrealized) on every mark-to-market tick with cumulative session figures, not increments. Call register_error() on every broker reject, socket timeout or 5xx, and register_success() on every acknowledged operation — an error counter that is never cleared drifts into a spurious halt.
  6. Classify before retrying, then register. A submission that timed out may still have reached the venue. Resolve the ambiguity (see order-placement-idempotency) before deciding whether it was an error; registering a timeout as an error and retrying it turns one ambiguous order into a duplicate fill plus a false connectivity signal.
  7. Act on the halt out of band. Pass an on_halt callback that cancels resting orders, flattens if policy requires it, and alerts through a channel independent of the bot's normal logging. The callback runs outside the engine's lock, so it may call back into the engine, and an exception it raises is logged and swallowed — a broken pager never unlatches the halt.
  8. Reset deliberately. manual_reset(token, operator=...) re-arms the gate but keeps the session's P&L history, so a reset issued while the drawdown is still breached re-halts inside the call rather than leaving a window in which orders flow. Granting a fresh drawdown budget requires the explicit rebaseline_session_pnl=True, which is recorded in the audit log. Always pass operator.

Full procedure: see references/workflows.md. Standards, limit provenance and regulatory context: see references/standards.md. Printable pre-flight checklist: see assets/checklist.md.

Common Pitfalls

  • Measuring "drawdown" from zero instead of from the peak. Treating the loss limit as abs(session P&L) when negative means a strategy that runs to +$400k and gives back $390k reports a drawdown of zero and never trips. Track a high-water mark seeded at flat and measure peak-to-trough against it. If you also need a hard floor on the day, that is a separate limit (max_daily_loss_usd), because a large intraday peak makes a catastrophic loss look like a modest give-back.
  • Letting a NaN disable the control. float('nan') >= limit is False, so a single bad mark silently turns the drawdown check into a no-op that reports ACTIVE. Treat non-finite P&L as a data-integrity failure that blocks orders, not as a value to compare.
  • Trusting a P&L feed that stopped updating. If nothing checks freshness, a dead mark-to-market process leaves the engine ACTIVE and permanently unaware of an unbounded loss. Absence of a breach signal is not evidence of no breach.
  • Timing the rolling window on the wall clock. time.time() is not monotonic. An NTP step forward empties the order-rate window and lets a runaway algorithm straight through; a step backward freezes it. Use time.monotonic() for every interval, and reserve wall-clock time for audit timestamps.
  • In-band risk checks. Embedding the kill switch inside strategy logic means a strategy bug can bypass the very check meant to contain it. It must sit between the strategy and the gateway.
  • Monitoring P&L but not order frequency. A strategy rapidly cancel-replacing far from the touch may never move P&L while it burns through exchange message budgets, order-to-trade ratio penalties, or an IP ban.
  • A hard-coded reset token. A kill switch clearable with a constant published in the source is not a kill switch. Read the secret from the environment or an injected authorizer, compare it in constant time, and deny every reset when none is configured.
  • A reset that forgets the losses. Zeroing the drawdown on reset hands the strategy a full second drawdown budget. Re-baselining is sometimes the right call, but it must be an explicit, recorded decision — never a side effect of clearing a halt.
  • In-memory state only. A halted engine that restarts into ACTIVE has un-halted itself. Persist the state and fail closed on an unreadable snapshot.
  • An unauthenticated, unlogged override. Who cleared the switch, when, and what they cleared is the first question after an incident and a standing expectation of any algo-trading governance regime.

Verification

  • Run python -m unittest discover -s skills/capital-preservation-mode-for-degraded-conditions/scripts from the repository root and confirm a 100% pass rate.
  • Drive a fake clock (not sleep) to assert the rolling-window boundary exactly: at the configured rate the gate must pass; one tick tighter it must halt.
  • Assert the give-back case explicitly: feed +$40,000 then +$29,000 against a $10,000 drawdown limit and confirm the engine halts while the session is still profitable.
  • Feed a NaN mark and confirm the gate blocks and the state is DEGRADED_WARNING, not ACTIVE.
  • Stop the P&L feed and confirm orders are blocked once max_pnl_staleness_seconds elapses, and that trading resumes by itself when the feed returns.
  • Snapshot a halted engine, construct a fresh one, restore, and confirm it comes back HALTED; repeat with a corrupt snapshot and confirm it also comes back HALTED.
  • Confirm manual_reset rejects a wrong token, rejects every token when no secret is configured, and re-halts immediately when the drawdown limit is still breached.
  • In a paper environment, engineer each trigger for real before relying on any of it live — an untested safety mechanism is not a safety mechanism.

Related Skills

  • kill-switch-and-drawdown-circuit-breakers
  • sec-rule-15c3-5-risk-controls-us
  • mifid-ii-algo-trading-compliance-eu
  • broker-side-order-throttle-detection
  • order-placement-idempotency
  • black-swan-playbook-for-halted-markets
  • risk-control-bypass-audit-logging

الملفات المرفقة

يقرأ النموذج هذه الملفات عند الحاجة ما دامت المهارة محمّلة. وهي متاحة للقراءة ولا تُنفّذ أبدًا.

الأسئلة الشائعة

ماذا تفعل مهارة الذكاء الاصطناعي Capital Preservation Mode For Degraded Conditions؟

استخدمه عندما يحتاج نظام يعمل مباشرةً إلى آلية مستقلة عن الاستراتيجية تمنع الأوامر الجديدة إذا تجاوز التراجع أو معدل إرسال الأوامر أو أخطاء منصة التداول المتتالية أو تقادم بيانات السوق حدًا معينًا. تمنع هذه الآلية الأوامر الجديدة؛ أما إلغاء الأوامر القائمة فهو مهمة مفتاح الإيقاف الطارئ.

لماذا تستخدم Capital Preservation Mode For Degraded Conditions على TypingMind؟

لأنك تثبّتها مرة واحدة وتستخدمها مع أي نموذج. مهارة Capital Preservation Mode For Degraded Conditions عبارة عن نص Markdown وليست شيفرة خاصة بمزود بعينه، لذا تعمل المهارة نفسها مع GPT-5 أو Claude أو Gemini أو Grok أو نموذج محلي، ويمكنك تبديل النموذج أثناء المحادثة دون تعطّل المهارة. يعمل TypingMind بمفاتيح API الخاصة بك، فتدفع للمزودين مباشرةً بدلًا من اشتراك لكل مقعد، وتبقى مهاراتك ومحادثاتك في مساحة التخزين الخاصة بك.

كيف أثبّت Capital Preservation Mode For Degraded Conditions في TypingMind؟

في TypingMind، افتح «الإضافات»، ثم «المهارات»، ثم اختر «التثبيت من GitHub» والصق https://github.com/HimanshuJ16/Algo-Trading-Skills/tree/main/skills/capital-preservation-mode-for-degraded-conditions. يقرأ TypingMind ملف SKILL.md الخاص بالمهارة، ويجمع ملفاتها ويثبّتها كمهارة يمكنك تفعيلها لكل محادثة على حدة.

ما نماذج الذكاء الاصطناعي التي يمكنها استخدام Capital Preservation Mode For Degraded Conditions؟

أي نموذج تربطه في TypingMind. مهارات الذكاء الاصطناعي عبارة عن تعليمات Markdown وليست شيفرة خاصة بمزود بعينه، لذا يمكن لكل من GPT وClaude وGemini وGrok والنماذج المحلية تحميل هذه المهارة عندما يتوافق الطلب معها.

كم نموذج ذكاء اصطناعي يمكنني استخدامه مع Capital Preservation Mode For Degraded Conditions؟

أي عدد تريده. ما دام النموذج يدعم المهارات، يمكنك استخدام Capital Preservation Mode For Degraded Conditions معه، سواء كان GPT أو Claude أو Gemini أو Grok أو DeepSeek أو Mistral أو Llama أو غيرها، وكل ذلك على TypingMind باستخدام مفاتيح API الخاصة بك.

هل مهارة الذكاء الاصطناعي Capital Preservation Mode For Degraded Conditions مجانية؟

نعم. نشرها HimanshuJ16 على GitHub بموجب ترخيص Apache-2.0. لا تدفع إلا لمزود الذكاء الاصطناعي الخاص بك مقابل التوكنات التي تستخدمها.

ما هي مهارات الذكاء الاصطناعي؟

مهارة الذكاء الاصطناعي حزمة تعليمات قابلة لإعادة الاستخدام تعلّم نموذج الذكاء الاصطناعي كيفية تنفيذ مهمة محددة. وتتبع تنسيق Agent Skills المفتوح: ملف SKILL.md يتضمن اسمًا ووصفًا، إلى جانب أي نصوص برمجية أو قوالب أو ملفات مرجعية قد يحتاج إليها النموذج. لا يقرأ النموذج التعليمات إلا عندما يتوافق طلبك مع المهارة، لذا لا تترتب على المهارة المثبتة أي تكلفة حتى تُستخدم.

كيف تختلف مهارات الذكاء الاصطناعي عن الإضافات أو موصلات MCP؟

تمنح الإضافة أو موصل MCP النموذج أدوات جديدة يمكنه استدعاؤها، وهي شيفرة تُنفَّذ في مكان ما وتُرجع نتيجة. أما مهارة الذكاء الاصطناعي فتزوّد النموذج بالمعرفة ومنهجية العمل: كيفية التعامل مع مهمة، والخطوات التي ينبغي اتباعها، وما ينبغي أن تكون عليه المخرجات الجيدة. المهارات عبارة عن نصوص Markdown، لذا لا تحتاج إلى خادم أو مفتاح API أو بيئة تشغيل، وتعمل مع أي نموذج.

عرض الكل

أنشئ مساحة عملك للذكاء الاصطناعي الآن

اشترك في نشرتنا الإخبارية لتصلك أخبار الميزات الجديدة والهدايا القادمة 👇