id: fb836035ae5a4a8b8cf908326a9c1bdf
parent_id: 
item_type: 1
item_id: 090cba28966f437bb7b7c4b788133677
item_updated_time: 1764345620981
title_diff: "[{\"diffs\":[[1,\"从零开始用Rust构建股票市场引擎（续）\"]],\"start1\":0,\"start2\":0,\"length1\":0,\"length2\":20}]"
body_diff: "[{\"diffs\":[[1,\"<html>\\\r\\\n<head>\\\r\\\n  <title>从零开始用Rust构建股票市场引擎（续）</title>\\\r\\\n  <basefont face=\\\"微软雅黑\\\" size=\\\"2\\\" />\\\r\\\n  <meta http-equiv=\\\"Content-Type\\\" content=\\\"text/html;charset=utf-8\\\" />\\\r\\\n  <meta name=\\\"exporter-version\\\" content=\\\"YXBJ Windows/608924 (zh-CN, DDL); Windows/10.0.0 (Win64); EDAMVersion=V2;\\\"/>\\\r\\\n  <meta name=\\\"content-class\\\" content=\\\"yinxiang.peso.superNote\\\"/>\\\r\\\n  <meta name=\\\"application-data:yinxiang.noteLayout\\\" content=\\\"{\\\"lineSpace\\\":\\\"recommend\\\",\\\"paragraphSpace\\\":\\\"recommend\\\"}\\\"/>\\\r\\\n  <style>\\\r\\\n\\tbody, td {\\\r\\\n\\t  font-family: 微软雅黑;\\\r\\\n\\t  font-size: 12pt;\\\r\\\n\\t}\\\r\\\n  </style>\\\r\\\n</head>\\\r\\\n<body>\\\r\\\n<a name=\\\"37352\\\"></a>\\\r\\\n<h1>从零开始用Rust构建股票市场引擎（续）</h1>\\\r\\\n\\\r\\\n<div><span style=\\\"margin:0px;\\\"><div style=\\\"padding:8px 0px;margin:8px auto;max-width:700px;\\\"> <div><span></span></div>\\\n<p></p>\\\n<div style=\\\"--en-blockquote:true;box-sizing: border-box; padding-left: 19px; padding-top: 6px; padding-bottom: 6px; border-left: 3px solid #b4c0cc; background-position: initial initial; background-repeat: initial initial; margin-top: 6px\\\"><div>原文链接: <a href=\\\"http://mp.weixin.qq.com/s?__biz=MzUyOTAzNDg2NA==&amp;mid=2247484587&amp;idx=1&amp;sn=25e43e0dc7082f24283f2f46edf83262&amp;chksm=fb2148ee398c7fec4efe97c7d667746bb60f5a2550562b85e55f09fd25050448136a9056312c&amp;mpshare=1&amp;scene=1&amp;srcid=0120q109vhoRgnRxH8Bmzn5E&amp;sharer_shareinfo=91ace8d6f9232d58b0e955994042a5b8&amp;sharer_shareinfo_first=91ace8d6f9232d58b0e955994042a5b8#rd\\\"><span>http://mp.weixin.qq.com/s?__biz=MzUyOTAzNDg2NA==&amp;mid=2247484...</span></a></div></div>\\\n<p></p>\\\n<div><span></span></div>\\\n<div style=\\\"-webkit-tap-highlight-color:transparent;\\\"><div style=\\\"-webkit-tap-highlight-color:transparent;\\\"><div style=\\\"-webkit-tap-highlight-color:transparent;\\\"><h1 style=\\\"-webkit-tap-highlight-color:transparent;margin:0\\\"> 从零开始用Rust构建股票市场引擎（续） </h1><div style=\\\"-webkit-tap-highlight-color:transparent;\\\"><span style=\\\"-webkit-tap-highlight-color:transparent;position:relative\\\">原创</span><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent;position:relative\\\">fintechhaibin</span></span><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><a style=\\\"-webkit-tap-highlight-color:transparent;position:relative\\\"> FinTechHi </a></span><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><em style=\\\"-webkit-tap-highlight-color:transparent\\\"></em></span></div><div style=\\\"-webkit-tap-highlight-color:transparent;\\\"><p style=\\\"-webkit-tap-highlight-color:transparent;margin:0;text-align:justify;line-height:1.6;margin-top:15.05pt;margin-bottom:-7.35pt;margin-left:0;margin-right:0\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent;color:rgba(0,0,0,0.9);font-size:17px;font-family:&quot;mp-quote&quot;,-apple-system-font,BlinkMacSystemFont,&quot;Helvetica Neue&quot;,&quot;PingFang SC&quot;,&quot;Hiragino Sans GB&quot;,&quot;Microsoft YaHei UI&quot;,&quot;Microsoft YaHei&quot;,Arial,sans-serif;line-height:1.6;letter-spacing:0.034em;font-style:normal;font-weight:normal\\\"><span style=\\\"-webkit-tap-highlight-color:transparent;font-size:20px;font-weight:bold\\\">1.core_engine</span></span></span></p><div style=\\\"-webkit-tap-highlight-color:transparent;\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><br style=\\\"-webkit-tap-highlight-color:transparent\\\"/></span></div><div style=\\\"-webkit-tap-highlight-color:transparent;\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent;font-size:14px\\\">从上篇图中：引擎包括了所有上市公司股票-&gt;每个股票有自己的订单薄-&gt;订单薄中包括了具体订单。</span></span></div><div style=\\\"-webkit-tap-highlight-color:transparent;\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent;font-size:14px\\\">上市公司一些基本属性代码定义参考如下：</span></span></div><div style=\\\"-webkit-tap-highlight-color:transparent;\\\"><pre style=\\\"-webkit-tap-highlight-color:transparent\\\"><div style=\\\"--en-codeblock:true;--en-meta:{&quot;title&quot;:&quot;&quot;,&quot;lang&quot;:&quot;Plain Text&quot;,&quot;theme&quot;:&quot;default&quot;,&quot;showLine&quot;:true,&quot;lineWrap&quot;:true};box-sizing: border-box; padding: 8px; font-family: Monaco, Menlo, Consolas, &quot;Courier New&quot;, monospace; font-size: 12px; color: rgb(51, 51, 51); border-top-left-radius: 4px; border-top-right-radius: 4px; border-bottom-right-radius: 4px; border-bottom-left-radius: 4px; background-color: rgb(251, 250, 248); border: 1px solid rgba(0, 0, 0, 0.14902); background-position: initial initial; background-repeat: initial initial; margin-top: 6px;\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">                                                               </span></span><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">pub </span><span style=\\\"-webkit-tap-highlight-color:transparent\\\">enum</span><span style=\\\"-webkit-tap-highlight-color:transparent\\\"> Market {</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">    IndianMarket(IndianExchange),</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">    USMarket(USExchange),</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">    CryptoMarket(CryptoExchange),</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">}</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">pub </span><span style=\\\"-webkit-tap-highlight-color:transparent\\\">enum</span><span style=\\\"-webkit-tap-highlight-color:transparent\\\"> IndianExchange {</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">    </span><span style=\\\"-webkit-tap-highlight-color:transparent\\\">NSE</span><span style=\\\"-webkit-tap-highlight-color:transparent\\\">,</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">    BSE,</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">}</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">pub </span><span style=\\\"-webkit-tap-highlight-color:transparent\\\">enum</span><span style=\\\"-webkit-tap-highlight-color:transparent\\\"> USExchange {</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">    NASDAQ,</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">    NYSE,</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">}</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">pub </span><span style=\\\"-webkit-tap-highlight-color:transparent\\\">enum</span><span style=\\\"-webkit-tap-highlight-color:transparent\\\"> CryptoExchange {</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">    WazirX,</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">    CoinDCX,</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">    Binance,</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">    Coinbase,</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">}</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">pub </span><span style=\\\"-webkit-tap-highlight-color:transparent\\\">enum</span><span style=\\\"-webkit-tap-highlight-color:transparent\\\"> Sector {</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">    Technology,</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">    Finance,</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">    Banking,</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">    Healthcare,</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">    Energy,</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">    ConsumerDiscretionary,</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">    ConsumerStaples,</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">    Industrials,</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">    Materials,</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">    RealEstate,</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">    CommunicationServices,</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">    Utilities</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">}</span></span></div></div></pre></div><div style=\\\"-webkit-tap-highlight-color:transparent;\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent;font-size:14px\\\">公司的结构及撮合引擎定义参考代码：</span></span></div><div style=\\\"-webkit-tap-highlight-color:transparent;\\\"><pre style=\\\"-webkit-tap-highlight-color:transparent\\\"><div style=\\\"--en-codeblock:true;--en-meta:{&quot;title&quot;:&quot;&quot;,&quot;lang&quot;:&quot;Plain Text&quot;,&quot;theme&quot;:&quot;default&quot;,&quot;showLine&quot;:true,&quot;lineWrap&quot;:true};box-sizing: border-box; padding: 8px; font-family: Monaco, Menlo, Consolas, &quot;Courier New&quot;, monospace; font-size: 12px; color: rgb(51, 51, 51); border-top-left-radius: 4px; border-top-right-radius: 4px; border-bottom-right-radius: 4px; border-bottom-left-radius: 4px; background-color: rgb(251, 250, 248); border: 1px solid rgba(0, 0, 0, 0.14902); background-position: initial initial; background-repeat: initial initial; margin-top: 6px;\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">                </span></span><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">use </span><span style=\\\"-webkit-tap-highlight-color:transparent\\\">std</span><span style=\\\"-webkit-tap-highlight-color:transparent\\\">::</span><span style=\\\"-webkit-tap-highlight-color:transparent\\\">collections</span><span style=\\\"-webkit-tap-highlight-color:transparent\\\">::</span><span style=\\\"-webkit-tap-highlight-color:transparent\\\">HashMap</span><span style=\\\"-webkit-tap-highlight-color:transparent\\\">;</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">use </span><span style=\\\"-webkit-tap-highlight-color:transparent\\\">super</span><span style=\\\"-webkit-tap-highlight-color:transparent\\\">::</span><span style=\\\"-webkit-tap-highlight-color:transparent\\\">orderbook</span><span style=\\\"-webkit-tap-highlight-color:transparent\\\">::</span><span style=\\\"-webkit-tap-highlight-color:transparent\\\">OrderBook</span><span style=\\\"-webkit-tap-highlight-color:transparent\\\">;</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">pub struct </span><span style=\\\"-webkit-tap-highlight-color:transparent\\\">Company</span><span style=\\\"-webkit-tap-highlight-color:transparent\\\"> {</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">    name : </span><span style=\\\"-webkit-tap-highlight-color:transparent\\\">String</span><span style=\\\"-webkit-tap-highlight-color:transparent\\\">,</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">    </span><span style=\\\"-webkit-tap-highlight-color:transparent\\\">symbol</span><span style=\\\"-webkit-tap-highlight-color:transparent\\\"> : </span><span style=\\\"-webkit-tap-highlight-color:transparent\\\">String</span><span style=\\\"-webkit-tap-highlight-color:transparent\\\">,</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">    sector : </span><span style=\\\"-webkit-tap-highlight-color:transparent\\\">Sector</span><span style=\\\"-webkit-tap-highlight-color:transparent\\\">,</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">    market : </span><span style=\\\"-webkit-tap-highlight-color:transparent\\\">Market</span><span style=\\\"-webkit-tap-highlight-color:transparent\\\">,</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">}</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">impl </span><span style=\\\"-webkit-tap-highlight-color:transparent\\\">Company</span><span style=\\\"-webkit-tap-highlight-color:transparent\\\"> {</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">    pub fn </span><span style=\\\"-webkit-tap-highlight-color:transparent\\\">new</span><span style=\\\"-webkit-tap-highlight-color:transparent\\\"> (</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">        name : </span><span style=\\\"-webkit-tap-highlight-color:transparent\\\">String</span><span style=\\\"-webkit-tap-highlight-color:transparent\\\">, </span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">        </span><span style=\\\"-webkit-tap-highlight-color:transparent\\\">symbol</span><span style=\\\"-webkit-tap-highlight-color:transparent\\\"> : </span><span style=\\\"-webkit-tap-highlight-color:transparent\\\">String</span><span style=\\\"-webkit-tap-highlight-color:transparent\\\">, </span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">        sector : </span><span style=\\\"-webkit-tap-highlight-color:transparent\\\">Sector</span><span style=\\\"-webkit-tap-highlight-color:transparent\\\">, </span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">        </span><span style=\\\"-webkit-tap-highlight-color:transparent\\\">market</span><span style=\\\"-webkit-tap-highlight-color:transparent\\\">: </span><span style=\\\"-webkit-tap-highlight-color:transparent\\\">Market</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">    ) -&gt; </span><span style=\\\"-webkit-tap-highlight-color:transparent\\\">Company</span><span style=\\\"-webkit-tap-highlight-color:transparent\\\"> {</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">          </span><span style=\\\"-webkit-tap-highlight-color:transparent\\\">Company</span><span style=\\\"-webkit-tap-highlight-color:transparent\\\"> {</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">            name,</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">            </span><span style=\\\"-webkit-tap-highlight-color:transparent\\\">symbol</span><span style=\\\"-webkit-tap-highlight-color:transparent\\\">,</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">            sector,</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">            market</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">          }</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">        }</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\"> }</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">pub struct </span><span style=\\\"-webkit-tap-highlight-color:transparent\\\">MatchingEngine</span><span style=\\\"-webkit-tap-highlight-color:transparent\\\"> {</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">    pub orderbooks : </span><span style=\\\"-webkit-tap-highlight-color:transparent\\\">HashMap</span><span style=\\\"-webkit-tap-highlight-color:transparent\\\">&lt;</span><span style=\\\"-webkit-tap-highlight-color:transparent\\\">Company</span><span style=\\\"-webkit-tap-highlight-color:transparent\\\">, </span><span style=\\\"-webkit-tap-highlight-color:transparent\\\">OrderBook</span><span style=\\\"-webkit-tap-highlight-color:transparent\\\">&gt;</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">}</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">impl </span><span style=\\\"-webkit-tap-highlight-color:transparent\\\">MatchingEngine</span><span style=\\\"-webkit-tap-highlight-color:transparent\\\"> {</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">    pub fn </span><span style=\\\"-webkit-tap-highlight-color:transparent\\\">new</span><span style=\\\"-webkit-tap-highlight-color:transparent\\\">() -&gt; </span><span style=\\\"-webkit-tap-highlight-color:transparent\\\">MatchingEngine</span><span style=\\\"-webkit-tap-highlight-color:transparent\\\"> {</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">        </span><span style=\\\"-webkit-tap-highlight-color:transparent\\\">MatchingEngine</span><span style=\\\"-webkit-tap-highlight-color:transparent\\\"> {</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">            orderbooks : </span><span style=\\\"-webkit-tap-highlight-color:transparent\\\">HashMap</span><span style=\\\"-webkit-tap-highlight-color:transparent\\\">::</span><span style=\\\"-webkit-tap-highlight-color:transparent\\\">new</span><span style=\\\"-webkit-tap-highlight-color:transparent\\\">()</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">        }</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">    }</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">}</span></span></div></div></pre></div><div style=\\\"-webkit-tap-highlight-color:transparent;\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent;font-size:14px\\\">查看股票信息及股票对应的订单薄：</span></span></div><div style=\\\"-webkit-tap-highlight-color:transparent;\\\"><pre style=\\\"-webkit-tap-highlight-color:transparent\\\"><div style=\\\"--en-codeblock:true;--en-meta:{&quot;title&quot;:&quot;&quot;,&quot;lang&quot;:&quot;Plain Text&quot;,&quot;theme&quot;:&quot;default&quot;,&quot;showLine&quot;:true,&quot;lineWrap&quot;:true};box-sizing: border-box; padding: 8px; font-family: Monaco, Menlo, Consolas, &quot;Courier New&quot;, monospace; font-size: 12px; color: rgb(51, 51, 51); border-top-left-radius: 4px; border-top-right-radius: 4px; border-bottom-right-radius: 4px; border-bottom-left-radius: 4px; background-color: rgb(251, 250, 248); border: 1px solid rgba(0, 0, 0, 0.14902); background-position: initial initial; background-repeat: initial initial; margin-top: 6px;\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\"> </span></span><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">impl MatchingEngine {</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">    </span><span style=\\\"-webkit-tap-highlight-color:transparent\\\">pub fn list_new_company</span><span style=\\\"-webkit-tap-highlight-color:transparent\\\">(&amp;mut </span><span style=\\\"-webkit-tap-highlight-color:transparent\\\">self</span><span style=\\\"-webkit-tap-highlight-color:transparent\\\">, company : Company) {</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">        let orderbook = </span><span style=\\\"-webkit-tap-highlight-color:transparent\\\">OrderBook</span><span style=\\\"-webkit-tap-highlight-color:transparent\\\">::</span><span style=\\\"-webkit-tap-highlight-color:transparent\\\">new</span><span style=\\\"-webkit-tap-highlight-color:transparent\\\">();</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">        </span><span style=\\\"-webkit-tap-highlight-color:transparent\\\">self</span><span style=\\\"-webkit-tap-highlight-color:transparent\\\">.orderbooks.</span><span style=\\\"-webkit-tap-highlight-color:transparent\\\">insert</span><span style=\\\"-webkit-tap-highlight-color:transparent\\\">(company, orderbook);</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">    }</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">    </span><span style=\\\"-webkit-tap-highlight-color:transparent\\\">pub fn get_company_orderbook</span><span style=\\\"-webkit-tap-highlight-color:transparent\\\">(&amp;mut </span><span style=\\\"-webkit-tap-highlight-color:transparent\\\">self</span><span style=\\\"-webkit-tap-highlight-color:transparent\\\">, company : &amp;Company) -&gt; Option&lt;&amp;mut OrderBook&gt; {</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">        </span><span style=\\\"-webkit-tap-highlight-color:transparent\\\">self</span><span style=\\\"-webkit-tap-highlight-color:transparent\\\">.orderbooks.</span><span style=\\\"-webkit-tap-highlight-color:transparent\\\">get_mut</span><span style=\\\"-webkit-tap-highlight-color:transparent\\\">(company)</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">    }</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">}</span></span></div></div></pre></div><div style=\\\"-webkit-tap-highlight-color:transparent;\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent;font-size:14px\\\">股票基本信息查询及订单薄操作：</span></span></div><div style=\\\"-webkit-tap-highlight-color:transparent;\\\"><pre style=\\\"-webkit-tap-highlight-color:transparent\\\"><div style=\\\"--en-codeblock:true;--en-meta:{&quot;title&quot;:&quot;&quot;,&quot;lang&quot;:&quot;Plain Text&quot;,&quot;theme&quot;:&quot;default&quot;,&quot;showLine&quot;:true,&quot;lineWrap&quot;:true};box-sizing: border-box; padding: 8px; font-family: Monaco, Menlo, Consolas, &quot;Courier New&quot;, monospace; font-size: 12px; color: rgb(51, 51, 51); border-top-left-radius: 4px; border-top-right-radius: 4px; border-bottom-right-radius: 4px; border-bottom-left-radius: 4px; background-color: rgb(251, 250, 248); border: 1px solid rgba(0, 0, 0, 0.14902); background-position: initial initial; background-repeat: initial initial; margin-top: 6px;\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><br style=\\\"-webkit-tap-highlight-color:transparent\\\"/></span><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">use </span><span style=\\\"-webkit-tap-highlight-color:transparent\\\">self</span><span style=\\\"-webkit-tap-highlight-color:transparent\\\">::</span><span style=\\\"-webkit-tap-highlight-color:transparent\\\">core_engine</span><span style=\\\"-webkit-tap-highlight-color:transparent\\\">::</span><span style=\\\"-webkit-tap-highlight-color:transparent\\\">engine</span><span style=\\\"-webkit-tap-highlight-color:transparent\\\">::{ </span><span style=\\\"-webkit-tap-highlight-color:transparent\\\">Company</span><span style=\\\"-webkit-tap-highlight-color:transparent\\\">, </span><span style=\\\"-webkit-tap-highlight-color:transparent\\\">IndianExchange</span><span style=\\\"-webkit-tap-highlight-color:transparent\\\">, </span><span style=\\\"-webkit-tap-highlight-color:transparent\\\">Market</span><span style=\\\"-webkit-tap-highlight-color:transparent\\\">, </span><span style=\\\"-webkit-tap-highlight-color:transparent\\\">MatchingEngine</span><span style=\\\"-webkit-tap-highlight-color:transparent\\\">, </span><span style=\\\"-webkit-tap-highlight-color:transparent\\\">Sector</span><span style=\\\"-webkit-tap-highlight-color:transparent\\\"> }; </span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">#[test]   </span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">fn </span><span style=\\\"-webkit-tap-highlight-color:transparent\\\">test_company_listing</span><span style=\\\"-webkit-tap-highlight-color:transparent\\\">() {</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">        </span><span style=\\\"-webkit-tap-highlight-color:transparent\\\">let</span><span style=\\\"-webkit-tap-highlight-color:transparent\\\"> mut engine = </span><span style=\\\"-webkit-tap-highlight-color:transparent\\\">MatchingEngine</span><span style=\\\"-webkit-tap-highlight-color:transparent\\\">::</span><span style=\\\"-webkit-tap-highlight-color:transparent\\\">new</span><span style=\\\"-webkit-tap-highlight-color:transparent\\\">();</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">        </span><span style=\\\"-webkit-tap-highlight-color:transparent\\\">let</span><span style=\\\"-webkit-tap-highlight-color:transparent\\\"> company = </span><span style=\\\"-webkit-tap-highlight-color:transparent\\\">Company</span><span style=\\\"-webkit-tap-highlight-color:transparent\\\">::</span><span style=\\\"-webkit-tap-highlight-color:transparent\\\">new</span><span style=\\\"-webkit-tap-highlight-color:transparent\\\">(</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">            </span><span style=\\\"-webkit-tap-highlight-color:transparent\\\">&quot;Nactore&quot;</span><span style=\\\"-webkit-tap-highlight-color:transparent\\\">.</span><span style=\\\"-webkit-tap-highlight-color:transparent\\\">to_string</span><span style=\\\"-webkit-tap-highlight-color:transparent\\\">(),</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">            </span><span style=\\\"-webkit-tap-highlight-color:transparent\\\">&quot;NACT&quot;</span><span style=\\\"-webkit-tap-highlight-color:transparent\\\">.</span><span style=\\\"-webkit-tap-highlight-color:transparent\\\">to_string</span><span style=\\\"-webkit-tap-highlight-color:transparent\\\">(),</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">            </span><span style=\\\"-webkit-tap-highlight-color:transparent\\\">Sector</span><span style=\\\"-webkit-tap-highlight-color:transparent\\\">::</span><span style=\\\"-webkit-tap-highlight-color:transparent\\\">Technology</span><span style=\\\"-webkit-tap-highlight-color:transparent\\\">,</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">            </span><span style=\\\"-webkit-tap-highlight-color:transparent\\\">Market</span><span style=\\\"-webkit-tap-highlight-color:transparent\\\">::</span><span style=\\\"-webkit-tap-highlight-color:transparent\\\">IndianMarket</span><span style=\\\"-webkit-tap-highlight-color:transparent\\\">(</span><span style=\\\"-webkit-tap-highlight-color:transparent\\\">IndianExchange</span><span style=\\\"-webkit-tap-highlight-color:transparent\\\">::</span><span style=\\\"-webkit-tap-highlight-color:transparent\\\">BSE</span><span style=\\\"-webkit-tap-highlight-color:transparent\\\">)</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">        );</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">        engine.</span><span style=\\\"-webkit-tap-highlight-color:transparent\\\">list_new_company</span><span style=\\\"-webkit-tap-highlight-color:transparent\\\">(company.</span><span style=\\\"-webkit-tap-highlight-color:transparent\\\">clone</span><span style=\\\"-webkit-tap-highlight-color:transparent\\\">());</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">        assert_eq!(engine.</span><span style=\\\"-webkit-tap-highlight-color:transparent\\\">orderbooks</span><span style=\\\"-webkit-tap-highlight-color:transparent\\\">.</span><span style=\\\"-webkit-tap-highlight-color:transparent\\\">len</span><span style=\\\"-webkit-tap-highlight-color:transparent\\\">(), </span><span style=\\\"-webkit-tap-highlight-color:transparent\\\">1</span><span style=\\\"-webkit-tap-highlight-color:transparent\\\">);</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">        match engine.</span><span style=\\\"-webkit-tap-highlight-color:transparent\\\">get_company_orderbook</span><span style=\\\"-webkit-tap-highlight-color:transparent\\\">(</span><span style=\\\"-webkit-tap-highlight-color:transparent\\\">&amp;company</span><span style=\\\"-webkit-tap-highlight-color:transparent\\\">) {</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">            </span><span style=\\\"-webkit-tap-highlight-color:transparent\\\">Some</span><span style=\\\"-webkit-tap-highlight-color:transparent\\\">(order_book) =&gt; {</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">                </span><span style=\\\"-webkit-tap-highlight-color:transparent\\\">// Create some buy orders.</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">                let buy_order_1 = Order::new(dec!(35), dec!(690), BuyOrSell::Buy);</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">                let buy_order_2 = Order::new(dec!(20), dec!(685), BuyOrSell::Buy);</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">                let buy_order_3 = Order::new(dec!(15), dec!(690), BuyOrSell::Buy);</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">                // Create some sell orders.</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">                let sell_order_1 = Order::new(dec!(10), dec!(700), BuyOrSell::Sell);</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">                let sell_order_2 = Order::new(dec!(25), dec!(705), BuyOrSell::Sell);</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">                let sell_order_3 = Order::new(dec!(30), dec!(700), BuyOrSell::Sell);</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">                // Add the orders to the order_book</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">                order_book.add_order_to_orderbook(buy_order_1);</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">                order_book.add_order_to_orderbook(buy_order_2);</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">                order_book.add_order_to_orderbook(buy_order_3);</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">                order_book.add_order_to_orderbook(sell_order_1);</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">                order_book.add_order_to_orderbook(sell_order_2);</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">                order_book.add_order_to_orderbook(sell_order_3);</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">            }</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">            None =&gt; panic!(&quot;Company not found&quot;),</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">        };</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">        assert_eq!(engine.get_company_orderbook(&amp;company).unwrap().buy_volume().unwrap(), dec!(70));</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">        assert_eq!(engine.get_company_orderbook(&amp;company).unwrap().sell_volume().unwrap(), dec!(65));</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">    }</span></span></div></div></pre></div><p style=\\\"-webkit-tap-highlight-color:transparent;margin:0;text-align:justify;line-height:1.6;margin-top:34.25pt;margin-bottom:-7.35pt;margin-left:0;margin-right:0\\\"><span style=\\\"-webkit-tap-highlight-color:transparent;font-size:15pt;font-family:微软雅黑;font-weight:normal;font-style:normal;color:#242424;background:#FFF;letter-spacing:-0.05pt;mso-font-width:100%;vertical-align:baseline\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent;font-size:14px\\\">通过上述代码，交易引擎实现了股票基本信息查询、股票订单簿构建、买卖订单订单处理。</span></span></span></p><p style=\\\"-webkit-tap-highlight-color:transparent;margin:0;text-align:justify;line-height:1.6;margin-top:34.25pt;margin-bottom:-7.35pt;margin-left:0;margin-right:0\\\"><span style=\\\"-webkit-tap-highlight-color:transparent;font-size:15pt;font-family:微软雅黑;font-weight:normal;font-style:normal;color:#242424;background:#FFF;letter-spacing:-0.05pt;mso-font-width:100%;vertical-align:baseline\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent;font-weight:bold\\\">2.order matching mechanisms</span></span></span></p><p style=\\\"-webkit-tap-highlight-color:transparent;margin:0\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><br style=\\\"-webkit-tap-highlight-color:transparent\\\"/></span></p><p style=\\\"-webkit-tap-highlight-color:transparent;margin:0\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent;font-size:14px\\\">第一篇中作者使用 HashMap在Orderbook中存储订单。当进行匹配订单代码编写时，需要每次都对订单簿进行排序，以获取最佳的买卖价格。</span></span></p><p style=\\\"-webkit-tap-highlight-color:transparent;margin:0\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent;font-size:14px\\\">在这个实现过程中，把 HashMap 转换为 BTreeMap 更有效率，主要原因：</span></span></p><p style=\\\"-webkit-tap-highlight-color:transparent;margin:0;text-align:justify;line-height:1.6;margin-top:34.25pt;margin-bottom:-7.35pt;margin-left:0;margin-right:0\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent;color:rgba(0,0,0,0.9);font-size:17px;font-family:&quot;mp-quote&quot;,-apple-system-font,BlinkMacSystemFont,&quot;Helvetica Neue&quot;,&quot;PingFang SC&quot;,&quot;Hiragino Sans GB&quot;,&quot;Microsoft YaHei UI&quot;,&quot;Microsoft YaHei&quot;,Arial,sans-serif;line-height:1.6;letter-spacing:0.034em;font-style:normal;font-weight:normal\\\"><span style=\\\"-webkit-tap-highlight-color:transparent;font-size:12px\\\">HashMap stores key-value pairs in an unordered manner, making lookups fast but not maintaining any specific order. </span></span></span></p><p style=\\\"-webkit-tap-highlight-color:transparent;margin:0;text-align:justify;line-height:1.6;margin-top:34.25pt;margin-bottom:-7.35pt;margin-left:0;margin-right:0\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent;color:rgba(0,0,0,0.9);font-size:17px;font-family:&quot;mp-quote&quot;,-apple-system-font,BlinkMacSystemFont,&quot;Helvetica Neue&quot;,&quot;PingFang SC&quot;,&quot;Hiragino Sans GB&quot;,&quot;Microsoft YaHei UI&quot;,&quot;Microsoft YaHei&quot;,Arial,sans-serif;line-height:1.6;letter-spacing:0.034em;font-style:normal;font-weight:normal\\\"><span style=\\\"-webkit-tap-highlight-color:transparent;font-size:12px\\\">On the other hand, BTreeMap organizes key-value pairs in a sorted order based on keys, allowing efficient retrieval of elements based on their position in the sorted sequence.</span></span></span><span lang=\\\"EN-US\\\" style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\"></span></span></p><p style=\\\"-webkit-tap-highlight-color:transparent;margin:0\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><br style=\\\"-webkit-tap-highlight-color:transparent\\\"/></span></p><p style=\\\"-webkit-tap-highlight-color:transparent;margin:0\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">使用<span style=\\\"-webkit-tap-highlight-color:transparent;font-size:14px\\\">BTreeMap重新实现订单薄结构代码参考如下：</span></span></p><div style=\\\"-webkit-tap-highlight-color:transparent;\\\"><pre style=\\\"-webkit-tap-highlight-color:transparent\\\"><div style=\\\"--en-codeblock:true;--en-meta:{&quot;title&quot;:&quot;&quot;,&quot;lang&quot;:&quot;Plain Text&quot;,&quot;theme&quot;:&quot;default&quot;,&quot;showLine&quot;:true,&quot;lineWrap&quot;:true};box-sizing: border-box; padding: 8px; font-family: Monaco, Menlo, Consolas, &quot;Courier New&quot;, monospace; font-size: 12px; color: rgb(51, 51, 51); border-top-left-radius: 4px; border-top-right-radius: 4px; border-bottom-right-radius: 4px; border-bottom-left-radius: 4px; background-color: rgb(251, 250, 248); border: 1px solid rgba(0, 0, 0, 0.14902); background-position: initial initial; background-repeat: initial initial; margin-top: 6px;\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">                </span></span><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">use std::collections::BTreeMap;</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">pub </span><span style=\\\"-webkit-tap-highlight-color:transparent\\\">struct</span><span style=\\\"-webkit-tap-highlight-color:transparent\\\"> </span><span style=\\\"-webkit-tap-highlight-color:transparent\\\">OrderBook</span><span style=\\\"-webkit-tap-highlight-color:transparent\\\"> {</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">    </span><span style=\\\"-webkit-tap-highlight-color:transparent\\\">// BTreeMap : [Key : Price, Value : All the orders at that price]</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">    pub buy_orders: BTreeMap&lt;Decimal, Vec&lt;Order&gt;&gt;,</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">    pub sell_orders: BTreeMap&lt;Decimal, Vec&lt;Order&gt;&gt;,</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">}</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">impl OrderBook {</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">    pub fn new() -&gt; OrderBook {</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">        OrderBook {</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">            buy_orders: BTreeMap::new(),</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">            sell_orders: BTreeMap::new(),</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">        }</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">    }</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">}</span></span></div></div></pre></div><p style=\\\"-webkit-tap-highlight-color:transparent;margin:0\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent;font-size:14px\\\">下面是作者对市价单的解释：</span></span></p><p style=\\\"-webkit-tap-highlight-color:transparent;margin:0\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent;font-size:12px\\\">Ideally Market Order is such an order where buyer or seller says that execute my order at the price which is currently demanded in the market. And this price is called Market Price.</span></span></p><p style=\\\"-webkit-tap-highlight-color:transparent;margin:0\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent;font-size:12px\\\">The price which you always see at the screen is always the price at which the last transaction was made. Based on that price the sentiments of the market are decided and buyers try to put a price below that price and sellers put above it. This is how market works in entiriety.</span></span></p><p style=\\\"-webkit-tap-highlight-color:transparent;margin:0\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent;font-size:14px\\\">实现的市价订单代码参考如下：</span></span></p><div style=\\\"-webkit-tap-highlight-color:transparent;\\\"><pre style=\\\"-webkit-tap-highlight-color:transparent\\\"><div style=\\\"--en-codeblock:true;--en-meta:{&quot;title&quot;:&quot;&quot;,&quot;lang&quot;:&quot;Plain Text&quot;,&quot;theme&quot;:&quot;default&quot;,&quot;showLine&quot;:true,&quot;lineWrap&quot;:true};box-sizing: border-box; padding: 8px; font-family: Monaco, Menlo, Consolas, &quot;Courier New&quot;, monospace; font-size: 12px; color: rgb(51, 51, 51); border-top-left-radius: 4px; border-top-right-radius: 4px; border-bottom-right-radius: 4px; border-bottom-left-radius: 4px; background-color: rgb(251, 250, 248); border: 1px solid rgba(0, 0, 0, 0.14902); background-position: initial initial; background-repeat: initial initial; margin-top: 6px;\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">                </span></span><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">pub fn market_price</span><span style=\\\"-webkit-tap-highlight-color:transparent\\\">(&amp;</span><span style=\\\"-webkit-tap-highlight-color:transparent\\\">self</span><span style=\\\"-webkit-tap-highlight-color:transparent\\\">, </span><span style=\\\"-webkit-tap-highlight-color:transparent\\\">order_type</span><span style=\\\"-webkit-tap-highlight-color:transparent\\\">: BuyOrSell) -&gt; Option&lt;Decimal&gt; {</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">    </span><span style=\\\"-webkit-tap-highlight-color:transparent\\\">match</span><span style=\\\"-webkit-tap-highlight-color:transparent\\\"> order_type {</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">        </span><span style=\\\"-webkit-tap-highlight-color:transparent\\\">BuyOrSell</span><span style=\\\"-webkit-tap-highlight-color:transparent\\\">::</span><span style=\\\"-webkit-tap-highlight-color:transparent\\\">Buy</span><span style=\\\"-webkit-tap-highlight-color:transparent\\\"> =&gt; </span><span style=\\\"-webkit-tap-highlight-color:transparent\\\">self</span><span style=\\\"-webkit-tap-highlight-color:transparent\\\">.</span><span style=\\\"-webkit-tap-highlight-color:transparent\\\">best_sell_price</span><span style=\\\"-webkit-tap-highlight-color:transparent\\\">(),</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">        </span><span style=\\\"-webkit-tap-highlight-color:transparent\\\">BuyOrSell</span><span style=\\\"-webkit-tap-highlight-color:transparent\\\">::</span><span style=\\\"-webkit-tap-highlight-color:transparent\\\">Sell</span><span style=\\\"-webkit-tap-highlight-color:transparent\\\"> =&gt; </span><span style=\\\"-webkit-tap-highlight-color:transparent\\\">self</span><span style=\\\"-webkit-tap-highlight-color:transparent\\\">.</span><span style=\\\"-webkit-tap-highlight-color:transparent\\\">best_buy_price</span><span style=\\\"-webkit-tap-highlight-color:transparent\\\">(),</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">    }</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">}</span></span></div></div></pre></div><p style=\\\"-webkit-tap-highlight-color:transparent;margin:0\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent;font-size:14px\\\">关于订单撮合机制：</span></span></p><ul style=\\\"-webkit-tap-highlight-color:transparent;margin:0;list-style-type:disc\\\"><li style=\\\"-webkit-tap-highlight-color:transparent\\\"><p style=\\\"-webkit-tap-highlight-color:transparent;margin:0;text-align:justify;margin-top:3pt;margin-bottom:3pt;margin-left:0;margin-right:0\\\"><span style=\\\"-webkit-tap-highlight-color:transparent;font-size:15pt;font-family:微软雅黑;font-weight:normal;font-style:normal;color:#242424;background:#FFF;letter-spacing:-0.05pt;mso-font-width:100%;vertical-align:baseline\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent;font-size:14px\\\">市场订单的买方将与最佳卖价匹配，而市场订单的卖方将与最佳买价匹配。</span></span></span></p></li><li style=\\\"-webkit-tap-highlight-color:transparent\\\"><p style=\\\"-webkit-tap-highlight-color:transparent;margin:0;text-align:justify;margin-top:3pt;margin-bottom:3pt;margin-left:0;margin-right:0\\\"><span style=\\\"-webkit-tap-highlight-color:transparent;font-size:15pt;font-family:微软雅黑;font-weight:normal;font-style:normal;color:#242424;background:#FFF;letter-spacing:-0.05pt;mso-font-width:100%;vertical-align:baseline\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent;font-size:14px\\\">每次以精确价格匹配订单可能并不总是有效，因为市场总是在变化。有时，你可能会找到愿意以甚至比你预期的更好的价格买卖股票的人。</span></span></span></p></li><li style=\\\"-webkit-tap-highlight-color:transparent\\\"><p style=\\\"-webkit-tap-highlight-color:transparent;margin:0;text-align:justify;margin-top:3pt;margin-bottom:3pt;margin-left:0;margin-right:0\\\"><span style=\\\"-webkit-tap-highlight-color:transparent;font-size:15pt;font-family:微软雅黑;font-weight:normal;font-style:normal;color:#242424;background:#FFF;letter-spacing:-0.05pt;mso-font-width:100%;vertical-align:baseline\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent;font-size:14px\\\">通过查看一系列价格，增加在瞬息万变的股票市场中获得最佳交易的可能。这就是为什么几乎每个交易平台都会显示其订单簿的前 N 个价格。</span></span></span><span lang=\\\"EN-US\\\" style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\"></span></span></p><p style=\\\"-webkit-tap-highlight-color:transparent;margin:0;text-align:justify;margin-top:3pt;margin-bottom:3pt;margin-left:0;margin-right:0\\\"><span style=\\\"-webkit-tap-highlight-color:transparent;font-size:15pt;font-family:微软雅黑;font-weight:normal;font-style:normal;color:#242424;background:#FFF;letter-spacing:-0.05pt;mso-font-width:100%;vertical-align:baseline\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><br style=\\\"-webkit-tap-highlight-color:transparent\\\"/></span></span><span lang=\\\"EN-US\\\" style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\"></span></span></p></li></ul><p style=\\\"-webkit-tap-highlight-color:transparent;margin:0\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent;font-size:14px\\\">实现 </span></span><span style=\\\"-webkit-tap-highlight-color:transparent;font-size:11.25pt;font-family:微软雅黑;font-weight:normal;font-style:normal;color:#242424;background:#F2F2F2;letter-spacing:-0.05pt;mso-font-width:100%;vertical-align:baseline\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent;font-size:14px\\\">top_n_buying_prices</span></span></span><span style=\\\"-webkit-tap-highlight-color:transparent;font-size:15pt;font-family:微软雅黑;font-weight:normal;font-style:normal;color:#242424;background:#FFF;letter-spacing:-0.05pt;mso-font-width:100%;vertical-align:baseline\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent;font-size:14px\\\"> 和 </span></span></span><span style=\\\"-webkit-tap-highlight-color:transparent;font-size:11.25pt;font-family:微软雅黑;font-weight:normal;font-style:normal;color:#242424;background:#F2F2F2;letter-spacing:-0.05pt;mso-font-width:100%;vertical-align:baseline\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent;font-size:14px\\\">top_n_selling_prices</span></span></span><span style=\\\"-webkit-tap-highlight-color:transparent;font-size:15pt;font-family:微软雅黑;font-weight:normal;font-style:normal;color:#242424;background:#FFF;letter-spacing:-0.05pt;mso-font-width:100%;vertical-align:baseline\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent;font-size:14px\\\"> 方法。在这里说成 </span></span></span><span style=\\\"-webkit-tap-highlight-color:transparent;font-size:11.25pt;font-family:微软雅黑;font-weight:normal;font-style:normal;color:#242424;background:#F2F2F2;letter-spacing:-0.05pt;mso-font-width:100%;vertical-align:baseline\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent;font-size:14px\\\">Top N</span></span></span><span style=\\\"-webkit-tap-highlight-color:transparent;font-size:15pt;font-family:微软雅黑;font-weight:normal;font-style:normal;color:#242424;background:#FFF;letter-spacing:-0.05pt;mso-font-width:100%;vertical-align:baseline\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent;font-size:14px\\\"> ，因为假设一个场景，只有 3 个买入订单，没有卖出订单。获取 top_5 没有意义。它可能是 top 1 或 2 或 3，但最多是 top_5。这就是为什么一般行情软件会看到它是 top N 订单。</span></span></span></p><div style=\\\"-webkit-tap-highlight-color:transparent;\\\"><pre style=\\\"-webkit-tap-highlight-color:transparent\\\"><div style=\\\"--en-codeblock:true;--en-meta:{&quot;title&quot;:&quot;&quot;,&quot;lang&quot;:&quot;Plain Text&quot;,&quot;theme&quot;:&quot;default&quot;,&quot;showLine&quot;:true,&quot;lineWrap&quot;:true};box-sizing: border-box; padding: 8px; font-family: Monaco, Menlo, Consolas, &quot;Courier New&quot;, monospace; font-size: 12px; color: rgb(51, 51, 51); border-top-left-radius: 4px; border-top-right-radius: 4px; border-bottom-right-radius: 4px; border-bottom-left-radius: 4px; background-color: rgb(251, 250, 248); border: 1px solid rgba(0, 0, 0, 0.14902); background-position: initial initial; background-repeat: initial initial; margin-top: 6px;\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><br style=\\\"-webkit-tap-highlight-color:transparent\\\"/></span><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">impl OrderBook {</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">    pub fn top_n_best_buy_prices(&amp;self) -&gt; Option&lt;Vec&lt;Decimal&gt;&gt; {</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">        let prices = self</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">            .buy_orders</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">            .keys()</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">            .rev()</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">            .take(</span><span style=\\\"-webkit-tap-highlight-color:transparent\\\">5</span><span style=\\\"-webkit-tap-highlight-color:transparent\\\">) // At Max </span><span style=\\\"-webkit-tap-highlight-color:transparent\\\">5</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">            .cloned()</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">            .collect::&lt;Vec&lt;Decimal&gt;&gt;();</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">        </span><span style=\\\"-webkit-tap-highlight-color:transparent\\\">if</span><span style=\\\"-webkit-tap-highlight-color:transparent\\\"> prices.is_empty() {</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">            </span><span style=\\\"-webkit-tap-highlight-color:transparent\\\">None</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">        } </span><span style=\\\"-webkit-tap-highlight-color:transparent\\\">else</span><span style=\\\"-webkit-tap-highlight-color:transparent\\\"> {</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">            Some(prices)</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">        }</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">    }</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">  pub fn top_n_best_sell_prices(&amp;self) -&gt; Option&lt;Vec&lt;Decimal&gt;&gt; {</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">        let prices = self</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">            .sell_orders</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">            .keys()</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">            .take(</span><span style=\\\"-webkit-tap-highlight-color:transparent\\\">5</span><span style=\\\"-webkit-tap-highlight-color:transparent\\\">) // At Max </span><span style=\\\"-webkit-tap-highlight-color:transparent\\\">5</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">            .cloned()</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">            .collect::&lt;Vec&lt;Decimal&gt;&gt;();</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">        </span><span style=\\\"-webkit-tap-highlight-color:transparent\\\">if</span><span style=\\\"-webkit-tap-highlight-color:transparent\\\"> prices.is_empty() {</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">            </span><span style=\\\"-webkit-tap-highlight-color:transparent\\\">None</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">        } </span><span style=\\\"-webkit-tap-highlight-color:transparent\\\">else</span><span style=\\\"-webkit-tap-highlight-color:transparent\\\"> {</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">            Some(prices)</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">        }</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">    }</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">}</span></span></div></div></pre></div><p style=\\\"-webkit-tap-highlight-color:transparent;margin:0;text-align:justify;line-height:1.6;margin-top:34.25pt;margin-bottom:-7.35pt;margin-left:0;margin-right:0\\\"><span style=\\\"-webkit-tap-highlight-color:transparent;font-size:15pt;font-family:微软雅黑;font-weight:normal;font-style:normal;color:#242424;background:#FFF;letter-spacing:-0.05pt;mso-font-width:100%;vertical-align:baseline\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent;font-size:14px\\\">当使用 BTreeMap 代替 HashMap 时，情况发生了变化，如果没有使用 BTreeMap，那么每次我们都需要对条目进行排序，然后从中获取 top_n。有了 BTreeMap，总是可以确保它是 top_n 或者 bottom_n。这使得逻辑和复杂性处理变得更加简单。</span></span></span></p><p style=\\\"-webkit-tap-highlight-color:transparent;margin:0;text-align:justify;line-height:1.6;margin-top:34.25pt;margin-bottom:-7.35pt;margin-left:0;margin-right:0\\\"><span style=\\\"-webkit-tap-highlight-color:transparent;font-size:15pt;font-family:微软雅黑;font-weight:normal;font-style:normal;color:#242424;background:#FFF;letter-spacing:-0.05pt;mso-font-width:100%;vertical-align:baseline\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent;font-size:14px\\\">以上逻辑实现的测试代码如下：</span></span></span></p><div style=\\\"-webkit-tap-highlight-color:transparent;\\\"><pre style=\\\"-webkit-tap-highlight-color:transparent\\\"><div style=\\\"--en-codeblock:true;--en-meta:{&quot;title&quot;:&quot;&quot;,&quot;lang&quot;:&quot;Plain Text&quot;,&quot;theme&quot;:&quot;default&quot;,&quot;showLine&quot;:true,&quot;lineWrap&quot;:true};box-sizing: border-box; padding: 8px; font-family: Monaco, Menlo, Consolas, &quot;Courier New&quot;, monospace; font-size: 12px; color: rgb(51, 51, 51); border-top-left-radius: 4px; border-top-right-radius: 4px; border-bottom-right-radius: 4px; border-bottom-left-radius: 4px; background-color: rgb(251, 250, 248); border: 1px solid rgba(0, 0, 0, 0.14902); background-position: initial initial; background-repeat: initial initial; margin-top: 6px;\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">                </span></span><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">#[test]</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">fn </span><span style=\\\"-webkit-tap-highlight-color:transparent\\\">test_top_n_buy_and_sell_prices</span><span style=\\\"-webkit-tap-highlight-color:transparent\\\">(){</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">    </span><span style=\\\"-webkit-tap-highlight-color:transparent\\\">// Initialze the new order_book</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">    let mut order_book = OrderBook::new();</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">    // Create some buy orders.</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">    let buy_order_1 = Order::new(dec!(35), dec!(690), BuyOrSell::Buy);</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">    let buy_order_2 = Order::new(dec!(20), dec!(685), BuyOrSell::Buy);</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">    let buy_order_3 = Order::new(dec!(15), dec!(690), BuyOrSell::Buy);</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">    // Create some sell orders.</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">    let sell_order_1 = Order::new(dec!(10), dec!(700), BuyOrSell::Sell);</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">    let sell_order_2 = Order::new(dec!(25), dec!(705), BuyOrSell::Sell);</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">    let sell_order_3 = Order::new(dec!(30), dec!(700), BuyOrSell::Sell);</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">    // Add the orders to the order_book</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">    order_book.add_order_to_orderbook(buy_order_1);</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">    order_book.add_order_to_orderbook(buy_order_2);</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">    order_book.add_order_to_orderbook(buy_order_3);</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">    order_book.add_order_to_orderbook(sell_order_1);</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">    order_book.add_order_to_orderbook(sell_order_2);</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">    order_book.add_order_to_orderbook(sell_order_3);</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">    assert_eq!(</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">      order_book.top_n_best_buy_prices(), </span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">      Some(vec![dec!(690), dec!(685)]) // Good for Sellers.</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">    );</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">    assert_eq!(</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">      order_book.top_n_best_sell_prices(), </span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">      Some(vec![dec!(700), dec!(705)]) // Good for Buyers.</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">    );</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">}</span></span></div></div></pre></div><p style=\\\"-webkit-tap-highlight-color:transparent;margin:0;text-align:justify;line-height:1.6;margin-top:34.25pt;margin-bottom:-7.35pt;margin-left:0;margin-right:0\\\"><span style=\\\"-webkit-tap-highlight-color:transparent;font-size:15pt;font-family:微软雅黑;font-weight:normal;font-style:normal;color:#242424;background:#FFF;letter-spacing:-0.05pt;mso-font-width:100%;vertical-align:baseline\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent;font-size:14px\\\">断言语句中价格已经按照最佳顺序到来。作为卖家，690 的买入价格比 685 更好，对我方发出的订单来说，作为买家，700 的卖出价格比 705 更好。</span></span></span></p><p style=\\\"-webkit-tap-highlight-color:transparent;margin:0;text-align:justify;line-height:1.6;margin-top:34.25pt;margin-bottom:-7.35pt;margin-left:0;margin-right:0\\\"><span style=\\\"-webkit-tap-highlight-color:transparent;font-size:15pt;font-family:微软雅黑;font-weight:normal;font-style:normal;color:#242424;background:#FFF;letter-spacing:-0.05pt;mso-font-width:100%;vertical-align:baseline\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent;font-size:14px\\\">如果我们的订单簿中没有 5 个条目，那么它只会以排序顺序提供两个价格。这完全证明了前 N名的合理性。</span></span></span><span lang=\\\"EN-US\\\" style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\"></span></span></p><p style=\\\"-webkit-tap-highlight-color:transparent;margin:0;text-align:justify;line-height:1.6;margin-top:15.05pt;margin-bottom:-7.35pt;margin-left:0;margin-right:0\\\"><span style=\\\"-webkit-tap-highlight-color:transparent;font-size:15pt;font-family:微软雅黑;font-weight:normal;font-style:normal;color:#242424;background:#FFF;letter-spacing:-0.05pt;mso-font-width:100%;vertical-align:baseline\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><br style=\\\"-webkit-tap-highlight-color:transparent\\\"/></span></span></p><p style=\\\"-webkit-tap-highlight-color:transparent;margin:0;text-align:justify;line-height:1.6;margin-top:15.05pt;margin-bottom:-7.35pt;margin-left:0;margin-right:0\\\"><span style=\\\"-webkit-tap-highlight-color:transparent;font-size:15pt;font-family:微软雅黑;font-weight:normal;font-style:normal;color:#242424;background:#FFF;letter-spacing:-0.05pt;mso-font-width:100%;vertical-align:baseline\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent;font-size:20px;font-weight:bold\\\">3.</span><span style=\\\"-webkit-tap-highlight-color:transparent;font-weight:bold\\\">The core matching algorithm</span></span></span><span lang=\\\"EN-US\\\" style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\"></span></span></p><p style=\\\"-webkit-tap-highlight-color:transparent;margin:0\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><br style=\\\"-webkit-tap-highlight-color:transparent\\\"/></span></p><p style=\\\"-webkit-tap-highlight-color:transparent;margin:0\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent;font-size:14px\\\">匹配的核心步骤如下：</span></span></p><ul style=\\\"-webkit-tap-highlight-color:transparent;margin:0;list-style-type:disc\\\"><li style=\\\"-webkit-tap-highlight-color:transparent\\\"><p style=\\\"-webkit-tap-highlight-color:transparent;margin:0\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent;font-size:12px\\\">Get all the valid best priced orders from the orderbook.</span></span></p></li><li style=\\\"-webkit-tap-highlight-color:transparent\\\"><p style=\\\"-webkit-tap-highlight-color:transparent;margin:0\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent;font-size:12px\\\">Match the quantity of the incoming order with the valid orders.</span></span></p></li></ul><p style=\\\"-webkit-tap-highlight-color:transparent;margin:0\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent;font-size:14px\\\">编写一个wrapper execute_match 以匹配 incoming orders 的数量与有效订单。</span></span></p><p style=\\\"-webkit-tap-highlight-color:transparent;margin:0\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent;font-size:14px\\\">Matching against quantity has 3 cases：</span></span></p><p style=\\\"-webkit-tap-highlight-color:transparent;margin:0\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent;font-size:14px;font-weight:bold\\\">Partially Matched </span><span style=\\\"-webkit-tap-highlight-color:transparent;font-size:14px\\\">: Incoming order’s quantity is more than existing order’s quantity.</span></span></p><p style=\\\"-webkit-tap-highlight-color:transparent;margin:0\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent;font-size:14px\\\">例如：</span></span></p><ul style=\\\"-webkit-tap-highlight-color:transparent;margin:0;list-style-type:disc\\\"><li style=\\\"-webkit-tap-highlight-color:transparent\\\"><p style=\\\"-webkit-tap-highlight-color:transparent;margin:0\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent;font-size:14px\\\">Incoming Order : BUY 30 units at 1000</span></span></p></li><li style=\\\"-webkit-tap-highlight-color:transparent\\\"><p style=\\\"-webkit-tap-highlight-color:transparent;margin:0\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent;font-size:14px\\\">Orderbook Order : SELL 20 units at 1000</span></span></p></li></ul><p style=\\\"-webkit-tap-highlight-color:transparent;margin:0\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent;font-size:14px\\\">将20股（假设交易单位）卖出订单和新订单成交后，则新订单还剩余10股未成交，进入排队（比如A股市场，会立即撤销或转限价委托，等待后续撮合。）</span></span></p><p style=\\\"-webkit-tap-highlight-color:transparent;margin:0\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent;font-size:14px;font-weight:bold\\\">Fully Matched</span><span style=\\\"-webkit-tap-highlight-color:transparent;font-size:14px\\\"> : Incoming order’s quantity is less than existing order’s quantity.</span></span></p><p style=\\\"-webkit-tap-highlight-color:transparent;margin:0\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent;font-size:14px\\\">例如：</span></span></p><ul style=\\\"-webkit-tap-highlight-color:transparent;margin:0;list-style-type:disc\\\"><li style=\\\"-webkit-tap-highlight-color:transparent\\\"><p style=\\\"-webkit-tap-highlight-color:transparent;margin:0\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent;font-size:14px\\\">Incoming Order : BUY 30 units at 1000</span></span></p></li><li style=\\\"-webkit-tap-highlight-color:transparent\\\"><p style=\\\"-webkit-tap-highlight-color:transparent;margin:0\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent;font-size:14px\\\">Orderbook Order : SELL 40 units at 1000</span></span></p></li></ul><p style=\\\"-webkit-tap-highlight-color:transparent;margin:0\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent;font-size:14px\\\">incoming order因为买入30股，订单薄上有40股卖出订单，则买入订单完全成交。新订单返回全部成交（程序中退出循环） 。</span></span></p><p style=\\\"-webkit-tap-highlight-color:transparent;margin:0\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent;font-size:14px;font-weight:bold\\\">Perfect Matched</span><span style=\\\"-webkit-tap-highlight-color:transparent;font-size:14px\\\"> : Incoming order’s quantity is equal to existing order’s quantity.</span></span></p><p style=\\\"-webkit-tap-highlight-color:transparent;margin:0\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent;font-size:14px\\\">例如：</span></span></p><ul style=\\\"-webkit-tap-highlight-color:transparent;margin:0;list-style-type:disc\\\"><li style=\\\"-webkit-tap-highlight-color:transparent\\\"><p style=\\\"-webkit-tap-highlight-color:transparent;margin:0\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent;font-size:14px\\\">Incoming Order : BUY 30 units at 1000</span></span></p></li><li style=\\\"-webkit-tap-highlight-color:transparent\\\"><p style=\\\"-webkit-tap-highlight-color:transparent;margin:0\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent;font-size:14px\\\">Orderbook Order : SELL 30 units at 1000</span></span></p></li></ul><p style=\\\"-webkit-tap-highlight-color:transparent;margin:0\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent;font-size:14px\\\">买入订单和卖出订单价量完全匹配，则直接撮合。</span></span></p><div style=\\\"-webkit-tap-highlight-color:transparent;\\\"><pre style=\\\"-webkit-tap-highlight-color:transparent\\\"><div style=\\\"--en-codeblock:true;--en-meta:{&quot;title&quot;:&quot;&quot;,&quot;lang&quot;:&quot;Plain Text&quot;,&quot;theme&quot;:&quot;default&quot;,&quot;showLine&quot;:true,&quot;lineWrap&quot;:true};box-sizing: border-box; padding: 8px; font-family: Monaco, Menlo, Consolas, &quot;Courier New&quot;, monospace; font-size: 12px; color: rgb(51, 51, 51); border-top-left-radius: 4px; border-top-right-radius: 4px; border-bottom-right-radius: 4px; border-bottom-left-radius: 4px; background-color: rgb(251, 250, 248); border: 1px solid rgba(0, 0, 0, 0.14902); background-position: initial initial; background-repeat: initial initial; margin-top: 6px;\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><br style=\\\"-webkit-tap-highlight-color:transparent\\\"/></span><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">use </span><span style=\\\"-webkit-tap-highlight-color:transparent\\\">rust_decimal_macros</span><span style=\\\"-webkit-tap-highlight-color:transparent\\\">::dec;</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">impl </span><span style=\\\"-webkit-tap-highlight-color:transparent\\\">Orderbook</span><span style=\\\"-webkit-tap-highlight-color:transparent\\\"> {  </span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">    fn </span><span style=\\\"-webkit-tap-highlight-color:transparent\\\">execute_match</span><span style=\\\"-webkit-tap-highlight-color:transparent\\\">(</span><span style=\\\"-webkit-tap-highlight-color:transparent\\\">valid_orders: &amp;mut Vec&lt;Order&gt;, incoming_order: &amp;mut Order</span><span style=\\\"-webkit-tap-highlight-color:transparent\\\">) {</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">        </span><span style=\\\"-webkit-tap-highlight-color:transparent\\\">for</span><span style=\\\"-webkit-tap-highlight-color:transparent\\\"> order </span><span style=\\\"-webkit-tap-highlight-color:transparent\\\">in</span><span style=\\\"-webkit-tap-highlight-color:transparent\\\"> valid_orders.</span><span style=\\\"-webkit-tap-highlight-color:transparent\\\">iter_mut</span><span style=\\\"-webkit-tap-highlight-color:transparent\\\">() {</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">            </span><span style=\\\"-webkit-tap-highlight-color:transparent\\\">// Partially Matched</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">            if order.quantity &lt; incoming_order.quantity {</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">                incoming_order.quantity -= order.quantity;</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">                order.quantity = dec!(0);</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">            } </span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">            // Perfectly Matched</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">            else if order.quantity == incoming_order.quantity {</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">                order.quantity = dec!(0);</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">                incoming_order.quantity = dec!(0);</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">                break;</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">            } </span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">            // Fully Matched</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">            else {</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">                order.quantity -= incoming_order.quantity;</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">                incoming_order.quantity = dec!(0);</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">                break;</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">            }</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">        }</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">    }</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">}</span></span></div></div></pre></div><p style=\\\"-webkit-tap-highlight-color:transparent;margin:0;text-align:justify;line-height:1.25;margin-top:20pt;margin-bottom:-4.5pt;margin-left:0;margin-right:0\\\"><span style=\\\"-webkit-tap-highlight-color:transparent;font-size:18pt;font-family:微软雅黑;font-weight:bold;font-style:normal;color:#242424;background:#FFF;letter-spacing:-0.25pt;mso-font-width:100%;vertical-align:baseline\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent;font-size:20px\\\">4.Selecting Best Price for Market / Limit Orders</span></span></span></p><p style=\\\"-webkit-tap-highlight-color:transparent;margin:0\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><br style=\\\"-webkit-tap-highlight-color:transparent\\\"/></span></p><p style=\\\"-webkit-tap-highlight-color:transparent;margin:0\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent;font-size:14px\\\">We have to take care of Market Orders and the Limit Orders in order to obtain the valid orders from the orderbook.</span></span></p><ul style=\\\"-webkit-tap-highlight-color:transparent;margin:0;list-style-type:disc\\\"><li style=\\\"-webkit-tap-highlight-color:transparent\\\"><p style=\\\"-webkit-tap-highlight-color:transparent;margin:0\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent;font-size:14px\\\">Market Orders : Best possible order at the moment in market.</span></span></p></li><li style=\\\"-webkit-tap-highlight-color:transparent\\\"><p style=\\\"-webkit-tap-highlight-color:transparent;margin:0\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent;font-size:14px\\\">Limit Orders : Best possible match beyond a threshold price.</span></span></p></li></ul><p style=\\\"-webkit-tap-highlight-color:transparent;margin:0\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><br style=\\\"-webkit-tap-highlight-color:transparent\\\"/></span></p><p style=\\\"-webkit-tap-highlight-color:transparent;margin:0\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent;font-size:14px\\\">Let’s write the </span><span style=\\\"-webkit-tap-highlight-color:transparent;font-size:14px;font-weight:bold\\\">match_market_order method</span><span style=\\\"-webkit-tap-highlight-color:transparent;font-size:14px\\\"> first. But before that make sure you add #[derive(Clone)] on top of struct Order and enum BuyOrSell .</span></span></p><div style=\\\"-webkit-tap-highlight-color:transparent;\\\"><pre style=\\\"-webkit-tap-highlight-color:transparent\\\"><div style=\\\"--en-codeblock:true;--en-meta:{&quot;title&quot;:&quot;&quot;,&quot;lang&quot;:&quot;Plain Text&quot;,&quot;theme&quot;:&quot;default&quot;,&quot;showLine&quot;:true,&quot;lineWrap&quot;:true};box-sizing: border-box; padding: 8px; font-family: Monaco, Menlo, Consolas, &quot;Courier New&quot;, monospace; font-size: 12px; color: rgb(51, 51, 51); border-top-left-radius: 4px; border-top-right-radius: 4px; border-bottom-right-radius: 4px; border-bottom-left-radius: 4px; background-color: rgb(251, 250, 248); border: 1px solid rgba(0, 0, 0, 0.14902); background-position: initial initial; background-repeat: initial initial; margin-top: 6px;\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\"> </span></span><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">impl </span><span style=\\\"-webkit-tap-highlight-color:transparent\\\">OrderBook</span><span style=\\\"-webkit-tap-highlight-color:transparent\\\"> {</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">    pub fn </span><span style=\\\"-webkit-tap-highlight-color:transparent\\\">match_market_order</span><span style=\\\"-webkit-tap-highlight-color:transparent\\\">(</span><span style=\\\"-webkit-tap-highlight-color:transparent\\\">&amp;mut self, incoming_order: &amp;mut Order</span><span style=\\\"-webkit-tap-highlight-color:transparent\\\">) {</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">        match incoming_order.</span><span style=\\\"-webkit-tap-highlight-color:transparent\\\">order_type</span><span style=\\\"-webkit-tap-highlight-color:transparent\\\"> {</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">            </span><span style=\\\"-webkit-tap-highlight-color:transparent\\\">BuyOrSell</span><span style=\\\"-webkit-tap-highlight-color:transparent\\\">::</span><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">Buy</span></span><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\"> =&gt;</span></span><span style=\\\"-webkit-tap-highlight-color:transparent\\\"> {</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">                </span><span style=\\\"-webkit-tap-highlight-color:transparent\\\">let</span><span style=\\\"-webkit-tap-highlight-color:transparent\\\"> possible_prices = self.</span><span style=\\\"-webkit-tap-highlight-color:transparent\\\">top_n_best_sell_prices</span><span style=\\\"-webkit-tap-highlight-color:transparent\\\">();</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">                match possible_prices {</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">                    </span><span style=\\\"-webkit-tap-highlight-color:transparent\\\">Some</span><span style=\\\"-webkit-tap-highlight-color:transparent\\\">(prices) =&gt; {</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">                        </span><span style=\\\"-webkit-tap-highlight-color:transparent\\\">for</span><span style=\\\"-webkit-tap-highlight-color:transparent\\\"> price </span><span style=\\\"-webkit-tap-highlight-color:transparent\\\">in</span><span style=\\\"-webkit-tap-highlight-color:transparent\\\"> prices {</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">                            </span><span style=\\\"-webkit-tap-highlight-color:transparent\\\">if</span><span style=\\\"-webkit-tap-highlight-color:transparent\\\"> </span><span style=\\\"-webkit-tap-highlight-color:transparent\\\">let</span><span style=\\\"-webkit-tap-highlight-color:transparent\\\"> </span><span style=\\\"-webkit-tap-highlight-color:transparent\\\">Some</span><span style=\\\"-webkit-tap-highlight-color:transparent\\\">(orders_at_this_price) = self.</span><span style=\\\"-webkit-tap-highlight-color:transparent\\\">sell_orders</span><span style=\\\"-webkit-tap-highlight-color:transparent\\\">.</span><span style=\\\"-webkit-tap-highlight-color:transparent\\\">get_mut</span><span style=\\\"-webkit-tap-highlight-color:transparent\\\">(</span><span style=\\\"-webkit-tap-highlight-color:transparent\\\">&amp;price</span><span style=\\\"-webkit-tap-highlight-color:transparent\\\">) {</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">                                </span><span style=\\\"-webkit-tap-highlight-color:transparent\\\">Self</span><span style=\\\"-webkit-tap-highlight-color:transparent\\\">::</span><span style=\\\"-webkit-tap-highlight-color:transparent\\\">execute_match</span><span style=\\\"-webkit-tap-highlight-color:transparent\\\">(orders_at_this_price, incoming_order);</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">                            }</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">                            </span><span style=\\\"-webkit-tap-highlight-color:transparent\\\">if</span><span style=\\\"-webkit-tap-highlight-color:transparent\\\"> incoming_order.</span><span style=\\\"-webkit-tap-highlight-color:transparent\\\">quantity</span><span style=\\\"-webkit-tap-highlight-color:transparent\\\"> == dec!(</span><span style=\\\"-webkit-tap-highlight-color:transparent\\\">0</span><span style=\\\"-webkit-tap-highlight-color:transparent\\\">) {</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">                                </span><span style=\\\"-webkit-tap-highlight-color:transparent\\\">break</span><span style=\\\"-webkit-tap-highlight-color:transparent\\\">;</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">                            }</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">                        }</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">                        </span><span style=\\\"-webkit-tap-highlight-color:transparent\\\">if</span><span style=\\\"-webkit-tap-highlight-color:transparent\\\"> incoming_order.</span><span style=\\\"-webkit-tap-highlight-color:transparent\\\">quantity</span><span style=\\\"-webkit-tap-highlight-color:transparent\\\"> != dec!(</span><span style=\\\"-webkit-tap-highlight-color:transparent\\\">0</span><span style=\\\"-webkit-tap-highlight-color:transparent\\\">) {</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">                            </span><span style=\\\"-webkit-tap-highlight-color:transparent\\\">// Incoming Order was not fully executed.</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">                            self.add_order_to_orderbook(incoming_order.clone());</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">                        }</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">                    }</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">                    None =&gt; self.add_order_to_orderbook(incoming_order.clone()),</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">                }</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">            }</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">            BuyOrSell::Sell =&gt; {</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">                let possible_prices = self.top_n_best_buy_prices();</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">                match possible_prices {</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">                    Some(prices) =&gt; {</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">                        for price in prices {</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">                            if let Some(orders_at_this_price) = self.buy_orders.get_mut(&amp;price) {</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">                                Self::execute_match(orders_at_this_price, incoming_order);</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">                            }</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">                            if incoming_order.quantity == dec!(0) {</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">                                break;</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">                            }</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">                        }</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">                        if incoming_order.quantity != dec!(0) {</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">                            // Incoming Order was not fully executed.</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">                            self.add_order_to_orderbook(incoming_order.clone());</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">                        }</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">                    }</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">                    None =&gt; self.add_order_to_orderbook(incoming_order.clone()),</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">                }</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">            }</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">        }</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">    }</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">}</span></span></div></div></pre></div><p style=\\\"-webkit-tap-highlight-color:transparent;margin:0\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent;font-size:14px\\\">主要实现逻辑如下：</span></span></p><p style=\\\"-webkit-tap-highlight-color:transparent;margin:0\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent;font-size:12px;font-weight:bold\\\">Determine if the order is to buy or sell</span><span style=\\\"-webkit-tap-highlight-color:transparent;font-size:12px\\\"> : The method first checks whether the incoming order is a buy order or a sell order.</span></span></p><p style=\\\"-webkit-tap-highlight-color:transparent;margin:0\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent;font-size:12px;font-weight:bold\\\">Find best possible price matches</span><span style=\\\"-webkit-tap-highlight-color:transparent;font-size:12px\\\">: Depending on whether it’s a buy or sell order, the system looks for potential prices in the order book at which we can execute the incoming order. This comes from top_n_buy_prices and top_n_sell_prices methods which we had wrote earlier.</span></span></p><p style=\\\"-webkit-tap-highlight-color:transparent;margin:0\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent;font-size:12px;font-weight:bold\\\">Attempt to match</span><span style=\\\"-webkit-tap-highlight-color:transparent;font-size:12px\\\"> : For each potential match found at a certain price, the system tries to match the incoming order with existing orders at that price. If there are orders at that price, it executes the matching process.</span></span></p><p style=\\\"-webkit-tap-highlight-color:transparent;margin:0\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent;font-size:12px;font-weight:bold\\\">Execute matching</span><span style=\\\"-webkit-tap-highlight-color:transparent;font-size:12px\\\"> : If there are orders at the same price, it tries to match the incoming order with those orders. This means if someone wants to buy at a price that someone else wants to sell, they can make a deal.</span></span></p><p style=\\\"-webkit-tap-highlight-color:transparent;margin:0\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent;font-size:12px;font-weight:bold\\\">Check quantity and repeat if needed</span><span style=\\\"-webkit-tap-highlight-color:transparent;font-size:12px\\\"> : After trying to match with orders at each price level, it checks if the incoming order has been fully executed (meaning all of the quantity has been matched with existing orders). If not, it repeats the process with other potential matches.</span></span></p><p style=\\\"-webkit-tap-highlight-color:transparent;margin:0\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent;font-size:12px;font-weight:bold\\\">Handle unmatched orders </span><span style=\\\"-webkit-tap-highlight-color:transparent;font-size:12px\\\">: If the incoming order hasn’t been fully executed after checking all potential best possible prices, it means there weren’t enough matching orders. In that case, the remaining part of the order is added to the order book for future matching.</span></span></p><p style=\\\"-webkit-tap-highlight-color:transparent;margin:0\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent;font-size:14px\\\">使用市价单的思路实现限价单参考代码如下：</span></span></p><div style=\\\"-webkit-tap-highlight-color:transparent;\\\"><pre style=\\\"-webkit-tap-highlight-color:transparent\\\"><div style=\\\"--en-codeblock:true;--en-meta:{&quot;title&quot;:&quot;&quot;,&quot;lang&quot;:&quot;Plain Text&quot;,&quot;theme&quot;:&quot;default&quot;,&quot;showLine&quot;:true,&quot;lineWrap&quot;:true};box-sizing: border-box; padding: 8px; font-family: Monaco, Menlo, Consolas, &quot;Courier New&quot;, monospace; font-size: 12px; color: rgb(51, 51, 51); border-top-left-radius: 4px; border-top-right-radius: 4px; border-bottom-right-radius: 4px; border-bottom-left-radius: 4px; background-color: rgb(251, 250, 248); border: 1px solid rgba(0, 0, 0, 0.14902); background-position: initial initial; background-repeat: initial initial; margin-top: 6px;\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">   </span></span><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">impl OrderBook {  </span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">    </span><span style=\\\"-webkit-tap-highlight-color:transparent\\\">pub fn match_limit_order</span><span style=\\\"-webkit-tap-highlight-color:transparent\\\">(&amp;mut </span><span style=\\\"-webkit-tap-highlight-color:transparent\\\">self</span><span style=\\\"-webkit-tap-highlight-color:transparent\\\">, </span><span style=\\\"-webkit-tap-highlight-color:transparent\\\">incoming_order</span><span style=\\\"-webkit-tap-highlight-color:transparent\\\">: &amp;mut Order) {</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">        </span><span style=\\\"-webkit-tap-highlight-color:transparent\\\">match</span><span style=\\\"-webkit-tap-highlight-color:transparent\\\"> incoming_order.order_type {</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">            </span><span style=\\\"-webkit-tap-highlight-color:transparent\\\">BuyOrSell</span><span style=\\\"-webkit-tap-highlight-color:transparent\\\">::</span><span style=\\\"-webkit-tap-highlight-color:transparent\\\">Buy</span><span style=\\\"-webkit-tap-highlight-color:transparent\\\"> =&gt; {</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">                let possible_prices = </span><span style=\\\"-webkit-tap-highlight-color:transparent\\\">self</span><span style=\\\"-webkit-tap-highlight-color:transparent\\\">.</span><span style=\\\"-webkit-tap-highlight-color:transparent\\\">top_n_best_sell_prices</span><span style=\\\"-webkit-tap-highlight-color:transparent\\\">();</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">                </span><span style=\\\"-webkit-tap-highlight-color:transparent\\\">match</span><span style=\\\"-webkit-tap-highlight-color:transparent\\\"> possible_prices {</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">                    </span><span style=\\\"-webkit-tap-highlight-color:transparent\\\">Some</span><span style=\\\"-webkit-tap-highlight-color:transparent\\\">(prices) =&gt; {</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">                        </span><span style=\\\"-webkit-tap-highlight-color:transparent\\\">for</span><span style=\\\"-webkit-tap-highlight-color:transparent\\\"> price in prices {</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">                            </span><span style=\\\"-webkit-tap-highlight-color:transparent\\\">if</span><span style=\\\"-webkit-tap-highlight-color:transparent\\\"> incoming_order.price &gt;= price {</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">                                </span><span style=\\\"-webkit-tap-highlight-color:transparent\\\">if</span><span style=\\\"-webkit-tap-highlight-color:transparent\\\"> let Some</span><span style=\\\"-webkit-tap-highlight-color:transparent\\\">(orders_at_this_price) = </span><span style=\\\"-webkit-tap-highlight-color:transparent\\\">self</span><span style=\\\"-webkit-tap-highlight-color:transparent\\\">.sell_orders.</span><span style=\\\"-webkit-tap-highlight-color:transparent\\\">get_mut</span><span style=\\\"-webkit-tap-highlight-color:transparent\\\">(&amp;price)</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">                                {</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">                                    </span><span style=\\\"-webkit-tap-highlight-color:transparent\\\">Self</span><span style=\\\"-webkit-tap-highlight-color:transparent\\\">::</span><span style=\\\"-webkit-tap-highlight-color:transparent\\\">execute_match</span><span style=\\\"-webkit-tap-highlight-color:transparent\\\">(orders_at_this_price, incoming_order);</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">                                }</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">                                </span><span style=\\\"-webkit-tap-highlight-color:transparent\\\">if</span><span style=\\\"-webkit-tap-highlight-color:transparent\\\"> incoming_order.quantity == dec!(</span><span style=\\\"-webkit-tap-highlight-color:transparent\\\">0</span><span style=\\\"-webkit-tap-highlight-color:transparent\\\">) {</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">                                    </span><span style=\\\"-webkit-tap-highlight-color:transparent\\\">break</span><span style=\\\"-webkit-tap-highlight-color:transparent\\\">;</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">                                }</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">                            }</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">                        }</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">                        </span><span style=\\\"-webkit-tap-highlight-color:transparent\\\">if</span><span style=\\\"-webkit-tap-highlight-color:transparent\\\"> incoming_order.quantity != dec!(</span><span style=\\\"-webkit-tap-highlight-color:transparent\\\">0</span><span style=\\\"-webkit-tap-highlight-color:transparent\\\">) {</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">                            </span><span style=\\\"-webkit-tap-highlight-color:transparent\\\">// Incoming Order was not fully executed.</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">                            self.add_order_to_orderbook(incoming_order.clone());</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">                        }</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">                    }</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">                    None =&gt; self.add_order_to_orderbook(incoming_order.clone()),</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">                }</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">            }</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">            BuyOrSell::Sell =&gt; {</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">                let possible_prices = self.top_n_best_buy_prices();</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">                match possible_prices {</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">                    Some(prices) =&gt; {</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">                        for price in prices {</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">                            if incoming_order.price &lt;= price {</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">                                if let Some(orders_at_this_price) = self.buy_orders.get_mut(&amp;price)</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">                                {</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">                                    Self::execute_match(orders_at_this_price, incoming_order);</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">                                }</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">                                if incoming_order.quantity == dec!(0) {</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">                                    break;</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">                                }</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">                            }</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">                        }</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">                        if incoming_order.quantity != dec!(0) {</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">                            // Incoming Order was not fully executed.</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">                            self.add_order_to_orderbook(incoming_order.clone());</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">                        }</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">                    }</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">                    None =&gt; self.add_order_to_orderbook(incoming_order.clone()),</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">                }</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">            }</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">        }</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">    }</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">}</span></span></div></div></pre></div><p style=\\\"-webkit-tap-highlight-color:transparent;margin:0;text-align:justify;line-height:1.6;margin-top:34.25pt;margin-bottom:-7.35pt;margin-left:0;margin-right:0\\\"><span style=\\\"-webkit-tap-highlight-color:transparent;font-size:15pt;font-family:微软雅黑;font-weight:normal;font-style:normal;color:#242424;background:#FFF;letter-spacing:-0.05pt;mso-font-width:100%;vertical-align:baseline\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent;font-size:14px\\\">限价订单与市价订单代码基本相同，区别在于价格阈值，主要检查 incoming order 的价格是否高于订单价格，以便仅在高于一定水平以下执行它。</span></span></span></p><p style=\\\"-webkit-tap-highlight-color:transparent;margin:0;text-align:justify;line-height:1.6;margin-top:34.25pt;margin-bottom:-7.35pt;margin-left:0;margin-right:0\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent;font-size:20px;font-weight:bold\\\">5.Testing Full Order Execution</span></span><span lang=\\\"EN-US\\\" style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\"></span></span></p><p style=\\\"-webkit-tap-highlight-color:transparent;margin:0\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><br style=\\\"-webkit-tap-highlight-color:transparent\\\"/></span></p><p style=\\\"-webkit-tap-highlight-color:transparent;margin:0\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent;font-size:14px\\\">参考如下订单簿：</span></span></p><p style=\\\"-webkit-tap-highlight-color:transparent;margin:0;text-align:justify;margin-top:3pt;margin-bottom:3pt;margin-left:0;margin-right:0\\\"><span style=\\\"-webkit-tap-highlight-color:transparent;display:inline-block;overflow:hidden;transform:rotate(0);width:554.1333333333333px;height:225.53490813648293px;text-indent:0\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><img src=\\\":/2d15e27eddb844269ec9a71a16fe47c0\\\" type=\\\"image/png\\\" data-filename=\\\"640.png\\\" height=\\\"225.535\\\" style=\\\"--en-marks:%7B%22align%22%3A%22center%22%7D;-webkit-tap-highlight-color:transparent;margin-left:0;margin-top:0;width:554.133px;height:225.535px\\\" width=\\\"554.133\\\"/></span></span></p><ul style=\\\"-webkit-tap-highlight-color:transparent;margin:0;list-style-type:disc\\\"><li style=\\\"-webkit-tap-highlight-color:transparent\\\"><p style=\\\"-webkit-tap-highlight-color:transparent;margin:0\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent;font-size:14px\\\">Total buying volume is 25+40+125+100+150 = 440</span></span></p></li><li style=\\\"-webkit-tap-highlight-color:transparent\\\"><p style=\\\"-webkit-tap-highlight-color:transparent;margin:0\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent;font-size:14px\\\">Total selling volume is 10+50+25+150+120 = 355</span></span></p></li></ul><p style=\\\"-webkit-tap-highlight-color:transparent;margin:0\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><br style=\\\"-webkit-tap-highlight-color:transparent\\\"/></span></p><p style=\\\"-webkit-tap-highlight-color:transparent;margin:0\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent;font-size:14px;font-weight:bold\\\">Example 1 : Buy 10 units at limit price of 1005</span></span></p><p style=\\\"-webkit-tap-highlight-color:transparent;margin:0\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent;font-size:14px\\\">As a buyer, I would always want that my order gets buyed at price of 1005 or lower since this is a limit order. Now if you check the order book there is already an order for selling at price 1005. We can match the orders here.（非常标准的用户故事描述）</span></span></p><p style=\\\"-webkit-tap-highlight-color:transparent;margin:0\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent;font-size:14px\\\">Thus Incoming Order’s quantity now becomes zero. And the selling volume from the orderbook reduces by 10 units from 355 to 345.</span></span></p><p style=\\\"-webkit-tap-highlight-color:transparent;margin:0;text-align:justify;margin-top:3pt;margin-bottom:3pt;margin-left:0;margin-right:0\\\"><span style=\\\"-webkit-tap-highlight-color:transparent;display:inline-block;overflow:hidden;transform:rotate(0);width:554.1333333333333px;height:218.17322834645668px;text-indent:0\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><img src=\\\":/437fbbdcbc75450786879ed4eec474c1\\\" type=\\\"image/png\\\" data-filename=\\\"640.png\\\" height=\\\"218.173\\\" style=\\\"--en-marks:%7B%22align%22%3A%22center%22%7D;-webkit-tap-highlight-color:transparent;margin-left:0;margin-top:0;width:554.133px;height:218.173px\\\" width=\\\"554.133\\\"/></span></span></p><p style=\\\"-webkit-tap-highlight-color:transparent;margin:0;text-align:justify;line-height:1.6;margin-top:34.25pt;margin-bottom:-7.35pt;margin-left:0;margin-right:0\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent;font-size:14px;font-weight:bold\\\">Example 2:</span></span></span><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent;font-size:14px;font-weight:bold\\\"> </span></span></span><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent;font-size:14px;font-weight:bold\\\">Sell 100 units at Market Price</span></span></span><span lang=\\\"EN-US\\\" style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\"></span></span></p><p style=\\\"-webkit-tap-highlight-color:transparent;margin:0;text-align:justify;line-height:1.6;margin-top:34.25pt;margin-bottom:-7.35pt;margin-left:0;margin-right:0\\\"><span style=\\\"-webkit-tap-highlight-color:transparent;font-size:15pt;font-family:微软雅黑;font-weight:normal;font-style:normal;color:#242424;background:#FFF;letter-spacing:-0.05pt;mso-font-width:100%;vertical-align:baseline\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent;font-size:14px\\\">As a seller at market price, I would need my orders to be sold at best available price in the market. Which here is 1004, 1003, 1002 and 1001 in order. The incoming sell order is matched against 65(25+40) units at 1004, 35 units at 1003. Thanks to the </span></span></span><span style=\\\"-webkit-tap-highlight-color:transparent;font-size:11.25pt;font-family:微软雅黑;font-weight:normal;font-style:normal;color:#242424;background:#F2F2F2;letter-spacing:-0.05pt;mso-font-width:100%;vertical-align:baseline\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent;font-size:14px\\\">market_price</span></span></span><span style=\\\"-webkit-tap-highlight-color:transparent;font-size:15pt;font-family:微软雅黑;font-weight:normal;font-style:normal;color:#242424;background:#FFF;letter-spacing:-0.05pt;mso-font-width:100%;vertical-align:baseline\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent;font-size:14px\\\"> method which we wrote</span></span></span><span lang=\\\"EN-US\\\" style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\"></span></span></p><p style=\\\"-webkit-tap-highlight-color:transparent;margin:0;text-align:justify;line-height:1.6;margin-top:34.25pt;margin-bottom:-7.35pt;margin-left:0;margin-right:0\\\"><span style=\\\"-webkit-tap-highlight-color:transparent;font-size:15pt;font-family:微软雅黑;font-weight:normal;font-style:normal;color:#242424;background:#FFF;letter-spacing:-0.05pt;mso-font-width:100%;vertical-align:baseline\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent;font-size:14px\\\">Thus Incoming Order’s quantity now becomes zero. And the buying volume from the orderbook reduces by 100 units from 440 to 340.</span></span></span><span lang=\\\"EN-US\\\" style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\"></span></span></p><p style=\\\"-webkit-tap-highlight-color:transparent;margin:0\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><br style=\\\"-webkit-tap-highlight-color:transparent\\\"/></span></p><p style=\\\"-webkit-tap-highlight-color:transparent;margin:0;text-align:justify;margin-top:3pt;margin-bottom:3pt;margin-left:0;margin-right:0\\\"><span style=\\\"-webkit-tap-highlight-color:transparent;display:inline-block;overflow:hidden;transform:rotate(0);width:554.1333333333333px;height:218.17322834645668px;text-indent:0\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><img src=\\\":/cf6e2871a1bf4e108f0fc0cc83dc75d1\\\" type=\\\"image/png\\\" data-filename=\\\"640.png\\\" height=\\\"218.173\\\" style=\\\"--en-marks:%7B%22align%22%3A%22center%22%7D;-webkit-tap-highlight-color:transparent;margin-left:0;margin-top:0;width:554.133px;height:218.173px\\\" width=\\\"554.133\\\"/></span></span></p><p style=\\\"-webkit-tap-highlight-color:transparent;margin:0\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><br style=\\\"-webkit-tap-highlight-color:transparent\\\"/></span></p><p style=\\\"-webkit-tap-highlight-color:transparent;margin:0\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent;font-size:14px;font-weight:bold\\\">Example 3 : Buy 40 units at 1008 Limit price</span></span></p><p style=\\\"-webkit-tap-highlight-color:transparent;margin:0\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent;font-size:14px\\\">As a buyer, I would always want that my order gets buyed at price of 1008 or lower since this is a limit order. Now if you check the order book there is already an order for selling at price 1006. We can match the orders here.</span></span></p><p style=\\\"-webkit-tap-highlight-color:transparent;margin:0\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent;font-size:14px\\\">Thus Incoming Order’s quantity now becomes zero. And the selling volume from the orderbook reduces by 10 units from 345 to 305.</span></span></p><p style=\\\"-webkit-tap-highlight-color:transparent;margin:0;text-align:justify;margin-top:3pt;margin-bottom:3pt;margin-left:0;margin-right:0\\\"><span style=\\\"-webkit-tap-highlight-color:transparent;display:inline-block;overflow:hidden;transform:rotate(0);width:554.1333333333333px;height:218.17322834645668px;text-indent:0\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><img src=\\\":/c1057a6215cf4c7eac55b2fb7c3c7c89\\\" type=\\\"image/png\\\" data-filename=\\\"640.png\\\" height=\\\"218.173\\\" style=\\\"--en-marks:%7B%22align%22%3A%22center%22%7D;-webkit-tap-highlight-color:transparent;margin-left:0;margin-top:0;width:554.133px;height:218.173px\\\" width=\\\"554.133\\\"/></span></span></p><p style=\\\"-webkit-tap-highlight-color:transparent;margin:0\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><br style=\\\"-webkit-tap-highlight-color:transparent\\\"/></span></p><p style=\\\"-webkit-tap-highlight-color:transparent;margin:0\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent;font-size:14px;font-weight:bold\\\">Example 4: Sell 20 units at 1004 Limit price</span></span></p><p style=\\\"-webkit-tap-highlight-color:transparent;margin:0\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent;font-size:14px\\\">As a seller at limit price of 1004, I would need my orders to be sold at price above 1004 in market. But there is nothing above or equal to 1004 to buy. So the order cannot be executed and will be added into the orderbook.</span></span></p><p style=\\\"-webkit-tap-highlight-color:transparent;margin:0\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent;font-size:14px\\\">Thus Incoming Order’s quantity remains 20. And the selling volume from the orderbook increases by 20 units from 305 to 325.</span></span></p><p style=\\\"-webkit-tap-highlight-color:transparent;margin:0;text-align:justify;margin-top:3pt;margin-bottom:3pt;margin-left:0;margin-right:0\\\"><span style=\\\"-webkit-tap-highlight-color:transparent;display:inline-block;overflow:hidden;transform:rotate(0);width:554.1333333333333px;height:218.17322834645668px;text-indent:0\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><img src=\\\":/d237058190ea4d6cb7fc348a62a4ad8d\\\" type=\\\"image/png\\\" data-filename=\\\"640.png\\\" height=\\\"218.173\\\" style=\\\"--en-marks:%7B%22align%22%3A%22center%22%7D;-webkit-tap-highlight-color:transparent;margin-left:0;margin-top:0;width:554.133px;height:218.173px\\\" width=\\\"554.133\\\"/></span></span></p><p style=\\\"-webkit-tap-highlight-color:transparent;margin:0\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent;font-size:14px\\\">测试用例如下：</span></span></p><div style=\\\"-webkit-tap-highlight-color:transparent;\\\"><pre style=\\\"-webkit-tap-highlight-color:transparent\\\"><div style=\\\"--en-codeblock:true;--en-meta:{&quot;title&quot;:&quot;&quot;,&quot;lang&quot;:&quot;Plain Text&quot;,&quot;theme&quot;:&quot;default&quot;,&quot;showLine&quot;:true,&quot;lineWrap&quot;:true};box-sizing: border-box; padding: 8px; font-family: Monaco, Menlo, Consolas, &quot;Courier New&quot;, monospace; font-size: 12px; color: rgb(51, 51, 51); border-top-left-radius: 4px; border-top-right-radius: 4px; border-bottom-right-radius: 4px; border-bottom-left-radius: 4px; background-color: rgb(251, 250, 248); border: 1px solid rgba(0, 0, 0, 0.14902); background-position: initial initial; background-repeat: initial initial; margin-top: 6px;\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">                </span></span><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">                </span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">                </span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">                </span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">&lt;!--p.</span><span style=\\\"-webkit-tap-highlight-color:transparent\\\">MsoNormal</span><span style=\\\"-webkit-tap-highlight-color:transparent\\\">{</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">        mso-style-</span><span style=\\\"-webkit-tap-highlight-color:transparent\\\">name</span><span style=\\\"-webkit-tap-highlight-color:transparent\\\">: 正文;</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">        mso-style-</span><span style=\\\"-webkit-tap-highlight-color:transparent\\\">parent</span><span style=\\\"-webkit-tap-highlight-color:transparent\\\">: </span><span style=\\\"-webkit-tap-highlight-color:transparent\\\">&quot;&quot;</span><span style=\\\"-webkit-tap-highlight-color:transparent\\\">;</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">        </span><span style=\\\"-webkit-tap-highlight-color:transparent\\\">margin</span><span style=\\\"-webkit-tap-highlight-color:transparent\\\">: 0pt;</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">        margin-</span><span style=\\\"-webkit-tap-highlight-color:transparent\\\">bottom</span><span style=\\\"-webkit-tap-highlight-color:transparent\\\">: .0001pt;</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">        mso-</span><span style=\\\"-webkit-tap-highlight-color:transparent\\\">pagination</span><span style=\\\"-webkit-tap-highlight-color:transparent\\\">: none;</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">        text-</span><span style=\\\"-webkit-tap-highlight-color:transparent\\\">justify</span><span style=\\\"-webkit-tap-highlight-color:transparent\\\">: inter-ideograph;</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">        mso-font-</span><span style=\\\"-webkit-tap-highlight-color:transparent\\\">kerning</span><span style=\\\"-webkit-tap-highlight-color:transparent\\\">: </span><span style=\\\"-webkit-tap-highlight-color:transparent\\\">1.</span><span style=\\\"-webkit-tap-highlight-color:transparent\\\">0000pt;</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">    }</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">            p.</span><span style=\\\"-webkit-tap-highlight-color:transparent\\\">paragraph</span><span style=\\\"-webkit-tap-highlight-color:transparent\\\">{</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">        mso-style-</span><span style=\\\"-webkit-tap-highlight-color:transparent\\\">noshow</span><span style=\\\"-webkit-tap-highlight-color:transparent\\\">: yes;</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">        margin-</span><span style=\\\"-webkit-tap-highlight-color:transparent\\\">top</span><span style=\\\"-webkit-tap-highlight-color:transparent\\\">: </span><span style=\\\"-webkit-tap-highlight-color:transparent\\\">5.</span><span style=\\\"-webkit-tap-highlight-color:transparent\\\">0000pt;</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">        margin-</span><span style=\\\"-webkit-tap-highlight-color:transparent\\\">right</span><span style=\\\"-webkit-tap-highlight-color:transparent\\\">: </span><span style=\\\"-webkit-tap-highlight-color:transparent\\\">0.</span><span style=\\\"-webkit-tap-highlight-color:transparent\\\">0000pt;</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">        margin-</span><span style=\\\"-webkit-tap-highlight-color:transparent\\\">bottom</span><span style=\\\"-webkit-tap-highlight-color:transparent\\\">: </span><span style=\\\"-webkit-tap-highlight-color:transparent\\\">5.</span><span style=\\\"-webkit-tap-highlight-color:transparent\\\">0000pt;</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">        margin-</span><span style=\\\"-webkit-tap-highlight-color:transparent\\\">left</span><span style=\\\"-webkit-tap-highlight-color:transparent\\\">: </span><span style=\\\"-webkit-tap-highlight-color:transparent\\\">0.</span><span style=\\\"-webkit-tap-highlight-color:transparent\\\">0000pt;</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">        mso-margin-top-</span><span style=\\\"-webkit-tap-highlight-color:transparent\\\">alt</span><span style=\\\"-webkit-tap-highlight-color:transparent\\\">: auto;</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">        mso-margin-bottom-</span><span style=\\\"-webkit-tap-highlight-color:transparent\\\">alt</span><span style=\\\"-webkit-tap-highlight-color:transparent\\\">: auto;</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">        text-</span><span style=\\\"-webkit-tap-highlight-color:transparent\\\">align</span><span style=\\\"-webkit-tap-highlight-color:transparent\\\">: left;</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">        font-</span><span style=\\\"-webkit-tap-highlight-color:transparent\\\">family</span><span style=\\\"-webkit-tap-highlight-color:transparent\\\">: 等线;</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">        mso-bidi-font-</span><span style=\\\"-webkit-tap-highlight-color:transparent\\\">family</span><span style=\\\"-webkit-tap-highlight-color:transparent\\\">: </span><span style=\\\"-webkit-tap-highlight-color:transparent\\\">'Times New Roman'</span><span style=\\\"-webkit-tap-highlight-color:transparent\\\">;</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">        font-</span><span style=\\\"-webkit-tap-highlight-color:transparent\\\">size</span><span style=\\\"-webkit-tap-highlight-color:transparent\\\">: </span><span style=\\\"-webkit-tap-highlight-color:transparent\\\">12.</span><span style=\\\"-webkit-tap-highlight-color:transparent\\\">0000pt;</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">    }</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">            --&gt;</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">#[test]</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">fn </span><span style=\\\"-webkit-tap-highlight-color:transparent\\\">test_match_full_order</span><span style=\\\"-webkit-tap-highlight-color:transparent\\\">() {</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">  </span><span style=\\\"-webkit-tap-highlight-color:transparent\\\">// Initialze the new order_book</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">  let mut order_book = OrderBook::new();</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">  // Create some buy orders.</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">  let buy_order_1 = Order::new(dec!(25), dec!(1004), BuyOrSell::Buy);</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">  let buy_order_2 = Order::new(dec!(40), dec!(1004), BuyOrSell::Buy);</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">  let buy_order_3 = Order::new(dec!(125), dec!(1003), BuyOrSell::Buy);</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">  let buy_order_4 = Order::new(dec!(100), dec!(1002), BuyOrSell::Buy);</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">  let buy_order_5 = Order::new(dec!(150), dec!(1001), BuyOrSell::Buy);</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">  // Create some sell orders.</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">  let sell_order_1 = Order::new(dec!(10), dec!(1005), BuyOrSell::Sell);</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">  let sell_order_2 = Order::new(dec!(50), dec!(1006), BuyOrSell::Sell);</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">  let sell_order_3 = Order::new(dec!(25), dec!(1007), BuyOrSell::Sell);</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">  let sell_order_4 = Order::new(dec!(150), dec!(1008), BuyOrSell::Sell);</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">  let sell_order_5 = Order::new(dec!(120), dec!(1009), BuyOrSell::Sell);</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">        </span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">   // Add the orders to the order_book</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">   order_book.add_order_to_orderbook(buy_order_1);</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">   order_book.add_order_to_orderbook(buy_order_2);</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">   order_book.add_order_to_orderbook(buy_order_3);</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">   order_book.add_order_to_orderbook(buy_order_4);</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">   order_book.add_order_to_orderbook(buy_order_5);</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">   order_book.add_order_to_orderbook(sell_order_1);</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">   order_book.add_order_to_orderbook(sell_order_2);</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">   order_book.add_order_to_orderbook(sell_order_3);</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">   order_book.add_order_to_orderbook(sell_order_4);</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">   order_book.add_order_to_orderbook(sell_order_5);</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">        </span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">        </span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">   assert_eq!(order_book.buy_volume(), Some(dec!(440)));</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">   assert_eq!(order_book.sell_volume(), Some(dec!(355)));</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">   // Example 1 : Buy 10 units at limit price of 1005</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">   let mut incoming_order_1 = Order::new(dec!(10), dec!(1005), BuyOrSell::Buy);</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">   order_book.match_limit_order(&amp;mut incoming_order_1);</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">   assert_eq!(incoming_order_1.quantity, dec!(0));</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">   assert_eq!(order_book.buy_volume(), Some(dec!(440)));</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">   assert_eq!(order_book.sell_volume(), Some(dec!(345)));</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">   // Example 2 : Sell 100 units at market price</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">   let sell_market_price = order_book.market_price(BuyOrSell::Sell).unwrap();</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">   assert_eq!(sell_market_price, dec!(1004));</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">   let mut incoming_order_2 = Order::new(dec!(100), sell_market_price, BuyOrSell::Sell);</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">   order_book.match_market_order(&amp;mut incoming_order_2);</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">   assert_eq!(incoming_order_2.quantity, dec!(0));</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">   assert_eq!(order_book.buy_volume(), Some(dec!(340)));</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">   assert_eq!(order_book.sell_volume(), Some(dec!(345)));</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">   // Example 3 : Buy 40 units at limit price of 1008</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">   let mut incoming_order_3 = Order::new(dec!(40), dec!(1008), BuyOrSell::Buy);</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">   order_book.match_limit_order(&amp;mut incoming_order_3);</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">   assert_eq!(incoming_order_3.quantity, dec!(0));</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">   assert_eq!(order_book.buy_volume(), Some(dec!(340)));</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">   assert_eq!(order_book.sell_volume(), Some(dec!(305)));</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">   // Example 4 : Sell 20 units at limit price of 1004</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">   let mut incoming_order_4 = Order::new(dec!(20), dec!(1004), BuyOrSell::Sell);</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">   order_book.match_limit_order(&amp;mut incoming_order_4);</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">   assert_eq!(incoming_order_4.quantity, dec!(20));</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">   assert_eq!(order_book.buy_volume(), Some(dec!(340)));</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">   assert_eq!(order_book.sell_volume(), Some(dec!(325)));</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\"> }</span></span></div></div></pre></div><p style=\\\"-webkit-tap-highlight-color:transparent;margin:0\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent;font-size:20px;font-weight:bold\\\">6.Testing Partial Order Execution</span></span><span lang=\\\"EN-US\\\" style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\"></span></span></p><p style=\\\"-webkit-tap-highlight-color:transparent;margin:0;text-align:justify;margin-top:3pt;margin-bottom:3pt;margin-left:0;margin-right:0\\\"><span style=\\\"-webkit-tap-highlight-color:transparent;display:inline-block;overflow:hidden;transform:rotate(0);width:554.1333333333333px;height:222.1887664041995px;text-indent:0\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><img src=\\\":/018daf9badb44fc9a7212389ee57fd76\\\" type=\\\"image/png\\\" data-filename=\\\"640.png\\\" height=\\\"222.189\\\" style=\\\"--en-marks:%7B%22align%22%3A%22center%22%7D;-webkit-tap-highlight-color:transparent;margin-left:0;margin-top:0;width:554.133px;height:222.189px\\\" width=\\\"554.133\\\"/></span></span></p><ul style=\\\"-webkit-tap-highlight-color:transparent;margin:0;list-style-type:disc\\\"><li style=\\\"-webkit-tap-highlight-color:transparent;font-size:14px\\\"><p style=\\\"-webkit-tap-highlight-color:transparent;margin:0\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent;font-size:14px\\\">Total buying volume is 10+25+50+40+120 = 245</span></span></p></li><li style=\\\"-webkit-tap-highlight-color:transparent;font-size:14px\\\"><p style=\\\"-webkit-tap-highlight-color:transparent;margin:0\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent;font-size:14px\\\">Total selling volume is 20+50+30+100+210 = 410</span></span></p></li></ul><p style=\\\"-webkit-tap-highlight-color:transparent;margin:0\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><br style=\\\"-webkit-tap-highlight-color:transparent\\\"/></span></p><p style=\\\"-webkit-tap-highlight-color:transparent;margin:0\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent;font-size:14px;font-weight:bold\\\">Example 1 : Buy 25 units at limit price of 1005</span></span></p><p style=\\\"-webkit-tap-highlight-color:transparent;margin:0\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent;font-size:14px\\\">As a buyer, I would always want that my order gets buyed at price of 1005 or lower since this is a limit order. Now if you check the order book there is already an order for selling at price 1005. We can match the orders here. But it is only 20 units. Remaining 5 units needs to be matched with some other order. But there is no order so eventually it is not possible and thus, We are left with no matching choice and add the order to the orderbook as a buy order of 5 units at price 1005.</span></span></p><p style=\\\"-webkit-tap-highlight-color:transparent;margin:0\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent;font-size:14px\\\">Thus Incoming Order’s quantity now becomes 5. And the selling volume from the orderbook reduces by 20 units from 410 to 390. But the buying volume increases in the orderbook by 5 units from 245 to 250.</span></span></p><p style=\\\"-webkit-tap-highlight-color:transparent;margin:0;text-align:justify;margin-top:3pt;margin-bottom:3pt;margin-left:0;margin-right:0\\\"><span style=\\\"-webkit-tap-highlight-color:transparent;display:inline-block;overflow:hidden;transform:rotate(0);width:554.1333333333333px;height:264.35107611548557px;text-indent:0\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><img src=\\\":/1f51965b8d12472ba2841ce4a399f71d\\\" type=\\\"image/png\\\" data-filename=\\\"640.png\\\" height=\\\"264.351\\\" style=\\\"--en-marks:%7B%22align%22%3A%22center%22%7D;-webkit-tap-highlight-color:transparent;margin-left:0;margin-top:0;width:554.133px;height:264.351px\\\" width=\\\"554.133\\\"/></span></span></p><p style=\\\"-webkit-tap-highlight-color:transparent;margin:0\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent;font-size:14px;font-weight:bold\\\">Example 2 : Sell 100 units at 1002</span></span></p><p style=\\\"-webkit-tap-highlight-color:transparent;margin:0\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent;font-size:14px\\\">As a seller at limit price of 1002, I would need my orders to be sold at price above or equal to 1002 in market. We have 5 units at 1005, 10 units at 1004, 25 units at 1003 and 50 units at 1002 which totals 90 units. Still 10 units are remaining that cannot be sold and will go straight into the orderbook.</span></span></p><p style=\\\"-webkit-tap-highlight-color:transparent;margin:0\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent;font-size:14px\\\">Thus Incoming Order’s quantity remains 10. And the buying volume from the orderbook reduces by 90 units from 250 to 160. But the selling volume increases in the orderbook by 10 units from 390 to 400.</span></span></p><p style=\\\"-webkit-tap-highlight-color:transparent;margin:0;text-align:justify;margin-top:3pt;margin-bottom:3pt;margin-left:0;margin-right:0\\\"><span style=\\\"-webkit-tap-highlight-color:transparent;display:inline-block;overflow:hidden;transform:rotate(0);width:554.1333333333333px;height:250.29690288713908px;text-indent:0\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><img src=\\\":/00436e2efbb048be9de7565534869c75\\\" type=\\\"image/png\\\" data-filename=\\\"640.png\\\" height=\\\"250.297\\\" style=\\\"--en-marks:%7B%22align%22%3A%22center%22%7D;-webkit-tap-highlight-color:transparent;margin-left:0;margin-top:0;width:554.133px;height:250.297px\\\" width=\\\"554.133\\\"/></span></span></p><p style=\\\"-webkit-tap-highlight-color:transparent;margin:0\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><br style=\\\"-webkit-tap-highlight-color:transparent\\\"/></span></p><p style=\\\"-webkit-tap-highlight-color:transparent;margin:0\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent;font-size:14px;font-weight:bold\\\">Example 3: Buy 30 units at market price</span></span></p><p style=\\\"-webkit-tap-highlight-color:transparent;margin:0\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent;font-size:14px\\\">As a buyer, I would always want that my order gets buyed at lowest price available. From the orderbook we can easily determine that the best possible buying price is for 10 units at 1002, 20 units at 1006.</span></span></p><p style=\\\"-webkit-tap-highlight-color:transparent;margin:0\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent;font-size:14px\\\">Thus Incoming Order’s quantity now becomes 0. And the selling volume from the orderbook reduces by 30 units from 400 to 370.</span></span></p><p style=\\\"-webkit-tap-highlight-color:transparent;margin:0;text-align:justify;margin-top:3pt;margin-bottom:3pt;margin-left:0;margin-right:0\\\"><span style=\\\"-webkit-tap-highlight-color:transparent;display:inline-block;overflow:hidden;transform:rotate(0);width:554.1333333333333px;height:250.07968503937008px;text-indent:0\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><img src=\\\":/da7bc520dfa149f684cd2e90bdcd996b\\\" type=\\\"image/png\\\" data-filename=\\\"640.png\\\" height=\\\"250.08\\\" style=\\\"--en-marks:%7B%22align%22%3A%22center%22%7D;-webkit-tap-highlight-color:transparent;margin-left:0;margin-top:0;width:554.133px;height:250.08px\\\" width=\\\"554.133\\\"/></span></span></p><p style=\\\"-webkit-tap-highlight-color:transparent;margin:0\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent;font-size:14px\\\">测试案例如下：</span></span></p><div style=\\\"-webkit-tap-highlight-color:transparent;\\\"><pre style=\\\"-webkit-tap-highlight-color:transparent\\\"><div style=\\\"--en-codeblock:true;--en-meta:{&quot;title&quot;:&quot;&quot;,&quot;lang&quot;:&quot;Plain Text&quot;,&quot;theme&quot;:&quot;default&quot;,&quot;showLine&quot;:true,&quot;lineWrap&quot;:true};box-sizing: border-box; padding: 8px; font-family: Monaco, Menlo, Consolas, &quot;Courier New&quot;, monospace; font-size: 12px; color: rgb(51, 51, 51); border-top-left-radius: 4px; border-top-right-radius: 4px; border-bottom-right-radius: 4px; border-bottom-left-radius: 4px; background-color: rgb(251, 250, 248); border: 1px solid rgba(0, 0, 0, 0.14902); background-position: initial initial; background-repeat: initial initial; margin-top: 6px;\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">   </span></span><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">#[test]</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">fn </span><span style=\\\"-webkit-tap-highlight-color:transparent\\\">test_match_partial_order</span><span style=\\\"-webkit-tap-highlight-color:transparent\\\">() {</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">    </span><span style=\\\"-webkit-tap-highlight-color:transparent\\\">// Initialze the new order_book</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">    let mut order_book = OrderBook::new();</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">    // Create some buy orders.</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">    let buy_order_1 = Order::new(dec!(10), dec!(1004), BuyOrSell::Buy);</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">    let buy_order_2 = Order::new(dec!(25), dec!(1003), BuyOrSell::Buy);</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">    let buy_order_3 = Order::new(dec!(50), dec!(1002), BuyOrSell::Buy);</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">    let buy_order_4 = Order::new(dec!(40), dec!(1001), BuyOrSell::Buy);</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">    let buy_order_5 = Order::new(dec!(120), dec!(1000), BuyOrSell::Buy);</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">    // Create some sell orders.</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">    let sell_order_1 = Order::new(dec!(20), dec!(1005), BuyOrSell::Sell);</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">    let sell_order_2 = Order::new(dec!(50), dec!(1006), BuyOrSell::Sell);</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">    let sell_order_3 = Order::new(dec!(30), dec!(1007), BuyOrSell::Sell);</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">    let sell_order_4 = Order::new(dec!(100), dec!(1008), BuyOrSell::Sell);</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">    let sell_order_5 = Order::new(dec!(210), dec!(1009), BuyOrSell::Sell);</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">    // Add the orders to the order_book</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">    order_book.add_order_to_orderbook(buy_order_1);</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">    order_book.add_order_to_orderbook(buy_order_2);</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">    order_book.add_order_to_orderbook(buy_order_3);</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">    order_book.add_order_to_orderbook(buy_order_4);</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">    order_book.add_order_to_orderbook(buy_order_5);</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">    order_book.add_order_to_orderbook(sell_order_1);</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">    order_book.add_order_to_orderbook(sell_order_2);</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">    order_book.add_order_to_orderbook(sell_order_3);</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">    order_book.add_order_to_orderbook(sell_order_4);</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">    order_book.add_order_to_orderbook(sell_order_5);</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">    assert_eq!(order_book.buy_volume(), Some(dec!(245)));</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">    assert_eq!(order_book.sell_volume(), Some(dec!(410)));</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">    // Example 1 : Buy 25 units at 1005</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">    let mut incoming_order_1 = Order::new(dec!(25), dec!(1005), BuyOrSell::Buy);</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">    order_book.match_limit_order(&amp;mut incoming_order_1);</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">    assert_eq!(incoming_order_1.quantity, dec!(5));</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">    assert_eq!(order_book.buy_volume(), Some(dec!(250)));</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">    assert_eq!(order_book.sell_volume(), Some(dec!(390)));</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">    // Example 2 : Sell 1002 units at 1002</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">    let mut incoming_order_2 = Order::new(dec!(100), dec!(1002), BuyOrSell::Sell);</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">    order_book.match_limit_order(&amp;mut incoming_order_2);</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">    assert_eq!(incoming_order_2.quantity, dec!(10));</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">    assert_eq!(order_book.buy_volume(), Some(dec!(160)));</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">    assert_eq!(order_book.sell_volume(), Some(dec!(400)));</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">    // Example 3 : Buy 30 units at Market Price</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">    let buy_market_price = order_book.market_price(BuyOrSell::Buy).unwrap();</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">    assert_eq!(buy_market_price, dec!(1002));</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">    let mut incoming_order_3 = Order::new(dec!(30), buy_market_price, BuyOrSell::Buy);</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">    order_book.match_market_order(&amp;mut incoming_order_3);</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">    assert_eq!(incoming_order_3.quantity, dec!(0));</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">    assert_eq!(order_book.buy_volume(), Some(dec!(160)));</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">    assert_eq!(order_book.sell_volume(), Some(dec!(370)));</span></span></div><div><span style=\\\"-webkit-tap-highlight-color:transparent\\\"><span style=\\\"-webkit-tap-highlight-color:transparent\\\">}</span></span></div></div></pre></div><p style=\\\"-webkit-tap-highlight-color:transparent;margin:0\\\"><span style=\\\"-webkit-tap-highlight-color:transparent;color:rgba(0,0,0,0.9);font-size:17px;font-family:&quot;mp-quote&quot;,-apple-system-font,BlinkMacSystemFont,&quot;Helvetica Neue&quot;,&quot;PingFang SC&quot;,&quot;Hiragino Sans GB&quot;,&quot;Microsoft YaHei UI&quot;,&quot;Microsoft YaHei&quot;,Arial,sans-serif;line-height:1.6;letter-spacing:0.034em;font-style:normal;font-weight:normal\\\"><span style=\\\"-webkit-tap-highlight-color:transparent;font-size:14px\\\">关于测试案例，作者参考的资料是：https://finlib.in/orders-matched-stock-exchange/。</span></span></p></div></div></div></div></div></span>\\\n</div></body></html>\\u0000\"]],\"start1\":0,\"start2\":0,\"length1\":0,\"length2\":165187}]"
metadata_diff: {"new":{"id":"090cba28966f437bb7b7c4b788133677","parent_id":"f67288c3a0be4374b5d532b5dcc3aabc","latitude":"0.00000000","longitude":"0.00000000","altitude":"0.0000","author":"","source_url":"","is_todo":0,"todo_due":0,"todo_completed":0,"source":"joplin-desktop","source_application":"net.cozic.joplin-desktop","application_data":"","order":1764348835046,"markup_language":2,"is_shared":0,"share_id":"","conflict_original_id":"","master_key_id":"","user_data":"","deleted_time":0},"deleted":[]}
encryption_cipher_text: 
encryption_applied: 0
updated_time: 2025-11-28T21:04:07.842Z
created_time: 2025-11-28T21:04:07.842Z
type_: 13