Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Finish rust event typing and reorganization #1378

Merged
merged 2 commits into from
Nov 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions nautilus_core/model/src/events/account/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// -------------------------------------------------------------------------------------------------
// Copyright (C) 2015-2023 Nautech Systems Pty Ltd. All rights reserved.
// https://nautechsystems.io
//
// Licensed under the GNU Lesser General Public License Version 3.0 (the "License");
// You may not use this file except in compliance with the License.
// You may obtain a copy of the License at https://www.gnu.org/licenses/lgpl-3.0.en.html
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// -------------------------------------------------------------------------------------------------

pub mod state;
39 changes: 39 additions & 0 deletions nautilus_core/model/src/events/account/state.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// -------------------------------------------------------------------------------------------------
// Copyright (C) 2015-2023 Nautech Systems Pty Ltd. All rights reserved.
// https://nautechsystems.io
//
// Licensed under the GNU Lesser General Public License Version 3.0 (the "License");
// You may not use this file except in compliance with the License.
// You may obtain a copy of the License at https://www.gnu.org/licenses/lgpl-3.0.en.html
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// -------------------------------------------------------------------------------------------------

use nautilus_core::{time::UnixNanos, uuid::UUID4};

use crate::{
enums::AccountType,
identifiers::account_id::AccountId,
types::{
balance::{AccountBalance, MarginBalance},
currency::Currency,
},
};

#[repr(C)]
#[derive(Debug)]
pub struct AccountState {
pub account_id: AccountId,
pub account_type: AccountType,
pub base_currency: Currency,
pub balances: Vec<AccountBalance>,
pub margins: Vec<MarginBalance>,
pub is_reported: bool,
pub event_id: UUID4,
pub ts_event: UnixNanos,
pub ts_init: UnixNanos,
}
1 change: 1 addition & 0 deletions nautilus_core/model/src/events/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,6 @@
// limitations under the License.
// -------------------------------------------------------------------------------------------------

pub mod account;
pub mod order;
pub mod position;
136 changes: 0 additions & 136 deletions nautilus_core/model/src/events/position.rs

This file was deleted.

52 changes: 52 additions & 0 deletions nautilus_core/model/src/events/position/changed.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
// -------------------------------------------------------------------------------------------------
// Copyright (C) 2015-2023 Nautech Systems Pty Ltd. All rights reserved.
// https://nautechsystems.io
//
// Licensed under the GNU Lesser General Public License Version 3.0 (the "License");
// You may not use this file except in compliance with the License.
// You may obtain a copy of the License at https://www.gnu.org/licenses/lgpl-3.0.en.html
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// -------------------------------------------------------------------------------------------------

use nautilus_core::time::UnixNanos;

use crate::{
enums::{OrderSide, PositionSide},
identifiers::{
account_id::AccountId, client_order_id::ClientOrderId, instrument_id::InstrumentId,
position_id::PositionId, strategy_id::StrategyId, trader_id::TraderId,
},
types::{currency::Currency, money::Money, price::Price, quantity::Quantity},
};

#[repr(C)]
#[derive(Clone, PartialEq, Debug)]
pub struct PositionChanged {
pub trader_id: TraderId,
pub strategy_id: StrategyId,
pub instrument_id: InstrumentId,
pub position_id: PositionId,
pub account_id: AccountId,
pub opening_order_id: ClientOrderId,
pub entry: OrderSide,
pub side: PositionSide,
pub signed_qty: f64,
pub quantity: Quantity,
pub peak_quantity: Quantity,
pub last_qty: Quantity,
pub last_px: Price,
pub currency: Currency,
pub avg_px_open: f64,
pub avg_px_closed: f64,
pub realized_return: f64,
pub realized_pnl: Money,
pub unrealized_pnl: Money,
pub ts_opened: UnixNanos,
pub ts_event: UnixNanos,
pub ts_init: UnixNanos,
}
54 changes: 54 additions & 0 deletions nautilus_core/model/src/events/position/closed.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
// -------------------------------------------------------------------------------------------------
// Copyright (C) 2015-2023 Nautech Systems Pty Ltd. All rights reserved.
// https://nautechsystems.io
//
// Licensed under the GNU Lesser General Public License Version 3.0 (the "License");
// You may not use this file except in compliance with the License.
// You may obtain a copy of the License at https://www.gnu.org/licenses/lgpl-3.0.en.html
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// -------------------------------------------------------------------------------------------------

use nautilus_core::time::{TimedeltaNanos, UnixNanos};

use crate::{
enums::{OrderSide, PositionSide},
identifiers::{
account_id::AccountId, client_order_id::ClientOrderId, instrument_id::InstrumentId,
position_id::PositionId, strategy_id::StrategyId, trader_id::TraderId,
},
types::{currency::Currency, money::Money, price::Price, quantity::Quantity},
};
#[repr(C)]
#[derive(Clone, PartialEq, Debug)]
pub struct PositionClosed {
pub trader_id: TraderId,
pub strategy_id: StrategyId,
pub instrument_id: InstrumentId,
pub position_id: PositionId,
pub account_id: AccountId,
pub opening_order_id: ClientOrderId,
pub closing_order_id: ClientOrderId,
pub entry: OrderSide,
pub side: PositionSide,
pub signed_qty: f64,
pub quantity: Quantity,
pub peak_quantity: Quantity,
pub last_qty: Quantity,
pub last_px: Price,
pub currency: Currency,
pub avg_px_open: f64,
pub avg_px_closed: f64,
pub realized_return: f64,
pub realized_pnl: Money,
pub unrealized_pnl: Money,
pub duration: TimedeltaNanos,
pub ts_opened: UnixNanos,
pub ts_closed: UnixNanos,
pub ts_event: UnixNanos,
pub ts_init: UnixNanos,
}
30 changes: 30 additions & 0 deletions nautilus_core/model/src/events/position/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// -------------------------------------------------------------------------------------------------
// Copyright (C) 2015-2023 Nautech Systems Pty Ltd. All rights reserved.
// https://nautechsystems.io
//
// Licensed under the GNU Lesser General Public License Version 3.0 (the "License");
// You may not use this file except in compliance with the License.
// You may obtain a copy of the License at https://www.gnu.org/licenses/lgpl-3.0.en.html
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// -------------------------------------------------------------------------------------------------

use crate::events::position::{
changed::PositionChanged, closed::PositionClosed, opened::PositionOpened,
};

pub mod changed;
pub mod closed;
pub mod opened;

pub mod state;

pub enum PositionEvent {
PositionOpened(PositionOpened),
PositionChanged(PositionChanged),
PositionClosed(PositionClosed),
}
46 changes: 46 additions & 0 deletions nautilus_core/model/src/events/position/opened.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
// -------------------------------------------------------------------------------------------------
// Copyright (C) 2015-2023 Nautech Systems Pty Ltd. All rights reserved.
// https://nautechsystems.io
//
// Licensed under the GNU Lesser General Public License Version 3.0 (the "License");
// You may not use this file except in compliance with the License.
// You may obtain a copy of the License at https://www.gnu.org/licenses/lgpl-3.0.en.html
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// -------------------------------------------------------------------------------------------------

use nautilus_core::time::UnixNanos;

use crate::{
enums::{OrderSide, PositionSide},
identifiers::{
account_id::AccountId, client_order_id::ClientOrderId, instrument_id::InstrumentId,
position_id::PositionId, strategy_id::StrategyId, trader_id::TraderId,
},
types::{currency::Currency, price::Price, quantity::Quantity},
};

#[repr(C)]
#[derive(Clone, PartialEq, Debug)]
pub struct PositionOpened {
pub trader_id: TraderId,
pub strategy_id: StrategyId,
pub instrument_id: InstrumentId,
pub position_id: PositionId,
pub account_id: AccountId,
pub opening_order_id: ClientOrderId,
pub entry: OrderSide,
pub side: PositionSide,
pub signed_qty: f64,
pub quantity: Quantity,
pub last_qty: Quantity,
pub last_px: Price,
pub currency: Currency,
pub avg_px_open: f64,
pub ts_event: UnixNanos,
pub ts_init: UnixNanos,
}
Loading
Loading