Broker Agnostic Adapter Interfaceのロゴ

Broker Agnostic Adapter Interface

コミュニティ
HimanshuJ16
broker-agnostic-adapter-interface

戦略コードを複数のブローカーで実行し、kiteconnect、alpaca-py、ibapiを直接インポートさせたくない場合に使用します。Decimal価格、型付き例外、取引所間で正規化された注文ステータスを備えるアダプター契約を定義します。

概要

公開者HimanshuJ16
リポジトリAlgo-Trading-Skills
スキル名broker-agnostic-adapter-interface
スター
50
フォーク
7
同梱ファイル
5
ライセンスApache-2.0
リンク
  • Markdown形式の指示

    モデルが必要に応じて読み込むSKILL.mdファイルです。関連するリクエストがあったときだけトークンを消費します。

  • どのLLMでも利用可能

    AIスキルはプロバイダー固有のコードではなく、通常のMarkdownなので、GPT、Claude、Gemini、Grok、ローカルモデルで利用できます。

  • 5個の同梱ファイル

    モデルが作業中に読み取れるスクリプト、テンプレート、参考資料です。ファイルは読み取り専用で、実行されることはありません。

  • オープンソース

    HimanshuJ16がGitHubで公開しています。インストールする前にソースを確認してください。

インストール

AIスキル「Broker Agnostic Adapter Interface」をTypingMindにインストールすれば、どのLLMでも利用できます。SKILL.mdを読み取れる別のAIエージェントに追加することもできます。

1

TypingMindにインストール

TypingMindはGitHubフォルダから直接スキルをインストールします。SKILL.mdを読み取り、リソースファイルをまとめてローカルに保存します。

  1. アプリを開き、「プラグイン」→「スキル」に移動します。
  2. 「GitHubからインストール」を選択します。
  3. 以下のスキルフォルダのURLを貼り付けて確定します。
    https://github.com/HimanshuJ16/Algo-Trading-Skills/tree/main/skills/broker-agnostic-adapter-interface
  4. スキルを利用したいチャットごとに、そのスキルを有効にしてください。
「プラグイン」→「スキル」→「スキルを追加」→「GitHubのURLから」を選択し、フォルダのURLを貼り付けて「続行」を押します。
2

別のAIエージェントにインストール

Agent Skills形式を読み取れるAIエージェントなら、このスキルを利用できます。フォルダをそのAIエージェントのスキルディレクトリにコピーしてください。

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/broker-agnostic-adapter-interface .claude/skills/broker-agnostic-adapter-interface
コピー後、新しいスキルを読み込むためにClaude Codeを再起動してください。

TypingMindで使用

TypingMindのチャットでBroker Agnostic Adapter Interfaceを有効にするだけで、あとはモデルが対応します。名前と説明がシステムプロンプトに含まれ、関連するリクエストがあると、モデルが指示の全文を自動で読み込みます。手動で呼び出す必要はなく、実際に使用されるまでトークンを消費しません。

関連するリクエストがあるとすぐに、モデルが自動的にBroker Agnostic Adapter Interfaceを読み込みます。

どのAIモデルでも利用可能

AIスキルはプロバイダー固有のコードではなく、通常のMarkdownで書かれた指示です。そのため、Broker Agnostic Adapter Interfaceは作成時に想定されたモデルに縛られません。TypingMindに一度インストールすれば、ご自身のAPIキーを使って、GPT-5、Claude、Gemini、Grok、DeepSeek、Mistral、Llama、またはご自身で実行するローカルモデルで利用できます。

  • 必要なときだけ読み込み

    システムプロンプトには名前と説明だけが含まれます。関連するリクエストが初めてあったときに指示を取得するため、スキルを使わない間は指示の読み込みにトークンを消費しません。

  • チャットの途中でモデルを切り替え

    スキルはコードではなく指示なので、モデルを切り替えてもそのまま使えます。次のモデルも同じSKILL.mdを読み込みます。

スキルの指示

モデルが読み込むSKILL.mdの内容です。スキルはモデルが従う指示なので、インストールする前に確認してください。

When to Use

Invoke this whenever building a trading platform or strategy engine intended to run across multiple brokers or venues. Coupling strategy code directly to broker SDKs (Zerodha kiteconnect, Alpaca alpaca-py, IBKR ibapi) fragments the codebase, leaks float imprecision into prices, and makes venue migration a rewrite. An abstract BaseBrokerAdapter with standardized models (OrderRequest, OrderResult, Position, AccountBalance) in Decimal isolates strategy code from broker API drift.

The two things this layer must get right, because everything downstream trusts it: the status normalization (does the strategy believe this order is live?) and the request validation (does a malformed order reach the venue?).

When NOT to Use

  • As a working broker client. scripts/broker_adapter.py defines the contract and ships simulated adapters that fabricate fills. It performs no network I/O, no auth, no rate limiting. Real adapters wrap real SDKs behind this interface.
  • As a single-broker abstraction. If you will only ever trade one venue, the indirection costs more than it saves; use the SDK directly and keep the enum normalization.
  • For anything the interface does not model. Bracket/OCO orders, order modification, multi-leg and options strategies, streaming order updates, and per-venue product types (Zerodha's MIS/CNC/NRML) are outside OrderRequest. Extend the model deliberately rather than smuggling them through a broker-specific side channel — that reintroduces the coupling this skill exists to remove.
  • As a substitute for idempotency or auth handling — see the Related Skills.

Prerequisites

  • Python abc for the interface and decimal.Decimal for all monetary values.
  • Each broker's documented status enumeration, not the four statuses you happened to see in testing. references/standards.md lists them with sources.
  • A typed exception hierarchy (BrokerAdapterError and subclasses) that every adapter maps its SDK errors into.
  • A registry key per broker, supplied by configuration.

Workflow

  1. Model the domain in Decimal, and enforce it at the boundary. _to_decimal accepts Decimal and int (exact) and rejects float with an explanatory error. A float that slips through survives every comparison and only fails much later, as a TypeError the first time it meets a Decimal in arithmetic — far from the code that introduced it.

  2. Validate the request on the base class, not in each adapter. _validate_request enforces symbol, enum types, finite positive quantity, and order-type/price consistency: LIMIT and STOP_LIMIT require a positive price, STOP and STOP_LIMIT require a positive stop price, and MARKET must not carry one. Putting it on the base class means a newly written adapter cannot forget it.

  3. Normalize status conservatively. normalize_status upper-cases and looks up _STATUS_MAP. An unmapped status returns OrderStatus.UNKNOWN and logs at ERROR — never PENDING. Handle UNKNOWN by re-querying or reconciling; it is neither live nor terminal, and OrderResult.is_terminal returns False for it. Treat its appearance as a defect report: the broker has a status your map does not know.

  4. Echo client_order_id on every OrderResult. Without it the caller cannot correlate a response to the request that produced it, and retry-safe submission is impossible.

  5. Register adapters explicitly; the factory registry starts empty. create() raises until you register a real adapter. The simulated adapters are not bound to production broker names by default — call register_simulated_adapters() to opt in for offline work. register() rejects any class that is not a BaseBrokerAdapter, so a bad wiring fails at startup rather than on the first order.

  6. Treat cancel_order as a request, not a cancellation. A True return means the broker accepted the cancellation request. The order can still fill in the race window. Confirm with get_order_status before releasing risk budget or reusing the ID.

Full step-by-step procedure with broker-specific detail: see references/workflows.md. Documented status sets per broker, with sources: see references/standards.md. Printable pre-flight checklist: see assets/checklist.md.

Common Pitfalls

  • Defaulting an unrecognized status to PENDING. This is the worst default available: it asserts the order is live and working. Real terminal statuses get missed by hand-written maps — Zerodha's LAPSED, IBKR's ApiCancelled, Alpaca's done_for_day and replaced are all finished, and calling any of them PENDING leaves the strategy waiting on a dead order or re-sending one that already resolved.
  • Case-sensitive status lookup. IBKR returns mixed-case strings (PreSubmitted, ApiCancelled). A lookup that matches "Filled" but not "FILLED" sends the variant to the default branch — a filled order reported as still working.
  • Mapping only the statuses you saw in testing. Kite documents roughly a dozen order states and Alpaca a dozen more; the four obvious ones are not the contract.
  • Binding simulated adapters to production broker names. A factory that resolves config["broker"] to a mock reports every order FILLED at an invented price, with no error anywhere.
  • Falsy-checking a price. if request.price treats Decimal("0") as absent, so a zero limit price gets silently replaced by a default instead of rejected.
  • Floating point at the boundary. float cannot represent ordinary decimal prices and tick sizes exactly; construct Decimal(str(value)) where the value enters.
  • Leaky abstractions. Broker SDK exceptions, raw JSON, and — easy to miss — decimal.InvalidOperation from a NaN comparison must all be wrapped into BrokerAdapterError subclasses before crossing the adapter boundary.
  • Treating a cancel acknowledgement as a cancellation.
  • Mutating the shared registry from library code. It is process-wide class state; use reset() for test isolation.

Verification

  • Run the unit suite and confirm every test passes: python -m unittest discover -s skills/broker-agnostic-adapter-interface/scripts
  • For each adapter, assert an invented status string returns UNKNOWN, not PENDING. This is the highest-value single assertion in the suite.
  • Assert every status in the broker's documented enumeration maps to something, and that terminal broker states map to terminal OrderStatus values.
  • Assert case variants ("Filled", "FILLED", "filled") normalize identically.
  • Assert a float quantity or price is rejected, and that an int widens to Decimal losslessly.
  • Assert create() raises on an empty registry, and that register() refuses a class that does not implement BaseBrokerAdapter.
  • Place orders through every adapter and confirm filled_quantity, average_price and commission are all Decimal instances.

Related Skills

  • order-placement-idempotency
  • broker-api-idempotent-cancel-requests
  • headless-broker-auth-patterns
  • multi-broker-rate-limit-handling

同梱ファイル

スキルが読み込まれている間、モデルは必要に応じてこれらを読み取ります。読み取り可能なファイルとして提供され、実行されることはありません。

よくある質問

AIスキル「Broker Agnostic Adapter Interface」では何ができますか?

戦略コードを複数のブローカーで実行し、kiteconnect、alpaca-py、ibapiを直接インポートさせたくない場合に使用します。Decimal価格、型付き例外、取引所間で正規化された注文ステータスを備えるアダプター契約を定義します。

TypingMindでBroker Agnostic Adapter Interfaceを使うメリットは何ですか?

一度インストールすれば、どのモデルでも使えるからです。Broker Agnostic Adapter Interfaceはプロバイダー固有のコードではなく、通常のMarkdownで記述されているため、同じスキルをGPT-5、Claude、Gemini、Grok、ローカルモデルで利用できます。チャットの途中でモデルを切り替えても、そのまま使い続けられます。TypingMindは自分のAPIキーで動作するため、シート単位のサブスクリプションではなく、プロバイダーに直接料金を支払います。スキルとチャットは自分のストレージに保持されます。

TypingMindにBroker Agnostic Adapter Interfaceをインストールするにはどうすればよいですか?

TypingMindで「プラグイン」→「スキル」→「GitHubからインストール」を開き、https://github.com/HimanshuJ16/Algo-Trading-Skills/tree/main/skills/broker-agnostic-adapter-interfaceを貼り付けてください。TypingMindがSKILL.mdを読み込み、関連ファイルをまとめて、チャットごとに有効にできるスキルとしてインストールします。

Broker Agnostic Adapter Interfaceを使えるAIモデルはどれですか?

TypingMindに接続したどのモデルでも利用できます。AIスキルはプロバイダー固有のコードではなく、通常のMarkdownで書かれた指示です。そのため、GPT、Claude、Gemini、Grok、ローカルモデルのいずれも、リクエストの内容がこのスキルの用途に合ったときに、このスキルを読み込めます。

Broker Agnostic Adapter Interfaceで使えるAIモデルの数に制限はありますか?

数に制限はありません。スキルに対応したモデルであれば、GPT、Claude、Gemini、Grok、DeepSeek、Mistral、Llamaなど、どのモデルでもBroker Agnostic Adapter Interfaceを利用できます。すべてTypingMind上で、自分のAPIキーを使って利用できます。

AIスキル「Broker Agnostic Adapter Interface」は無料ですか?

はい。HimanshuJ16がApache-2.0ライセンスのもとでGitHubに公開しています。ご利用のAIプロバイダーに支払うのは、使用したトークンの料金だけです。

AIスキルとは何ですか?

AIスキルは、特定のタスクの実行方法をAIモデルに教える、再利用可能な指示のセットです。オープンなAgent Skills形式に従い、名前と説明を含むSKILL.mdファイルに加え、モデルが必要とするスクリプト、テンプレート、参照ファイルで構成されます。モデルはリクエストがスキルに合致したときだけ指示を読み込むため、インストール済みのスキルも、使うまでは費用がかかりません。

AIスキルは、プラグインやMCPサーバーとどう違いますか?

プラグインやMCPサーバーは、モデルが呼び出せる新しいツールを提供します。ツールとは、どこかで実行され、結果を返すコードです。一方、AIスキルは、タスクへの取り組み方、従うべき手順、望ましい出力の例といった知識や進め方をモデルに伝えます。スキルは通常のMarkdownで記述されているため、サーバー、APIキー、実行環境は不要で、どのモデルでも利用できます。

すべて見る

今すぐ自分専用のAIワークスペースを作成

ニュースレターに登録すると、新機能や今後のプレゼント企画のお知らせが届きます👇