bt_api_py
The current checkout has SDK-family submodules under bt_api/, including Base, CTP, OKX, Binance, Risk, Gateway, Execution and Monitor. A checkout or installed package does not establish that a provider route, service, account or release has been accepted. Historical descriptions below are dated source snapshots.
The CTP operator calendar configuration can explicitly select native session day
changes instead of a fixed simulation bootstrap. Keep mode: SIMULATION_ONLY,
set simulation_bootstrap to null, and add:
day_switch:
source: CTP_AUTHENTICATED_SESSION
poll_interval_seconds: 1
owner_wait_seconds: 1
close_timeout_seconds: 3
The existing explicit calendar root, grants and range policies remain required.
The original Gateway owner captures and rechecks its authenticated read session;
a separate worker loads receipt-checked calendar files. A strictly later native
trading day can activate a new version. Same-day publication or reconnect keeps
the bound version; a new process can load the latest valid publication. A stale
session, regressing day or failed load retains the old fixed view and reports a
finite degraded status through binding.calendar_day_switch_status(). Unconfirmed
worker cleanup retains the original resources. This observation does not establish
settlement, R-3 recovery, account readiness or permission to trade. Calendar data
keeps its existing simulation provenance and coverage limits.
GatewayRecoveryClockQualifier can qualify a past interval against the original
owner's explicitly enabled clock publication history. It returns conservative UTC
endpoint bounds and local sample references, or UNKNOWN for unavailable history,
expired coverage or inconsistent overlapping calibrations. Truncated history is
usable only after omitted calibrations are provably expired or a recorded reset
starts a new segment. The result is local to the process; SNTP remains unauthenticated.
The trusted Python factory can persist these results through the explicit
local_clock_v1 recorder option described below. The trading operator loader
supports explicit recorder settings; Monitor duration evaluation is not yet
connected. Qualification does not prove that a recovery condition held.
Iteration 64 is in progress and not accepted. The SDK assembles an independent Risk service and authenticated Gateway clients; Risk owns pre-trade policy and its ledger, while providers supply source facts. Default self-trade protection currently refuses OPEN/CLOSE because complete source-bound active-order coverage is unavailable. Account and intraday coverage, financial facts, Execution parent/child write authority and cross-generation not-sent proof remain gaps. R-11 v2 parses scoped rule metadata but does not by itself prove venue facts or enable trading. Selected Risk never falls back to direct. Consult the Backtrader iteration-64 review for scoped source, simulation and wheel evidence.
Risk operator cancellation requires an explicit scope grant in the Risk service
principal configuration. The following is an illustrative principal entry:
- principal_ref: operations-example
role: operator
actor_ref: operations-actor
strategy_refs: []
operations: [risk.cancel.request, risk.cancel.status]
public_key_file: keys/operations-example.public
cancel_scope_grants:
account: false
strategies: [strategy-a]
instruments: ["SHFE:rb"]
account, strategies and instruments are independent grants: account-wide
permission does not imply permission for a strategy or instrument. Instrument
entries use <venue>:<native_symbol>. Omitting cancel_scope_grants denies
all operator cancel scopes; configurations that previously relied only on
risk.cancel.request or risk.cancel.status must add explicit grants. A
malformed grant is rejected before key files are read. A caller also needs the
corresponding operation and Gateway authorization. Strategy-scope Gateway
dispatch and source-bound status remain under development; an authorized
strategy request does not establish that any cancellation was sent or completed.
The Risk service setting service.strict_admin_cancel is optional and defaults
to false. Set it to true to require Registry admission around the local
operator-cancel claim and its commit-time grant recheck. This mode records a
local UNKNOWN intent only and does not send a cancellation to Gateway; a
repeat or uncertain commit does not authorize a retry. With false, the
existing operator-cancel path remains in use: it can call the Gateway control
adapter for supported scopes, but strategy scope is currently refused locally
and remote status remains UNKNOWN without original journal/generation binding.
Neither mode proves that a venue cancellation occurred.
Risk clients require a runtime that proves strict unregister acknowledgement. The SDK compose() path constructs its own lazy runtime and is the only path that installs an automatic reconnect factory. A publicly injected runtime_factory is accepted for compatibility but is not invoked; an injected initial runtime is a trusted in-process extension, not a sandbox against arbitrary Python side effects. Unconfirmed registrations or cleanup retain the original resources and block replacement; this can make automatic recovery unavailable. Explicit ACK does not by itself prove an earlier handler has drained or resolve an UNKNOWN command.
The Risk host now binds account-observer RPC responses to the configured Gateway
SERVICE identity and CURVE key through the runtime owner's call_bound path,
including after reconnect. An acknowledgement requires the original read's
client-held token, epoch, registration and contiguous returned prefix; the Risk
cursor is committed before acknowledgement. This authenticates the particular
response, not account completeness or continuing authorization across a later
database transaction. The v1 order quarantine remains enabled. Other callers of
GatewayAccountObserverClient retain the compatibility mode unless both peer
and fingerprint are explicitly supplied.
CTP front selection uses bt_api_ctp.ctp_env_selector; the old SDK facade and its YAML configuration are removed. The provider selects its own defaults, which differ from the old facade, and automatic set1 selection requires verified trading-day evidence. This source change has not been behavior- or account-accepted.
Position-mode acknowledgement codes are provider declarations: the Base default is unspecified. Binance, CTP and non-swap OKX preserve the previous 200; OKX swap preserves 0, and ten historical policies retain 200. These inherited values do not prove venue capability. Third-party Base subclasses no longer receive a default; dynamic policies, packaging and behavior remain unvalidated.
Binance/OKX bound read-only runtime registration and exact owner/config checks live in their providers; Base carries the SDK-injected API type, and SDK owns composition and finite error mapping. The two SDK-specific registration modules and compose_binance_read_only_runtime / compose_okx_read_only_runtime are removed. compose_read_only_runtime creates a new owner and differs from reusing an existing one. Entry points, thread/cleanup and behavior remain unaccepted. CTP managed-runtime route, environment and instrument-field checks live in bt_api_ctp.managed_runtime_route_validation; SDK retains grant expiry, session and lifecycle. Importing the CTP-specific SDK module requires that provider. CTP preflight settlement settings are provider-owned; the SDK selects the route and retains the call timing and error type. The CTP provider is loaded on demand and this path is unaccepted.
Execution-ledger identity format is declared per provider via bt_api_base.execution_ledger_identity_policy, not hard-coded venue names. The 13 built-in providers retain their prior format choices; this does not prove identity. Missing or undiscoverable declarations fail, including historical/custom providers, and successful selections are process-cached. Migration, packaging and behavior remain unaccepted. A separate provider account_risk_source_policy declares whether native account binding is still required for neutral risk reads. CTP remains unavailable; the other 12 retain the old branch, not proof of source. Undeclared providers fail and discovery/behavior are unaccepted.
Gateway SDK composition now accepts the neutral GatewayMarketBinding and a trusted provider factory; GatewayOkxMarketBinding and the okx_market parameter are removed. An OKX caller supplies bt_api_okx.market_provider.OkxTickerQueueMarketProvider as its factory. The generic binding permits nonempty per-principal subsets; OKX key validation occurs at subscription and provider settings at construction. This breaking source change and lifecycle behavior are unaccepted.
CTP managed Risk order payload construction and cancel-target matching live in bt_api_ctp.risk_dispatch_binding; Base declares the optional provider contract, while SDK retains evidence selection; Risk retains claims and journal fencing. Target orders with a schema now require a matching provider declaration: undeclared schemas fail, a breaking change. Journal compatibility and behavior remain unvalidated. The CTP provider also owns native request field comparison, dispatch/zero-fill projections and zero-fill evidence field matching; SDK retains session, exact type/source checks and journal lifecycle. The provider is trusted for field matching. Risk-order position-dimension source projection is selected by the provider policy, without an SDK venue-name branch. CTP declares the projection at bt_api_ctp.risk_source_position_projection; the other 12 built-ins retain the previous generic path. Missing declarations or required projectors fail closed, so third-party policies need updates. SDK retains source/session checks and error mapping; provider discovery and behavior are unvalidated.
CTP recovery row instrument/side/offset fields, active-order classification, order/intent matching and trade-key projection live in bt_api_ctp.recovery_row_projection; the SDK supplies its original value selector, quantity checks and instrument resolver, retaining proof, journal, session and authorization. The provider participates in field decisions; import timing and behavior remain unvalidated.
SDK account_risk_projection.position_audit_close_error classifies a blocked order using caller-supplied local position facts; the Broker retains its audit state and framework objects. This decision does not establish account provenance or grant write authority, and behavior is unvalidated. Neutral top-of-book checks and midpoint projection live in SDK market_stream_contracts.orderbook_midpoint; Feed retains event dispatch and bar-line updates. Tick trading-day and action-day fields are explicitly selected by each provider: CTP includes TradingDay and ActionDay alongside neutral names; the other 12 select neutral names only. Base defaults are None, and the former uppercase candidates for the other ten have been removed. Dynamic input coverage remains unvalidated. Base order-book sequence/audit defaults omit Binance-native fields; legacy providers keep their old values. Base balance, position, order, trade, status and position-mode defaults no longer include selected Binance/OKX/CTP native aliases; the explicit historical policy and its four direct consumers retain the prior mappings. Base permission, position-mode, event-identity and instrument-symbol defaults also contain neutral fields only; the three explicit provider policies retain their declarations and ten legacy providers retain historical fields. Third-party Base subclasses change behavior; coverage and behavior remain unaccepted.
All 13 providers explicitly declare trade_id_fields using neutral names and native fields confirmed in their container source; Base defaults to None and the SDK reads the selected fields. Bybit, dYdX and Kraken declare no additional native trade-ID fields. Unconfirmed generic id/tradeId aliases are no longer assumed across venues; narrowing and additions are breaking changes. The group_fill provenance alias contract is separate: IDs including Gateio, HTX and MEXC still require verification and normalization does not prove them. Dynamic inputs and behavior remain unvalidated.
Order-status and trade-fee field candidates are selected by provider policy. All 13 providers explicitly declare order-status candidates: Binance, OKX and CTP retain their existing declarations, while the other ten each declare status, order_status and state; the Base legacy policy no longer declares these candidates. Trade-fee candidates remain policy-selected. A policy without declarations fails explicitly. This field ownership move does not establish native status coverage; third-party policies and behavior remain unvalidated. Placement position-mode fencing is also provider-declared: OKX/Binance retain the existing guard, other built-in routes retain the previous unguarded behavior, and undeclared routes reject placement. This breaking change does not prove venue capability.
Neutral position-row matching against configured route and instrument identities lives in bt_api_py.broker_event_envelope; Backtrader retains feed/order binding collection and local positions. This source change is unaccepted.
The neutral unverified execution-event identifier projection lives in bt_api_py.execution_event_projection; Backtrader retains local order binding, UNKNOWN updates and drop recording. The Store completed-bar delivery queue remains framework-owned. Cross-package behavior is unaccepted.
CTP managed order and cancel identity value types live in bt_api_ctp.managed_request_identity. SDK request models resolve them lazily when those fields are used, with lazy legacy SDK exports. Module identity, serialization, annotation resolution, source binding, optional packaging and behavior remain unaccepted; these values grant no execution authority.
Binance, OKX and CTP declare their own explicit order-identity aliases and side projections; the remaining providers explicitly retain the historical set. Known identity aliases outside the selected policy raise an execution-unknown error. Dynamic payload coverage, packaging and behavior remain unvalidated.
Order provenance selects neutral fields and native aliases declared by each of the 13 providers, using scoped v5/v6. Risk and group proofs use only v6, bind route-specific alias digests, and group source events persist and recheck that digest. The v1–v4 contracts have been removed. Bybit, dYdX and Kraken currently declare no native fill aliases; their field coverage requires review. This is uncommitted source work; dynamic providers, old-record handling, packaging and behavior remain unvalidated.