weirdnet-exchange
Exchange-neutral trading types and traits for Weird Brains apps on
Weirdnet. Adapters for real venues live in their own crates and implement the traits here;
apps talk to the traits and can swap in the in-memory Paper exchange for tests and dry runs.
This crate has no exchange adapters and makes no network calls.
- Exact numbers.
PriceandQtywrap a decimal (no floats) and serialize as strings. Rounding to a product's increments is explicit (Rounding::Down,Up,Nearest). - Instruments.
Market(venue and product),Productwith increments, size and notional limits, status, and kind (spot, dated future, perpetual).Product::check_ordermakes the checks a venue would. - Orders.
Side,OrderType(market, limit with post-only, stop-limit, stop-market),TimeInForce(GTC, GTD, IOC, FOK), base or quote sizes, validatedClientOrderIds, and anOrderstate machine that refuses impossible transitions and overfills and ignores replayed fills. - Accounts.
Fill,Balance(available and held),FeeTier,PositionandPositionBook(weighted-average entry, realized and unrealized PnL, flips),MarginSummary. - Market data.
Trade,Ticker,BookSnapshotandBookDelta, anOrderBookthat applies deltas and reports sequence gaps,CandleandCandleBuilder, andMarketEvent. - Adapter traits.
MarketData(public data and streams) andTrading(balances, fees, preview, idempotent placement, cancel, queries, positions and user streams), withCapabilities;Exchangeis both. Errors say whether a retry is safe. - Helpers.
CostModelandBookCostModel(fees, spread, slippage, carry), and a shared token-bucketRateLimiterwith retry-after back-off. - Credentials.
Credential<Live>andCredential<Test>are checked against their source's environment, so a live adapter can't be built from test credentials. - Paper exchange.
Papermatches market, limit, post-only, IOC, FOK, GTC and GTD orders against the books and trades you give it, holds funds, charges fees and tracks positions.
use *;
async
The design notes explain the choices. API documentation is on docs.rs.
Features
| Feature | Default | Adds |
|---|---|---|
vault |
no | vault::VaultSecret: credentials from weirdnet-vault, scoped per account and venue, test and live kept apart |
service |
no | feeds::MarketHubs: books, trades, tickers and candles as weirdnet-service hub topics |
Status
The API may change before 1.0. The paper exchange is a simulation: resting orders fill optimistically (no queue position) and margin is not modelled.
License
BSD-3-Clause, copyright Weird Brains LLC. See LICENSE.
A Weird Brains project.