Expand description
§Financial Types
Core financial type definitions for trading systems.
This crate provides fundamental enums used across financial applications:
UnderlyingAssetType— Classification of asset classes (stocks, crypto, forex, etc.)Action— Trading actions (buy, sell)Side— Position directional exposure (long, short)OptionStyle— Option contract style (call, put)
All enums use #[repr(u8)] for compact memory layout and are designed for
high-performance financial systems.
§Features
- Full
serdeserialization/deserialization support - Optional
utoipasupport for OpenAPI schema generation (enable theutoipafeature) #[repr(u8)]on all enums for deterministic layout#[must_use]on pure helper methodsFromStr,TryFrom<&str>, andTryFrom<u8>on every public enum, returningParseEnumErroron failure. String parsing is case-insensitive and trims whitespace.
§Wire format
serde JSON encoding is part of the public contract. The string
used for every variant is fixed and SemVer-tracked: renaming any
variant string is a breaking change.
| Enum | Variant | JSON |
|---|---|---|
UnderlyingAssetType | Crypto | "Crypto" |
UnderlyingAssetType | Stock | "Stock" |
UnderlyingAssetType | Forex | "Forex" |
UnderlyingAssetType | Commodity | "Commodity" |
UnderlyingAssetType | Bond | "Bond" |
UnderlyingAssetType | Other | "Other" |
UnderlyingAssetType | Future | "Future" |
UnderlyingAssetType | Forward | "Forward" |
Action | Buy | "Buy" |
Action | Sell | "Sell" |
Action | Other | "Other" |
Side | Long | "Long" |
Side | Short | "Short" |
OptionStyle | Call | "Call" |
OptionStyle | Put | "Put" |
§no_std
The crate compiles in no_std environments. Disable default features:
[dependencies]
financial_types = { version = "0.1", default-features = false }The alloc crate is always required (used by ParseEnumError).
Re-enable the std feature to opt into std::error::Error-style
integration that pulls in serde/std.
§Usage
use financial_types::{Action, Side, OptionStyle, UnderlyingAssetType};
let action = Action::Buy;
let side = Side::Long;
let style = OptionStyle::Call;
let asset = UnderlyingAssetType::Stock;
assert_eq!(format!("{action}"), "Buy");
assert_eq!(format!("{side}"), "Long");
assert_eq!(format!("{style}"), "Call");
assert_eq!(format!("{asset}"), "Stock");
assert!(style.is_call());
assert!(side.is_long());
assert!(action.is_buy());Modules§
- prelude
- Prelude module for convenient imports.
Structs§
- Parse
Enum Error - Error returned when a string or
u8cannot be converted into one of the public financial enums defined by this crate.
Enums§
- Action
- Represents trading actions in a financial context.
- Option
Style - Specifies the style of an option contract.
- Side
- Defines the directional exposure of a financial position.
- Underlying
Asset Type - Classification of the underlying asset for a financial instrument.