{"id":1416,"date":"2021-10-17T23:20:14","date_gmt":"2021-10-17T23:20:14","guid":{"rendered":"https:\/\/fpganow.com\/?page_id=1416"},"modified":"2025-12-23T13:49:19","modified_gmt":"2025-12-23T13:49:19","slug":"part-4-order-book","status":"publish","type":"page","link":"https:\/\/fpganow.com\/index.php\/part-4-order-book\/","title":{"rendered":"Part 4: Order Book"},"content":{"rendered":"\n<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_79_2 counter-hierarchy ez-toc-counter ez-toc-grey ez-toc-container-direction\">\n<p class=\"ez-toc-title\" style=\"cursor:inherit\">Table of Contents<\/p>\n<label for=\"ez-toc-cssicon-toggle-item-69d5018d9d9d6\" class=\"ez-toc-cssicon-toggle-label\"><span class=\"\"><span class=\"eztoc-hide\" style=\"display:none;\">Toggle<\/span><span class=\"ez-toc-icon-toggle-span\"><svg style=\"fill: #999;color:#999\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" class=\"list-377408\" width=\"20px\" height=\"20px\" viewBox=\"0 0 24 24\" fill=\"none\"><path d=\"M6 6H4v2h2V6zm14 0H8v2h12V6zM4 11h2v2H4v-2zm16 0H8v2h12v-2zM4 16h2v2H4v-2zm16 0H8v2h12v-2z\" fill=\"currentColor\"><\/path><\/svg><svg style=\"fill: #999;color:#999\" class=\"arrow-unsorted-368013\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"10px\" height=\"10px\" viewBox=\"0 0 24 24\" version=\"1.2\" baseProfile=\"tiny\"><path d=\"M18.2 9.3l-6.2-6.3-6.2 6.3c-.2.2-.3.4-.3.7s.1.5.3.7c.2.2.4.3.7.3h11c.3 0 .5-.1.7-.3.2-.2.3-.5.3-.7s-.1-.5-.3-.7zM5.8 14.7l6.2 6.3 6.2-6.3c.2-.2.3-.5.3-.7s-.1-.5-.3-.7c-.2-.2-.4-.3-.7-.3h-11c-.3 0-.5.1-.7.3-.2.2-.3.5-.3.7s.1.5.3.7z\"\/><\/svg><\/span><\/span><\/label><input type=\"checkbox\"  id=\"ez-toc-cssicon-toggle-item-69d5018d9d9d6\"  aria-label=\"Toggle\" \/><nav><ul class='ez-toc-list ez-toc-list-level-1 ' ><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/fpganow.com\/index.php\/part-4-order-book\/#Summary\" >Summary<\/a><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/fpganow.com\/index.php\/part-4-order-book\/#High_Level_View\" >High Level View<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/fpganow.com\/index.php\/part-4-order-book\/#Integration\" >Integration<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/fpganow.com\/index.php\/part-4-order-book\/#Interface\" >Interface<\/a><ul class='ez-toc-list-level-4' ><li class='ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-5\" href=\"https:\/\/fpganow.com\/index.php\/part-4-order-book\/#What_is_a_Command\" >What is a Command?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-6\" href=\"https:\/\/fpganow.com\/index.php\/part-4-order-book\/#What_is_a_Result\" >What is a Result?<\/a><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-7\" href=\"https:\/\/fpganow.com\/index.php\/part-4-order-book\/#Examples\" >Examples<\/a><ul class='ez-toc-list-level-4' ><li class='ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-8\" href=\"https:\/\/fpganow.com\/index.php\/part-4-order-book\/#Add_Order_Example\" >Add Order Example<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-9\" href=\"https:\/\/fpganow.com\/index.php\/part-4-order-book\/#Get_Top_of_OrderBook_Example\" >Get Top of OrderBook Example<\/a><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-10\" href=\"https:\/\/fpganow.com\/index.php\/part-4-order-book\/#Data_Types\" >Data Types<\/a><ul class='ez-toc-list-level-4' ><li class='ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-11\" href=\"https:\/\/fpganow.com\/index.php\/part-4-order-book\/#Command_Signal_Descriptions\" >Command Signal Descriptions<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-12\" href=\"https:\/\/fpganow.com\/index.php\/part-4-order-book\/#Result_Signal_Descriptions\" >Result Signal Descriptions<\/a><\/li><\/ul><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-13\" href=\"https:\/\/fpganow.com\/index.php\/part-4-order-book\/#Core_Usage\" >Core Usage<\/a><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-14\" href=\"https:\/\/fpganow.com\/index.php\/part-4-order-book\/#How_can_you_test_it\" >How can you test it?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-15\" href=\"https:\/\/fpganow.com\/index.php\/part-4-order-book\/#VHDL_Source_Code\" >VHDL Source Code?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-16\" href=\"https:\/\/fpganow.com\/index.php\/part-4-order-book\/#LabVIEW_Simulation\" >LabVIEW Simulation<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-17\" href=\"https:\/\/fpganow.com\/index.php\/part-4-order-book\/#Vivado_Simulation\" >Vivado Simulation<\/a><\/li><\/ul><\/li><\/ul><\/nav><\/div>\n<h2><span class=\"ez-toc-section\" id=\"Summary\"><\/span><strong>Summary<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h2>\n<h3><span class=\"ez-toc-section\" id=\"High_Level_View\"><\/span>High Level View<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>The Fpga Ip described in this document is of a simple OrderBook implementation that is part of the <strong>Smart Fpga Nic<\/strong>&nbsp;(<a href=\"https:\/\/fpganow.com\/index.php\/smart-fpga-nic\/\" target=\"_blank\" rel=\"noopener\">https:\/\/fpganow.com\/index.php\/smart-fpga-nic\/<\/a>).&nbsp; This Ip was written so that it can be used in other projects including LabVIEW Fpga based projects, and traditional Verilog\/VHDL projects with the use of the <strong>LabVIEW FPGA IP Export Utility<\/strong> (<a href=\"https:\/\/www.ni.com\/en-us\/shop\/software\/products\/labview-fpga-ip-export-utility.html\" target=\"_blank\" rel=\"noopener\">https:\/\/www.ni.com\/en-us\/shop\/software\/products\/labview-fpga-ip-export-utility.html<\/a>) provided by NI (formerly National Instruments).<\/p>\n<h3><span class=\"ez-toc-section\" id=\"Integration\"><\/span>Integration<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>The following diagram shows where this OrderBook Ip fits in with the Smart Fpga Nic.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"732\" height=\"369\" src=\"https:\/\/fpganow.com\/wp-content\/uploads\/2021\/05\/Part-4-OrderBook.Red_-1.png\" alt=\"\" class=\"wp-image-1426\" srcset=\"https:\/\/fpganow.com\/wp-content\/uploads\/2021\/05\/Part-4-OrderBook.Red_-1.png 732w, https:\/\/fpganow.com\/wp-content\/uploads\/2021\/05\/Part-4-OrderBook.Red_-1-300x151.png 300w\" sizes=\"auto, (max-width: 732px) 100vw, 732px\" \/><\/figure>\n\n\n\n<p> <strong><em><span class=\"has-inline-color has-luminous-vivid-orange-color\">Figure 1<\/span><\/em><\/strong> <\/p>\n\n\n\n<p>The OrderBook IP accepts a &#8216;Command&#8217; per clock cycle and produces one &#8216;Result&#8217; per clock cycle.  The OrderBook Ip uses traditional handshake signals such as &#8216;Input.Valid&#8217; and &#8216;Ready.for.Input&#8217; to avoid dropping Commands and Results.  <\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Interface\"><\/span>Interface<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>Here is a diagram outlining how the signals of the Command and Result fit in to the OrderBook Ip.<\/p>\n\n\n\n<p><img loading=\"lazy\" decoding=\"async\" width=\"500\" height=\"241\" class=\"wp-image-1491\" style=\"width: 500px;\" src=\"http:\/\/fpganow.com\/wp-content\/uploads\/2021\/09\/OrderBook.Interface.png\" alt=\"\" srcset=\"https:\/\/fpganow.com\/wp-content\/uploads\/2021\/09\/OrderBook.Interface.png 506w, https:\/\/fpganow.com\/wp-content\/uploads\/2021\/09\/OrderBook.Interface-300x145.png 300w\" sizes=\"auto, (max-width: 500px) 100vw, 500px\" \/><\/p>\n\n\n\n<p><strong><em><span class=\"has-inline-color has-luminous-vivid-orange-color\">Figure 2<\/span><\/em><\/strong><\/p>\n\n\n\n<h4 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"What_is_a_Command\"><\/span>What is a Command?<span class=\"ez-toc-section-end\"><\/span><\/h4>\n\n\n\n<p>A Command is made up of the following control and data signals\/wires:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>[Boolean] [in] OrderBook.Command.Valid<\/li>\n\n\n\n<li>[Boolean] [out] Ready.For.OrderBook.Command<\/li>\n\n\n\n<li>[Boolean] [in] Reset<\/li>\n\n\n\n<li>[in] OrderBook.Command\n<ul class=\"wp-block-list\">\n<li>Type\n<ul class=\"wp-block-list\">\n<li>Add Order<\/li>\n\n\n\n<li>Order Executed<\/li>\n\n\n\n<li>Order Reduced<\/li>\n\n\n\n<li>Modify Order<\/li>\n\n\n\n<li>Delete Order<\/li>\n\n\n\n<li>Get Top of Book<\/li>\n\n\n\n<li>Get All Orders<\/li>\n<\/ul>\n<\/li>\n\n\n\n<li>Side<\/li>\n\n\n\n<li>Order Id<\/li>\n\n\n\n<li>Quantity<\/li>\n\n\n\n<li>Symbol<\/li>\n\n\n\n<li>Price<\/li>\n\n\n\n<li>Executed Quantity<\/li>\n\n\n\n<li>Cancelled Quantity<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n\n\n\n<p><img loading=\"lazy\" decoding=\"async\" width=\"300\" height=\"570\" class=\"wp-image-1493\" style=\"width: 300px;\" src=\"http:\/\/fpganow.com\/wp-content\/uploads\/2021\/09\/OrderBook.Command.lv_.png\" alt=\"\" srcset=\"https:\/\/fpganow.com\/wp-content\/uploads\/2021\/09\/OrderBook.Command.lv_.png 249w, https:\/\/fpganow.com\/wp-content\/uploads\/2021\/09\/OrderBook.Command.lv_-158x300.png 158w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/p>\n\n\n\n<p><strong><em><span class=\"has-inline-color has-luminous-vivid-orange-color\">Figure 3<\/span><\/em><\/strong><\/p>\n\n\n\n<h4 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"What_is_a_Result\"><\/span>What is a Result?<span class=\"ez-toc-section-end\"><\/span><\/h4>\n\n\n\n<p>A Result is made up of the following signals\/wires:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>[Boolean] [out] OrderBook.Result.Valid<\/li>\n\n\n\n<li>[out] OrderBook.Result\n<ul class=\"wp-block-list\">\n<li>OrderBook.Result<\/li>\n\n\n\n<li>Order Id<\/li>\n\n\n\n<li>Side<\/li>\n\n\n\n<li>Quantity<\/li>\n\n\n\n<li>Symbol<\/li>\n\n\n\n<li>Price<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n\n\n\n<p><img loading=\"lazy\" decoding=\"async\" width=\"300\" height=\"822\" class=\"wp-image-1494\" style=\"width: 300px;\" src=\"http:\/\/fpganow.com\/wp-content\/uploads\/2021\/09\/OrderBook.Result.lv_.png\" alt=\"\" srcset=\"https:\/\/fpganow.com\/wp-content\/uploads\/2021\/09\/OrderBook.Result.lv_.png 170w, https:\/\/fpganow.com\/wp-content\/uploads\/2021\/09\/OrderBook.Result.lv_-109x300.png 109w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/p>\n\n\n\n<p><strong><em><span class=\"has-inline-color has-luminous-vivid-orange-color\">Figure 4<\/span><\/em><\/strong> <\/p>\n\n\n\n<h3><span class=\"ez-toc-section\" id=\"Examples\"><\/span>Examples<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>Whenever a normalized Market Data message comes in from the Arbitrator, the Arbitrator uses the signals\/wires described above to construct and send a new Command to the OrderBook Core.  The OrderBook processor then acts on this Command and if there is a result &#8211; such as is the case with the &#8216;Get.Top&#8217; and &#8216;Get.All&#8217; commands &#8211; it will output the results using the Result signals described above and shown in Figure 4.  If there are multiple results, it will output each value on a separate clock cycle, with each value using only one clock cycle.<\/p>\n\n\n\n<p>The Results listener is always waiting for a result by monitoring the OrderBook.Result.Valid signal.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Add_Order_Example\"><\/span>Add Order Example<span class=\"ez-toc-section-end\"><\/span><\/h4>\n\n\n\n<ol class=\"wp-block-list\">\n<li>Wait until the OrderBook is ready for a new Command by checking the &#8216;Ready.for.Command&#8217; signal<\/li>\n\n\n\n<li>Set the following signals:\n<ol class=\"wp-block-list\">\n<li>Command.Valid &lt;= true<\/li>\n\n\n\n<li>Reset &lt;= false<\/li>\n\n\n\n<li>Command\n<ol class=\"wp-block-list\">\n<li>Type &lt;= Add Order<\/li>\n\n\n\n<li>Side &lt;= Buy<\/li>\n\n\n\n<li>Quantity &lt;= 100<\/li>\n\n\n\n<li>Symbol &lt;= MSFT<\/li>\n\n\n\n<li>Price &lt;= 305.00<\/li>\n<\/ol>\n<\/li>\n<\/ol>\n<\/li>\n\n\n\n<li>Wait until &#8216;Ready.for.Command&#8217; is set to true again.<\/li>\n<\/ol>\n\n\n\n<p><img loading=\"lazy\" decoding=\"async\" width=\"500\" height=\"626\" class=\"wp-image-1496\" style=\"width: 500px;\" src=\"http:\/\/fpganow.com\/wp-content\/uploads\/2021\/09\/Add.Order_.Example.png\" alt=\"\" srcset=\"https:\/\/fpganow.com\/wp-content\/uploads\/2021\/09\/Add.Order_.Example.png 445w, https:\/\/fpganow.com\/wp-content\/uploads\/2021\/09\/Add.Order_.Example-240x300.png 240w\" sizes=\"auto, (max-width: 500px) 100vw, 500px\" \/><\/p>\n\n\n\n<p><strong><em><span class=\"has-inline-color has-luminous-vivid-orange-color\">Figure 5<\/span><\/em><\/strong> <\/p>\n\n\n\n<h4 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Get_Top_of_OrderBook_Example\"><\/span>Get Top of OrderBook Example<span class=\"ez-toc-section-end\"><\/span><\/h4>\n\n\n\n<p>Now for the results, first you have to have sent a Command that generates a result, such as the &#8216;Get Top&#8217; or &#8216;Get All Orders&#8217; Command.Type.<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>Wait until the OrderBook is ready for a new Command by checking the &#8216;Ready.for.Command&#8217; signal<\/li>\n\n\n\n<li>Set the following signals:\n<ol class=\"wp-block-list\">\n<li>Command.Valid &lt;= true<\/li>\n\n\n\n<li>Reset &lt;= false<\/li>\n\n\n\n<li>Command\n<ol class=\"wp-block-list\">\n<li>Type &lt;= Get.Top<\/li>\n\n\n\n<li>Symbol &lt;= MSFT<\/li>\n<\/ol>\n<\/li>\n<\/ol>\n<\/li>\n\n\n\n<li>Wait until Result.Valid is set to true<\/li>\n\n\n\n<li>Read the details of the order at the top of the order book, including:\n<ol class=\"wp-block-list\">\n<li>Order Id<\/li>\n\n\n\n<li>Side<\/li>\n\n\n\n<li>Quantity<\/li>\n\n\n\n<li>Symbol<\/li>\n\n\n\n<li>Price<\/li>\n<\/ol>\n<\/li>\n<\/ol>\n\n\n\n<p><img loading=\"lazy\" decoding=\"async\" width=\"500\" height=\"397\" class=\"wp-image-1497\" style=\"width: 500px;\" src=\"http:\/\/fpganow.com\/wp-content\/uploads\/2021\/09\/Get.Top_.Example.png\" alt=\"\" srcset=\"https:\/\/fpganow.com\/wp-content\/uploads\/2021\/09\/Get.Top_.Example.png 634w, https:\/\/fpganow.com\/wp-content\/uploads\/2021\/09\/Get.Top_.Example-300x238.png 300w\" sizes=\"auto, (max-width: 500px) 100vw, 500px\" \/><\/p>\n\n\n\n<p><strong><em><span class=\"has-inline-color has-luminous-vivid-orange-color\">Figure 6<\/span><\/em><\/strong> <\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Data_Types\"><\/span>Data Types<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<h4 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Command_Signal_Descriptions\"><\/span>Command Signal Descriptions<span class=\"ez-toc-section-end\"><\/span><\/h4>\n\n\n\n<ul class=\"wp-block-list\">\n<li>OrderBook.Command.Valid<\/li>\n\n\n\n<li>Ready.For.OrderBook.Command<\/li>\n\n\n\n<li>Reset\n<ul class=\"wp-block-list\">\n<li>This is your generic FPGA &#8216;Reset&#8217; command, it will clear any state inside the OrderBook, including the number of buy and sell orders.  After this command completes, you will have an empty order book that is awaiting a new command<\/li>\n<\/ul>\n<\/li>\n\n\n\n<li>OrderBook.Command\n<ul class=\"wp-block-list\">\n<li>Type\n<ul class=\"wp-block-list\">\n<li>Add\n<ul class=\"wp-block-list\">\n<li>Inserts a new order into the OrderBook by using the <a href=\"https:\/\/www.geeksforgeeks.org\/insertion-sort\/\" data-type=\"URL\" data-id=\"https:\/\/www.geeksforgeeks.org\/insertion-sort\/\" target=\"_blank\" rel=\"noreferrer noopener\">Insertion Sort<\/a> algorithm.  It starts at index 0, and iterates up to the length of the OrderBook.  If the price of the new order should go at the current index, it is inserted and each of the remaining items are shifted back by one element.  Of course, the total # of orders is also incremented.<\/li>\n<\/ul>\n<\/li>\n\n\n\n<li>Execute\n<ul class=\"wp-block-list\">\n<li>There are two types of executions &#8211; execute fully and execute partially.  It scans through the orderbook and when it encounters the order which matches the OrderId, it either removes the current order or modifies it.  Removing an order is accomplished by maintaining to separate addresses &#8211; one for read and one for write.  As iteration over the orderbook occurs, normally both are incremented, but if the order is to be removed only the read address is incremented. And finally when the final element is read, the numbers of orders is decremented by one.<\/li>\n<\/ul>\n<\/li>\n\n\n\n<li>Reduce\n<ul class=\"wp-block-list\">\n<li>The OrderBook iterates over all orders and upon reaching a matching OrderId, it writes the new values that are passed with the Reduce command and stops iterating.<\/li>\n<\/ul>\n<\/li>\n\n\n\n<li>Modify\n<ul class=\"wp-block-list\">\n<li>Same thing as Reduce, just that modify is able to modify price in addition to size.<\/li>\n<\/ul>\n<\/li>\n\n\n\n<li>Delete\n<ul class=\"wp-block-list\">\n<li>This deletes an order with the matching OrderId.  The order is removed by not incrementing the write address while iterating through the orders where the OrderId matches.<\/li>\n<\/ul>\n<\/li>\n\n\n\n<li>Get Top of Book\n<ul class=\"wp-block-list\">\n<li>Returns just one order &#8211; the best ask or the best bid depending on what the side is in the command<\/li>\n<\/ul>\n<\/li>\n\n\n\n<li>Get All Orders\n<ul class=\"wp-block-list\">\n<li>Returns all orders, in properly sorted order.<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<\/li>\n\n\n\n<li>Side\n<ul class=\"wp-block-list\">\n<li>The side comes in as the ASCII code for the letter &#8216;B&#8217; or &#8216;S&#8217;, if the data is in BATS format.<\/li>\n<\/ul>\n<\/li>\n\n\n\n<li>Order Id\n<ul class=\"wp-block-list\">\n<li>The BATS specification sends an Order ID in the format of 8 ASCII characters, which fits nicely into a 64 bit integer.<\/li>\n<\/ul>\n<\/li>\n\n\n\n<li>Quantity\n<ul class=\"wp-block-list\">\n<li>The BATS specification sends the price as an decimal number multiplied by 100 to move the decimal places out.<\/li>\n<\/ul>\n<\/li>\n\n\n\n<li>Symbol\n<ul class=\"wp-block-list\">\n<li>An unsigned 32-bit integer.<\/li>\n<\/ul>\n<\/li>\n\n\n\n<li>Price\n<ul class=\"wp-block-list\">\n<li>The BATS specification for the price are an unsigned integer with 4 implied decimal places.<\/li>\n<\/ul>\n<\/li>\n\n\n\n<li>Executed Quantity\n<ul class=\"wp-block-list\">\n<li>An unsigned 32-bit integer.<\/li>\n<\/ul>\n<\/li>\n\n\n\n<li>Cancelled Quantity\n<ul class=\"wp-block-list\">\n<li>An unsigned 32-bit integer.<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n\n\n\n<h4 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Result_Signal_Descriptions\"><\/span>Result Signal Descriptions<span class=\"ez-toc-section-end\"><\/span><\/h4>\n\n\n\n<ul class=\"wp-block-list\">\n<li>OrderBook.Result.Valid\n<ul class=\"wp-block-list\">\n<li>Specifies if the output signals are valid.  Should remain true for only one clock cycle per valid value\/result.<\/li>\n<\/ul>\n<\/li>\n\n\n\n<li>OrderBook.Result\n<ul class=\"wp-block-list\">\n<li>Result\n<ul class=\"wp-block-list\">\n<li>A flag with the value of Found or Not.Found.  Keeping things simple for now&#8230;<\/li>\n<\/ul>\n<\/li>\n\n\n\n<li>Order Id\n<ul class=\"wp-block-list\">\n<li>The OrderId of the result &#8211; if a result was found. <\/li>\n<\/ul>\n<\/li>\n\n\n\n<li>Side\n<ul class=\"wp-block-list\">\n<li>Buy = &#8216;B&#8217;, Sell = &#8216;S&#8217;<\/li>\n<\/ul>\n<\/li>\n\n\n\n<li>Quantity\n<ul class=\"wp-block-list\">\n<li>Integer<\/li>\n<\/ul>\n<\/li>\n\n\n\n<li>Symbol\n<ul class=\"wp-block-list\">\n<li>ASCII representation of ticker\/symbol, right-justified\\<\/li>\n<\/ul>\n<\/li>\n\n\n\n<li>Price\n<ul class=\"wp-block-list\">\n<li>Price that conforms to the BATS standard &#8211; i.e. an integer that has to be divided by one hundred, last 2 digits are decimal points.<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Core_Usage\"><\/span>Core Usage<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>If you are experienced with FPGAs and the Xilinx toolchain, use the following VHDL wrapper and Xilinx Design Checkpoint:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Wrapper (.vhd):\n<ul class=\"wp-block-list\">\n<li><a href=\"https:\/\/github.com\/fpganow\/arty_bats\/blob\/main\/ip\/NiFpgaIPWrapper_orderbook.vhd\" target=\"_blank\" rel=\"noreferrer noopener\">https:\/\/github.com\/fpganow\/arty_bats\/blob\/main\/ip\/NiFpgaIPWrapper_orderbook.vhd<\/a><\/li>\n<\/ul>\n<\/li>\n\n\n\n<li>Design Checkpoint (.dcp):\n<ul class=\"wp-block-list\">\n<li><a href=\"https:\/\/github.com\/fpganow\/arty_bats\/blob\/main\/ip\/NiFpgaAG_orderbook.dcp\" target=\"_blank\" rel=\"noreferrer noopener\">https:\/\/github.com\/fpganow\/arty_bats\/blob\/main\/ip\/NiFpgaAG_orderbook.dcp<\/a><\/li>\n<\/ul>\n<\/li>\n<\/ul>\n\n\n\n<p>If you are a LabVIEW FPGA developer, just open the following VI for an example where I wire up the inputs and outputs to a LabVIEW FPGA FIFO:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Full LabVIEW Example:\n<ul class=\"wp-block-list\">\n<li><a href=\"https:\/\/github.com\/fpganow\/arty_bats\/blob\/orderbook\/labview\/host\/main\/host.orderbook.tester.vi\" data-type=\"URL\" data-id=\"https:\/\/github.com\/fpganow\/arty_bats\/blob\/orderbook\/labview\/host\/main\/host.orderbook.tester.vi\">https:\/\/github.com\/fpganow\/arty_bats\/blob\/main\/labview\/host\/orderbook\/host.orderbook.tester.vi<\/a><\/li>\n<\/ul>\n<\/li>\n<\/ul>\n\n\n\n<p>You can also open any vi in the tests folder.  That&#8217;s right, Test-Driven Development not only helps the developer (me) develop faster and more accurate, it also helps you &#8211; my user &#8211; quickly understand and start using my code.  See any vi in this folder:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a href=\"https:\/\/github.com\/fpganow\/arty_bats\/tree\/main\/labview\/host\/orderbook\/tests\" target=\"_blank\" rel=\"noreferrer noopener\">https:\/\/github.com\/fpganow\/arty_bats\/tree\/main\/labview\/host\/orderbook\/tests<\/a><\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"How_can_you_test_it\"><\/span>How can you test it?<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>If you are a Verilog\/VHDL FPGA developer, create a testbench that uses the following ip like so:<\/p>\n\n\n\n<p><a href=\"https:\/\/github.com\/fpganow\/arty_bats\/blob\/main\/vivado\/src\/hdl\/test\/orderbook_tb.v\" target=\"_blank\" rel=\"noreferrer noopener\">https:\/\/github.com\/fpganow\/arty_bats\/blob\/main\/vivado\/src\/hdl\/test\/orderbook_tb.v<\/a><\/p>\n\n\n\n<p>If you are a LabVIEW FPGA developer, open the test runner referenced above and run all of the tests: (make sure you set the FPGA to Simulation mode)<\/p>\n\n\n\n<p><a href=\"https:\/\/github.com\/fpganow\/arty_bats\/blob\/main\/labview\/host\/orderbook\/test.orderbook.vi\" target=\"_blank\" rel=\"noreferrer noopener\">https:\/\/github.com\/fpganow\/arty_bats\/blob\/main\/labview\/host\/orderbook\/test.orderbook.vi<\/a><\/p>\n\n\n\n<p>Or, open an individual test such as the &#8220;Get.Top&#8221; test.  Notice it is very simple, it adds 4 orders and then queries for the best order.<\/p>\n\n\n\n<p><a href=\"https:\/\/github.com\/fpganow\/arty_bats\/tree\/main\/labview\/host\/orderbook\/tests\" target=\"_blank\" rel=\"noreferrer noopener\">https:\/\/github.com\/fpganow\/arty_bats\/tree\/main\/labview\/host\/orderbook\/tests<\/a><\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"VHDL_Source_Code\"><\/span>VHDL Source Code?<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>You will have to purchase a license to the LabVIEW FPGA IP Export Utility with the &#8220;VHDL&#8221; option selected, which retails for $2,723.00 as of today (October 11th, 2021)<\/p>\n\n\n\n<p><a href=\"https:\/\/www.ni.com\/en-us\/shop\/software\/products\/labview-fpga-ip-export-utility.html\" target=\"_blank\" rel=\"noreferrer noopener\">https:\/\/www.ni.com\/en-us\/shop\/software\/products\/labview-fpga-ip-export-utility.html<\/a><\/p>\n\n\n\n<h3><span class=\"ez-toc-section\" id=\"LabVIEW_Simulation\"><\/span>LabVIEW Simulation<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p><a href=\"http:\/\/fpganow.com\/wp-content\/uploads\/2021\/10\/Simulation.Results.LabVIEW.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-1512\" src=\"http:\/\/fpganow.com\/wp-content\/uploads\/2021\/10\/Simulation.Results.LabVIEW.png\" alt=\"\" width=\"1104\" height=\"796\" srcset=\"https:\/\/fpganow.com\/wp-content\/uploads\/2021\/10\/Simulation.Results.LabVIEW.png 1104w, https:\/\/fpganow.com\/wp-content\/uploads\/2021\/10\/Simulation.Results.LabVIEW-300x216.png 300w, https:\/\/fpganow.com\/wp-content\/uploads\/2021\/10\/Simulation.Results.LabVIEW-1024x738.png 1024w, https:\/\/fpganow.com\/wp-content\/uploads\/2021\/10\/Simulation.Results.LabVIEW-768x554.png 768w\" sizes=\"auto, (max-width: 1104px) 100vw, 1104px\" \/><\/a><\/p>\n<h3><span class=\"ez-toc-section\" id=\"Vivado_Simulation\"><\/span>Vivado Simulation<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p><a href=\"http:\/\/fpganow.com\/wp-content\/uploads\/2021\/10\/Simulation.Wire_.Up_.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-1508\" src=\"http:\/\/fpganow.com\/wp-content\/uploads\/2021\/10\/Simulation.Wire_.Up_.png\" alt=\"\" width=\"1278\" height=\"408\" srcset=\"https:\/\/fpganow.com\/wp-content\/uploads\/2021\/10\/Simulation.Wire_.Up_.png 1278w, https:\/\/fpganow.com\/wp-content\/uploads\/2021\/10\/Simulation.Wire_.Up_-300x96.png 300w, https:\/\/fpganow.com\/wp-content\/uploads\/2021\/10\/Simulation.Wire_.Up_-1024x327.png 1024w, https:\/\/fpganow.com\/wp-content\/uploads\/2021\/10\/Simulation.Wire_.Up_-768x245.png 768w\" sizes=\"auto, (max-width: 1278px) 100vw, 1278px\" \/><\/a><\/p>\n<p>\u00a0<\/p>\n<p><a href=\"http:\/\/fpganow.com\/wp-content\/uploads\/2021\/10\/Simulation.TestBench.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-1509\" src=\"http:\/\/fpganow.com\/wp-content\/uploads\/2021\/10\/Simulation.TestBench.png\" alt=\"\" width=\"764\" height=\"486\" srcset=\"https:\/\/fpganow.com\/wp-content\/uploads\/2021\/10\/Simulation.TestBench.png 764w, https:\/\/fpganow.com\/wp-content\/uploads\/2021\/10\/Simulation.TestBench-300x191.png 300w\" sizes=\"auto, (max-width: 764px) 100vw, 764px\" \/><\/a><\/p>\n<p><a href=\"http:\/\/fpganow.com\/wp-content\/uploads\/2021\/10\/Simulation.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-1510\" src=\"http:\/\/fpganow.com\/wp-content\/uploads\/2021\/10\/Simulation.png\" alt=\"\" width=\"1266\" height=\"932\" srcset=\"https:\/\/fpganow.com\/wp-content\/uploads\/2021\/10\/Simulation.png 1266w, https:\/\/fpganow.com\/wp-content\/uploads\/2021\/10\/Simulation-300x221.png 300w, https:\/\/fpganow.com\/wp-content\/uploads\/2021\/10\/Simulation-1024x754.png 1024w, https:\/\/fpganow.com\/wp-content\/uploads\/2021\/10\/Simulation-768x565.png 768w\" sizes=\"auto, (max-width: 1266px) 100vw, 1266px\" \/><\/a><\/p>\n<p><a href=\"http:\/\/fpganow.com\/wp-content\/uploads\/2021\/10\/Simulation.Results.Zoomed.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-1511\" src=\"http:\/\/fpganow.com\/wp-content\/uploads\/2021\/10\/Simulation.Results.Zoomed.png\" alt=\"\" width=\"1373\" height=\"447\" srcset=\"https:\/\/fpganow.com\/wp-content\/uploads\/2021\/10\/Simulation.Results.Zoomed.png 1373w, https:\/\/fpganow.com\/wp-content\/uploads\/2021\/10\/Simulation.Results.Zoomed-300x98.png 300w, https:\/\/fpganow.com\/wp-content\/uploads\/2021\/10\/Simulation.Results.Zoomed-1024x333.png 1024w, https:\/\/fpganow.com\/wp-content\/uploads\/2021\/10\/Simulation.Results.Zoomed-768x250.png 768w\" sizes=\"auto, (max-width: 1373px) 100vw, 1373px\" \/><\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Summary High Level View The Fpga Ip described in this document is of a simple OrderBook implementation that is part of the Smart Fpga Nic&nbsp;(https:\/\/fpganow.com\/index.php\/smart-fpga-nic\/).&nbsp; This Ip was written so that it can be used in other projects including LabVIEW Fpga based projects, and traditional Verilog\/VHDL projects with the use of the LabVIEW FPGA IP &#8230; <a title=\"Part 4: Order Book\" class=\"read-more\" href=\"https:\/\/fpganow.com\/index.php\/part-4-order-book\/\" aria-label=\"Read more about Part 4: Order Book\">Read more<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"_coblocks_attr":"","_coblocks_dimensions":"","_coblocks_responsive_height":"","_coblocks_accordion_ie_support":"","footnotes":""},"class_list":["post-1416","page","type-page","status-publish"],"_links":{"self":[{"href":"https:\/\/fpganow.com\/index.php\/wp-json\/wp\/v2\/pages\/1416","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fpganow.com\/index.php\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/fpganow.com\/index.php\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/fpganow.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fpganow.com\/index.php\/wp-json\/wp\/v2\/comments?post=1416"}],"version-history":[{"count":79,"href":"https:\/\/fpganow.com\/index.php\/wp-json\/wp\/v2\/pages\/1416\/revisions"}],"predecessor-version":[{"id":19933,"href":"https:\/\/fpganow.com\/index.php\/wp-json\/wp\/v2\/pages\/1416\/revisions\/19933"}],"wp:attachment":[{"href":"https:\/\/fpganow.com\/index.php\/wp-json\/wp\/v2\/media?parent=1416"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}