Financial Types
Core financial type definitions for trading systems in Rust.
Overview
financial_types is a lightweight Rust crate providing fundamental enums for
financial applications. These types are the building blocks used across trading
systems, options pricing libraries, and portfolio management tools.
All enums use #[repr(u8)] for compact memory layout (1 byte each) and include
serde serialization support out of the box.
Types
| Type | Variants | Description |
|---|---|---|
UnderlyingAssetType |
Crypto, Stock, Forex, Commodity, Bond, Other | Classification of asset classes |
Action |
Buy, Sell, Other | Trading actions |
Side |
Long, Short | Position directional exposure |
OptionStyle |
Call, Put | Option contract style |
Features
- Compact: All enums are
#[repr(u8)]— 1 byte each - Safe:
#[must_use]on all pure helper methods - Serde: Full serialization/deserialization support
- OpenAPI: Optional
utoipasupport via feature flag - Helpers:
is_*()andopposite()methods on applicable types
Installation
Add this to your Cargo.toml:
[]
= "0.1"
To enable OpenAPI schema support:
[]
= { = "0.1", = ["utoipa"] }
Quick Start
use ;
let action = Buy;
let side = Long;
let style = Call;
let asset = Stock;
assert_eq!;
assert_eq!;
assert_eq!;
assert_eq!;
// Helper methods
assert!;
assert!;
assert!;
// Opposite helpers
assert_eq!;
assert_eq!;
API
UnderlyingAssetType
use UnderlyingAssetType;
let asset = Stock;
assert!;
assert!;
Helpers: is_stock(), is_crypto(), is_forex(), is_commodity(), is_bond()
Action
use Action;
let action = Buy;
assert!;
assert!;
Helpers: is_buy(), is_sell()
Side
use Side;
let side = Long;
assert!;
assert_eq!;
Helpers: is_long(), is_short(), opposite()
OptionStyle
use OptionStyle;
let style = Call;
assert!;
assert_eq!;
assert!; // Ord supported
Helpers: is_call(), is_put(), opposite()
Serialization
use Side;
let side = Long;
let json = to_string.unwrap; // "\"Long\""
let parsed: Side = from_str.unwrap;
assert_eq!;
License
This project is licensed under the MIT License.
Contribution and Contact
We welcome contributions to this project! If you would like to contribute, please follow these steps:
- Fork the repository.
- Create a new branch for your feature or bug fix.
- Make your changes and ensure that the project still builds and all tests pass.
- Commit your changes and push your branch to your forked repository.
- Submit a pull request to the main repository.
If you have any questions, issues, or would like to provide feedback, please feel free to contact the project maintainer:
Contact Information
- Author: Joaquín Béjar García
- Email: jb@taunais.com
- Telegram: @joaquin_bejar
- Repository: https://github.com/joaquinbejar/financial_types
- Documentation: https://docs.rs/financial_types
We appreciate your interest and look forward to your contributions!
✍️ License
Licensed under MIT license