OnixS C++ ICE Binary Order Entry Handler 1.1.1
API Documentation
Loading...
Searching...
No Matches
Book.cpp
Go to the documentation of this file.
1/*
2* Copyright Onix Solutions Limited [OnixS]. All rights reserved.
3*
4* This software owned by Onix Solutions Limited [OnixS] and is protected by copyright law
5* and international copyright treaties.
6*
7* Access to and use of the software is governed by the terms of the applicable OnixS Software
8* Services Agreement (the Agreement) and Customer end user license agreements granting
9* a non-assignable, non-transferable and non-exclusive license to use the software
10* for it's own data processing purposes under the terms defined in the Agreement.
11*
12* Except as otherwise granted within the terms of the Agreement, copying or reproduction of any part
13* of this source code or associated reference material to any other location for further reproduction
14* or redistribution, and any amendments to this copyright notice, are expressly prohibited.
15*
16* Any reproduction or redistribution for sale or hiring of the Software not in accordance with
17* the terms of the Agreement is a violation of copyright law.
18*/
19#include "Book.h"
20
21namespace Samples {
22
24{
25 return store(newEntry, newEntry->id());
26}
27
29{
30 const Guard guard(mutex_);
31
32 store(entry->sellSideOrder_);
33 store(entry->buySideOrder_);
34
35 const auto res = crossOrders_.insert(std::make_pair(entry->id(), entry));
36
37 if (!res.second)
38 throw std::domain_error("Cross orders already has an entry registered under ID = '" + std::to_string(entry->id()) + "'.");
39
40 return *res.first->second;
41}
42
44{
45 assert(newEntry);
46
47 const Guard guard(mutex_);
48
49 const auto res = entries_.emplace(
50 std::piecewise_construct,
51 std::forward_as_tuple(id),
52 std::forward_as_tuple(newEntry)
53 );
54
55 if (!res.second)
56 throw std::domain_error("Book already has an entry registered under ID = '" + std::to_string(id) + "'.");
57
58 auto& order = res.first->second;
59
60 assert(id == order->id());
61
62 return *order;
63}
64
65Book::OrdersList Book::getEntries(std::function<bool(const Order&)> predicate)
66{
67 OrdersList list;
68
69 const Guard guard(mutex_);
70
71 for (const auto& entry : entries_)
72 if(predicate(*entry.second))
73 list.push_back(entry.second);
74
75 return list;
76}
77
79{
80 const Guard guard(mutex_);
81
82 const auto entry = entries_.find(id);
83 return entry == entries_.end() ? OptionalRef<Order>{} : OptionalRef<Order>{entry->second};
84}
85
87{
88 const Guard guard(mutex_);
89
90 const auto entry = crossOrders_.find(id);
91 return entry == crossOrders_.end() ? OptionalRef<CrossOrder>{} : OptionalRef<CrossOrder>{entry->second};
92}
93
94}
OptionalRef< CrossOrder > findCross(BookEntryId id)
Finds a cross order.
Definition Book.cpp:86
OrdersList getEntries(std::function< bool(const Order &)> predicate=[](const Order &){ return true;})
Definition Book.cpp:65
Order & store(OrderPtr entry)
Adds an entry to the book.
Definition Book.cpp:23
Order::OrderId BookEntryId
Definition Book.h:37
OptionalRef< Order > find(BookEntryId id)
Finds an instance of the entry by its identifier.
Definition Book.cpp:78
std::vector< OrderPtr > OrdersList
Returns collection of all the entries.
Definition Book.h:55
std::shared_ptr< CrossOrder > CrossOrderPtr
Definition Order.h:104
std::optional< std::shared_ptr< T > > OptionalRef
Manages an optional contained reference.
Definition Utils.h:224
std::shared_ptr< Order > OrderPtr
Definition Order.h:75
2-sides cross order.
Definition Order.h:84