Purpose
Validates B3-specific connectivity configuration and manages connection state for algorithmic trading systems connecting to the B3 PUMA Trading System. Its central job is to make one architectural asymmetry impossible to get wrong: B3's legacy FIX/FAST UMDF publishes TCP-based recovery services, while the newer Binary UMDF (SBE) feed does not — so an SBE consumer must implement its own gap recovery or it will lose market data silently.
Scope — what this skill does NOT do
This module performs no network I/O. It opens no sockets, sends no FIX/FIXP messages, and contacts nothing. connect() drives a state machine and delegates to an injected connector callable; with no connector supplied it logs a warning and reports success without touching the network.
A successful connect() is therefore not evidence of reachability, valid credentials, IP whitelisting, or entitlement. Earlier versions of this skill presented if engine.connect(): print("Connected to B3") as a connectivity example, which was misleading — it would print success on a machine with no network at all. Inject a real connector (OnixS, B2BITS, or your own socket layer) for actual sessions.
When to Use
- Validating B3 DMA configuration before handing it to a real session layer
- Choosing between the legacy FIX/FAST stack and the Binary SBE stack
- Enforcing the SBE gap-recovery precondition in CI or at application startup
- Managing connection lifecycle state around a vendor SDK
When NOT to Use
- As a connectivity or credential test — it performs no I/O (see Scope above)
- As a FIX/FIXP engine or SBE decoder — use
binary-protocol-parsing-for-low-latency-feeds and a real session library
- Connecting to B3 via broker-provided APIs (use broker-specific adapters)
- Systems that do not need direct exchange connectivity
Prerequisites
- Python 3.10+
- Network connectivity to B3 colocation or a certified B3 network provider
- B3-assigned SenderCompID/TargetCompID from B3 Membership Services
- Valid B3 credentials and IP whitelisting for order entry and market data
- For Binary SBE: an application-level gap recovery implementation (sequence tracking + snapshot recovery), which is outside this skill
Protocol Selection
|
LEGACY_FIX_FAST |
MODERN_BINARY_SBE |
| Order entry |
FIX 4.4 |
Binary Order Entry (FIXP + SBE) |
| Market data |
UMDF FIX/FAST |
Binary UMDF (SBE) |
| Book model |
MBP / Top of Book available |
MBO only — no MBP, no TOB |
| Gap recovery |
TCP Replayer, TCP Historical Replayer, Snapshot Recovery |
No TCP recovery channel; sequence tracking + snapshot |
enable_application_gap_recovery |
Optional |
Must be True (enforced) |
Legacy is not a neutral long-term choice. B3 has been reducing FIX order entry gateways in phases — Derivatives in Q4 2025, Equities 10 April – 15 May 2026 — reassigning IPs, ports, and TargetCompIDs, with login failures for participants who miss their cutoff. Confirm current gateway status with B3 before starting new legacy work. See references/standards.md for sources and dating.
Workflow
- Create
B3ConnectionConfig. Validation runs in __post_init__ and raises B3ConfigurationError (a ValueError subclass):
comp_id — matched against a conservative ^[A-Za-z0-9_]{1,12}$ whitelist. This is this skill's defensive default, not a published B3 grammar; override via comp_id_pattern once you confirm the real limits with B3.
password — excluded from repr so it cannot leak into logs or tracebacks.
order_entry_ip — must be a dotted-quad string and must not be multicast (order entry is point-to-point TCP).
market_data_multicast_ip — must be a genuine multicast address unless you pass require_multicast_market_data=False for an isolated test rig.
protocol_suite — must be a B3ProtocolSuite member, not a string.
- Construct
B3IntegrationEngine. If protocol_suite is MODERN_BINARY_SBE and enable_application_gap_recovery is False, construction fails — the SBE feed has no TCP gap-fill channel to fall back on.
- Inject a connector if you want real connectivity. Without one,
connect() is a state-machine simulation and says so at WARNING level.
- Call
connect(). DISCONNECTED/FAILED → CONNECTING → CONNECTED. A connector that raises moves the engine to FAILED and raises B3ConnectionError; retry with backoff from there, since connect() is callable again after a failure.
- Implement SBE gap recovery separately. Track sequence numbers on every message, detect gaps, and recover via the snapshot/refresh streams — not via a TCP gap-fill request, which Binary UMDF does not offer.
- Call
disconnect() on shutdown. Idempotent, and it forces the state to DISCONNECTED even if the injected disconnector raises, so a failing teardown cannot strand the session.
Full procedure: see references/workflows.md.
Protocol specifics, recovery mechanisms, and sources: see references/standards.md.
Printable pre-flight checklist: see assets/checklist.md.
Common Pitfalls
- Reading
connect() == True as connectivity. With no connector injected this function does nothing but set an enum. It is configuration validation, not a reachability check.
- Expecting a TCP gap-fill channel on Binary UMDF. It does not exist. Legacy FIX/FAST offers TCP Replayer and TCP Historical Replayer; the SBE feed gives you sequence numbers and snapshot recovery, and nothing else. Building against a gap-fill request that Binary UMDF does not implement is a design dead end.
- Assuming Binary UMDF is a drop-in upgrade. It is MBO-only — no Market-by-Price, no Top of Book. An algorithm consuming aggregated MBP from the legacy feed must rebuild the book from individual order events, not merely re-point at a new multicast group.
- Treating a data-quality gap as recoverable after the fact. Once an SBE consumer has missed messages without detecting it, book state is wrong and every downstream signal is wrong with it. Detect at receive time via sequence continuity.
- Assuming legacy FIX will stay available on the same endpoints. B3 has been consolidating FIX order entry gateways and reassigning IPs, ports, and TargetCompIDs; sessions that miss a cutoff fail to log in.
- Logging the config object. A credential in a dataclass
repr ends up in logs and crash reporters. password is repr=False here; keep it that way if you extend the config.
- Unicast market data addresses in production. UMDF is multicast; a unicast address means no data arrives. This is now rejected by default rather than merely warned about in prose.
- Trusting unsourced latency figures. The precise microsecond ranges commonly quoted for B3 trace to no B3 or vendor publication — measure in your own footprint.
Verification
Run python -m unittest discover -s skills/b3-brazil-exchange-api-integration/scripts — 29 tests, 100% pass rate. The suite covers:
MODERN_BINARY_SBE rejected without enable_application_gap_recovery, accepted with it; LEGACY_FIX_FAST allowed without it
- CompID whitelist, including the regression that special characters and control characters were accepted whenever the ID also contained an underscore
- IP validation: malformed addresses, integer addresses, multicast enforcement on market data, and multicast rejection on order entry
- State machine: idempotent connect/disconnect, and the
FAILED state, which was previously unreachable
- Credential redaction from
repr
- Concurrent connect/disconnect leaving a valid state
Related Skills
binary-protocol-parsing-for-low-latency-feeds — decoding the SBE market data messages
fix-protocol-session-management-across-venues — full FIX/FIXP session handling
order-placement-idempotency — safe order submission once connected
sequence-number-gap-detection-for-feeds — the gap detection this skill requires but does not implement
exchange-multicast-feed-handling — multicast joins and feed plumbing
market-data-cost-optimization-tiered-subscriptions — B3 market data subscription costs
References
1---2name: b3-brazil-exchange-api-integration3description: >-4 Use when configuring B3 PUMA Trading System connectivity and choosing between the5 legacy FIX/FAST stack and Binary SBE; enforces the SBE gap-recovery precondition that6 separates them, and manages connection lifecycle state around a vendor SDK.7license: Apache-2.08metadata:9 source: https://skillmd.com/skills/himanshuj16/b3-brazil-exchange-api-integration10 domain: algorithmic-trading11 subdomain: global-market-integration12 tags: b3, brazil, puma-trading-system, fix-fast, umdf, sbe, binary-order-entry, direct-market-access, low-latency13 brokers_frameworks: "B3 PUMA Trading System; B3 UMDF (Unified Market Data Feed); B3 Binary Order Entry (FIXP/SBE); FIX 4.4"14 version: "2.0.0"15 author: algo-trading-skills-contributors16---1718## Purpose1920Validates B3-specific connectivity configuration and manages connection state for algorithmic trading systems connecting to the B3 PUMA Trading System. Its central job is to make one architectural asymmetry impossible to get wrong: B3's legacy FIX/FAST UMDF publishes TCP-based recovery services, while the newer Binary UMDF (SBE) feed does not — so an SBE consumer must implement its own gap recovery or it will lose market data silently.2122## Scope — what this skill does NOT do2324**This module performs no network I/O.** It opens no sockets, sends no FIX/FIXP messages, and contacts nothing. `connect()` drives a state machine and delegates to an injected `connector` callable; with no connector supplied it logs a warning and reports success without touching the network.2526A successful `connect()` is therefore **not** evidence of reachability, valid credentials, IP whitelisting, or entitlement. Earlier versions of this skill presented `if engine.connect(): print("Connected to B3")` as a connectivity example, which was misleading — it would print success on a machine with no network at all. Inject a real connector (OnixS, B2BITS, or your own socket layer) for actual sessions.2728## When to Use2930- Validating B3 DMA configuration before handing it to a real session layer31- Choosing between the legacy FIX/FAST stack and the Binary SBE stack32- Enforcing the SBE gap-recovery precondition in CI or at application startup33- Managing connection lifecycle state around a vendor SDK3435## When NOT to Use3637- **As a connectivity or credential test** — it performs no I/O (see Scope above)38- **As a FIX/FIXP engine or SBE decoder** — use `binary-protocol-parsing-for-low-latency-feeds` and a real session library39- Connecting to B3 via broker-provided APIs (use broker-specific adapters)40- Systems that do not need direct exchange connectivity4142## Prerequisites4344- Python 3.10+45- Network connectivity to B3 colocation or a certified B3 network provider46- B3-assigned SenderCompID/TargetCompID from B3 Membership Services47- Valid B3 credentials and IP whitelisting for order entry and market data48- For Binary SBE: an application-level gap recovery implementation (sequence tracking + snapshot recovery), which is **outside this skill**4950## Protocol Selection5152| | `LEGACY_FIX_FAST` | `MODERN_BINARY_SBE` |53|---|---|---|54| Order entry | FIX 4.4 | Binary Order Entry (FIXP + SBE) |55| Market data | UMDF FIX/FAST | Binary UMDF (SBE) |56| Book model | MBP / Top of Book available | **MBO only** — no MBP, no TOB |57| Gap recovery | TCP Replayer, TCP Historical Replayer, Snapshot Recovery | **No TCP recovery channel**; sequence tracking + snapshot |58| `enable_application_gap_recovery` | Optional | **Must be True** (enforced) |5960**Legacy is not a neutral long-term choice.** B3 has been reducing FIX order entry gateways in phases — Derivatives in Q4 2025, Equities 10 April – 15 May 2026 — reassigning IPs, ports, and TargetCompIDs, with login failures for participants who miss their cutoff. Confirm current gateway status with B3 before starting new legacy work. See `references/standards.md` for sources and dating.6162## Workflow63641. **Create `B3ConnectionConfig`.** Validation runs in `__post_init__` and raises `B3ConfigurationError` (a `ValueError` subclass):65 - `comp_id` — matched against a conservative `^[A-Za-z0-9_]{1,12}$` whitelist. This is *this skill's* defensive default, not a published B3 grammar; override via `comp_id_pattern` once you confirm the real limits with B3.66 - `password` — excluded from `repr` so it cannot leak into logs or tracebacks.67 - `order_entry_ip` — must be a dotted-quad string and must **not** be multicast (order entry is point-to-point TCP).68 - `market_data_multicast_ip` — must be a genuine multicast address unless you pass `require_multicast_market_data=False` for an isolated test rig.69 - `protocol_suite` — must be a `B3ProtocolSuite` member, not a string.702. **Construct `B3IntegrationEngine`.** If `protocol_suite` is `MODERN_BINARY_SBE` and `enable_application_gap_recovery` is False, construction fails — the SBE feed has no TCP gap-fill channel to fall back on.713. **Inject a connector** if you want real connectivity. Without one, `connect()` is a state-machine simulation and says so at WARNING level.724. **Call `connect()`.** DISCONNECTED/FAILED → CONNECTING → CONNECTED. A connector that raises moves the engine to `FAILED` and raises `B3ConnectionError`; retry with backoff from there, since `connect()` is callable again after a failure.735. **Implement SBE gap recovery separately.** Track sequence numbers on every message, detect gaps, and recover via the snapshot/refresh streams — **not** via a TCP gap-fill request, which Binary UMDF does not offer.746. **Call `disconnect()` on shutdown.** Idempotent, and it forces the state to DISCONNECTED even if the injected disconnector raises, so a failing teardown cannot strand the session.7576> Full procedure: see `references/workflows.md`.77> Protocol specifics, recovery mechanisms, and sources: see `references/standards.md`.78> Printable pre-flight checklist: see `assets/checklist.md`.7980## Common Pitfalls8182- **Reading `connect() == True` as connectivity.** With no connector injected this function does nothing but set an enum. It is configuration validation, not a reachability check.83- **Expecting a TCP gap-fill channel on Binary UMDF.** It does not exist. Legacy FIX/FAST offers TCP Replayer and TCP Historical Replayer; the SBE feed gives you sequence numbers and snapshot recovery, and nothing else. Building against a gap-fill request that Binary UMDF does not implement is a design dead end.84- **Assuming Binary UMDF is a drop-in upgrade.** It is MBO-only — no Market-by-Price, no Top of Book. An algorithm consuming aggregated MBP from the legacy feed must rebuild the book from individual order events, not merely re-point at a new multicast group.85- **Treating a data-quality gap as recoverable after the fact.** Once an SBE consumer has missed messages without detecting it, book state is wrong and every downstream signal is wrong with it. Detect at receive time via sequence continuity.86- **Assuming legacy FIX will stay available on the same endpoints.** B3 has been consolidating FIX order entry gateways and reassigning IPs, ports, and TargetCompIDs; sessions that miss a cutoff fail to log in.87- **Logging the config object.** A credential in a dataclass `repr` ends up in logs and crash reporters. `password` is `repr=False` here; keep it that way if you extend the config.88- **Unicast market data addresses in production.** UMDF is multicast; a unicast address means no data arrives. This is now rejected by default rather than merely warned about in prose.89- **Trusting unsourced latency figures.** The precise microsecond ranges commonly quoted for B3 trace to no B3 or vendor publication — measure in your own footprint.9091## Verification9293Run `python -m unittest discover -s skills/b3-brazil-exchange-api-integration/scripts` — 29 tests, 100% pass rate. The suite covers:9495- `MODERN_BINARY_SBE` rejected without `enable_application_gap_recovery`, accepted with it; `LEGACY_FIX_FAST` allowed without it96- CompID whitelist, including the regression that special characters and control characters were accepted whenever the ID also contained an underscore97- IP validation: malformed addresses, integer addresses, multicast enforcement on market data, and multicast rejection on order entry98- State machine: idempotent connect/disconnect, and the `FAILED` state, which was previously unreachable99- Credential redaction from `repr`100- Concurrent connect/disconnect leaving a valid state101102## Related Skills103104- `binary-protocol-parsing-for-low-latency-feeds` — decoding the SBE market data messages105- `fix-protocol-session-management-across-venues` — full FIX/FIXP session handling106- `order-placement-idempotency` — safe order submission once connected107- `sequence-number-gap-detection-for-feeds` — the gap detection this skill requires but does not implement108- `exchange-multicast-feed-handling` — multicast joins and feed plumbing109- `market-data-cost-optimization-tiered-subscriptions` — B3 market data subscription costs110111## References112113- B3 PUMA Trading System: https://www.b3.com.br/en_us/solutions/platforms/puma-trading-system/114- B3 FIX/FAST UMDF: https://www.b3.com.br/en_us/solutions/platforms/puma-trading-system/for-developers-and-vendors/fix-fast-umdf/115- FIX Protocol standards (FIXP, SBE): https://www.fixtrading.org/standards/