nautilus_common/python/xrate.rs
1// -------------------------------------------------------------------------------------------------
2// Copyright (C) 2015-2025 Nautech Systems Pty Ltd. All rights reserved.
3// https://nautechsystems.io
4//
5// Licensed under the GNU Lesser General Public License Version 3.0 (the "License");
6// You may not use this file except in compliance with the License.
7// You may obtain a copy of the License at https://www.gnu.org/licenses/lgpl-3.0.en.html
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14// -------------------------------------------------------------------------------------------------
15
16use std::collections::HashMap;
17
18use nautilus_core::python::to_pyvalue_err;
19use nautilus_model::enums::PriceType;
20use pyo3::prelude::*;
21use ustr::Ustr;
22
23use crate::xrate::get_exchange_rate;
24
25#[pyfunction]
26#[pyo3(name = "get_exchange_rate")]
27#[pyo3(signature = (from_currency, to_currency, price_type, quotes_bid, quotes_ask))]
28pub fn py_get_exchange_rate(
29 from_currency: &str,
30 to_currency: &str,
31 price_type: PriceType,
32 quotes_bid: HashMap<String, f64>,
33 quotes_ask: HashMap<String, f64>,
34) -> PyResult<Option<f64>> {
35 get_exchange_rate(
36 Ustr::from(from_currency),
37 Ustr::from(to_currency),
38 price_type,
39 quotes_bid,
40 quotes_ask,
41 )
42 .map_err(to_pyvalue_err)
43}