use crate::core::{AccountControl, AccountGroups, AccountGroupsHandle, GroupLookup};
use crate::param::{AccountGroupId, AccountId};
use crate::storage::{self, StorageBuilder};
pub struct PreTradeContext<StorageFactory>
where
StorageFactory: storage::LockingPolicyFactory + storage::CreateStorageFor<AccountId> + 'static,
{
pub account_control: Option<AccountControl<StorageFactory>>,
group_lookup: GroupLookup<StorageFactory>,
}
impl<StorageFactory> PreTradeContext<StorageFactory>
where
StorageFactory: storage::LockingPolicyFactory + storage::CreateStorageFor<AccountId> + 'static,
{
pub(crate) fn with_groups(
account_control: Option<AccountControl<StorageFactory>>,
account_groups: AccountGroupsHandle<StorageFactory>,
account: Option<AccountId>,
) -> Self {
Self {
account_control,
group_lookup: GroupLookup::new(account_groups, account),
}
}
pub fn new(account_control: Option<AccountControl<StorageFactory>>) -> Self
where
StorageFactory: Default,
{
let builder = StorageBuilder::new(StorageFactory::default());
let handle = AccountGroupsHandle::from_inner(StorageFactory::new_shared(
AccountGroups::new(&builder),
));
Self::with_groups(account_control, handle, None)
}
pub fn account_group(&self) -> Option<AccountGroupId> {
self.group_lookup.group()
}
}
impl<StorageFactory> crate::marketdata::AccountInfo for PreTradeContext<StorageFactory>
where
StorageFactory: storage::LockingPolicyFactory + storage::CreateStorageFor<AccountId> + 'static,
{
fn group(&self) -> Option<AccountGroupId> {
self.account_group()
}
}