swift_mt_message/fields/field36.rs
1use serde::{Deserialize, Serialize};
2use swift_mt_message_macros::SwiftField;
3
4/// **Field 36: Exchange Rate**
5///
6/// ## Purpose
7/// Specifies the exchange rate used to convert the instructed currency amount to the
8/// settlement currency amount in cross-currency transactions. This field is critical
9/// for currency conversion calculations, enabling precise conversion between different
10/// currencies while maintaining audit trails and enabling proper reconciliation.
11///
12/// ## Format
13/// - **Swift Format**: `12d`
14/// - **Description**: Decimal rate with comma as decimal separator
15/// - **Precision**: Up to 12 digits including decimal places
16/// - **Rate Expression**: Direct rate from instructed currency to settlement currency
17///
18/// ## Presence
19/// - **Status**: Mandatory when currency conversion is performed on sender's side
20/// - **Swift Error Codes**: T40 (invalid rate), T51 (format violation), T43 (rate validation)
21/// - **Usage Context**: Cross-currency payment processing and currency conversion
22///
23/// ## Usage Rules
24/// - **Conversion Requirement**: Required when Field 33B currency differs from Field 32A currency
25/// - **Rate Direction**: Rate from instructed currency (33B) to settlement currency (32A)
26/// - **Calculation Logic**: Instructed Amount × Exchange Rate = Settlement Amount (before charges)
27/// - **Precision**: Must provide sufficient precision for accurate conversion
28///
29/// ## Network Validation Rules
30/// - **Format Validation**: Must follow 12d format with decimal comma
31/// - **Positive Rate**: Exchange rate must be greater than zero
32/// - **Reasonable Range**: Rate must be within acceptable market ranges
33/// - **Precision Rules**: Integer part must contain at least one digit
34/// - **Decimal Requirement**: Decimal comma is mandatory even for whole numbers
35///
36/// ## Exchange Rate Calculation
37/// ```logic
38/// Basic Formula:
39/// Field 33B Amount × Field 36 Rate = Converted Amount
40/// Converted Amount ± Charges = Field 32A Amount
41///
42/// Example:
43/// EUR 1,000.00 × 1,2500 = USD 1,250.00
44/// USD 1,250.00 - USD 25.00 (charges) = USD 1,225.00 (settlement)
45/// ```
46///
47/// ## Business Context
48/// - **Currency Conversion**: Essential for multi-currency transaction processing
49/// - **Market Rates**: Reflects prevailing market exchange rates at execution time
50/// - **Risk Management**: Enables proper currency risk assessment and hedging
51/// - **Reconciliation**: Provides audit trail for currency conversion calculations
52///
53/// ## Examples
54/// ```logic
55/// :36:1,2500 // EUR to USD rate: 1 EUR = 1.2500 USD
56/// :36:0,8500 // USD to EUR rate: 1 USD = 0.8500 EUR
57/// :36:110,2500 // USD to JPY rate: 1 USD = 110.2500 JPY
58/// :36:1,3250 // GBP to USD rate: 1 GBP = 1.3250 USD
59/// ```
60///
61/// ## Rate Types and Sources
62/// - **Market Rates**: Current interbank market rates
63/// - **Customer Rates**: Institution-specific customer rates
64/// - **Fixed Rates**: Predetermined contractual rates
65/// - **Spot Rates**: Real-time market rates for immediate settlement
66///
67/// ## Rate Precision Considerations
68/// - **Major Currencies**: Typically 4-6 decimal places (EUR/USD, GBP/USD)
69/// - **Emerging Markets**: May require higher precision for accuracy
70/// - **Cross Rates**: Calculated rates may need additional precision
71/// - **Rounding Rules**: Institutional rounding policies for rate application
72///
73/// ## Regional Considerations
74/// - **European Markets**: EUR cross-rates and ECB reference rates
75/// - **US Markets**: USD-based rates and Federal Reserve considerations
76/// - **Asian Markets**: Local currency rates and central bank policies
77/// - **Emerging Markets**: Volatility considerations and rate validation
78///
79/// ## Error Prevention
80/// - **Rate Validation**: Verify rate is within reasonable market ranges
81/// - **Currency Pair Check**: Ensure rate applies to correct currency pair
82/// - **Precision Verification**: Confirm adequate precision for accurate conversion
83/// - **Market Validation**: Check rate against current market conditions
84///
85/// ## Related Fields
86/// - **Field 33B**: Currency/Instructed Amount (source currency and amount)
87/// - **Field 32A**: Value Date, Currency, Amount (target currency and amount)
88/// - **Field 71F**: Sender's Charges (deductions from converted amount)
89/// - **Field 71G**: Receiver's Charges (additions to final amount)
90///
91/// ## Conversion Flow
92/// 1. **Source**: Field 33B provides original currency and amount
93/// 2. **Conversion**: Field 36 rate applied to convert currency
94/// 3. **Charges**: Fields 71F/71G adjust for transaction charges
95/// 4. **Settlement**: Field 32A shows final currency and amount
96///
97/// ## Market Rate Management
98/// - **Rate Sources**: Reuters, Bloomberg, central bank rates
99/// - **Rate Timing**: Execution time, value date, or agreed timing
100/// - **Rate Updates**: Real-time or periodic rate refreshes
101/// - **Rate Validation**: Market reasonableness checks
102///
103/// ## STP Processing
104/// - **Automated Conversion**: System-driven rate application and calculation
105/// - **Rate Validation**: Real-time market rate validation
106/// - **Exception Handling**: Automated detection of unreasonable rates
107/// - **Quality Control**: Continuous monitoring of conversion accuracy
108///
109/// ## Compliance Framework
110/// - **Regulatory Rates**: Central bank or regulatory mandated rates
111/// - **Audit Requirements**: Complete rate documentation and justification
112/// - **Market Conduct**: Fair and reasonable rate application
113/// - **Documentation**: Proper rate source and timing documentation
114///
115/// ## Risk Management
116/// - **Currency Risk**: Exposure assessment and hedging implications
117/// - **Market Risk**: Rate volatility and timing considerations
118/// - **Operational Risk**: Rate accuracy and conversion precision
119/// - **Compliance Risk**: Regulatory rate requirements and documentation
120///
121/// ## See Also
122/// - Swift FIN User Handbook: Exchange Rate Specifications
123/// - Currency Conversion Guidelines: Rate Application Standards
124/// - Market Rate Sources: Authorized Rate Providers
125/// - Risk Management: Currency Conversion Risk Controls
126/// **Field 36: Exchange Rate Structure**
127///
128/// Contains the exchange rate for currency conversion calculations.
129#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, SwiftField)]
130pub struct Field36 {
131 /// Exchange rate for currency conversion
132 ///
133 /// Format: 12d - Decimal rate with comma separator (up to 12 digits)
134 /// Rate from instructed currency (Field 33B) to settlement currency (Field 32A)
135 /// Must be positive and within reasonable market ranges
136 #[component("12d")]
137 pub rate: f64,
138}