financial_types 0.1.0

Core financial type definitions for trading systems: asset types, trading actions, position sides, and option styles.
Documentation

Dual License Crates.io Downloads Stars Issues PRs Build Status Coverage Dependencies Documentation Wiki

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 utoipa support via feature flag
  • Helpers: is_*() and opposite() methods on applicable types

Installation

Add this to your Cargo.toml:

[dependencies]
financial_types = "0.1"

To enable OpenAPI schema support:

[dependencies]
financial_types = { version = "0.1", features = ["utoipa"] }

Quick Start

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");

// Helper methods
assert!(style.is_call());
assert!(side.is_long());
assert!(action.is_buy());

// Opposite helpers
assert_eq!(side.opposite(), Side::Short);
assert_eq!(style.opposite(), OptionStyle::Put);

API

UnderlyingAssetType

use financial_types::UnderlyingAssetType;

let asset = UnderlyingAssetType::Stock;
assert!(asset.is_stock());
assert!(!asset.is_crypto());

Helpers: is_stock(), is_crypto(), is_forex(), is_commodity(), is_bond()

Action

use financial_types::Action;

let action = Action::Buy;
assert!(action.is_buy());
assert!(!action.is_sell());

Helpers: is_buy(), is_sell()

Side

use financial_types::Side;

let side = Side::Long;
assert!(side.is_long());
assert_eq!(side.opposite(), Side::Short);

Helpers: is_long(), is_short(), opposite()

OptionStyle

use financial_types::OptionStyle;

let style = OptionStyle::Call;
assert!(style.is_call());
assert_eq!(style.opposite(), OptionStyle::Put);
assert!(OptionStyle::Call < OptionStyle::Put); // Ord supported

Helpers: is_call(), is_put(), opposite()

Serialization

use financial_types::Side;

let side = Side::Long;
let json = serde_json::to_string(&side).unwrap();  // "\"Long\""
let parsed: Side = serde_json::from_str(&json).unwrap();
assert_eq!(side, parsed);

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:

  1. Fork the repository.
  2. Create a new branch for your feature or bug fix.
  3. Make your changes and ensure that the project still builds and all tests pass.
  4. Commit your changes and push your branch to your forked repository.
  5. 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

We appreciate your interest and look forward to your contributions!

✍️ License

Licensed under MIT license