OnixS C++ ICE Binary Order Entry Handler 1.1.1
API Documentation
Loading...
Searching...
No Matches
Book Class Reference

Public Types

using BookEntryId = Order::OrderId
using BookEntries = std::unordered_map<BookEntryId, OrderPtr>
using Id2crossOrderMap = std::unordered_map<BookEntryId, CrossOrderPtr>
using OrdersList = std::vector<OrderPtr>

Public Member Functions

Orderstore (OrderPtr entry)
Orderstore (OrderPtr entry, BookEntryId id)
CrossOrderstore (CrossOrderPtr entry)
OptionalRef< Orderfind (BookEntryId id)
OptionalRef< CrossOrderfindCross (BookEntryId id)
OrdersList getEntries (std::function< bool(const Order &)> predicate=[](const Order &){ return true;})

Detailed Description

Definition at line 34 of file Book.h.

Member Typedef Documentation

◆ BookEntries

using BookEntries = std::unordered_map<BookEntryId, OrderPtr>

Definition at line 38 of file Book.h.

◆ BookEntryId

Definition at line 37 of file Book.h.

◆ Id2crossOrderMap

using Id2crossOrderMap = std::unordered_map<BookEntryId, CrossOrderPtr>

Definition at line 39 of file Book.h.

◆ OrdersList

using OrdersList = std::vector<OrderPtr>

Returns collection of all the entries.

Definition at line 55 of file Book.h.

Member Function Documentation

◆ find()

OptionalRef< Order > find ( BookEntryId id)

Finds an instance of the entry by its identifier.

Definition at line 78 of file Book.cpp.

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}

◆ findCross()

OptionalRef< CrossOrder > findCross ( BookEntryId id)

Finds a cross order.

Definition at line 86 of file Book.cpp.

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}

◆ getEntries()

Book::OrdersList getEntries ( std::function< bool(const Order &)> predicate = [](const Order&){ return true; })

Definition at line 65 of file Book.cpp.

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}

◆ store() [1/3]

CrossOrder & store ( CrossOrderPtr entry)

Adds order cross entries to the book.

Definition at line 28 of file Book.cpp.

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}

◆ store() [2/3]

Order & store ( OrderPtr entry)

Adds an entry to the book.

Definition at line 23 of file Book.cpp.

24{
25 return store(newEntry, newEntry->id());
26}

◆ store() [3/3]

Order & store ( OrderPtr entry,
BookEntryId id )

Definition at line 43 of file Book.cpp.

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}