Tesser RFC-001: Native Multi-Exchange Architecture & Symbol Reification #77
Closed
EwigMidori
started this conversation in
Ideas
Replies: 1 comment
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Tesser RFC-001: Native Multi-Exchange Architecture & Symbol Reification
1. Summary
This RFC proposes a foundational refactoring of Tesser's type system and runtime architecture. We will transition from a string-based, single-venue model to a strongly-typed, multi-venue federated architecture.
Currently,
Symbolis an alias forString. This prevents the type system from distinguishing betweenBTCUSDTon Binance andBTCUSDTon Bybit. By reifyingSymbol,ExchangeId, andAssetIdinto distinct types, and introducing a Routing Layer, we will enable institutional-grade strategies (e.g., triangular arbitrage, basis trading) while eliminating entire classes of runtime errors.Note: As Tesser is pre-production, this refactor will not prioritize backward compatibility. We will prioritize correctness and type safety.
2. Core Type System Overhaul (
tesser-core)The primitive
Stringtypes currently used for identifiers must be replaced with structured types that carry context.2.1
ExchangeIdA lightweight,
Copy-able identifier for physical execution venues.u8oru16."binance_perp") to IDs at runtime startup.O(1)routing decisions and hash map lookups without heap allocations.2.2
AssetIdAssets must be scoped to their custody location (the exchange) or chain, not treated as global platonic ideals.
struct AssetId { exchange: ExchangeId, inner: u32 }(whereinnermaps to an interned string like "USDT").AssetId(Binance, USDT)!=AssetId(Bybit, USDT).2.3
Symbol(The Breaking Change)The
Symboltype alias becomes a struct.3. The Virtualized Broker Layer (
tesser-broker)We will implement the Composite Pattern. The strategy interaction layer remains unchanged (
ExecutionClienttrait), but the implementation changes from a direct connector to a Router.3.1 The Router (
RouterExecutionClient)This component holds a map of
ExchangeId -> Arc<dyn ExecutionClient>.place_order(request).request.symbol.exchange.UUID(Globally unique).TESSER_{InternalUUID}).3.2 Unified Market Stream (
RouterMarketStream)NWebSocket tasks (one per exchange).MPSCchannel to fan-inTick,Candle, andOrderBookevents.exchange_timestampacross venues, as clock drift and network jitter will introduce unacceptable latency or stalled streams.4. Portfolio Isolation (
tesser-portfolio)The
Portfoliostruct must transition from a "Global Wallet" to a "Federation of Wallets".4.1 Hierarchical Accounting
Currently, Tesser assumes a single pool of
USDT. This is dangerous for cross-exchange trading.New Structure:
4.2 Risk Management Implications
PreTradeRiskCheckermust be updated to be Venue-Aware.5. Corner Cases & Safety Mechanisms
5.1 The "Legging" Risk (Atomic Failure)
In cross-exchange arbitrage, if one leg fills and the other fails, the system enters a toxic state.
OrderOrchestratorneeds a new primitive:ExecutionGroup.Criticalalert level (PagerDuty).5.2 Precision Mismatches
When arbitraging
BTCUSDTon Binance vs Bybit:0.1, Lot Size:0.0010.5, Lot Size:0.01MarketRegistrymust expose anormalize_quantity(symbol_a, symbol_b, qty)helper that rounds down to the coarsest granularity of both venues.5.3 Fee Currency Ambiguity
BNB(if enabled), Bybit deducts inUSDT(Linear) orBTC(Inverse).Fillevent structure must includefee_asset: AssetId. The Portfolio must support negative balances in fee assets temporarily if the exchange allows it, or correctly deduct from the specific asset balance.6. Implementation Plan
Phase 1: Type System & Config
ExchangeIdenum/struct intesser-core.Symboltype alias to struct.tesser-configto accept[[exchanges]]list instead of single table.String-based symbols and fix compilation errors.Phase 2: Registry & Static Data
MarketRegistryto store(ExchangeId, SymbolStr) -> Instrument.InstrumentInfomerging logic.Phase 3: The Router & Execution
RouterExecutionClient.RouterMarketStream.Portfolioto supportSubAccountisolation.tesser-test-utilsto spin up multiple mock exchange instances.Phase 4: Strategy Adaptation
PairsTradingstrategy runs on the new architecture.Strategy::subscriptions()to returnVec<Symbol>structs.StrategyContextto provide lookup bySymbolstruct.PairsTradingArbitrageto use explicit exchange targets.7. Future Implications
This architecture paves the way for:
Symbolis now a struct with an integer ID, we can replace HashMaps withVec-based direct indexing in the hot path for extreme performance.All reactions