nautilus_model/events/position/mod.rs
1// -------------------------------------------------------------------------------------------------
2// Copyright (C) 2015-2025 Posei Systems Pty Ltd. All rights reserved.
3// https://poseitrader.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
25#[derive(Debug)]
26pub enum PositionEvent {
27 PositionOpened(PositionOpened),
28 PositionChanged(PositionChanged),
29 PositionClosed(PositionClosed),
30}
31
32impl PositionEvent {
33 pub fn instrument_id(&self) -> InstrumentId {
34 match self {
35 PositionEvent::PositionOpened(position) => position.instrument_id,
36 PositionEvent::PositionChanged(position) => position.instrument_id,
37 PositionEvent::PositionClosed(position) => position.instrument_id,
38 }
39 }
40
41 pub fn account_id(&self) -> AccountId {
42 match self {
43 PositionEvent::PositionOpened(position) => position.account_id,
44 PositionEvent::PositionChanged(position) => position.account_id,
45 PositionEvent::PositionClosed(position) => position.account_id,
46 }
47 }
48}