{"id":4218,"date":"2010-11-04T14:07:32","date_gmt":"2010-11-04T19:07:32","guid":{"rendered":"http:\/\/bobbeaty.com\/wp\/?p=4218"},"modified":"2010-11-04T14:53:16","modified_gmt":"2010-11-04T19:53:16","slug":"creating-a-national-best-bidoffer-engine-cont","status":"publish","type":"post","link":"https:\/\/bobbeaty.com\/wp\/archives\/4218","title":{"rendered":"Creating a National Best Bid\/Offer Engine (cont.)"},"content":{"rendered":"<p><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/bobbeaty.com\/wp\/wp-content\/uploads\/2008\/03\/generaldev.jpg\" alt=\"GeneralDev.jpg\" title=\"GeneralDev.jpg\" border=\"0\" width=\"128\" height=\"128\" style=\"float:right;\" \/><\/p>\n<p>Well... it took me a little bit, and I had to re-arrange the code slightly, but in the end, I have the logic I need for the NBBO engine that works when you remove the one NBBO component. It's a little more complex, but it's still very clean.<\/p>\n<p>The previous code was slick, and this is <em>nearly<\/em> as slick, but it's a little more complex because of the different cases I had to deal with in the change of the 'best values'. Still... it's straight-through code with only the one lock to control it's updating, and I think it's going to be plenty fast enough. But we'll have to see how long it takes in real loading conditions.<\/p>\n<pre class=\"cpp\" style=\"font-family:monospace;\"><ol><li style=\"margin: 0; font-weight: normal; vertical-align:top;\"><div style=\"font: normal normal 1em\/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;\">  <span style=\"color: #0000ff;\">if<\/span> <span style=\"color: #008000;\">&#40;<\/span><span style=\"color: #008000;\">&#40;<\/span>bidExch <span style=\"color: #000040;\">!<\/span><span style=\"color: #000080;\">=<\/span> <span style=\"color: #FF0000;\">'<span style=\"color: #006699; font-weight: bold;\">\\0<\/span>'<\/span><span style=\"color: #008000;\">&#41;<\/span> <span style=\"color: #000040;\">&amp;&amp;<\/span> <span style=\"color: #008000;\">&#40;<\/span>bidPrice <span style=\"color: #000080;\">&gt;<\/span> <span style=\"color:#800080;\">0.0<\/span><span style=\"color: #008000;\">&#41;<\/span> <span style=\"color: #000040;\">&amp;&amp;<\/span> <span style=\"color: #008000;\">&#40;<\/span>bidSize <span style=\"color: #000080;\">&gt;<\/span> <span style=\"color: #0000dd;\">0<\/span><span style=\"color: #008000;\">&#41;<\/span><span style=\"color: #008000;\">&#41;<\/span> <span style=\"color: #008000;\">&#123;<\/span><\/div><\/li><li style=\"margin: 0; font-weight: normal; vertical-align:top;\"><div style=\"font: normal normal 1em\/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;\">    <span style=\"color: #666666;\">\/\/ get the exchange as an index into the arrays<\/span><\/div><\/li><li style=\"margin: 0; font-weight: normal; vertical-align:top;\"><div style=\"font: normal normal 1em\/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;\">    <span style=\"color: #0000ff;\">uint8_t<\/span>    idx <span style=\"color: #000080;\">=<\/span> bidExch <span style=\"color: #000040;\">-<\/span> <span style=\"color: #FF0000;\">'A'<\/span><span style=\"color: #008080;\">;<\/span><\/div><\/li><li style=\"margin: 0; font-weight: normal; vertical-align:top;\"><div style=\"font: normal normal 1em\/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;\">    <span style=\"color: #0000ff;\">if<\/span> <span style=\"color: #008000;\">&#40;<\/span>bidPrice <span style=\"color: #000080;\">&gt;<\/span> myExchData<span style=\"color: #000040;\">-<\/span><span style=\"color: #000080;\">&gt;<\/span>nbboBidPrice<span style=\"color: #008000;\">&#41;<\/span> <span style=\"color: #008000;\">&#123;<\/span><\/div><\/li><li style=\"margin: 0; font-weight: normal; vertical-align:top;\"><div style=\"font: normal normal 1em\/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;\">      <span style=\"color: #666666;\">\/\/ with a new leading bid, we are all there is to consider<\/span><\/div><\/li><li style=\"margin: 0; font-weight: normal; vertical-align:top;\"><div style=\"font: normal normal 1em\/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;\">      myExchData<span style=\"color: #000040;\">-<\/span><span style=\"color: #000080;\">&gt;<\/span>nbboBidPrice <span style=\"color: #000080;\">=<\/span> bidPrice<span style=\"color: #008080;\">;<\/span><\/div><\/li><li style=\"margin: 0; font-weight: normal; vertical-align:top;\"><div style=\"font: normal normal 1em\/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;\">      myExchData<span style=\"color: #000040;\">-<\/span><span style=\"color: #000080;\">&gt;<\/span>nbboBidSize <span style=\"color: #000080;\">=<\/span> bidSize<span style=\"color: #008080;\">;<\/span><\/div><\/li><li style=\"margin: 0; font-weight: normal; vertical-align:top;\"><div style=\"font: normal normal 1em\/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;\">      newNBBO <span style=\"color: #000080;\">=<\/span> <span style=\"color: #0000ff;\">true<\/span><span style=\"color: #008080;\">;<\/span><\/div><\/li><li style=\"margin: 0; font-weight: normal; vertical-align:top;\"><div style=\"font: normal normal 1em\/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;\">    <span style=\"color: #008000;\">&#125;<\/span> <span style=\"color: #0000ff;\">else<\/span> <span style=\"color: #0000ff;\">if<\/span> <span style=\"color: #008000;\">&#40;<\/span>bidPrice <span style=\"color: #000080;\">==<\/span> myExchData<span style=\"color: #000040;\">-<\/span><span style=\"color: #000080;\">&gt;<\/span>nbboBidPrice<span style=\"color: #008000;\">&#41;<\/span> <span style=\"color: #008000;\">&#123;<\/span><\/div><\/li><li style=\"margin: 0; font-weight: normal; vertical-align:top;\"><div style=\"font: normal normal 1em\/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;\">      <span style=\"color: #666666;\">\/\/ if we had something in the old NBBO, remove it now<\/span><\/div><\/li><li style=\"margin: 0; font-weight: normal; vertical-align:top;\"><div style=\"font: normal normal 1em\/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;\">      <span style=\"color: #0000ff;\">if<\/span> <span style=\"color: #008000;\">&#40;<\/span>myExchData<span style=\"color: #000040;\">-<\/span><span style=\"color: #000080;\">&gt;<\/span>bidPrice<span style=\"color: #008000;\">&#91;<\/span>idx<span style=\"color: #008000;\">&#93;<\/span> <span style=\"color: #000080;\">==<\/span> myExchData<span style=\"color: #000040;\">-<\/span><span style=\"color: #000080;\">&gt;<\/span>nbboBidPrice<span style=\"color: #008000;\">&#41;<\/span> <span style=\"color: #008000;\">&#123;<\/span><\/div><\/li><li style=\"margin: 0; font-weight: normal; vertical-align:top;\"><div style=\"font: normal normal 1em\/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;\">        myExchData<span style=\"color: #000040;\">-<\/span><span style=\"color: #000080;\">&gt;<\/span>nbboBidSize <span style=\"color: #000040;\">-<\/span><span style=\"color: #000080;\">=<\/span> myExchData<span style=\"color: #000040;\">-<\/span><span style=\"color: #000080;\">&gt;<\/span>bidSize<span style=\"color: #008000;\">&#91;<\/span>idx<span style=\"color: #008000;\">&#93;<\/span><span style=\"color: #008080;\">;<\/span><\/div><\/li><li style=\"margin: 0; font-weight: normal; vertical-align:top;\"><div style=\"font: normal normal 1em\/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;\">      <span style=\"color: #008000;\">&#125;<\/span><\/div><\/li><li style=\"margin: 0; font-weight: normal; vertical-align:top;\"><div style=\"font: normal normal 1em\/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;\">      <span style=\"color: #666666;\">\/\/ ...and we know we need to add in our contribution now<\/span><\/div><\/li><li style=\"margin: 0; font-weight: normal; vertical-align:top;\"><div style=\"font: normal normal 1em\/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;\">      myExchData<span style=\"color: #000040;\">-<\/span><span style=\"color: #000080;\">&gt;<\/span>nbboBidSize <span style=\"color: #000040;\">+<\/span><span style=\"color: #000080;\">=<\/span> bidSize<span style=\"color: #008080;\">;<\/span><\/div><\/li><li style=\"margin: 0; font-weight: normal; vertical-align:top;\"><div style=\"font: normal normal 1em\/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;\">      newNBBO <span style=\"color: #000080;\">=<\/span> <span style=\"color: #008000;\">&#40;<\/span><span style=\"color: #008000;\">&#40;<\/span>myExchData<span style=\"color: #000040;\">-<\/span><span style=\"color: #000080;\">&gt;<\/span>bidPrice<span style=\"color: #008000;\">&#91;<\/span>idx<span style=\"color: #008000;\">&#93;<\/span> <span style=\"color: #000040;\">!<\/span><span style=\"color: #000080;\">=<\/span> bidPrice<span style=\"color: #008000;\">&#41;<\/span> <span style=\"color: #000040;\">||<\/span><\/div><\/li><li style=\"margin: 0; font-weight: normal; vertical-align:top;\"><div style=\"font: normal normal 1em\/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;\">                 <span style=\"color: #008000;\">&#40;<\/span>myExchData<span style=\"color: #000040;\">-<\/span><span style=\"color: #000080;\">&gt;<\/span>bidSize<span style=\"color: #008000;\">&#91;<\/span>idx<span style=\"color: #008000;\">&#93;<\/span> <span style=\"color: #000040;\">!<\/span><span style=\"color: #000080;\">=<\/span> bidSize<span style=\"color: #008000;\">&#41;<\/span><span style=\"color: #008000;\">&#41;<\/span><span style=\"color: #008080;\">;<\/span><\/div><\/li><li style=\"margin: 0; font-weight: normal; vertical-align:top;\"><div style=\"font: normal normal 1em\/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;\">    <span style=\"color: #008000;\">&#125;<\/span> <span style=\"color: #0000ff;\">else<\/span> <span style=\"color: #0000ff;\">if<\/span> <span style=\"color: #008000;\">&#40;<\/span>myExchData<span style=\"color: #000040;\">-<\/span><span style=\"color: #000080;\">&gt;<\/span>bidPrice<span style=\"color: #008000;\">&#91;<\/span>idx<span style=\"color: #008000;\">&#93;<\/span> <span style=\"color: #000080;\">==<\/span> myExchData<span style=\"color: #000040;\">-<\/span><span style=\"color: #000080;\">&gt;<\/span>nbboBidPrice<span style=\"color: #008000;\">&#41;<\/span> <span style=\"color: #008000;\">&#123;<\/span><\/div><\/li><li style=\"margin: 0; font-weight: normal; vertical-align:top;\"><div style=\"font: normal normal 1em\/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;\">      <span style=\"color: #666666;\">\/\/ we had something in the old NBBO, remove it now<\/span><\/div><\/li><li style=\"margin: 0; font-weight: normal; vertical-align:top;\"><div style=\"font: normal normal 1em\/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;\">      myExchData<span style=\"color: #000040;\">-<\/span><span style=\"color: #000080;\">&gt;<\/span>nbboBidSize <span style=\"color: #000040;\">-<\/span><span style=\"color: #000080;\">=<\/span> myExchData<span style=\"color: #000040;\">-<\/span><span style=\"color: #000080;\">&gt;<\/span>bidSize<span style=\"color: #008000;\">&#91;<\/span>idx<span style=\"color: #008000;\">&#93;<\/span><span style=\"color: #008080;\">;<\/span><\/div><\/li><li style=\"margin: 0; font-weight: normal; vertical-align:top;\"><div style=\"font: normal normal 1em\/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;\">      newNBBO <span style=\"color: #000080;\">=<\/span> <span style=\"color: #008000;\">&#40;<\/span>myExchData<span style=\"color: #000040;\">-<\/span><span style=\"color: #000080;\">&gt;<\/span>bidSize<span style=\"color: #008000;\">&#91;<\/span>idx<span style=\"color: #008000;\">&#93;<\/span> <span style=\"color: #000080;\">&gt;<\/span> <span style=\"color: #0000dd;\">0<\/span><span style=\"color: #008000;\">&#41;<\/span><span style=\"color: #008080;\">;<\/span><\/div><\/li><li style=\"margin: 0; font-weight: normal; vertical-align:top;\"><div style=\"font: normal normal 1em\/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;\">      <span style=\"color: #666666;\">\/\/ see if this was the only one in the NBBO<\/span><\/div><\/li><li style=\"margin: 0; font-weight: normal; vertical-align:top;\"><div style=\"font: normal normal 1em\/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;\">      <span style=\"color: #0000ff;\">if<\/span> <span style=\"color: #008000;\">&#40;<\/span>myExchData<span style=\"color: #000040;\">-<\/span><span style=\"color: #000080;\">&gt;<\/span>bboBidSize <span style=\"color: #000080;\">==<\/span> <span style=\"color: #0000dd;\">0<\/span><span style=\"color: #008000;\">&#41;<\/span> <span style=\"color: #008000;\">&#123;<\/span><\/div><\/li><li style=\"margin: 0; font-weight: normal; vertical-align:top;\"><div style=\"font: normal normal 1em\/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;\">        <span style=\"color: #666666;\">\/\/ reset the bid part of the NBBO<\/span><\/div><\/li><li style=\"margin: 0; font-weight: normal; vertical-align:top;\"><div style=\"font: normal normal 1em\/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;\">        newBidPrice <span style=\"color: #000080;\">=<\/span> <span style=\"color:#800080;\">0.0<\/span><span style=\"color: #008080;\">;<\/span><\/div><\/li><li style=\"margin: 0; font-weight: normal; vertical-align:top;\"><div style=\"font: normal normal 1em\/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;\">        newBidSize <span style=\"color: #000080;\">=<\/span> <span style=\"color: #0000dd;\">0<\/span><span style=\"color: #008080;\">;<\/span><\/div><\/li><li style=\"margin: 0; font-weight: normal; vertical-align:top;\"><div style=\"font: normal normal 1em\/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;\">        <span style=\"color: #666666;\">\/\/ save what we have now for the scan<\/span><\/div><\/li><li style=\"margin: 0; font-weight: normal; vertical-align:top;\"><div style=\"font: normal normal 1em\/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;\">        myExchData<span style=\"color: #000040;\">-<\/span><span style=\"color: #000080;\">&gt;<\/span>bidPrice<span style=\"color: #008000;\">&#91;<\/span>idx<span style=\"color: #008000;\">&#93;<\/span> <span style=\"color: #000080;\">=<\/span> bidPrice<span style=\"color: #008080;\">;<\/span><\/div><\/li><li style=\"margin: 0; font-weight: normal; vertical-align:top;\"><div style=\"font: normal normal 1em\/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;\">        myExchData<span style=\"color: #000040;\">-<\/span><span style=\"color: #000080;\">&gt;<\/span>bidSize<span style=\"color: #008000;\">&#91;<\/span>idx<span style=\"color: #008000;\">&#93;<\/span> <span style=\"color: #000080;\">=<\/span> bidSize<span style=\"color: #008080;\">;<\/span><\/div><\/li><li style=\"margin: 0; font-weight: normal; vertical-align:top;\"><div style=\"font: normal normal 1em\/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;\">        <span style=\"color: #666666;\">\/\/ ...and scan all the data (skipping this guy)<\/span><\/div><\/li><li style=\"margin: 0; font-weight: normal; vertical-align:top;\"><div style=\"font: normal normal 1em\/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;\">        <span style=\"color: #0000ff;\">for<\/span> <span style=\"color: #008000;\">&#40;<\/span><span style=\"color: #0000ff;\">uint8_t<\/span> e <span style=\"color: #000080;\">=<\/span> <span style=\"color: #0000dd;\">0<\/span><span style=\"color: #008080;\">;<\/span> e <span style=\"color: #000080;\">&lt;<\/span> <span style=\"color: #0000dd;\">26<\/span><span style=\"color: #008080;\">;<\/span> <span style=\"color: #000040;\">++<\/span>e<span style=\"color: #008000;\">&#41;<\/span> <span style=\"color: #008000;\">&#123;<\/span><\/div><\/li><li style=\"margin: 0; font-weight: normal; vertical-align:top;\"><div style=\"font: normal normal 1em\/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;\">          <span style=\"color: #0000ff;\">if<\/span> <span style=\"color: #008000;\">&#40;<\/span>myExchData<span style=\"color: #000040;\">-<\/span><span style=\"color: #000080;\">&gt;<\/span>bidPrice<span style=\"color: #008000;\">&#91;<\/span>e<span style=\"color: #008000;\">&#93;<\/span> <span style=\"color: #000080;\">&gt;<\/span> newBidPrice<span style=\"color: #008000;\">&#41;<\/span> <span style=\"color: #008000;\">&#123;<\/span><\/div><\/li><li style=\"margin: 0; font-weight: normal; vertical-align:top;\"><div style=\"font: normal normal 1em\/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;\">            newBidPrice <span style=\"color: #000080;\">=<\/span> myExchData<span style=\"color: #000040;\">-<\/span><span style=\"color: #000080;\">&gt;<\/span>bidPrice<span style=\"color: #008000;\">&#91;<\/span>e<span style=\"color: #008000;\">&#93;<\/span><span style=\"color: #008080;\">;<\/span><\/div><\/li><li style=\"margin: 0; font-weight: normal; vertical-align:top;\"><div style=\"font: normal normal 1em\/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;\">            newBidSize <span style=\"color: #000080;\">=<\/span> myExchData<span style=\"color: #000040;\">-<\/span><span style=\"color: #000080;\">&gt;<\/span>bidSize<span style=\"color: #008000;\">&#91;<\/span>e<span style=\"color: #008000;\">&#93;<\/span><span style=\"color: #008080;\">;<\/span><\/div><\/li><li style=\"margin: 0; font-weight: normal; vertical-align:top;\"><div style=\"font: normal normal 1em\/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;\">          <span style=\"color: #008000;\">&#125;<\/span> <span style=\"color: #0000ff;\">else<\/span> <span style=\"color: #0000ff;\">if<\/span> <span style=\"color: #008000;\">&#40;<\/span>myExchData<span style=\"color: #000040;\">-<\/span><span style=\"color: #000080;\">&gt;<\/span>bidPrice<span style=\"color: #008000;\">&#91;<\/span>e<span style=\"color: #008000;\">&#93;<\/span> <span style=\"color: #000080;\">==<\/span> newBidPrice<span style=\"color: #008000;\">&#41;<\/span> <span style=\"color: #008000;\">&#123;<\/span><\/div><\/li><li style=\"margin: 0; font-weight: normal; vertical-align:top;\"><div style=\"font: normal normal 1em\/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;\">            newBidSize <span style=\"color: #000040;\">+<\/span><span style=\"color: #000080;\">=<\/span> myExchData<span style=\"color: #000040;\">-<\/span><span style=\"color: #000080;\">&gt;<\/span>bidSize<span style=\"color: #008000;\">&#91;<\/span>e<span style=\"color: #008000;\">&#93;<\/span><span style=\"color: #008080;\">;<\/span><\/div><\/li><li style=\"margin: 0; font-weight: normal; vertical-align:top;\"><div style=\"font: normal normal 1em\/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;\">          <span style=\"color: #008000;\">&#125;<\/span><\/div><\/li><li style=\"margin: 0; font-weight: normal; vertical-align:top;\"><div style=\"font: normal normal 1em\/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;\">        <span style=\"color: #008000;\">&#125;<\/span><\/div><\/li><li style=\"margin: 0; font-weight: normal; vertical-align:top;\"><div style=\"font: normal normal 1em\/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;\">        <span style=\"color: #666666;\">\/\/ make sure we have something<\/span><\/div><\/li><li style=\"margin: 0; font-weight: normal; vertical-align:top;\"><div style=\"font: normal normal 1em\/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;\">        <span style=\"color: #0000ff;\">if<\/span> <span style=\"color: #008000;\">&#40;<\/span>newBidSize <span style=\"color: #000080;\">&gt;<\/span> <span style=\"color: #0000dd;\">0<\/span><span style=\"color: #008000;\">&#41;<\/span> <span style=\"color: #008000;\">&#123;<\/span><\/div><\/li><li style=\"margin: 0; font-weight: normal; vertical-align:top;\"><div style=\"font: normal normal 1em\/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;\">          myExchData<span style=\"color: #000040;\">-<\/span><span style=\"color: #000080;\">&gt;<\/span>nbboBidPrice <span style=\"color: #000080;\">=<\/span> newBidPrice<span style=\"color: #008080;\">;<\/span><\/div><\/li><li style=\"margin: 0; font-weight: normal; vertical-align:top;\"><div style=\"font: normal normal 1em\/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;\">          myExchData<span style=\"color: #000040;\">-<\/span><span style=\"color: #000080;\">&gt;<\/span>nbboBidSize <span style=\"color: #000080;\">=<\/span> newBidSize<span style=\"color: #008080;\">;<\/span><\/div><\/li><li style=\"margin: 0; font-weight: normal; vertical-align:top;\"><div style=\"font: normal normal 1em\/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;\">          <span style=\"color: #666666;\">\/\/ we KNOW this is a new one<\/span><\/div><\/li><li style=\"margin: 0; font-weight: normal; vertical-align:top;\"><div style=\"font: normal normal 1em\/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;\">          newNBBO <span style=\"color: #000080;\">=<\/span> <span style=\"color: #0000ff;\">true<\/span><span style=\"color: #008080;\">;<\/span><\/div><\/li><li style=\"margin: 0; font-weight: normal; vertical-align:top;\"><div style=\"font: normal normal 1em\/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;\">        <span style=\"color: #008000;\">&#125;<\/span><\/div><\/li><li style=\"margin: 0; font-weight: normal; vertical-align:top;\"><div style=\"font: normal normal 1em\/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;\">      <span style=\"color: #008000;\">&#125;<\/span><\/div><\/li><li style=\"margin: 0; font-weight: normal; vertical-align:top;\"><div style=\"font: normal normal 1em\/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;\">    <span style=\"color: #008000;\">&#125;<\/span><\/div><\/li><li style=\"margin: 0; font-weight: normal; vertical-align:top;\"><div style=\"font: normal normal 1em\/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;\">    <span style=\"color: #666666;\">\/\/ no matter what, save the bid for the next time<\/span><\/div><\/li><li style=\"margin: 0; font-weight: normal; vertical-align:top;\"><div style=\"font: normal normal 1em\/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;\">    myExchData<span style=\"color: #000040;\">-<\/span><span style=\"color: #000080;\">&gt;<\/span>bidPrice<span style=\"color: #008000;\">&#91;<\/span>idx<span style=\"color: #008000;\">&#93;<\/span> <span style=\"color: #000080;\">=<\/span> bidPrice<span style=\"color: #008080;\">;<\/span><\/div><\/li><li style=\"margin: 0; font-weight: normal; vertical-align:top;\"><div style=\"font: normal normal 1em\/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;\">    myExchData<span style=\"color: #000040;\">-<\/span><span style=\"color: #000080;\">&gt;<\/span>bidSize<span style=\"color: #008000;\">&#91;<\/span>idx<span style=\"color: #008000;\">&#93;<\/span> <span style=\"color: #000080;\">=<\/span> bidSize<span style=\"color: #008080;\">;<\/span><\/div><\/li><li style=\"margin: 0; font-weight: normal; vertical-align:top;\"><div style=\"font: normal normal 1em\/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;\">  <span style=\"color: #008000;\">&#125;<\/span><\/div><\/li><\/ol><\/pre>\n<p>There are a few neat things in this guy. First off, we look for the <em>obvious winners<\/em> - if we have a brand new best bid, or an addition to the size on the existing best bid. We needed to be careful when looking at adding the value in (line 11), and especially careful about sending out a new NBBO message out (line 16).<\/p>\n<p>But the really new part is the scanning of the existing exchange data (line 31). This is done <strong><em>only<\/em><\/strong> when there was a single component to the best bid, and he's just taken himself out of the mix. For those cases, we have no choice but to start all over and see what we can come up with. The wrinkle was that we need to add back in our current data so it too was included in the scan. It's possible, after all, that it's still part of the best bid, just ad a different price. And maybe with some friends.<\/p>\n<p>All told, I really liked this code. It's fun, and the test frame for exercising it was a blast to write. I have the ability to throw any number of sequences of ticks to the engine and test each subsequent value. It's nice. Good, fun, work.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Well&#8230; it took me a little bit, and I had to re-arrange the code slightly, but in the end, I have the logic I need for the NBBO engine that works when you remove the one NBBO component. It&#8217;s a little more complex, but it&#8217;s still very clean. The previous code was slick, and this [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3,6],"tags":[],"class_list":["post-4218","post","type-post","status-publish","format-standard","hentry","category-coding","category-cube-life"],"_links":{"self":[{"href":"https:\/\/bobbeaty.com\/wp\/wp-json\/wp\/v2\/posts\/4218","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/bobbeaty.com\/wp\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/bobbeaty.com\/wp\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/bobbeaty.com\/wp\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/bobbeaty.com\/wp\/wp-json\/wp\/v2\/comments?post=4218"}],"version-history":[{"count":7,"href":"https:\/\/bobbeaty.com\/wp\/wp-json\/wp\/v2\/posts\/4218\/revisions"}],"predecessor-version":[{"id":4225,"href":"https:\/\/bobbeaty.com\/wp\/wp-json\/wp\/v2\/posts\/4218\/revisions\/4225"}],"wp:attachment":[{"href":"https:\/\/bobbeaty.com\/wp\/wp-json\/wp\/v2\/media?parent=4218"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/bobbeaty.com\/wp\/wp-json\/wp\/v2\/categories?post=4218"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/bobbeaty.com\/wp\/wp-json\/wp\/v2\/tags?post=4218"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}