nautilus_model/events/position/mod.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 crate::{
17 events::{PositionChanged, PositionClosed, PositionOpened},
18 identifiers::{AccountId, InstrumentId},
19};
20pub mod changed;
21pub mod closed;
22pub mod opened;
23pub mod snapshot;
24
25pub enum PositionEvent {
26 PositionOpened(PositionOpened),
27 PositionChanged(PositionChanged),
28 PositionClosed(PositionClosed),
29}
30
31impl PositionEvent {
32 pub fn instrument_id(&self) -> InstrumentId {
33 match self {
34 PositionEvent::PositionOpened(position) => position.instrument_id,
35 PositionEvent::PositionChanged(position) => position.instrument_id,
36 PositionEvent::PositionClosed(position) => position.instrument_id,
37 }
38 }
39
40 pub fn account_id(&self) -> AccountId {
41 match self {
42 PositionEvent::PositionOpened(position) => position.account_id,
43 PositionEvent::PositionChanged(position) => position.account_id,
44 PositionEvent::PositionClosed(position) => position.account_id,
45 }
46 }
47}