Expand description
§polyoxide-venue
The vocabulary every polyoxide crate shares, whichever venue it talks to.
Classsorts every failure into one of eight classes, andClassify, implemented by every public error type in the workspace, reports an error’s class, whether it is a fault, and how long the server asked the caller to wait.ClassifiedErrorcarries any of them.class_for_status,class_for_close_codeandclass_for_handshake_statusare the one status and close-code table, andimpl_ws_classification!expands the one socket table forpolyoxide_ws::WsErrorin the venue crate that wraps it.parse_retry_afteris the oneRetry-Afterparser, andretry_delaylets it only lengthen the client’s own backoff.Secretholds a value itsDebugnever prints, andUnixMillisis the time venues stamp things with.wire_enum!andopen_enum!declare an enum whose variants each have one wire spelling; a closed one refuses an unknown spelling withUnknownVariant, and an open one keeps it inOther.- With the
decimalfeature,positionalreads and writes rows sent as bare arrays of decimal strings. - With the
keysfeature,MarketKeynames one instrument asvenue.product:id. Only a product’sKeySpacemakes one, so two keys are equal exactly when they name the same instrument;RawKeyis text split into its parts and checked by no product yet. EachKeySpacedeclares its product’sProductClass, which every key it makes carries. - With the
marketfeature, the traits a venue’s products implement so market data reads the same on every venue:MarketData, which every product implements, and the capability traitsInstruments,Trades,Candles,FundingandEventGroups, each with aDynwrapper. The class bundlesPerpetualMarket,EventContractMarketandSpotMarketname what every product of a class offers. The traits return the records market data is read into (Instrument,Quote,Book,Trade,Candle,FundingRateandEventGroup), each carryingExtensions, a venue’s own facts on a shared record, one value per type. - With the
tradingfeature,Tradingplaces and cancels orders, reads open orders, positions and balances, and streams a venue’s acknowledgements and fills asTradingEvents, which begins with aResyncand carries another after every reconnect. It works inOrderRequest,Order,Fill,PositionandBalance, with the opaqueOrderId,FillIdandClientOrderId, each record carryingExtensions;Extensions::ensure_declaredis how a venue refuses an option it does not declare.
By default the crate depends on nothing (on wasm32, only web-time, which
reads the browser’s wall clock), so a credential-free socket crate can use
it without building an HTTP or signing stack. The enum macros name
::serde, so a crate that invokes them depends on serde itself, with
serde’s derive feature for wire_enum!, which derives the two traits;
open_enum! implements them by hand.
use polyoxide_venue::{class_for_status, Class};
let class = class_for_status(503).unwrap().with_code("dependency_unavailable");
assert!(class.is_retriable());
assert_eq!(class.code(), Some("dependency_unavailable"));
assert_eq!(class_for_status(451), Some(Class::Restricted));Modules§
- positional
- Rows a venue sends as bare JSON arrays, with decimals as strings, such as
a kline
[open_time, "open", "high", ..]or a book level["price", "quantity"].
Macros§
- impl_
ws_ classification - Expands, in the invoking module, to the one socket classification table
(AD-15) for
polyoxide_ws::WsError: three private functions a venue’sClassifyimpl calls on itsWsError-carrying arm. - open_
enum - Declares a set the venue reports and extends over time: a spelling this
version does not know is kept verbatim in
Otherinstead of failing the response. - wire_
enum - Declares a closed set the client sends: one wire spelling per variant.
Structs§
- Balance
- What the account holds of one asset.
- Book
- An instrument’s order book at one moment.
- Candle
- One candle. A venue that samples one price per interval gives only
close. - Candle
Query - Which candles to read: their width and the open times they span.
- Classified
Error - An error with its class, from any crate: the one error type a venue-neutral caller handles.
- Client
Order Id - The id a caller gives an order, which the venue echoes back or the implementation keeps for the orders it placed.
- Duplicate
Extension - A value was inserted into
Extensionsthat already held one of its type. AnInvalidRequest: the caller’s misuse. - DynCandles
- Dyn-compatible wrapper for
Candles. - DynEvent
Groups - Dyn-compatible wrapper for
EventGroups. - DynFunding
- Dyn-compatible wrapper for
Funding. - DynInstruments
- Dyn-compatible wrapper for
Instruments. - DynMarket
Data - Dyn-compatible wrapper for
MarketData. - DynTrades
- Dyn-compatible wrapper for
Trades. - DynTrading
- Dyn-compatible wrapper for
Trading. - Event
Group - An event and every outcome it groups, across its markets.
- Event
Outcome - One outcome of an event: a key of its own, in one of the event’s markets.
- Extensions
- Facts only one venue has, carried on a shared record: at most one value of each type, read back by its type.
- Fill
- One order’s part in a trade.
- FillId
- The venue’s id for a fill: one order’s part in a trade.
- Funding
Rate - A perpetual’s funding rate: the one now accruing, or one already settled.
- Instrument
- An instrument a venue lists, and the one record that carries its trading
rules: tick size, minimum size and
SizeUnit. - Level
- One price level of a book.
- Market
Key - One instrument’s name, written
venue.product:id, such asacme.perp:ABCUSD. - NotListed
- The venue’s answer identifies the key as an instrument it does not list.
A
VenueRefusal, as the venue’s own answer for an unknown instrument is. - Order
- An order as the venue reports it.
- OrderId
- The venue’s id for an order.
- Order
Request - An order to place.
- Position
- What the account holds of one instrument or outcome.
- Product
Id - A product’s id: the
productofvenue.product:id, naming the module that trades the instrument. - Quote
- An instrument’s best bid and ask at one moment.
- RawKey
- A key’s text split into venue, product and id, checked by no product yet.
- Secret
- A credential or other value that must not reach a log.
- Trade
- One public trade.
- TradeId
- A trade’s id at its venue. Opaque: compare it, never parse it.
- Trading
Events - The stream
Trading::eventsreturns: the account’s acknowledgements and fills, from an unbounded queue. - Undeclared
Extension - A request carried an extension of a type its venue does not declare
(
Extensions::ensure_declared). AnInvalidRequest: the caller’s misuse, refused before anything is sent. - Unix
Millis - Milliseconds since the Unix epoch, the unit venues stamp orders and frames with.
- Unknown
Variant - A string that is not one of a closed set’s wire spellings.
- Unserved
Interval - A query asked for a candle width the venue does not serve
(
CandleQuery::ensure_served). AnInvalidRequest: the caller’s misuse, refused before anything is sent, and no wait or retry cures it. - VenueId
- A venue’s id: the
venueofvenue.product:id.
Enums§
- Candle
Interval - How long a candle spans. A venue serves some or all of these widths, the
ones its
Candles::intervalslists, and handles every variant, since the enum is exhaustive: a new width is a breaking change that fails to compile at a venue that does not handle it. - Class
- What kind of failure an error is, whichever venue or transport produced it.
- KeyError
- Why text or a key named no instrument a product could read. Every one is
an
InvalidRequest: the caller named something no request can carry. - Kill
Reason - Why an order was killed.
- Liquidity
- Whether a fill took or made liquidity.
- Order
Status - Where an order stands.
- Product
Class - What a product trades, which fixes what its shared records mean.
- Side
- Which side of the book an order, or the taker of a trade, is on.
- Size
Unit - What an instrument’s sizes count.
- Time
InForce - How long an order rests.
- Trading
Event - What
Trading::eventsreports.
Traits§
- Candles
- Candles.
- Classify
- Implemented by every public error type in the workspace.
- Event
Contract Market - What every event-contract product offers:
MarketDataandEventGroups, so a function generic over event contracts needs one bound. - Event
Groups - Events that group an event-contract venue’s outcomes.
- Funding
- A perpetual’s funding.
- Instruments
- Every instrument a product lists, where one request or a few return them.
- KeySpace
- A product’s keys. A venue crate implements it once for each product it
trades, and its methods are the only way to make a
MarketKey. - Market
Data - What every product implements: its instruments, quotes and books.
- Perpetual
Market - What every perpetual-future product offers:
MarketDataandFunding, so a function generic over perpetuals needs one bound. - Spot
Market - What every
ProductClass::Spotproduct offers:MarketData, and nothing beyond it, so a function generic over products that trade the asset itself needs one bound. - Trades
- Public trades.
- Trading
- Places, cancels and reconciles orders on one venue, and reports what happens to them.
Functions§
- class_
for_ close_ code - The class of a socket the server closed, from the close frame’s code.
- class_
for_ handshake_ status - The class of a WebSocket upgrade the server refused with an HTTP status.
- class_
for_ status - The class an HTTP error status decides, before any body is read.
- parse_
retry_ after - Reads a
Retry-Aftervalue as decimal seconds, whole or fractional, capped atclamp. - retry_
delay - The delay before the next attempt: the longer of what the server asked for and the client’s own backoff.