### Liquibook Manual Entry Example Source: https://github.com/enewhuis/liquibook/blob/master/README_ORDER_ENTRY.md Provides a concrete example of the manual entry program's interaction for adding orders, including symbol processing and order book creation prompts. ```text > buy 100 ibm 50; New Symbol IBM. Add [S]imple book, or [D]epth book, or 'N' to cancel request. [SDN}: d Create new depth order book for IBM ADDING order: [#1 BUY 100 IBM $50 Last Event:{Submitted BUY 100 IBM @50}] Accepted: [#1 BUY 100 IBM $50 Open: 100 Last Event:{Accepted }] Book Change: IBM Depth Change: IBM Changed Change Id: 1 Published: 0 BIDS: Price 50 Count: 1 Quantity: 100 Change id#: 1 BBO Change: IBM Changed Change Id: 1 Published: 0 > buy 200 t 78; New Symbol T. Add [S]imple book, or [D]epth book, or 'N' to cancel request. [SDN}: s Create new order book for T ADDING order: [#2 BUY 200 T $78 Last Event:{Submitted BUY 200 T @78}] Accepted: [#2 BUY 200 T $78 Open: 200 Last Event:{Accepted }] Book Change: T > buy 50 r 99; New Symbol R. Add [S]imple book, or [D]epth book, or 'N' to cancel request. [SDN}: n Request ignored Cannot process command BUY 50 R 99 ; ``` -------------------------------- ### Building Liquibook on Linux Source: https://github.com/enewhuis/liquibook/blob/master/README.md Commands to build Liquibook and its examples on a Linux system using MPC. ```shell cd liquibook . ./env.sh $MPC_ROOT/mwc.pl -type make liquibook.mwc make depend make all ``` -------------------------------- ### Build Environment Setup and Project Generation Source: https://github.com/enewhuis/liquibook/blob/master/README.md Commands to navigate to the liquibook directory, optionally copy and edit the winenv.bat file, set environment variables, and generate Visual Studio solution and project files using mpc.bat. ```batch > cd liquibook > copy winenv.bat w.bat #optional if you want to keep the original # note that single character batch file names are ignored in # .getignore so the customized # file will not be checked into the git repository (a good thing.) > edit w.bat # edit is your choice of text editor # follow the instructions in the file itself. > w.bat # sets and verifies environment variables > mpc.bat # generate the visual studio solution and project files. ``` -------------------------------- ### Main Function: Publisher Initialization Source: https://github.com/enewhuis/liquibook/blob/master/doc/settAug2013/liquibook_sett.html The main function orchestrates the publisher's setup, including establishing feed connections, creating the publisher and exchange, and populating the exchange with securities. ```cpp int main(int argc, const char* argv[]) { // Feed connection examples::DepthFeedConnection connection(argc, argv); // Open connection in background thread connection.accept(); boost::function acceptor( boost::bind(&examples::DepthFeedConnection::run, &connection)); boost::thread acceptor_thread(acceptor); // Create feed publisher examples::DepthFeedPublisher feed; feed.set_connection(&connection); // Create exchange examples::Exchange exchange(&feed, &feed); // Create securities SecurityVector securities; create_securities(securities); // Populate exchange with securities populate_exchange(exchange, securities); // Generate random orders generate_orders(exchange, securities); return 0; } ``` -------------------------------- ### Boost Library Source: https://github.com/enewhuis/liquibook/blob/master/README.md Information about the Boost library, its role in Liquibook tests and examples, and a link to its website. ```APIDOC Boost Library: Description: A collection of C++ libraries used in Liquibook tests and some examples. Website: http://www.boost.org/ ``` -------------------------------- ### DepthFeedConnection: Message Handler Setup Source: https://github.com/enewhuis/liquibook/blob/master/doc/settAug2013/liquibook_sett.html Sets the message handler callback for the connection. ```cpp void DepthFeedConnection::set_message_handler(MessageHandler handler) { msg_handler_ = handler; } ``` -------------------------------- ### Publisher Application Functionality Source: https://github.com/enewhuis/liquibook/blob/master/doc/settAug2013/liquibook_sett.html The publisher application within the example project implements the exchange logic. It generates orders, manages them in order books, handles trade and depth events via listeners, encodes data using QuickFAST, and transmits it using Boost ASIO. ```en Publisher Application: - Implements exchange logic. - Generates orders and adds them to order books. - Handles trade and depth events through listeners. - Encodes data using QuickFAST. - Sends data using Boost ASIO. ``` -------------------------------- ### DepthFeedConnection: Reset Handler Setup Source: https://github.com/enewhuis/liquibook/blob/master/doc/settAug2013/liquibook_sett.html Sets the reset handler callback for the connection. ```cpp void DepthFeedConnection::set_reset_handler(ResetHandler handler) { reset_handler_ = handler; } ``` -------------------------------- ### DepthFeedConnection Buffer Management (C++) Source: https://github.com/enewhuis/liquibook/blob/master/doc/settAug2013/liquibook_sett.html Manages a pool of buffers for efficient message sending and receiving. `reserve_recv_buffer` is used by the subscriber to get a buffer for receiving messages, and `reserve_send_buffer` is used by the publisher to get a buffer for serializing messages. ```cpp BufferPtr reserve_recv_buffer(); WorkingBufferPtr reserve_send_buffer(); ``` -------------------------------- ### DepthFeedSubscriber Constructor and Initialization Source: https://github.com/enewhuis/liquibook/blob/master/doc/settAug2013/liquibook_sett.html Implements the constructor for DepthFeedSubscriber, initializing the QuickFAST decoder with provided templates and setting the initial expected sequence number to 1. ```cpp namespace liquibook { namespace examples { const uint64_t DepthFeedSubscriber::MSG_TYPE_DEPTH(11); const uint64_t DepthFeedSubscriber::MSG_TYPE_TRADE(22); using QuickFAST::ValueType; DepthFeedSubscriber::DepthFeedSubscriber( const QuickFAST::Codecs::TemplateRegistryPtr& templates) : decoder_(templates), expected_seq_(1) { } } } ``` -------------------------------- ### DepthFeedSession Constructor Source: https://github.com/enewhuis/liquibook/blob/master/doc/settAug2013/liquibook_sett.html The constructor for the DepthFeedSession class, initializing connection status, sequence number, socket, and the QuickFAST encoder. ```cpp DepthFeedSession::DepthFeedSession( boost::asio::io_service& ios, DepthFeedConnection* connection, QuickFAST::Codecs::TemplateRegistryPtr& templates) : connected_(false), seq_num_(0), ios_(ios), socket_(ios), connection_(connection), encoder_(templates) { } ``` -------------------------------- ### SyntaxHighlighter Initialization Source: https://github.com/enewhuis/liquibook/blob/master/doc/settAug2013/liquibook_sett.html This JavaScript code initializes the SyntaxHighlighter library, which is used for code highlighting on the page. ```javascript SyntaxHighlighter.all() ``` -------------------------------- ### DepthFeedSession send_incr_update Method Source: https://github.com/enewhuis/liquibook/blob/master/doc/settAug2013/liquibook_sett.html Sends an incremental update message for a given symbol if the symbol has been previously started. It encodes and sends the message similarly to send_trade. ```cpp bool DepthFeedSession::send_incr_update(const std::string& symbol, QuickFAST::Messages::FieldSet& message) { bool sent = false; // If the session has been started for this symbol if (sent_symbols_.find(symbol) != sent_symbols_.end()) { QuickFAST::Codecs::DataDestination dest; // Add or update sequence number in message set_sequence_num(message); encoder_.encodeMessage(dest, TID_DEPTH_MESSAGE, message); WorkingBufferPtr wb = connection_->reserve_send_buffer(); dest.toWorkingBuffer(*wb); SendHandler send_handler = boost::bind(&DepthFeedSession::on_send, this, wb, _1, _2); boost::asio::const_buffers_1 buffer( boost::asio::buffer(wb->begin(), wb->size())); socket_.async_send(buffer, 0, send_handler); sent = true; } return sent; } ``` -------------------------------- ### Liquibook OrderBook Integration Source: https://github.com/enewhuis/liquibook/blob/master/web/easy.html Demonstrates how to integrate Liquibook by implementing the Order Interface, instantiating OrderBook, handling callbacks, and managing callback execution. ```cpp class MyOrderBook : public OrderBook { ... } ``` ```cpp typedef boost::shared_ptr MyOrderPtr; class MyOrderBook : public OrderBook { ... } ``` ```cpp depth_.add_order(...); depth_.fill_order(...); depth_.close_order(...); depth_.replace_order(...); depth_.ignore_fill_qty(...); ``` ```cpp typedef book::Depth<10> MyDepth ``` ```cpp typedef book::Depth<10> MyBBO ``` -------------------------------- ### Subscriber Initialization and Execution (C++) Source: https://github.com/enewhuis/liquibook/blob/master/doc/settAug2013/liquibook_sett.html Demonstrates the main function for a Liquibook depth feed subscriber. It covers creating the connection, initializing the subscriber, setting up message and reset handlers, and connecting to the publisher. ```cpp int main(int argc, const char* argv[]) { // Create the connection liquibook::examples::DepthFeedConnection connection(argc, argv); // Create feed subscriber liquibook::examples::DepthFeedSubscriber feed(connection.get_templates()); // Set up handlers liquibook::examples::MessageHandler msg_handler = boost::bind(&liquibook::examples::DepthFeedSubscriber::handle_message, &feed, _1, _2); liquibook::examples::ResetHandler reset_handler = boost::bind(&liquibook::examples::DepthFeedSubscriber::handle_reset, &feed); connection.set_message_handler(msg_handler); connection.set_reset_handler(reset_handler); // Connect to server connection.connect(); connection.run(); return 0; } ``` -------------------------------- ### Project Dependencies Source: https://github.com/enewhuis/liquibook/blob/master/doc/settAug2013/liquibook_sett.html To build the Liquibook project, the following dependencies are required: Boost version 1.53 or later, Xerces version 3.1.1 or later, QuickFAST version 1.5.0 or later, and Liquibook version 1.1.0 or later. ```en Dependencies: - Boost: >= 1.53 - Xerces: >= 3.1.1 - QuickFAST: >= 1.5.0 - Liquibook: >= 1.1.0 ``` -------------------------------- ### DepthFeedConnection Constructor Initialization (C++) Source: https://github.com/enewhuis/liquibook/blob/master/doc/settAug2013/liquibook_sett.html Initializes the DepthFeedConnection object by deriving configuration variables from command-line arguments using helper methods. ```cpp DepthFeedConnection::DepthFeedConnection(int argc, const char* argv[]) : template_filename_(template_file_from_args(argc, argv)), ``` -------------------------------- ### DepthFeedSession Constructor and Members Source: https://github.com/enewhuis/liquibook/blob/master/doc/settAug2013/liquibook_sett.html Declares the DepthFeedSession class, its constructor, and essential member functions for managing connection status and accessing the TCP socket. The constructor initializes the session with an IO service, connection pointer, and QuickFAST templates. ```cpp namespace liquibook { namespace examples { typedef boost::shared_ptr WorkingBufferPtr; typedef std::deque WorkingBuffers; typedef boost::array Buffer; typedef boost::shared_ptr BufferPtr; typedef boost::function MessageHandler; typedef boost::function ResetHandler; typedef boost::function SendHandler; typedef boost::function RecvHandler; class DepthFeedConnection; // Session between a publisher and one subscriber class DepthFeedSession : boost::noncopyable { public: DepthFeedSession(boost::asio::io_service& ios, DepthFeedConnection* connection, QuickFAST::Codecs::TemplateRegistryPtr& templates); // Is this session connected? bool connected() const { return connected_; } // Mark this session as connected void set_connected() { connected_ = true; } // Get the socket for this session boost::asio::ip::tcp::socket& socket() { return socket_; } private: bool connected_; uint64_t seq_num_; boost::asio::io_service& ios_; boost::asio::ip::tcp::socket socket_; DepthFeedConnection* connection_; QuickFAST::Codecs::Encoder encoder_; }; }} ``` -------------------------------- ### DepthFeedPublisher Constructor and Setter Implementation Source: https://github.com/enewhuis/liquibook/blob/master/doc/settAug2013/liquibook_sett.html Implementation of the DepthFeedPublisher constructor and the set_connection method. ```cpp namespace liquibook { namespace examples { using namespace QuickFAST::Messages; DepthFeedPublisher::DepthFeedPublisher() : connection_(NULL) { } void DepthFeedPublisher::set_connection(DepthFeedConnection* connection) { connection_ = connection; } ``` -------------------------------- ### DepthFeedConnection Constructor and Accessors Source: https://github.com/enewhuis/liquibook/blob/master/doc/settAug2013/liquibook_sett.html Declares the DepthFeedConnection class, which handles connections for both publishers and subscribers. The constructor accepts command line arguments. It also provides access to parsed templates and methods for connecting and accepting connections. ```cpp class DepthFeedConnection : boost::noncopyable { public: DepthFeedConnection(int argc, const char* argv[]); // Get the template registry const QuickFAST::Codecs::TemplateRegistryPtr& get_templates() { return templates_; } // Connect to publisher void connect(); // Accept connection from subscriber void accept(); // Let the IO service run void run(); private: typedef boost::shared_ptr SessionPtr; // ... other members }; ``` -------------------------------- ### Parse Template File from Arguments Source: https://github.com/enewhuis/liquibook/blob/master/doc/settAug2013/liquibook_sett.html Parses command-line arguments to find a template file specified after the '-t' flag. Returns a default template path if not found. ```c++ const char* DepthFeedConnection::template_from_args(int argc, const char* argv[]) { bool next_is_name = false; for (int i = 0; i < argc; ++i) { if (next_is_name) { return argv[i]; } else if (strcmp(argv[i], "-t") == 0) { next_is_name = true; } } return "./templates/depth.xml"; } ``` -------------------------------- ### Client Application Functionality Source: https://github.com/enewhuis/liquibook/blob/master/doc/settAug2013/liquibook_sett.html The client application connects to the market data feed, decodes updates to reconstruct trade events, and reproduces market depth. It utilizes QuickFAST for decoding, Boost ASIO for network I/O, and Liquibook for depth reproduction. ```en Client Application: - Connects to the feed. - Decodes updates using QuickFAST. - Reproduces market depth using Liquibook. - Handles network I/O using Boost ASIO. ``` -------------------------------- ### MPC Build System Source: https://github.com/enewhuis/liquibook/blob/master/README.md Information about the MPC program used for creating build files, its platform support, and a link to its documentation. ```APIDOC MPC: Description: A program used to create build files for various platforms. Usage: Used in conjunction with Liquibook to generate Visual Studio solution and project files. Platform Support: Supports a wide variety of platforms. Documentation: https://github.com/objectcomputing/MPC ``` -------------------------------- ### Build Depth Level Source: https://github.com/enewhuis/liquibook/blob/master/doc/settAug2013/liquibook_sett.html A helper method to construct a single depth level entry for a QuickFAST sequence, including level number, order count, price, and aggregate quantity. ```cpp void DepthFeedPublisher::build_depth_level( QuickFAST::Messages::SequencePtr& level_seq, const book::DepthLevel* level, int level_index) { FieldSetPtr level_fields(new FieldSet(4)); level_fields->addField(id_level_num_, FieldUInt8::create(level_index)); level_fields->addField(id_order_count_, FieldUInt32::create(level->order_count())); level_fields->addField(id_price_, FieldUInt32::create(level->price())); level_fields->addField(id_size_, FieldUInt32::create(level->aggregate_qty())); level_seq->addEntry(level_fields); } ``` -------------------------------- ### DepthFeedPublisher::build_trade_message Source: https://github.com/enewhuis/liquibook/blob/master/doc/settAug2013/liquibook_sett.html Constructs a QuickFAST trade message by adding fields for timestamp, symbol, quantity, and cost. ```cpp void DepthFeedPublisher::build_trade_message( QuickFAST::Messages::FieldSet& message, const std::string& symbol, book::Quantity qty, book::Cost cost) { message.addField(id_timestamp_, FieldUInt32::create(time_stamp())); message.addField(id_symbol_, FieldString::create(symbol)); message.addField(id_qty_, FieldUInt32::create(qty)); message.addField(id_cost_, FieldUInt32::create(cost)); } ``` -------------------------------- ### DepthFeedConnection: Asynchronous Acceptance Source: https://github.com/enewhuis/liquibook/blob/master/doc/settAug2013/liquibook_sett.html Sets up an asynchronous TCP acceptor for incoming connections. It creates new sessions for each accepted connection and registers an acceptance callback. ```cpp void DepthFeedConnection::accept() { if (!acceptor_) { acceptor_.reset(new tcp::acceptor(ios_)); tcp::endpoint endpoint(tcp::v4(), port_); acceptor_->open(endpoint.protocol()); boost::system::error_code ec; acceptor_->set_option(boost::asio::socket_base::reuse_address(true), ec); acceptor_->bind(endpoint); acceptor_->listen(); } SessionPtr session(new DepthFeedSession(ios_, this, templates_)); acceptor_->async_accept( session->socket(), boost::bind(&DepthFeedConnection::on_accept, this, session, _1)); } ``` -------------------------------- ### Basic HTML Structure for Liquibook Source: https://github.com/enewhuis/liquibook/blob/master/web/get-started.html This snippet shows the basic HTML structure used for the Liquibook documentation, including navigation links and content sections. ```HTML Liquibook
``` -------------------------------- ### Exchange Class Constructor Implementation Source: https://github.com/enewhuis/liquibook/blob/master/doc/settAug2013/liquibook_sett.html Implements the constructor for the Exchange class, initializing the listener pointers with the provided arguments. ```cpp namespace liquibook { namespace examples { Exchange::Exchange(ExampleOrderBook::TypedDepthListener* depth_listener, ExampleOrderBook::TypedTradeListener* trade_listener) : depth_listener_(depth_listener), trade_listener_(trade_listener) { } } } ``` -------------------------------- ### Publisher's Order Class Declaration and Implementation Source: https://github.com/enewhuis/liquibook/blob/master/doc/settAug2013/liquibook_sett.html Shows the publisher's implementation of the Liquibook Order interface. It includes the constructor, method implementations (is_buy, order_qty, price), and a static precision field for price conversion. ```c++ namespace liquibook { namespace examples { class Order : public book::Order { public: Order(bool buy, const double& price, book::Quantity qty); virtual bool is_buy() const; virtual book::Quantity order_qty() const; virtual book::Price price() const; static const uint8_t precision_; private: bool is_buy_; double price_; book::Quantity qty_; }; } } namespace liquibook { namespace examples { const uint8_t Order::precision_(100); Order::Order(bool buy, const double& price, book::Quantity qty) : is_buy_(buy), price_(price), qty_(qty) { } bool Order::is_buy() const { return is_buy_; } book::Quantity Order::order_qty() const { return qty_; } book::Price Order::price() const { return price_ * precision_; } } } ``` -------------------------------- ### DepthFeedConnection: Asynchronous Connection Source: https://github.com/enewhuis/liquibook/blob/master/doc/settAug2013/liquibook_sett.html Initiates an asynchronous TCP connection to a specified host and port using Boost.ASIO. It sets up a callback for the connection completion. ```cpp void DepthFeedConnection::connect() { std::cout << "Connecting to feed" << std::endl; tcp::endpoint endpoint(address::from_string(host_), port_); socket_.async_connect(endpoint, boost::bind(&DepthFeedConnection::on_connect, this, _1)); } ``` -------------------------------- ### ExampleOrderBook Class Declaration Source: https://github.com/enewhuis/liquibook/blob/master/doc/settAug2013/liquibook_sett.html Declaration of the `ExampleOrderBook` class, which inherits from `book::DepthOrderBook`. It is designed to provide access to the security symbol associated with the order book. ```cpp namespace liquibook { namespace examples { typedef boost::shared_ptr OrderPtr; class ExampleOrderBook : public book::DepthOrderBook { public: ExampleOrderBook(const std::string& symbol); const std::string& symbol() const; private: std::string symbol_; }; } } ``` -------------------------------- ### JavaScript for UI Element Configuration Source: https://github.com/enewhuis/liquibook/blob/master/doc/settAug2013/liquibook_sett.html Configures UI elements using JavaScript, specifically setting attributes for Google+ 'plusone' button size and addThis sharing delay. ```JavaScript document.getElementById("plusone").setAttribute("g:plusone:size", "medium"); document.getElementById("addthis").setAttribute("addthis:ui_delay", "500"); ``` -------------------------------- ### Exchange::add_order_book Method Implementation Source: https://github.com/enewhuis/liquibook/blob/master/doc/settAug2013/liquibook_sett.html Implements the add_order_book method, which creates a new ExampleOrderBook for a given symbol, sets its depth and trade listeners, and adds it to the internal map of order books. ```cpp void Exchange::add_order_book(const std::string& sym) { std::pair result; result = order_books_.insert(std::make_pair(sym, ExampleOrderBook(sym))); result.first->second.set_depth_listener(depth_listener_); result.first->second.set_trade_listener(trade_listener_); } ``` -------------------------------- ### Parse Host from Arguments Source: https://github.com/enewhuis/liquibook/blob/master/doc/settAug2013/liquibook_sett.html Parses command-line arguments to find a host name specified after the '-h' flag. Returns '127.0.0.1' as the default host if not found. ```c++ const char* DepthFeedConnection::host_from_args(int argc, const char* argv[]) { bool next_is_host = false; for (int i = 0; i < argc; ++i) { if (next_is_host) { return argv[i]; } else if (strcmp(argv[i], "-h") == 0) { next_is_host = true; } } return "127.0.0.1"; } ``` -------------------------------- ### HELP Command Source: https://github.com/enewhuis/liquibook/blob/master/README_ORDER_ENTRY.md Displays brief help information for requests. ```APIDOC HELP or ? ``` -------------------------------- ### DepthFeedConnection Private Members and Methods (C++) Source: https://github.com/enewhuis/liquibook/blob/master/doc/settAug2013/liquibook_sett.html Declares private members for configuration (template filename, host, port), event handlers, parsed templates, buffer pools, sessions, and ASIO helpers. Also includes private methods for issuing reads and parsing command-line arguments. ```cpp private: typedef std::deque Buffers; typedef std::vector Sessions; const char* template_filename_; const char* host_; int port_; MessageHandler msg_handler_; ResetHandler reset_handler_; QuickFAST::Codecs::TemplateRegistryPtr templates_; Buffers unused_recv_buffers_; WorkingBuffers unused_send_buffers_; Sessions sessions_; boost::shared_ptr acceptor_; boost::asio::io_service ios_; boost::asio::ip::tcp::socket socket_; boost::shared_ptr work_ptr_; void issue_read(); static const char* template_file_from_args(int argc, const char* argv[]); static const char* host_from_args(int argc, const char* argv[]); static int port_from_args(int argc, const char* argv[]); ``` -------------------------------- ### Liquibook HTML Structure Source: https://github.com/enewhuis/liquibook/blob/master/web/easy.html Basic HTML structure for the Liquibook documentation site, including navigation links. ```html body { padding-top: 60px; /* 60px to make the container go all the way to the bottom of the topbar */ } [Liquibook](index.html) * [Home](index.html) * [Fast](fast.html) * [Flexible](flexible.html) * [Easy](easy.html) * [Get Started](get-started.html) ``` -------------------------------- ### Log Depth Information (C++) Source: https://github.com/enewhuis/liquibook/blob/master/doc/settAug2013/liquibook_sett.html Logs the bid and ask depth information for a given security. It formats and prints bid and ask levels side-by-side. ```cpp void DepthFeedSubscriber::log_depth(book::Depth<5>& depth) { book::DepthLevel* bid = depth.bids(); book::DepthLevel* ask = depth.asks(); printf("----------BID---------- ----------ASK----------\n"); while (bid || ask) { if (bid && bid->order_count()) { printf("%8.2f %9d [%2d]", (double)bid->price() / Order::precision_, bid->aggregate_qty(), bid->order_count()); if (bid == depth.last_bid_level()) { bid = NULL; } else { ++bid; } } else { // Blank lines printf(" "); bid = NULL; } if (ask && ask->order_count()) { printf(" %8.2f %9d [%2d]\n", (double)ask->price() / Order::precision_, ask->aggregate_qty(), ask->order_count()); if (ask == depth.last_ask_level()) { ask = NULL; } else { ++ask; } } else { // Newline printf("\n"); ask = NULL; } } } ``` -------------------------------- ### Build Depth Message Logic Source: https://github.com/enewhuis/liquibook/blob/master/doc/settAug2013/liquibook_sett.html Explains the process of building a depth message, including adding timestamp and symbol fields, creating bid and ask sequences, and managing change IDs for incremental updates. ```cpp void DepthFeedPublisher::build_depth_message( QuickFAST::Messages::MessagePtr& message, const book::Depth* depth, const book::DepthLevel* bid, int bid_count, const book::DepthLevel* ask, int ask_count, bool full_message) { message->addInt32(id_timestamp_, time_stamp()); message->addString(id_symbol_, depth->symbol()); QuickFAST::Messages::SequencePtr asks_seq; if (ask_count > 0) { asks_seq = QuickFAST::Messages::SequencePtr(new QuickFAST::Messages::Sequence(id_depth_level_)); for (int i = 0; i < ask_count; ++i) { build_depth_level(asks_seq, &ask[i], i); } } message->addField(id_asks_, FieldSequence::create(asks_seq)); QuickFAST::Messages::SequencePtr bids_seq; if (bid_count > 0) { bids_seq = QuickFAST::Messages::SequencePtr(new QuickFAST::Messages::Sequence(id_depth_level_)); for (int i = 0; i < bid_count; ++i) { build_depth_level(bids_seq, &bid[i], i); } } message->addField(id_bids_, FieldSequence::create(bids_seq)); std::cout << "Encoding " << (full_message ? "full" : "incr") << " depth message for symbol " << depth->symbol() << " with " << bid_count << " bids, " << ask_count << " asks" << std::endl; } ``` -------------------------------- ### DepthFeedConnection::on_accept in C++ Source: https://github.com/enewhuis/liquibook/blob/master/doc/settAug2013/liquibook_sett.html Handles the acceptance of a new client connection. If successful, it adds the session to the list and marks it as connected. On failure, it resets the session pointer, waits, and then restarts the accept cycle. ```C++ void DepthFeedConnection::on_accept(SessionPtr session, const boost::system::error_code& error) { if (!error) { std::cout << "accepted client connection" << std::endl; sessions_.push_back(session); session->set_connected(); } else { std::cout << "on_accept, error=" << error << std::endl; session.reset(); sleep(2); } // accept again accept(); } ``` -------------------------------- ### Handle Depth Message (C++) Source: https://github.com/enewhuis/liquibook/blob/master/doc/settAug2013/liquibook_sett.html Handles a depth message by extracting bid and ask levels from a QuickFAST message and updating the depth map for a given symbol. ```cpp bool DepthFeedSubscriber::handle_depth_message( const std::string& symbol, uint64_t& seq_num, uint64_t& timestamp, QuickFAST::Messages::Message& msg) { size_t bids_length, asks_length; std::cout << timestamp << " Got depth msg " << seq_num << " for symbol " << symbol << std::endl; // Create or find depth std::pair results = depth_map_.insert( std::make_pair(symbol, book::Depth<5>())); book::Depth<5>& depth = results.first->second; if (msg.getSequenceLength(id_bids_, bids_length)) { for (size_t i = 0; i < bids_length; ++i) { const QuickFAST::Messages::MessageAccessor* accessor; if (msg.getSequenceEntry(id_bids_, i, accessor)) { uint64_t level_num, price, order_count, aggregate_qty; if (!accessor->getUnsignedInteger(id_level_num_, ValueType::UINT8, level_num)) { std::cout << "Could not get Bid level from depth msg" << std::endl; return false; } if (!accessor->getUnsignedInteger(id_price_, ValueType::UINT32, price)) { std::cout << "Could not get Bid price from depth msg" << std::endl; return false; } if (!accessor->getUnsignedInteger(id_order_count_, ValueType::UINT32, order_count)) { std::cout << "Could not get Bid count from depth msg" << std::endl; return false; } if (!accessor->getUnsignedInteger(id_size_, ValueType::UINT32, aggregate_qty)) { std::cout << "Could not get Bid agg qty from depth msg" << std::endl; return false; } book::DepthLevel& level = depth.bids()[level_num]; level.set(price, aggregate_qty, order_count); } else { std::cout << "Failed to get bid " << i << std::endl; return false; } msg.endSequenceEntry(id_bids_, i, accessor); } } if (msg.getSequenceLength(id_asks_, asks_length)) { for (size_t i = 0; i < asks_length; ++i) { const QuickFAST::Messages::MessageAccessor* accessor; if (msg.getSequenceEntry(id_asks_, i, accessor)) { uint64_t level_num, price, order_count, aggregate_qty; ``` -------------------------------- ### Liquibook Core Features Source: https://github.com/enewhuis/liquibook/blob/master/web/fast.html Highlights the key design principles and benefits of Liquibook, emphasizing its speed and efficiency. ```cpp // Liquibook was designed to meet the needs of the most demanding customers. // Therefore it: // * Is written in C++ // * Has no floating point comparisons // * Performs minimal copying of data from your order objects ``` -------------------------------- ### TemplateConsumer Class Implementation (C++) Source: https://github.com/enewhuis/liquibook/blob/master/doc/settAug2013/liquibook_sett.html Provides the implementation for the TemplateConsumer class, including the initialization of field identities and the parse_templates() method. The parse_templates() method reads a template file and parses it using QuickFAST's XMLTemplateParser. ```cpp namespace liquibook { namespace examples { using namespace QuickFAST::Messages; const FieldIdentity TemplateConsumer::id_seq_num_("SequenceNumber"); const FieldIdentity TemplateConsumer::id_msg_type_("MessageType"); const FieldIdentity TemplateConsumer::id_timestamp_("Timestamp"); // more like this... } } ``` ```cpp QuickFAST::Codecs::TemplateRegistryPtr TemplateConsumer::parse_templates(const std::string& template_filename) { std::ifstream template_stream(template_filename.c_str()); QuickFAST::Codecs::XMLTemplateParser parser; return parser.parse(template_stream); } } } ``` -------------------------------- ### TradeListener Interface Source: https://github.com/enewhuis/liquibook/blob/master/doc/settAug2013/liquibook_sett.html Defines the interface for listening to trade events in the order book. Implement this to build a trade feed. ```cpp namespace liquibook { namespace book { /// @brief listener of trade events. Implement to build a trade feed. template class TradeListener { public: /// @brief callback for a trade /// @param book the order book of the fill (not defined whether this is before /// or after fill) /// @param qty the quantity of this fill /// @param cost the cost of this fill (qty * price) virtual void on_trade(const OrderBook* book, Quantity qty, Cost cost) = 0; }; } } ``` -------------------------------- ### DepthFeedConnection::template_file_from_args in C++ Source: https://github.com/enewhuis/liquibook/blob/master/doc/settAug2013/liquibook_sett.html Parses command-line arguments to find the template file name. It iterates through the arguments, looking for a flag that indicates the next argument is the template file path. ```C++ const char* DepthFeedConnection::template_file_from_args(int argc, const char* argv[]) { bool next_is_name = false; for (int i = 0; i < argc; ++i) { if (next_is_name) { return argv[i]; } if (strcmp(argv[i], "-t") == 0 || strcmp(argv[i], "--template") == 0) { next_is_name = true; } } return nullptr; } ``` -------------------------------- ### Helper Function: create_securities Source: https://github.com/enewhuis/liquibook/blob/master/doc/settAug2013/liquibook_sett.html Populates a SecurityVector with initial security information, such as AAPL, ADBE, and ADI, with their respective reference prices. ```cpp void create_securities(SecurityVector& securities) { securities.push_back(SecurityInfo("AAPL", 436.36)); securities.push_back(SecurityInfo("ADBE", 45.06)); securities.push_back(SecurityInfo("ADI", 43.93)); // Repeated for 100 securities... } ``` -------------------------------- ### Liquibook Navigation Links Source: https://github.com/enewhuis/liquibook/blob/master/web/fast.html HTML structure for the main navigation links in the Liquibook project. ```html ``` -------------------------------- ### DepthFeedSession Static Member Initialization Source: https://github.com/enewhuis/liquibook/blob/master/doc/settAug2013/liquibook_sett.html Implementation for initializing the static template IDs for trade and depth messages within the DepthFeedSession class. ```cpp QuickFAST::template_id_t DepthFeedSession::TID_TRADE_MESSAGE(1); QuickFAST::template_id_t DepthFeedSession::TID_DEPTH_MESSAGE(2); ``` -------------------------------- ### Liquibook Performance Benchmarks Source: https://github.com/enewhuis/liquibook/blob/master/README.md Liquibook is implemented in C++ utilizing modern, high-performance techniques. Benchmark tests demonstrate sustained insertion rates ranging from 2.0 million to 2.5 million per second. These figures are order-of-magnitude estimates and may vary based on hardware and operating system configurations. ```APIDOC Performance: - Implementation: C++ with modern, high-performance techniques. - Benchmark Results: - Sustained insert rates: 2.0 million to 2.5 million inserts per second. - Note: Performance may vary depending on hardware and operating system. ``` -------------------------------- ### Basic HTML Structure for Liquibook Source: https://github.com/enewhuis/liquibook/blob/master/web/sub-template.html This snippet shows the basic HTML structure used for the Liquibook documentation, including navigation links and content sections. ```HTML Liquibook
``` -------------------------------- ### QuickFAST Trade Message Template Source: https://github.com/enewhuis/liquibook/blob/master/doc/settAug2013/liquibook_sett.html Defines the structure for a trade message using QuickFAST XML templates. Includes fields like MessageType, SequenceNumber, Timestamp, Symbol, Quantity, and Cost. ```XML ``` -------------------------------- ### QuickFAST Depth Message Template Source: https://github.com/enewhuis/liquibook/blob/master/doc/settAug2013/liquibook_sett.html Defines the structure for a depth update message using QuickFAST XML templates. Includes common fields and sequences for Bids and Asks, detailing level information, order count, price, and aggregate quantity. ```XML ``` -------------------------------- ### DepthListener Interface Source: https://github.com/enewhuis/liquibook/blob/master/doc/settAug2013/liquibook_sett.html Defines the interface for listening to depth events in the order book. Implement this to build an aggregate depth feed. ```cpp namespace liquibook { namespace book { /// @brief listener of depth events. Implement to build an aggregate depth /// feed. template class DepthListener { public: /// @brief callback for change in tracked aggregated depth virtual void on_depth_change( const OrderBook* book, const typename OrderBook::DepthTracker* depth) = 0; }; } } ``` -------------------------------- ### Helper Function: populate_exchange Source: https://github.com/enewhuis/liquibook/blob/master/doc/settAug2013/liquibook_sett.html Adds order books for each security in the provided SecurityVector to the exchange. This prepares the exchange to receive orders for these securities. ```cpp void populate_exchange(examples::Exchange& exchange, const SecurityVector& securities) { SecurityVector::const_iterator sec; for (sec = securities.begin(); sec != securities.end(); ++sec) { exchange.add_order_book(sec->symbol); } } ``` -------------------------------- ### Liquibook Order Entry Commands Source: https://github.com/enewhuis/liquibook/blob/master/README_ORDER_ENTRY.md This section outlines the core commands used in the Liquibook manual order entry program for managing buy and sell orders, cancellations, modifications, and displaying order information. ```APIDOC BUY or B: Enter a new order to buy a security. Parameters: Quantity, Symbol, Limit Price or MKT, Order Type (AON, IOC, STOP), Termination (';' or END). Example: BUY 100 GOOG 850 AON; SELL or S: Enter a new order to sell a security. Parameters: Quantity, Symbol, Limit Price or MKT, Order Type (AON, IOC, STOP), Termination (';' or END). Example: SELL 50 AAPL 150.50 IOC; CANCEL or C: Request that an existing order be canceled. Parameters: Order ID. Example: C 12345; MODIFY or M: Request that an existing order be modified. Parameters: Order ID, New Quantity, New Price, New Order Type. Example: M 12345 110 860 AON; DISPLAY or D: Display information about existing orders. Parameters: Optional filter criteria (e.g., Symbol, Order ID). Example: D GOOG; FILE or F: Open or close a script file for batch processing. Parameters: Script file name or '-' to switch to console input. Example: F my_orders.txt Example: F - ?: Display help for requests. Example: ? QUIT: Exit the program. Example: QUIT ``` -------------------------------- ### Liquibook Depth Listener for Market Data Source: https://github.com/enewhuis/liquibook/blob/master/doc/settAug2013/liquibook_sett.html Utilizes Liquibook's DepthListener to receive notifications about changes in the top depth levels of the market. This is essential for creating aggregated depth feeds. ```C++ class DepthListener : public liquibook::IMarketDataListener { public: DepthListener(liquibook::DepthOrderBook& orderBook) : m_orderBook(orderBook) {} void onDepthUpdate(const liquibook::DepthUpdate& p_depthUpdate) override { // Process depth updates here } private: liquibook::DepthOrderBook& m_orderBook; }; ``` -------------------------------- ### Liquibook Navigation Links Source: https://github.com/enewhuis/liquibook/blob/master/web/flexible.html This HTML snippet represents the main navigation menu for the Liquibook project, linking to different sections of the documentation. ```html ```