Skip to main content

nautilus_dydx/
types.rs

1// -------------------------------------------------------------------------------------------------
2//  Copyright (C) 2015-2026 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
16//! Custom data types specific to the dYdX adapter.
17
18use nautilus_core::UnixNanos;
19use nautilus_model::{identifiers::InstrumentId, types::Price};
20
21/// dYdX oracle price update.
22///
23/// Oracle prices on dYdX are used for:
24/// - Mark price calculations for perpetual markets
25/// - Liquidation price determination
26/// - Funding rate calculations
27///
28/// Oracle prices are streamed via the v4_markets WebSocket channel and represent
29/// off-chain price feeds aggregated by dYdX validators.
30#[cfg_attr(
31    feature = "python",
32    pyo3::pyclass(module = "nautilus_trader.core.nautilus_pyo3.dydx", from_py_object)
33)]
34#[cfg_attr(
35    feature = "python",
36    pyo3_stub_gen::derive::gen_stub_pyclass(module = "nautilus_trader.dydx")
37)]
38#[derive(Clone, Debug, PartialEq, Eq, Hash)]
39pub struct DydxOraclePrice {
40    /// The instrument ID for the oracle price.
41    pub instrument_id: InstrumentId,
42    /// The oracle price reported by dYdX validators.
43    pub oracle_price: Price,
44    /// UNIX timestamp (nanoseconds) when the oracle price was updated.
45    pub ts_event: UnixNanos,
46    /// UNIX timestamp (nanoseconds) when the data object was initialized.
47    pub ts_init: UnixNanos,
48}
49
50impl DydxOraclePrice {
51    /// Creates a new [`DydxOraclePrice`] instance.
52    #[must_use]
53    pub const fn new(
54        instrument_id: InstrumentId,
55        oracle_price: Price,
56        ts_event: UnixNanos,
57        ts_init: UnixNanos,
58    ) -> Self {
59        Self {
60            instrument_id,
61            oracle_price,
62            ts_event,
63            ts_init,
64        }
65    }
66}