{"id":481621,"date":"2026-05-29T15:29:47","date_gmt":"2026-05-29T15:29:47","guid":{"rendered":"https:\/\/savepearlharbor.com\/?p=481621"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=481621","title":{"rendered":"\u0423\u0434\u043e\u0431\u043d\u0430\u044f \u043a\u043e\u043c\u043f\u043e\u043d\u043e\u0432\u043a\u0430 (\u0432 \u0440\u0430\u0441\u0442\u0435)"},"content":{"rendered":"<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<p>\u041f\u043e\u0447\u0438\u0442\u0430\u043b \u0443 \u0438\u0437\u0432\u0435\u0441\u0442\u043d\u043e\u0433\u043e \u0447\u0435\u043b\u0430 \u043e \u043f\u043e\u0441\u0442-\u0443\u0441\u043b\u043e\u0432\u0438\u044f\u0445 (\u201c\u043f\u043e\u0441\u0442\u043a\u043e\u043d\u0434\u0438\u0448\u043d\u0441\u201d) \u043d\u0430 \u0441\u0432\u0438\u0444\u0442\u0435 &#8212; \u0438 \u0437\u043d\u0430\u0435\u0442\u0435, \u0440\u0430\u0441\u0442 \u0432\u0441\u0435 \u0440\u0430\u0432\u043d\u043e \u043b\u0443\u0447\u0448\u0435. \u0422\u0443\u043f\u043e \u043f\u0440\u0438\u044f\u0442\u043d\u0435\u0435 \u044f\u0437\u044b\u043a \u0434\u0430\u0436\u0435 \u0434\u043b\u044f \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u0442\u043e\u0440\u0433\u043e\u0432\u043e\u0439 \u0431\u0438\u0440\u0436\u0438 \u0441\u043e \u0441\u0432\u043e\u0435\u0439 \u043c\u0443\u0434\u0440\u0435\u043d\u043e\u0439 \u0431\u0438\u0437\u043d\u0435\u0441-\u043b\u043e\u0433\u0438\u043a\u043e\u0439 &#8212; \u0442\u0438\u043a\u0435\u0440\u0430\u043c\u0438, \u043b\u043e\u0433\u0438\u043a\u043e\u0439 \u0441\u0442\u043e\u043f\u043e\u0432 \u0438 \u043b\u0438\u043c\u0438\u0442\u043d\u044b\u0445 \u043e\u0440\u0434\u0435\u0440\u043e\u0432, \u043c\u043d\u043e\u0433\u043e\u043f\u043e\u0442\u043e\u0447\u043d\u043e\u0441\u0442\u044c\u044e, \u043f\u0430\u0442\u0442\u0435\u0440\u043d \u043c\u0430\u0442\u0447\u0438\u043d\u0433\u043e\u043c, \u0434\u0435\u0446\u0435\u043d\u0442\u0440\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043d\u043d\u043e\u0439 \u0441\u0435\u0442\u044c\u044e, \u0433\u0440\u0430\u0444\u0438\u043a\u0430\u043c\u0438, \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044f\u043c\u0438 \u043f\u0430\u0440\u0435\u0442\u043e, \u0433\u0430\u0443\u0441\u0441\u0430, \u0441\u0442\u044c\u044e\u0434\u0435\u043d\u0442\u0430. \u041d\u0435 \u0442\u0440\u043e\u0433\u0430\u044f \u0434\u0435\u0440\u0435\u0432\u0430\u0442\u0438\u0432\u043e\u0432 \u0438 \u0440\u0430\u0437\u043d\u0438\u0446\u0443 \u0444\u043e\u0440\u0432\u0430\u0440\u0434\/\u0444\u044c\u044e\u0447\u0435\u0440\u0441, \u0435\u0441\u0442\u044c \u201c\u0430\u0441\u043a\u201d \u0438 \u201c\u0431\u0438\u0434\u201d, \u0442\u0440\u0438 \u0432\u0438\u0434\u0430 \u043e\u0440\u0434\u0435\u0440\u043e\u0432, \u0442\u0438\u043a\u0435\u0440\u044b, \u0432\u0437\u043b\u0435\u0442\u044b \u0438 \u043f\u0430\u0434\u0435\u043d\u0438\u044f, \u0432\u0438\u0441\u043a\u0430\u0440\u044c-\u0442\u0440\u0435\u0432\u043e\u0433\u0438-\u0440\u043e\u0431\u043e\u0442\u044b &#8212; \u043a\u043e\u0440\u043e\u0447\u0435, \u0447\u0442\u043e \u043d\u0443\u0436\u043d\u043e \u0441\u0434\u0435\u043b\u0430\u0435\u043c (\u043a\u0440\u043e\u043c\u0435 \u0440\u043e\u0431\u043e\u0442\u043e\u0432), \u0430 \u0434\u043b\u044f \u0432\u0441\u0435\u0433\u043e \u043e\u0441\u0442\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u043c\u0430\u0441\u0442\u0435\u0440 \u043a\u0430\u0440\u0434 (\u0438\u043b\u0438 \u041c\u0418\u0420, \u0430 \u0434\u043b\u044f \u0435\u0432\u0440\u043e\u043f\u0435\u0439\u0446\u0435\u0432 \u201c\u0435-\u0446\u201d \u043a\u0430\u0440\u0442\u044b).<\/p>\n<p>\u041f\u0440\u043e\u0441\u0442\u0435\u0439\u0448\u0430\u044f \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0439 \u0431\u0438\u0440\u0436\u044b (\u0442\u0438\u043a\u0435\u0440\u0430) \u0441\u043a\u043b\u0430\u0434\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u0432\u0441\u0435\u0433\u043e \u0438\u0437 \u0434\u0432\u0443\u0445 \u043a\u0443\u0447 (binary heap) \u0438\u043b\u0438 \u0434\u0432\u0443\u0445 \u0441\u0442\u0430\u043a\u0430\u043d\u043e\u0432: \u201c\u0430\u0441\u043a\u201d (\u043f\u0440\u043e\u0434\u0430\u0436\u0430) \u0438 \u201c\u0431\u0438\u0434\u201d (\u043f\u043e\u043a\u0443\u043f\u043a\u0430), \u0438 \u0441\u043b\u0435\u0434\u0441\u0442\u0432\u0438\u0435\u043c \u0438\u0445 \u043f\u0435\u0440\u0435\u0441\u0435\u0447\u0435\u043d\u0438\u044f \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0441\u0434\u0435\u043b\u043a\u0430. \u041a\u0442\u043e-\u043b\u0438\u0431\u043e \u0441\u043e\u0437\u0434\u0430\u0435\u0442 \u043e\u0440\u0434\u0435\u0440 \u043d\u0430 \u043f\u043e\u043a\u0443\u043f\u043a\u0443, \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u044f \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e, \u0438 \u043e\u0440\u0434\u0435\u0440 \u0438\u0441\u043f\u043e\u043b\u043d\u044f\u0435\u0442\u0441\u044f \u043c\u0433\u043d\u043e\u0432\u0435\u043d\u043d\u043e \u043f\u043e \u0432\u0435\u0440\u0445\u043d\u0435\u0439 \u0446\u0435\u043d\u0435 \u0432 \u0441\u0442\u0430\u043a\u0430\u043d\u0435. \u0415\u0441\u043b\u0438 \u0445\u043e\u0447\u0435\u0442\u0441\u044f \u043a\u0443\u043f\u0438\u0442\u044c \u0434\u0435\u0448\u0435\u0432\u043b\u0435, \u0441\u043e\u0437\u0434\u0430\u0435\u0442\u0441\u044f \u043b\u0438\u043c\u0438\u0442\u043d\u044b\u0439 \u043e\u0440\u0434\u0435\u0440 \u0441 \u0443\u043a\u0430\u0437\u0430\u043d\u0438\u0435\u043c \u0446\u0435\u043d\u044b, \u0430 \u0441\u0434\u0435\u043b\u043a\u0430 \u043e\u0436\u0438\u0434\u0430\u0435\u0442 \u043f\u0440\u043e\u0434\u0430\u0432\u0446\u0430, \u0441\u043e\u0433\u043b\u0430\u0441\u043d\u043e\u0433\u043e \u043f\u0440\u043e\u0434\u0430\u0442\u044c \u0432\u0430\u043c \u043f\u043e \u0443\u043a\u0430\u0437\u0430\u043d\u043d\u043e\u0439 \u0446\u0435\u043d\u0435. \u0421 \u0442\u043e\u0447\u043a\u0438 \u0437\u0440\u0435\u043d\u0438\u044f \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u043d\u0435\u0442 \u043e\u0441\u043e\u0431\u043e\u0439 \u0440\u0430\u0437\u043d\u0438\u0446\u044b \u043c\u0435\u0436\u0434\u0443 \u201casap\u201d \u0438 \u043b\u0438\u043c\u0438\u0442\u043d\u044b\u043c\u0438 \u043e\u0440\u0434\u0435\u0440\u0430\u043c\u0438. \u0427\u0443\u0442\u044c \u0441\u043b\u043e\u0436\u043d\u0435\u0435 \u0441\u0442\u043e\u043f\u044b.<\/p>\n<p>\u0421\u0442\u043e\u043f\u044b (\u043e\u0440\u0434\u0435\u0440\u044b) \u0437\u0430\u0432\u0438\u0441\u044f\u0442 \u043e\u0442 \u0446\u0435\u043d \u043d\u0430 \u0442\u0430\u0431\u043b\u043e \u0438 \u0438\u0441\u043f\u043e\u043b\u043d\u044f\u044e\u0442\u0441\u044f \u043d\u0430 \u043f\u0440\u043e\u0434\u0430\u0436\u0443 \u043f\u043e \u043b\u044e\u0431\u043e\u0439 \u0446\u0435\u043d\u0435 (\u043c\u0433\u043d\u043e\u0432\u0435\u043d\u043d\u043e) \u043f\u0440\u0438 \u0446\u0435\u043d\u0435 \u043d\u0430 \u0442\u0430\u0431\u043b\u043e \u0440\u0430\u0432\u043d\u043e\u0439 \u0438\u043b\u0438 \u043c\u0435\u043d\u044c\u0448\u0435 \u0443\u043a\u0430\u0437\u0430\u043d\u043d\u043e\u0439 \u0432 \u043e\u0440\u0434\u0435\u0440\u0435. \u0421\u0442\u043e\u043f\u044b \u043c\u043e\u0433\u0443\u0442 \u0442\u0440\u0438\u0433\u0435\u0440\u043d\u0443\u0442\u044c \u0434\u0440\u0443\u0433\u0438\u0435 \u0441\u0442\u043e\u043f\u044b, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0432 \u0440\u0435\u0430\u043b\u0438\u0437\u0446\u0430\u0438\u0438 \u0447\u0443\u0442\u044c \u0441\u043b\u043e\u0436\u043d\u0435\u0435.<\/p>\n<p>\u0411\u0438\u0440\u0436\u0430 \u043d\u0430 \u0431\u0443\u043c\u0430\u0433\u0435 \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u043a\u0430\u043a-\u0442\u043e \u0442\u0430\u043a: StockRaw -&gt; StockRawWithStop -&gt; StockWithHistory -&gt; Broker -&gt; Client. \u0412 \u0440\u0430\u0441\u0442\u0435 \u0432\u043f\u043e\u043b\u043d\u0435 \u0435\u0441\u0442\u0435\u0441\u0442\u0432\u0435\u043d\u043d\u043e \u0437\u0430\u0432\u0435\u0440\u043d\u0443\u0442\u044c \u0432 \u201c\u0435\u043d\u0430\u043c\u044b\u201d \u0434\u0430\u043d\u043d\u044b\u0435 \u0438 \u0443\u0434\u043e\u0431\u043d\u043e \u0440\u0430\u0441\u043a\u0440\u044b\u0442\u044c \u043f\u0430\u0442\u0442\u0435\u0440\u043d \u043c\u0430\u0442\u0447\u0438\u043d\u0433\u043e\u043c \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u044e\u0449\u0435\u0439 \u0441\u0442\u043e\u0440\u043e\u043d\u044b \u043d\u0430 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0432\u0443\u0435\u0449\u0435\u043c \u0443\u0440\u043e\u0432\u043d\u0435, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440: <code>Intent::Buy(Limit(Price(p), Quantity(q)))<\/code> \u0438\u043b\u0438 <code>Intent::Sell(Asap(Quantity(q)))<\/code> &#8212; \u0431\u0440\u043e\u043a\u0435\u0440\u0443 \u0432\u0430\u0436\u043d\u043e \u043b\u0438\u0448\u044c \u043d\u0430\u043c\u0435\u0440\u0435\u043d\u0438\u0435 \u043a\u043b\u0438\u0435\u043d\u0442\u0430 (intent), \u0438\u043b\u0438 \u043b\u0438\u043c\u0438\u0442\u043d\u044b\u0439 \u043e\u0440\u0434\u0435\u0440 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442\u0441\u044f \u043d\u0430 \u043d\u0438\u0436\u043d\u0435\u043c \u0443\u0440\u043e\u0432\u043d\u0435.<\/p>\n<p>\u041c\u043e\u0436\u043d\u043e \u043e\u0442\u043c\u0435\u0442\u0438\u0442\u044c, \u0447\u0442\u043e \u0432 \u0440\u0430\u0441\u0442\u0435 \u043e\u0447\u0435\u043d\u044c \u0443\u0434\u043e\u0431\u043d\u043e \u043a\u043e\u043c\u043f\u043e\u043d\u043e\u0432\u0430\u0442\u044c &#8212; \u043d\u0438\u0436\u0435 \u0447\u0435\u0442\u044b\u0440\u0435 \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u0430 \u043f\u043e\u043a\u0440\u044b\u0442\u044b \u0434\u0432\u0443\u043c\u044f \u201c\u043a\u0435\u0439\u0437\u0430\u043c\u0438\u201d, \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u043c\u043e\u0435 \u044d\u043b\u0435\u0433\u0430\u043d\u0442\u043d\u043e \u0440\u0430\u0437\u0432\u0435\u0440\u043d\u0443\u0442\u043e, \u0441\u043b\u0435\u043f\u043b\u0435\u043d\u043e \u0438 \u0437\u0430\u0432\u0435\u0440\u043d\u0443\u0442\u043e \u043e\u0431\u0440\u0430\u0442\u043d\u043e:<\/p>\n<pre><code class=\"rust\">match (x,y) {(Some(xs), Some(ys)) =&gt; Some(vec![xs, ys].concat()), (x,y) =&gt; x.or(y)}<\/code><div class=\"code-explainer\"><a href=\"https:\/\/sourcecraft.dev\/\" class=\"tm-button code-explainer__link\" style=\"visibility: hidden;\"><img style=\"width:87px;height:14px;object-fit:cover;object-position:left;\"\/><\/a><\/div><\/pre>\n<p>\u041f\u043e\u0441\u0442-\u0443\u0441\u043b\u043e\u0432\u0438\u0435 (\u201c\u043f\u043e\u0441\u0442\u043a\u043e\u043d\u0434\u0438\u0448\u043d\u0441\u201d) &#8212; \u044d\u0442\u043e \u0442\u0430\u043a\u043e\u0439 \u0441\u043f\u043e\u0441\u043e\u0431 \u043d\u0435 \u043f\u043e\u0442\u0435\u0440\u044f\u0442\u044c \u043a\u043e\u0440\u0440\u0435\u043a\u0442\u043d\u043e\u0441\u0442\u044c \u0432 \u0441\u043b\u0435\u0433\u043a\u0430 \u0437\u0430\u043f\u0443\u0442\u0430\u043d\u043d\u043e\u0439 \u0431\u0438\u0437\u043d\u0435\u0441-\u043b\u043e\u0433\u0438\u043a\u0435. \u0412 \u043f\u0440\u0438\u043c\u0435\u0440\u0435 (\u043d\u0438\u0436\u0435) \u043c\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c \u201c\u0434\u0438\u0444\u0444\u0435\u0440\u0435\u043d\u0446\u201d \u043c\u0435\u0436\u0434\u0443 \u043d\u0430\u0448\u0435\u0439 \u0431\u0438\u0440\u0436\u0435\u0439 \u0438 \u043e\u0440\u0434\u0435\u0440\u043e\u043c, \u0438 \u0434\u0430\u043b\u0435\u0435 (\u0432 \u043c\u0435\u0442\u043e\u0434\u0435 \u201cdeal\u201d) \u0443\u0441\u0438\u043b\u0438\u0432\u0430\u0435\u043c \u043f\u043e\u0441\u0442-\u0443\u0441\u043b\u043e\u0432\u0438\u0435, \u0433\u0430\u0440\u0430\u043d\u0442\u0438\u0440\u0443\u044f \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u043e\u0440\u0434\u0435\u0440\u043e\u0432 \u043d\u0430 \u0431\u0438\u0440\u0436\u0435 \u0434\u043e \u0438 \u043f\u043e\u0441\u043b\u0435 \u0441\u0434\u0435\u043b\u043a\u0438.<\/p>\n<pre><code class=\"rust\">impl Stock {\/\/\/ postcondition: \/\/\/ stock.quantity - new_stock.quantity &lt;= order.quantity * 2 fn difference(&amp;mut self, x: Order) {self.ask.pop().map(|Reverse(a)| a - x).map(|a| if a.quantity != 0 { self.ask.push(Reverse(a)); } );self.bid.pop().map(|b| b - x).map(|b| if b.quantity != 0 { self.bid.push(b); } );}\/\/\/ postcondition: \/\/\/ stock.quantity - new_stock.quantity = ret.quantity * 2  fn deal(&amp;mut self) -&gt; Option&lt;Deal&gt; {self.ask.peek().zip(self.bid.peek()).and_then(|(Reverse(a), b)| if a &lt;= b { Some((*a,*b)) } else { None }).map(|(a, b)| {self.difference(a &amp; b);Deal::new(a, b) })}}<\/code><div class=\"code-explainer\"><a href=\"https:\/\/sourcecraft.dev\/\" class=\"tm-button code-explainer__link\" style=\"visibility: hidden;\"><img style=\"width:14px;height:14px;object-fit:cover;object-position:left;\"\/><\/a><\/div><\/pre>\n<p>\u041c\u043d\u043e\u0433\u043e\u043f\u043e\u0442\u043e\u0447\u043d\u043e\u0435 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u0441\u043b\u043e\u0436\u043d\u0430\u044f \u0448\u0442\u0443\u043a\u0430, \u0438 \u0432 \u0440\u0430\u0441\u0442\u0435, \u0438 \u0433\u0434\u0435-\u043b\u0438\u0431\u043e \u0435\u0449\u0435. \u0422\u0443\u043f\u043e, \u043a\u0430\u043a \u043c\u043d\u0435 \u043a\u0430\u0436\u0435\u0442\u0441\u044f, \u043d\u0435 \u0445\u0432\u0430\u0442\u0430\u0435\u0442 \u043f\u0440\u0438\u043c\u0438\u0442\u0438\u0432\u043e\u0432 &#8212; \u043d\u0435 \u0442\u0435\u0445 \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0430\u0442\u043e\u043c\u0438\u043a\u0438, \u0430 \u043d\u0430 \u0443\u0440\u043e\u0432\u043d\u0435 \u043a\u043e\u043c\u043f\u043e\u043d\u043e\u0432\u043a\u0438. \u0421\u0435\u0439\u0447\u0430\u0441 \u043c\u043d\u043e\u0433\u043e\u043f\u043e\u0442\u043e\u0447\u043d\u043e\u0435 \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442, \u0441\u043e\u0440\u044f\u043d \u0437\u0430 \u043c\u0435\u0442\u0430\u0444\u043e\u0440\u0443 &#8212; \u043a\u0430\u043a \u043e\u0434\u043d\u043e\u0432\u0440\u0435\u043c\u0435\u043d\u043d\u0430\u044f \u043e\u0431\u0436\u0430\u0440\u043a\u0430 \u0438 \u0437\u0430\u043c\u043e\u0440\u043e\u0437\u043a\u0430 \u043c\u044f\u0441\u043d\u043e\u0433\u043e. \u0412 \u043e\u0431\u044b\u0447\u043d\u043e\u043c \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0438 \u0443 \u043d\u0430\u0441 \u0435\u0441\u0442\u044c \u0444\u0443\u043d\u043a\u0446\u0438\u0438, \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u044b, \u043f\u0435\u0442\u043b\u0438 (loop), \u0440\u0435\u043a\u0443\u0440\u0441\u0438\u044f &#8212; \u0443 \u0440\u0430\u0441\u0442\u0430, \u043a\u0441\u0442\u0430\u0442\u0438, \u043f\u0440\u0435\u043a\u0440\u0430\u0441\u043d\u044b\u0435 \u043f\u0440\u0438\u043c\u0438\u0442\u0438\u0432\u044b \u0434\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u0441 \u043f\u0435\u0442\u043b\u044f\u043c\u0438 (<code>std::iter::successors<\/code> \u0438 <code>std::iter::from_fn<\/code>) &#8212; \u0438 \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c \u0445\u043e\u0440\u043e\u0448\u0438\u0435 \u0441\u0438\u0441\u0442\u0435\u043c\u044b, \u043d\u043e \u043e\u0442\u043d\u043e\u0441\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u043c\u0435\u0434\u043b\u0435\u043d\u043d\u044b\u0435. \u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u0443\u0441\u043a\u043e\u0440\u044f\u0435\u043c \u0441\u0430\u043c\u044b\u043c \u0442\u0443\u043f\u044b\u043c \u0438 \u043f\u0440\u043e\u0441\u0442\u044b\u043c \u0441\u043f\u043e\u0441\u043e\u0431\u043e\u043c &#8212; \u043c\u0443\u0442\u0435\u043a\u0441\u043e\u043c (\u0447\u0442\u043e-\u0442\u043e \u0442\u0438\u043f\u0430 <code>static STOCK: Mutex&lt;Stock&gt; = Mutex::new(Stock::new())<\/code>), \u043d\u0435 \u0437\u0430\u0431\u044b\u0432\u0430\u044f \u043f\u043e\u0434\u0430\u0432\u0430\u0442\u044c \u043e\u0440\u0434\u0435\u0440\u044b \u043f\u0430\u0447\u043a\u0430\u043c\u0438 (batch), \u043a\u043e\u043c\u043f\u0435\u043d\u0441\u0438\u0440\u0443\u044f \u0441\u0442\u043e\u0438\u043c\u043e\u0441\u0442\u044c \u043b\u043e\u043a\u0430.<\/p>\n<p>\u041f\u0438\u0448\u0435\u043c \u044e\u043d\u0438\u0442 \u0442\u0435\u0441\u0442\u044b, \u0441\u0442\u0440\u043e\u0438\u043c \u0433\u0440\u0430\u0444\u0438\u043a\u0430\u043c\u0438 \u0442\u0440\u0438 \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044f (\u043d\u0430 \u0440\u0438\u0441\u0443\u043d\u043a\u0435 \u043d\u0438\u0436\u0435), \u0438 \u043e\u0434\u043d\u043e \u0438\u0437 \u043d\u0438\u0445 (\u043f\u0430\u0440\u0435\u0442\u043e) \u0432\u0437\u044f\u0442\u043e \u043f\u043e \u043b\u043e\u0433\u0430\u0440\u0438\u0444\u043c\u0438\u0447\u0435\u0441\u043a\u043e\u0439 \u0448\u043a\u0430\u043b\u0435. \u041d\u0430 \u0433\u0440\u0430\u0444\u0438\u043a\u0435 \u0432 \u0442\u0435\u0447\u0435\u043d\u0438\u0435 \u0433\u043e\u0434\u0430 \u0447\u0435\u0442\u044b\u0440\u0435 \u043a\u043b\u0438\u0435\u043d\u0442\u0430 \u043f\u044b\u0442\u0430\u044e\u0442\u0441\u044f \u0432\u044b\u0438\u0433\u0440\u0430\u0442\u044c \u0443 \u0440\u044b\u043d\u043a\u0430 \u043d\u0430 \u043a\u0430\u0436\u0434\u043e\u0439 \u043c\u0438\u043d\u0443\u0442\u0435, \u0430 \u0442\u0440\u0438 \u0444\u043e\u043d\u0434\u0430 &#8212; \u0441\u043e \u0441\u0434\u0435\u043b\u043a\u0430\u043c\u0438 \u0440\u0430\u0437 \u0432 \u0434\u0435\u043d\u044c (\u0447\u0442\u043e-\u0442\u043e \u0442\u0438\u043f\u0430 <code>Client{vol: 0.01, p: 0.5, quantity: 1000, distribution, s: Strategy::Limit}<\/code>).<\/p>\n<figure class=\"full-width \"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/edf\/c45\/89c\/edfc4589c1924811eb69e8fb63e32526.png\" alt=\"\u0422\u0440\u0438 \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044f\" title=\"\u0422\u0440\u0438 \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044f\" width=\"1397\" height=\"450\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/r\/w780\/getpro\/habr\/upload_files\/edf\/c45\/89c\/edfc4589c1924811eb69e8fb63e32526.png 780w,&#10;       https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/edf\/c45\/89c\/edfc4589c1924811eb69e8fb63e32526.png 781w\" loading=\"lazy\" decode=\"async\"\/><\/p>\n<div><figcaption>\u0422\u0440\u0438 \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044f<\/figcaption><\/div>\n<\/figure>\n<p>\u0414\u043b\u044f \u0441\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u044f \u0433\u0440\u0430\u0444\u0438\u043a (\u0433\u0435\u043e\u043c\u0435\u0442\u0440\u0438\u0447\u0435\u0441\u043a\u043e\u0433\u043e) \u0431\u0440\u043e\u0443\u043d\u043e\u0432\u0441\u043a\u043e\u0433\u043e \u0434\u0432\u0438\u0436\u0435\u043d\u0438\u044f \u0430\u043a\u0442\u0438\u0432\u0430 \u0441 \u0432\u043e\u043b\u0430\u0442\u0438\u043b\u044c\u043d\u043e\u0441\u0442\u044c\u044e \u0432 \u043e\u0434\u0438\u043d \u043f\u0440\u043e\u0446\u0435\u043d\u0442 \u043d\u0430 \u0434\u0435\u043d\u044c \u0438\u043b\u0438 15.7 % \u0432 \u0433\u043e\u0434.<\/p>\n<figure class=\"full-width \"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/cfd\/0b7\/5c6\/cfd0b75c644dd94122805c9427ac4d85.png\" alt=\"\u0411\u0440\u043e\u0443\u043d\u043e\u0432\u0441\u043a\u043e\u0435 \u0434\u0432\u0438\u0436\u0435\u043d\u0438\u0435\" title=\"\u0411\u0440\u043e\u0443\u043d\u043e\u0432\u0441\u043a\u043e\u0435 \u0434\u0432\u0438\u0436\u0435\u043d\u0438\u0435\" width=\"1397\" height=\"450\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/r\/w780\/getpro\/habr\/upload_files\/cfd\/0b7\/5c6\/cfd0b75c644dd94122805c9427ac4d85.png 780w,&#10;       https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/cfd\/0b7\/5c6\/cfd0b75c644dd94122805c9427ac4d85.png 781w\" loading=\"lazy\" decode=\"async\"\/><\/p>\n<div><figcaption>\u0411\u0440\u043e\u0443\u043d\u043e\u0432\u0441\u043a\u043e\u0435 \u0434\u0432\u0438\u0436\u0435\u043d\u0438\u0435<\/figcaption><\/div>\n<\/figure>\n<p>\u0418\u0441\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0435 \u0431\u0438\u0440\u0436\u0438 (\u0442\u0438\u043a\u0435\u0440\u0430) \u0434\u043e\u0432\u043e\u043b\u044c\u043d\u043e-\u0442\u0430\u043a\u0438 \u043f\u0440\u044f\u043c\u043e\u043b\u0438\u043d\u0435\u0439\u043d\u043e\u0435, \u0438 \u0434\u043b\u044f \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0434\u0435\u0446\u0435\u043d\u0442\u0440\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043d\u043d\u043e\u0439 \u0431\u0438\u0440\u0436\u0438 \u043d\u0430\u043c \u043d\u0443\u0436\u0435\u043d \u0435\u0449\u0435 \u0438 \u0445\u0435\u0448, \u0438 \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0430 \u0433\u043e\u043b\u043e\u0441\u043e\u0432\u0430\u043d\u0438\u0435\u043c &#8212; \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u043c (\u043d\u0430 \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0443) \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0441\u0434\u0435\u043b\u043a\u0438 &#8212; \u0435\u0441\u043b\u0438 \u043d\u0435 \u043e\u043a, \u0431\u0435\u0440\u0435\u043c \u0432\u0435\u0440\u0441\u0438\u044e \u0440\u0435\u0431\u044f\u0442, \u0432 \u043f\u0440\u043e\u0442\u0438\u0432\u043d\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u043a\u043e\u043c\u043c\u0438\u0442\u0438\u043c\u0441\u044f \u043f\u043e\u0441\u043b\u0435 \u201c\u0434\u0440\u0430\u0439\u0440\u0430\u043d\u0430\u201d (dry_run). \u0425\u0435\u0448 \u0431\u0435\u0440\u0435\u043c \u0440\u0430\u0432\u043d\u044b\u043c \u043e\u0440\u0434\u0435\u0440\u0443 \u044e\u0437\u0435\u0440\u0430 \u0438 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0443 \u0441\u0434\u0435\u043b\u043a\u0438. \u201c\u0414\u0440\u0430\u0439\u0420\u0430\u043d\u201d \u0443\u0434\u043e\u0431\u043d\u043e \u0432\u044b\u043d\u0435\u0441\u0442\u0438 \u0432 \u201c\u0442\u0440\u044d\u0439\u0442\u201d, \u0438 \u0434\u043b\u044f \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0431\u0435\u0437 \u0431\u0430\u0433\u043e\u0432 \u043f\u043e\u043c\u043e\u0433\u0430\u0435\u0442 \u0441\u043e\u0431\u043b\u044e\u0434\u0435\u043d\u0438\u0435 \u043f\u043e\u0441\u0442-\u0443\u0441\u043b\u043e\u0432\u0438\u0439.<\/p>\n<pre><code class=\"rust\">impl Stock  {\/\/\/ postcondition: \/\/\/ stock.quantity == new_stock.quantity fn ask_dry_run(&amp;mut self, order: Order) -&gt; Vec&lt;Deal&gt; {self.ask.push(Reverse(order));let (quantity, deals) = self.execute_ask_dry_run();if quantity != order.quantity { self.ask.pop(); } deals}\/\/\/ postcondition: \/\/\/ stock.bid.quantity == new_stock.bid.quantity fn execute_ask_dry_run(&amp;mut self) -&gt; (u32, Vec&lt;Deal&gt;) {let deals = self.execute();for d in &amp;deals { self.bid.push(d.bid); }(deals.iter().map(|d| d.quantity).sum(), deals)}  }<\/code><div class=\"code-explainer\"><a href=\"https:\/\/sourcecraft.dev\/\" class=\"tm-button code-explainer__link\" style=\"visibility: hidden;\"><img style=\"width:14px;height:14px;object-fit:cover;object-position:left;\"\/><\/a><\/div><\/pre>\n<p>\u0420\u0430\u0441\u0442 \u043d\u0435 \u201c\u044d\u0440\u043b\u0430\u043d\u0433\u201d, \u043d\u043e \u0447\u0442\u043e-\u0442\u043e \u0443\u043c\u0435\u0435\u0442 \u0432 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u044f\u0445: \u0434\u043e\u0432\u043e\u043b\u044c\u043d\u043e \u0443\u0434\u043e\u0431\u043d\u043e \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u043e\u0431\u0440\u0430\u0442\u043d\u044b\u0439 \u0430\u0434\u0440\u0435\u0441 (\u0447\u0430\u0441\u0442\u044c \u043a\u0430\u043d\u0430\u043b\u0430) \u0432 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435:<\/p>\n<pre><code class=\"rust\">impl Host {fn ask_verify(&amp;self, p: Payload) -&gt; Vec&lt;Receiver&lt;Msg&gt;&gt; {self.hosts.iter().map(|host| {let (tx, rx) = channel();host.send((p, tx));return rx;}).collect()}}<\/code><div class=\"code-explainer\"><a href=\"https:\/\/sourcecraft.dev\/\" class=\"tm-button code-explainer__link\" style=\"visibility: hidden;\"><img style=\"width:14px;height:14px;object-fit:cover;object-position:left;\"\/><\/a><\/div><\/pre>\n<p>\u041d\u0430 \u0441\u0435\u0433\u043e\u0434\u043d\u044f \u0432\u0441\u0435. \u0423\u0434\u0430\u0447\u043d\u043e\u0433\u043e \u043a\u043e\u0434\u0438\u043d\u0433\u0430 \ud83d\ude42<\/p>\n<\/div>\n<p>\u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/articles\/1041308\/\">https:\/\/habr.com\/ru\/articles\/1041308\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u041f\u043e\u0447\u0438\u0442\u0430\u043b \u0443 \u0438\u0437\u0432\u0435\u0441\u0442\u043d\u043e\u0433\u043e \u0447\u0435\u043b\u0430 \u043e \u043f\u043e\u0441\u0442-\u0443\u0441\u043b\u043e\u0432\u0438\u044f\u0445 (\u201c\u043f\u043e\u0441\u0442\u043a\u043e\u043d\u0434\u0438\u0448\u043d\u0441\u201d) \u043d\u0430 \u0441\u0432\u0438\u0444\u0442\u0435 &#8212; \u0438 \u0437\u043d\u0430\u0435\u0442\u0435, \u0440\u0430\u0441\u0442 \u0432\u0441\u0435 \u0440\u0430\u0432\u043d\u043e \u043b\u0443\u0447\u0448\u0435. \u0422\u0443\u043f\u043e \u043f\u0440\u0438\u044f\u0442\u043d\u0435\u0435 \u044f\u0437\u044b\u043a \u0434\u0430\u0436\u0435 \u0434\u043b\u044f \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u0442\u043e\u0440\u0433\u043e\u0432\u043e\u0439 \u0431\u0438\u0440\u0436\u0438 \u0441\u043e \u0441\u0432\u043e\u0435\u0439 \u043c\u0443\u0434\u0440\u0435\u043d\u043e\u0439 \u0431\u0438\u0437\u043d\u0435\u0441-\u043b\u043e\u0433\u0438\u043a\u043e\u0439 &#8212; \u0442\u0438\u043a\u0435\u0440\u0430\u043c\u0438, \u043b\u043e\u0433\u0438\u043a\u043e\u0439 \u0441\u0442\u043e\u043f\u043e\u0432 \u0438 \u043b\u0438\u043c\u0438\u0442\u043d\u044b\u0445 \u043e\u0440\u0434\u0435\u0440\u043e\u0432, \u043c\u043d\u043e\u0433\u043e\u043f\u043e\u0442\u043e\u0447\u043d\u043e\u0441\u0442\u044c\u044e, \u043f\u0430\u0442\u0442\u0435\u0440\u043d \u043c\u0430\u0442\u0447\u0438\u043d\u0433\u043e\u043c, \u0434\u0435\u0446\u0435\u043d\u0442\u0440\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043d\u043d\u043e\u0439 \u0441\u0435\u0442\u044c\u044e, \u0433\u0440\u0430\u0444\u0438\u043a\u0430\u043c\u0438, \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044f\u043c\u0438 \u043f\u0430\u0440\u0435\u0442\u043e, \u0433\u0430\u0443\u0441\u0441\u0430, \u0441\u0442\u044c\u044e\u0434\u0435\u043d\u0442\u0430. \u041d\u0435 \u0442\u0440\u043e\u0433\u0430\u044f \u0434\u0435\u0440\u0435\u0432\u0430\u0442\u0438\u0432\u043e\u0432 \u0438 \u0440\u0430\u0437\u043d\u0438\u0446\u0443 \u0444\u043e\u0440\u0432\u0430\u0440\u0434\/\u0444\u044c\u044e\u0447\u0435\u0440\u0441, \u0435\u0441\u0442\u044c \u201c\u0430\u0441\u043a\u201d \u0438 \u201c\u0431\u0438\u0434\u201d, \u0442\u0440\u0438 \u0432\u0438\u0434\u0430 \u043e\u0440\u0434\u0435\u0440\u043e\u0432, \u0442\u0438\u043a\u0435\u0440\u044b, \u0432\u0437\u043b\u0435\u0442\u044b \u0438 \u043f\u0430\u0434\u0435\u043d\u0438\u044f, \u0432\u0438\u0441\u043a\u0430\u0440\u044c-\u0442\u0440\u0435\u0432\u043e\u0433\u0438-\u0440\u043e\u0431\u043e\u0442\u044b &#8212; \u043a\u043e\u0440\u043e\u0447\u0435, \u0447\u0442\u043e \u043d\u0443\u0436\u043d\u043e \u0441\u0434\u0435\u043b\u0430\u0435\u043c (\u043a\u0440\u043e\u043c\u0435 \u0440\u043e\u0431\u043e\u0442\u043e\u0432), \u0430 \u0434\u043b\u044f \u0432\u0441\u0435\u0433\u043e \u043e\u0441\u0442\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u043c\u0430\u0441\u0442\u0435\u0440 \u043a\u0430\u0440\u0434 (\u0438\u043b\u0438 \u041c\u0418\u0420, \u0430 \u0434\u043b\u044f \u0435\u0432\u0440\u043e\u043f\u0435\u0439\u0446\u0435\u0432 \u201c\u0435-\u0446\u201d \u043a\u0430\u0440\u0442\u044b).\u041f\u0440\u043e\u0441\u0442\u0435\u0439\u0448\u0430\u044f \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0439 \u0431\u0438\u0440\u0436\u044b (\u0442\u0438\u043a\u0435\u0440\u0430) \u0441\u043a\u043b\u0430\u0434\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u0432\u0441\u0435\u0433\u043e \u0438\u0437 \u0434\u0432\u0443\u0445 \u043a\u0443\u0447 (binary heap) \u0438\u043b\u0438 \u0434\u0432\u0443\u0445 \u0441\u0442\u0430\u043a\u0430\u043d\u043e\u0432: \u201c\u0430\u0441\u043a\u201d (\u043f\u0440\u043e\u0434\u0430\u0436\u0430) \u0438 \u201c\u0431\u0438\u0434\u201d (\u043f\u043e\u043a\u0443\u043f\u043a\u0430), \u0438 \u0441\u043b\u0435\u0434\u0441\u0442\u0432\u0438\u0435\u043c \u0438\u0445 \u043f\u0435\u0440\u0435\u0441\u0435\u0447\u0435\u043d\u0438\u044f \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0441\u0434\u0435\u043b\u043a\u0430. \u041a\u0442\u043e-\u043b\u0438\u0431\u043e \u0441\u043e\u0437\u0434\u0430\u0435\u0442 \u043e\u0440\u0434\u0435\u0440 \u043d\u0430 \u043f\u043e\u043a\u0443\u043f\u043a\u0443, \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u044f \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e, \u0438 \u043e\u0440\u0434\u0435\u0440 \u0438\u0441\u043f\u043e\u043b\u043d\u044f\u0435\u0442\u0441\u044f \u043c\u0433\u043d\u043e\u0432\u0435\u043d\u043d\u043e \u043f\u043e \u0432\u0435\u0440\u0445\u043d\u0435\u0439 \u0446\u0435\u043d\u0435 \u0432 \u0441\u0442\u0430\u043a\u0430\u043d\u0435. \u0415\u0441\u043b\u0438 \u0445\u043e\u0447\u0435\u0442\u0441\u044f \u043a\u0443\u043f\u0438\u0442\u044c \u0434\u0435\u0448\u0435\u0432\u043b\u0435, \u0441\u043e\u0437\u0434\u0430\u0435\u0442\u0441\u044f \u043b\u0438\u043c\u0438\u0442\u043d\u044b\u0439 \u043e\u0440\u0434\u0435\u0440 \u0441 \u0443\u043a\u0430\u0437\u0430\u043d\u0438\u0435\u043c \u0446\u0435\u043d\u044b, \u0430 \u0441\u0434\u0435\u043b\u043a\u0430 \u043e\u0436\u0438\u0434\u0430\u0435\u0442 \u043f\u0440\u043e\u0434\u0430\u0432\u0446\u0430, \u0441\u043e\u0433\u043b\u0430\u0441\u043d\u043e\u0433\u043e \u043f\u0440\u043e\u0434\u0430\u0442\u044c \u0432\u0430\u043c \u043f\u043e \u0443\u043a\u0430\u0437\u0430\u043d\u043d\u043e\u0439 \u0446\u0435\u043d\u0435. \u0421 \u0442\u043e\u0447\u043a\u0438 \u0437\u0440\u0435\u043d\u0438\u044f \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u043d\u0435\u0442 \u043e\u0441\u043e\u0431\u043e\u0439 \u0440\u0430\u0437\u043d\u0438\u0446\u044b \u043c\u0435\u0436\u0434\u0443 \u201casap\u201d \u0438 \u043b\u0438\u043c\u0438\u0442\u043d\u044b\u043c\u0438 \u043e\u0440\u0434\u0435\u0440\u0430\u043c\u0438. \u0427\u0443\u0442\u044c \u0441\u043b\u043e\u0436\u043d\u0435\u0435 \u0441\u0442\u043e\u043f\u044b.\u0421\u0442\u043e\u043f\u044b (\u043e\u0440\u0434\u0435\u0440\u044b) \u0437\u0430\u0432\u0438\u0441\u044f\u0442 \u043e\u0442 \u0446\u0435\u043d \u043d\u0430 \u0442\u0430\u0431\u043b\u043e \u0438 \u0438\u0441\u043f\u043e\u043b\u043d\u044f\u044e\u0442\u0441\u044f \u043d\u0430 \u043f\u0440\u043e\u0434\u0430\u0436\u0443 \u043f\u043e \u043b\u044e\u0431\u043e\u0439 \u0446\u0435\u043d\u0435 (\u043c\u0433\u043d\u043e\u0432\u0435\u043d\u043d\u043e) \u043f\u0440\u0438 \u0446\u0435\u043d\u0435 \u043d\u0430 \u0442\u0430\u0431\u043b\u043e \u0440\u0430\u0432\u043d\u043e\u0439 \u0438\u043b\u0438 \u043c\u0435\u043d\u044c\u0448\u0435 \u0443\u043a\u0430\u0437\u0430\u043d\u043d\u043e\u0439 \u0432 \u043e\u0440\u0434\u0435\u0440\u0435. \u0421\u0442\u043e\u043f\u044b \u043c\u043e\u0433\u0443\u0442 \u0442\u0440\u0438\u0433\u0435\u0440\u043d\u0443\u0442\u044c \u0434\u0440\u0443\u0433\u0438\u0435 \u0441\u0442\u043e\u043f\u044b, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0432 \u0440\u0435\u0430\u043b\u0438\u0437\u0446\u0430\u0438\u0438 \u0447\u0443\u0442\u044c \u0441\u043b\u043e\u0436\u043d\u0435\u0435.\u0411\u0438\u0440\u0436\u0430 \u043d\u0430 \u0431\u0443\u043c\u0430\u0433\u0435 \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u043a\u0430\u043a-\u0442\u043e \u0442\u0430\u043a: StockRaw -&gt; StockRawWithStop -&gt; StockWithHistory -&gt; Broker -&gt; Client. \u0412 \u0440\u0430\u0441\u0442\u0435 \u0432\u043f\u043e\u043b\u043d\u0435 \u0435\u0441\u0442\u0435\u0441\u0442\u0432\u0435\u043d\u043d\u043e \u0437\u0430\u0432\u0435\u0440\u043d\u0443\u0442\u044c \u0432 \u201c\u0435\u043d\u0430\u043c\u044b\u201d \u0434\u0430\u043d\u043d\u044b\u0435 \u0438 \u0443\u0434\u043e\u0431\u043d\u043e \u0440\u0430\u0441\u043a\u0440\u044b\u0442\u044c \u043f\u0430\u0442\u0442\u0435\u0440\u043d \u043c\u0430\u0442\u0447\u0438\u043d\u0433\u043e\u043c \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u044e\u0449\u0435\u0439 \u0441\u0442\u043e\u0440\u043e\u043d\u044b \u043d\u0430 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0432\u0443\u0435\u0449\u0435\u043c \u0443\u0440\u043e\u0432\u043d\u0435, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440: Intent::Buy(Limit(Price(p), Quantity(q))) \u0438\u043b\u0438 Intent::Sell(Asap(Quantity(q))) &#8212; \u0431\u0440\u043e\u043a\u0435\u0440\u0443 \u0432\u0430\u0436\u043d\u043e \u043b\u0438\u0448\u044c \u043d\u0430\u043c\u0435\u0440\u0435\u043d\u0438\u0435 \u043a\u043b\u0438\u0435\u043d\u0442\u0430 (intent), \u0438\u043b\u0438 \u043b\u0438\u043c\u0438\u0442\u043d\u044b\u0439 \u043e\u0440\u0434\u0435\u0440 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442\u0441\u044f \u043d\u0430 \u043d\u0438\u0436\u043d\u0435\u043c \u0443\u0440\u043e\u0432\u043d\u0435.\u041c\u043e\u0436\u043d\u043e \u043e\u0442\u043c\u0435\u0442\u0438\u0442\u044c, \u0447\u0442\u043e \u0432 \u0440\u0430\u0441\u0442\u0435 \u043e\u0447\u0435\u043d\u044c \u0443\u0434\u043e\u0431\u043d\u043e \u043a\u043e\u043c\u043f\u043e\u043d\u043e\u0432\u0430\u0442\u044c &#8212; \u043d\u0438\u0436\u0435 \u0447\u0435\u0442\u044b\u0440\u0435 \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u0430 \u043f\u043e\u043a\u0440\u044b\u0442\u044b \u0434\u0432\u0443\u043c\u044f \u201c\u043a\u0435\u0439\u0437\u0430\u043c\u0438\u201d, \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u043c\u043e\u0435 \u044d\u043b\u0435\u0433\u0430\u043d\u0442\u043d\u043e \u0440\u0430\u0437\u0432\u0435\u0440\u043d\u0443\u0442\u043e, \u0441\u043b\u0435\u043f\u043b\u0435\u043d\u043e \u0438 \u0437\u0430\u0432\u0435\u0440\u043d\u0443\u0442\u043e \u043e\u0431\u0440\u0430\u0442\u043d\u043e:match (x,y) {(Some(xs), Some(ys)) =&gt; Some(vec![xs, ys].concat()), (x,y) =&gt; x.or(y)}\u041f\u043e\u0441\u0442-\u0443\u0441\u043b\u043e\u0432\u0438\u0435 (\u201c\u043f\u043e\u0441\u0442\u043a\u043e\u043d\u0434\u0438\u0448\u043d\u0441\u201d) &#8212; \u044d\u0442\u043e \u0442\u0430\u043a\u043e\u0439 \u0441\u043f\u043e\u0441\u043e\u0431 \u043d\u0435 \u043f\u043e\u0442\u0435\u0440\u044f\u0442\u044c \u043a\u043e\u0440\u0440\u0435\u043a\u0442\u043d\u043e\u0441\u0442\u044c \u0432 \u0441\u043b\u0435\u0433\u043a\u0430 \u0437\u0430\u043f\u0443\u0442\u0430\u043d\u043d\u043e\u0439 \u0431\u0438\u0437\u043d\u0435\u0441-\u043b\u043e\u0433\u0438\u043a\u0435. \u0412 \u043f\u0440\u0438\u043c\u0435\u0440\u0435 (\u043d\u0438\u0436\u0435) \u043c\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c \u201c\u0434\u0438\u0444\u0444\u0435\u0440\u0435\u043d\u0446\u201d \u043c\u0435\u0436\u0434\u0443 \u043d\u0430\u0448\u0435\u0439 \u0431\u0438\u0440\u0436\u0435\u0439 \u0438 \u043e\u0440\u0434\u0435\u0440\u043e\u043c, \u0438 \u0434\u0430\u043b\u0435\u0435 (\u0432 \u043c\u0435\u0442\u043e\u0434\u0435 \u201cdeal\u201d) \u0443\u0441\u0438\u043b\u0438\u0432\u0430\u0435\u043c \u043f\u043e\u0441\u0442-\u0443\u0441\u043b\u043e\u0432\u0438\u0435, \u0433\u0430\u0440\u0430\u043d\u0442\u0438\u0440\u0443\u044f \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u043e\u0440\u0434\u0435\u0440\u043e\u0432 \u043d\u0430 \u0431\u0438\u0440\u0436\u0435 \u0434\u043e \u0438 \u043f\u043e\u0441\u043b\u0435 \u0441\u0434\u0435\u043b\u043a\u0438.impl Stock {\/\/\/ postcondition: \/\/\/ stock.quantity &#8212; new_stock.quantity &lt;= order.quantity * 2 fn difference(&amp;mut self, x: Order) {self.ask.pop().map(|Reverse(a)| a &#8212; x).map(|a| if a.quantity != 0 { self.ask.push(Reverse(a)); } );self.bid.pop().map(|b| b &#8212; x).map(|b| if b.quantity != 0 { self.bid.push(b); } );}\/\/\/ postcondition: \/\/\/ stock.quantity &#8212; new_stock.quantity = ret.quantity * 2  fn deal(&amp;mut self) -&gt; Option&lt;Deal&gt; {self.ask.peek().zip(self.bid.peek()).and_then(|(Reverse(a), b)| if a &lt;= b { Some((*a,*b)) } else { None }).map(|(a, b)| {self.difference(a &amp; b);Deal::new(a, b) })}}\u041c\u043d\u043e\u0433\u043e\u043f\u043e\u0442\u043e\u0447\u043d\u043e\u0435 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u0441\u043b\u043e\u0436\u043d\u0430\u044f \u0448\u0442\u0443\u043a\u0430, \u0438 \u0432 \u0440\u0430\u0441\u0442\u0435, \u0438 \u0433\u0434\u0435-\u043b\u0438\u0431\u043e \u0435\u0449\u0435. \u0422\u0443\u043f\u043e, \u043a\u0430\u043a \u043c\u043d\u0435 \u043a\u0430\u0436\u0435\u0442\u0441\u044f, \u043d\u0435 \u0445\u0432\u0430\u0442\u0430\u0435\u0442 \u043f\u0440\u0438\u043c\u0438\u0442\u0438\u0432\u043e\u0432 &#8212; \u043d\u0435 \u0442\u0435\u0445 \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0430\u0442\u043e\u043c\u0438\u043a\u0438, \u0430 \u043d\u0430 \u0443\u0440\u043e\u0432\u043d\u0435 \u043a\u043e\u043c\u043f\u043e\u043d\u043e\u0432\u043a\u0438. \u0421\u0435\u0439\u0447\u0430\u0441 \u043c\u043d\u043e\u0433\u043e\u043f\u043e\u0442\u043e\u0447\u043d\u043e\u0435 \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442, \u0441\u043e\u0440\u044f\u043d \u0437\u0430 \u043c\u0435\u0442\u0430\u0444\u043e\u0440\u0443 &#8212; \u043a\u0430\u043a \u043e\u0434\u043d\u043e\u0432\u0440\u0435\u043c\u0435\u043d\u043d\u0430\u044f \u043e\u0431\u0436\u0430\u0440\u043a\u0430 \u0438 \u0437\u0430\u043c\u043e\u0440\u043e\u0437\u043a\u0430 \u043c\u044f\u0441\u043d\u043e\u0433\u043e. \u0412 \u043e\u0431\u044b\u0447\u043d\u043e\u043c \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0438 \u0443 \u043d\u0430\u0441 \u0435\u0441\u0442\u044c \u0444\u0443\u043d\u043a\u0446\u0438\u0438, \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u044b, \u043f\u0435\u0442\u043b\u0438 (loop), \u0440\u0435\u043a\u0443\u0440\u0441\u0438\u044f &#8212; \u0443 \u0440\u0430\u0441\u0442\u0430, \u043a\u0441\u0442\u0430\u0442\u0438, \u043f\u0440\u0435\u043a\u0440\u0430\u0441\u043d\u044b\u0435 \u043f\u0440\u0438\u043c\u0438\u0442\u0438\u0432\u044b \u0434\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u0441 \u043f\u0435\u0442\u043b\u044f\u043c\u0438 (std::iter::successors \u0438 std::iter::from_fn) &#8212; \u0438 \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c \u0445\u043e\u0440\u043e\u0448\u0438\u0435 \u0441\u0438\u0441\u0442\u0435\u043c\u044b, \u043d\u043e \u043e\u0442\u043d\u043e\u0441\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u043c\u0435\u0434\u043b\u0435\u043d\u043d\u044b\u0435. \u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u0443\u0441\u043a\u043e\u0440\u044f\u0435\u043c \u0441\u0430\u043c\u044b\u043c \u0442\u0443\u043f\u044b\u043c \u0438 \u043f\u0440\u043e\u0441\u0442\u044b\u043c \u0441\u043f\u043e\u0441\u043e\u0431\u043e\u043c &#8212; \u043c\u0443\u0442\u0435\u043a\u0441\u043e\u043c (\u0447\u0442\u043e-\u0442\u043e \u0442\u0438\u043f\u0430 static STOCK: Mutex&lt;Stock&gt; = Mutex::new(Stock::new())), \u043d\u0435 \u0437\u0430\u0431\u044b\u0432\u0430\u044f \u043f\u043e\u0434\u0430\u0432\u0430\u0442\u044c \u043e\u0440\u0434\u0435\u0440\u044b \u043f\u0430\u0447\u043a\u0430\u043c\u0438 (batch), \u043a\u043e\u043c\u043f\u0435\u043d\u0441\u0438\u0440\u0443\u044f \u0441\u0442\u043e\u0438\u043c\u043e\u0441\u0442\u044c \u043b\u043e\u043a\u0430.\u041f\u0438\u0448\u0435\u043c \u044e\u043d\u0438\u0442 \u0442\u0435\u0441\u0442\u044b, \u0441\u0442\u0440\u043e\u0438\u043c \u0433\u0440\u0430\u0444\u0438\u043a\u0430\u043c\u0438 \u0442\u0440\u0438 \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044f (\u043d\u0430 \u0440\u0438\u0441\u0443\u043d\u043a\u0435 \u043d\u0438\u0436\u0435), \u0438 \u043e\u0434\u043d\u043e \u0438\u0437 \u043d\u0438\u0445 (\u043f\u0430\u0440\u0435\u0442\u043e) \u0432\u0437\u044f\u0442\u043e \u043f\u043e \u043b\u043e\u0433\u0430\u0440\u0438\u0444\u043c\u0438\u0447\u0435\u0441\u043a\u043e\u0439 \u0448\u043a\u0430\u043b\u0435. \u041d\u0430 \u0433\u0440\u0430\u0444\u0438\u043a\u0435 \u0432 \u0442\u0435\u0447\u0435\u043d\u0438\u0435 \u0433\u043e\u0434\u0430 \u0447\u0435\u0442\u044b\u0440\u0435 \u043a\u043b\u0438\u0435\u043d\u0442\u0430 \u043f\u044b\u0442\u0430\u044e\u0442\u0441\u044f \u0432\u044b\u0438\u0433\u0440\u0430\u0442\u044c \u0443 \u0440\u044b\u043d\u043a\u0430 \u043d\u0430 \u043a\u0430\u0436\u0434\u043e\u0439 \u043c\u0438\u043d\u0443\u0442\u0435, \u0430 \u0442\u0440\u0438 \u0444\u043e\u043d\u0434\u0430 &#8212; \u0441\u043e \u0441\u0434\u0435\u043b\u043a\u0430\u043c\u0438 \u0440\u0430\u0437 \u0432 \u0434\u0435\u043d\u044c (\u0447\u0442\u043e-\u0442\u043e \u0442\u0438\u043f\u0430 Client{vol: 0.01, p: 0.5, quantity: 1000, distribution, s: Strategy::Limit}).\u0422\u0440\u0438 \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044f\u0414\u043b\u044f \u0441\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u044f \u0433\u0440\u0430\u0444\u0438\u043a (\u0433\u0435\u043e\u043c\u0435\u0442\u0440\u0438\u0447\u0435\u0441\u043a\u043e\u0433\u043e) \u0431\u0440\u043e\u0443\u043d\u043e\u0432\u0441\u043a\u043e\u0433\u043e \u0434\u0432\u0438\u0436\u0435\u043d\u0438\u044f \u0430\u043a\u0442\u0438\u0432\u0430 \u0441 \u0432\u043e\u043b\u0430\u0442\u0438\u043b\u044c\u043d\u043e\u0441\u0442\u044c\u044e \u0432 \u043e\u0434\u0438\u043d \u043f\u0440\u043e\u0446\u0435\u043d\u0442 \u043d\u0430 \u0434\u0435\u043d\u044c \u0438\u043b\u0438 15.7 % \u0432 \u0433\u043e\u0434.\u0411\u0440\u043e\u0443\u043d\u043e\u0432\u0441\u043a\u043e\u0435 \u0434\u0432\u0438\u0436\u0435\u043d\u0438\u0435\u0418\u0441\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0435 \u0431\u0438\u0440\u0436\u0438 (\u0442\u0438\u043a\u0435\u0440\u0430) \u0434\u043e\u0432\u043e\u043b\u044c\u043d\u043e-\u0442\u0430\u043a\u0438 \u043f\u0440\u044f\u043c\u043e\u043b\u0438\u043d\u0435\u0439\u043d\u043e\u0435, \u0438 \u0434\u043b\u044f \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0434\u0435\u0446\u0435\u043d\u0442\u0440\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043d\u043d\u043e\u0439 \u0431\u0438\u0440\u0436\u0438 \u043d\u0430\u043c \u043d\u0443\u0436\u0435\u043d \u0435\u0449\u0435 \u0438 \u0445\u0435\u0448, \u0438 \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0430 \u0433\u043e\u043b\u043e\u0441\u043e\u0432\u0430\u043d\u0438\u0435\u043c &#8212; \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u043c (\u043d\u0430 \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0443) \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0441\u0434\u0435\u043b\u043a\u0438 &#8212; \u0435\u0441\u043b\u0438 \u043d\u0435 \u043e\u043a, \u0431\u0435\u0440\u0435\u043c \u0432\u0435\u0440\u0441\u0438\u044e \u0440\u0435\u0431\u044f\u0442, \u0432 \u043f\u0440\u043e\u0442\u0438\u0432\u043d\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u043a\u043e\u043c\u043c\u0438\u0442\u0438\u043c\u0441\u044f \u043f\u043e\u0441\u043b\u0435 \u201c\u0434\u0440\u0430\u0439\u0440\u0430\u043d\u0430\u201d (dry_run). \u0425\u0435\u0448 \u0431\u0435\u0440\u0435\u043c \u0440\u0430\u0432\u043d\u044b\u043c \u043e\u0440\u0434\u0435\u0440\u0443 \u044e\u0437\u0435\u0440\u0430 \u0438 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0443 \u0441\u0434\u0435\u043b\u043a\u0438. \u201c\u0414\u0440\u0430\u0439\u0420\u0430\u043d\u201d \u0443\u0434\u043e\u0431\u043d\u043e \u0432\u044b\u043d\u0435\u0441\u0442\u0438 \u0432 \u201c\u0442\u0440\u044d\u0439\u0442\u201d, \u0438 \u0434\u043b\u044f \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0431\u0435\u0437 \u0431\u0430\u0433\u043e\u0432 \u043f\u043e\u043c\u043e\u0433\u0430\u0435\u0442 \u0441\u043e\u0431\u043b\u044e\u0434\u0435\u043d\u0438\u0435 \u043f\u043e\u0441\u0442-\u0443\u0441\u043b\u043e\u0432\u0438\u0439.impl Stock  {\/\/\/ postcondition: \/\/\/ stock.quantity == new_stock.quantity fn ask_dry_run(&amp;mut self, order: Order) -&gt; Vec&lt;Deal&gt; {self.ask.push(Reverse(order));let (quantity, deals) = self.execute_ask_dry_run();if quantity != order.quantity { self.ask.pop(); } deals}\/\/\/ postcondition: \/\/\/ stock.bid.quantity == new_stock.bid.quantity fn execute_ask_dry_run(&amp;mut self) -&gt; (u32, Vec&lt;Deal&gt;) {let deals = self.execute();for d in &amp;deals { self.bid.push(d.bid); }(deals.iter().map(|d| d.quantity).sum(), deals)}  }\u0420\u0430\u0441\u0442 \u043d\u0435 \u201c\u044d\u0440\u043b\u0430\u043d\u0433\u201d, \u043d\u043e \u0447\u0442\u043e-\u0442\u043e \u0443\u043c\u0435\u0435\u0442 \u0432 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u044f\u0445: \u0434\u043e\u0432\u043e\u043b\u044c\u043d\u043e \u0443\u0434\u043e\u0431\u043d\u043e \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u043e\u0431\u0440\u0430\u0442\u043d\u044b\u0439 \u0430\u0434\u0440\u0435\u0441 (\u0447\u0430\u0441\u0442\u044c \u043a\u0430\u043d\u0430\u043b\u0430) \u0432 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435:impl Host {fn ask_verify(&amp;self, p: Payload) -&gt; Vec&lt;Receiver&lt;Msg&gt;&gt; {self.hosts.iter().map(|host| {let (tx, rx) = channel();host.send((p, tx));return rx;}).collect()}}\u041d\u0430 \u0441\u0435\u0433\u043e\u0434\u043d\u044f \u0432\u0441\u0435. \u0423\u0434\u0430\u0447\u043d\u043e\u0433\u043e \u043a\u043e\u0434\u0438\u043d\u0433\u0430 :)\u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 https:\/\/habr.com\/ru\/articles\/1041308\/<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-481621","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/481621","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=481621"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/481621\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=481621"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=481621"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=481621"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}