<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Daniel Szemerey</title>
    <description>The latest articles on DEV Community by Daniel Szemerey (@szemyd).</description>
    <link>https://dev.to/szemyd</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F4269632%2F7d4aa5d7-17ac-441e-b4b2-5b56b7759d0d.png</url>
      <title>DEV Community: Daniel Szemerey</title>
      <link>https://dev.to/szemyd</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/szemyd"/>
    <language>en</language>
    <item>
      <title>Realistic transaction costs for crypto perp backtests: BTC vs a tokenised stock on Binance</title>
      <dc:creator>Daniel Szemerey</dc:creator>
      <pubDate>Sat, 28 Nov 2026 19:56:29 +0000</pubDate>
      <link>https://dev.to/szemyd/realistic-transaction-costs-for-crypto-perp-backtests-btc-vs-a-tokenised-stock-on-binance-393b</link>
      <guid>https://dev.to/szemyd/realistic-transaction-costs-for-crypto-perp-backtests-btc-vs-a-tokenised-stock-on-binance-393b</guid>
      <description>&lt;p&gt;You backtest a signal on BTC perps, it makes a fraction of a basis point a trade, and you subtract the spread as your cost. On Binance's BTC perp the spread is about a hundredth of a basis point, so almost anything survives. What does a market order on a perp really cost, and which part of that cost decides whether a strategy survives?&lt;/p&gt;

&lt;p&gt;I measured it on two free slices of our data. One is a month of 5-minute bars on the BTC perp (May 2025). The other is a month of hourly bars on Binance's NVDA perp, a tokenised Nvidia share (July 2026). On BTC, a market order paid about 0.27 bp per side against the mid, in half the spread plus slippage past the best quote. Binance's base taker fee is 5 bp, about 19 times that. On NVDA the same market cost was about 0.95 bp, three to four times BTC's, with a top of book a few hundred times thinner.&lt;/p&gt;

&lt;p&gt;Then I ran a simple order-flow rule through those costs. It made about 200 bp over May before costs, lost about 55 bp after spread and slippage, and lost about 3,100 bp after the taker fee.&lt;/p&gt;

&lt;p&gt;Caveat: these are two one-month samples, from different years and at different bar sizes. The fee is Binance's base tier, and active traders pay less.&lt;/p&gt;

&lt;p&gt;We originally built Aperiodic for our own MFT stat arb prop trading, because crypto data is such a mess. (Full disclosure: the data here is ours.)&lt;/p&gt;

&lt;h2&gt;
  
  
  I. The three parts of a taker's cost
&lt;/h2&gt;

&lt;p&gt;A market order pays three things, measured against the mid:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Half the spread, to cross from the mid to the best quote. I use &lt;code&gt;spread_bps_avg&lt;/code&gt; from our &lt;code&gt;l1_liquidity&lt;/code&gt; dataset, the spread averaged over the bar.&lt;/li&gt;
&lt;li&gt;Slippage past the touch: what a trade pays beyond the best quote when it eats into the book. I use &lt;code&gt;slippage_bps_vwap&lt;/code&gt; from &lt;code&gt;slippage&lt;/code&gt;, the volume-weighted average over every trade in the bar. The median trade pays nothing past the touch on either perp, so this number is what size pays.&lt;/li&gt;
&lt;li&gt;The fee. Binance's regular-user tier for USDⓈ-M futures is 0.05% (5 bp) for takers and 0.02% for makers, according to its &lt;a href="https://www.binance.com/en/support/faq/360033544231" rel="noopener noreferrer"&gt;fee FAQ&lt;/a&gt;, checked 27 Nov 2026. VIP tiers and paying in BNB bring it down.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fxxmzzsq8h04hkxz695kv.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fxxmzzsq8h04hkxz695kv.png" alt="Cost per side of a market order on Binance perps: on BTC, half the spread is 0.01 bp and slippage 0.26 bp against a 5 bp taker fee; on the NVDA perp, 0.26 bp and 0.69 bp" width="800" height="450"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Per side, against the mid&lt;/th&gt;
&lt;th&gt;BTC perp, May 2025 (5m)&lt;/th&gt;
&lt;th&gt;NVDA perp, July 2026 (1h)&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Half the spread, mean (bp)&lt;/td&gt;
&lt;td&gt;0.006&lt;/td&gt;
&lt;td&gt;0.256&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Slippage past the touch, mean (bp)&lt;/td&gt;
&lt;td&gt;0.261&lt;/td&gt;
&lt;td&gt;0.695&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Market cost, mean (bp)&lt;/td&gt;
&lt;td&gt;0.267&lt;/td&gt;
&lt;td&gt;0.951&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Market cost, median (bp)&lt;/td&gt;
&lt;td&gt;0.151&lt;/td&gt;
&lt;td&gt;0.862&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Market cost, 95th percentile (bp)&lt;/td&gt;
&lt;td&gt;0.872&lt;/td&gt;
&lt;td&gt;1.792&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Top-of-book depth, median ($)&lt;/td&gt;
&lt;td&gt;1,970,324&lt;/td&gt;
&lt;td&gt;4,558&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Taker fee, base tier (bp)&lt;/td&gt;
&lt;td&gt;5&lt;/td&gt;
&lt;td&gt;5&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;On BTC the spread is a rounding error and the fee is the cost. On NVDA the spread and the slippage are real money, and the book is thin. A median of about $4,600 sits at the best bid and ask together, so any order of size walks the book.&lt;/p&gt;

&lt;h2&gt;
  
  
  II. When BTC is cheapest to trade
&lt;/h2&gt;

&lt;p&gt;The market cost moves through the day. On BTC in May it averaged about 0.20 bp per side at 11:00 UTC, the cheapest hour, and about 0.36 bp at 14:00 UTC, the dearest. That's the first full hour after the US stock market opens (13:30 UTC in May). My guess is that the open brings faster moves and bigger takers, but I haven't tested it. Either way, every hour is small next to a 5 bp fee.&lt;/p&gt;

&lt;h2&gt;
  
  
  III. What costs do to a strategy
&lt;/h2&gt;

&lt;p&gt;To see the costs at work, I took the signal from &lt;a href="https://dev.to/szemyd/point-in-time-order-flow-for-binance-perps-it-explains-the-bar-not-the-next-one-3fe7"&gt;my last post&lt;/a&gt;: flow pressure, the net share of taker volume that bought in a 5-minute bar. I fixed two rules before looking at the results:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Always in: hold the sign of this bar's flow pressure through the next bar.&lt;/li&gt;
&lt;li&gt;Strong flow only: the same, but only when flow pressure is at least 50 either way (about 4% of bars), and flat otherwise.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Each rule trades at the end of the bar at the mid, plus that bar's own market cost. A change of one unit of position pays one side; a flip from long to short pays two.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;BTC perp, May 2025&lt;/th&gt;
&lt;th&gt;Always in&lt;/th&gt;
&lt;th&gt;Strong flow only&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Bars in the market&lt;/td&gt;
&lt;td&gt;8,927&lt;/td&gt;
&lt;td&gt;321&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Units of position change&lt;/td&gt;
&lt;td&gt;8,195&lt;/td&gt;
&lt;td&gt;614&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Gross (bp, sum over the month)&lt;/td&gt;
&lt;td&gt;−2,282&lt;/td&gt;
&lt;td&gt;+200&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;After spread and slippage (bp)&lt;/td&gt;
&lt;td&gt;−4,355&lt;/td&gt;
&lt;td&gt;−55&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;After a 5 bp taker fee too (bp)&lt;/td&gt;
&lt;td&gt;−45,330&lt;/td&gt;
&lt;td&gt;−3,125&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Market cost per unit of change (bp)&lt;/td&gt;
&lt;td&gt;0.253&lt;/td&gt;
&lt;td&gt;0.414&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Break-even fee per side (bp)&lt;/td&gt;
&lt;td&gt;−0.53&lt;/td&gt;
&lt;td&gt;−0.09&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Always in loses before any cost, because the next-bar relationship is a slight reversal. Strong flow only makes about 0.3 bp per unit of position change before costs, which is more than the average market cost of 0.27 bp. It still loses after spread and slippage, because it pays about 0.41 bp a side. It trades exactly when flow is one-sided, and on those bars a market order costs more. Charged the month's average cost instead, the same rule would have shown about 36 bp of profit before fees. Costing each trade at its own bar shows it isn't there.&lt;/p&gt;

&lt;h2&gt;
  
  
  IV. Where it breaks
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;The samples are short, and BTC and NVDA come from different years at different bar sizes, so the comparison isn't like for like.&lt;/li&gt;
&lt;li&gt;Slippage here is the average trade's, weighted by volume. Your own order's slippage depends on its size against the book.&lt;/li&gt;
&lt;li&gt;The fee is the base tier. Maker orders pay less but may not fill, which is a cost of its own.&lt;/li&gt;
&lt;li&gt;The two rules illustrate the costs. They aren't strategies.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Past results say nothing certain about future returns, and none of this is investment advice.&lt;/p&gt;

&lt;h2&gt;
  
  
  V. Reproduce it
&lt;/h2&gt;

&lt;p&gt;This prints the cost per side for both perps from the free slices:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="c1"&gt;# pip install "aperiodic[pandas]"&lt;/span&gt;
&lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="n"&gt;datetime&lt;/span&gt; &lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="n"&gt;date&lt;/span&gt;

&lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="n"&gt;aperiodic&lt;/span&gt; &lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="n"&gt;get_metrics&lt;/span&gt;


&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;cost_per_side&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;symbol&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;interval&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;start&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;end&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="s2"&gt;"""What a market order pays against the mid, in bp: half the spread plus slippage past the touch."""&lt;/span&gt;
    &lt;span class="n"&gt;kw&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kt"&gt;dict&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;exchange&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"binance-futures"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;symbol&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;symbol&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;interval&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;interval&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;timestamp&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"exchange"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
              &lt;span class="n"&gt;start_date&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;start&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;end_date&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;end&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;preview&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="kc"&gt;True&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;output&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"pandas"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;show_progress&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="kc"&gt;False&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;spread&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;get_metrics&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;metric&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"l1_liquidity"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="o"&gt;**&lt;/span&gt;&lt;span class="n"&gt;kw&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;set_index&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"time"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"spread_bps_avg"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
    &lt;span class="n"&gt;slip&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;get_metrics&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;metric&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"slippage"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="o"&gt;**&lt;/span&gt;&lt;span class="n"&gt;kw&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;set_index&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"time"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"slippage_bps_vwap"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;spread&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;slip&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;mean&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;


&lt;span class="n"&gt;btc&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;cost_per_side&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"perpetual-BTC-USDT:USDT"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"5m"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nf"&gt;date&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;2025&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nf"&gt;date&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;2025&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;31&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;nvda&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;cost_per_side&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"perpetual-NVDA-USDT:USDT"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"1h"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nf"&gt;date&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;2026&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;7&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nf"&gt;date&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;2026&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;7&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;31&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;f&lt;/span&gt;&lt;span class="s2"&gt;"BTC perp, May 2025:  {btc:.2f} bp per side"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;f&lt;/span&gt;&lt;span class="s2"&gt;"NVDA perp, July 2026: {nvda:.2f} bp per side"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;f&lt;/span&gt;&lt;span class="s2"&gt;"A 5 bp taker fee is {5 / btc:.0f}x the BTC market cost"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;BTC perp, May 2025:  0.27 bp per side
NVDA perp, July 2026: 0.95 bp per side
A 5 bp taker fee is 19x the BTC market cost
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If you backtest perps, try costing each trade with the spread and slippage of its own bar rather than an average, and see what it does to your numbers.&lt;/p&gt;

&lt;p&gt;You can also pull the same data straight into an AI agent through our &lt;a href="https://aperiodic.io/mcp" rel="noopener noreferrer"&gt;MCP server&lt;/a&gt;, no key needed for the free slice.&lt;/p&gt;

&lt;p&gt;If you need help with data, feel free to reach out!&lt;/p&gt;

</description>
      <category>python</category>
      <category>datascience</category>
      <category>cryptocurrency</category>
      <category>fintech</category>
    </item>
    <item>
      <title>A free microstructure dataset for crypto and tokenised stock perps, and how each metric is built</title>
      <dc:creator>Daniel Szemerey</dc:creator>
      <pubDate>Sat, 28 Nov 2026 19:54:39 +0000</pubDate>
      <link>https://dev.to/szemyd/a-free-microstructure-dataset-for-crypto-and-tokenised-stock-perps-and-how-each-metric-is-built-44i6</link>
      <guid>https://dev.to/szemyd/a-free-microstructure-dataset-for-crypto-and-tokenised-stock-perps-and-how-each-metric-is-built-44i6</guid>
      <description>&lt;p&gt;When we went looking, Hugging Face had plenty of crypto market data and nothing on tokenised stock perps. So we put a free quarter of ours there, and I want to show what's in it and how the numbers are made, because that's the part most datasets leave out.&lt;/p&gt;

&lt;p&gt;It covers Q3 2026 in hourly bars, for 37 perpetual contracts on Binance, OKX and Hyperliquid: BTC, ETH, SOL and ten real-world asset perps such as Tesla, Nvidia, gold and the S&amp;amp;P 500. That's 21 datasets, 226 metric columns and about 1.6M rows. One short form on the page gets you in.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F0fg2jkqurrj6ravtla9w.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F0fg2jkqurrj6ravtla9w.png" alt="The Aperiodic dataset page on Hugging Face: crypto-perp-microstructure-q3-2026, Parquet, tagged market microstructure, order book, order flow and liquidity, behind a short access form" width="800" height="450"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Every metric comes from the exchange's own trades and quotes, point in time: a bar only uses what happened up to its end, on the exchange's clock. Three of them, and how they're built:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Flow pressure: the net share of taker volume that bought in the bar, from −100 (every taker sold) to +100 (every taker bought).&lt;/li&gt;
&lt;li&gt;Spread and depth: the gap between the best bid and ask in basis points of the mid, and the dollars quoted at the best bid and ask, both averaged over the bar.&lt;/li&gt;
&lt;li&gt;Price impact: Kyle's lambda, fitted on the bar's own trades (the covariance of trade returns and signed size, over the variance of signed size), then scaled to how far $1M of net buying would move the price, in bp.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;That last step matters more than it looks. Per unit of size, BTC's perp and Nvidia's have almost the same lambda. Per $1M, Nvidia's moves about 600 times more, because one unit of BTC costs about 500 times as much. (Those two numbers come from our free preview slices, BTC in May 2025 and NVDA in July 2026.)&lt;/p&gt;

&lt;p&gt;To load a dataset, accept the license on the page, log in once with &lt;code&gt;hf auth login&lt;/code&gt;, then:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="n"&gt;datasets&lt;/span&gt; &lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="n"&gt;load_dataset&lt;/span&gt;

&lt;span class="n"&gt;flow&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;load_dataset&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"aperiodic-io/crypto-perp-microstructure-q3-2026"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"flow"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;split&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"train"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It's not perfect: some datasets have holes, mostly order book data in August, and the dataset page lists every one.&lt;/p&gt;

&lt;p&gt;Every column is defined in our catalog, and the same data comes through our Python SDK too, with a smaller preview that needs no key at all.&lt;/p&gt;

&lt;p&gt;If you build something with it, I'd love to see it!&lt;/p&gt;

</description>
      <category>showdev</category>
      <category>datascience</category>
      <category>python</category>
      <category>cryptocurrency</category>
    </item>
    <item>
      <title>Point-in-time order flow for Binance perps: it explains the bar, not the next one</title>
      <dc:creator>Daniel Szemerey</dc:creator>
      <pubDate>Sat, 28 Nov 2026 12:58:12 +0000</pubDate>
      <link>https://dev.to/szemyd/point-in-time-order-flow-for-binance-perps-it-explains-the-bar-not-the-next-one-3fe7</link>
      <guid>https://dev.to/szemyd/point-in-time-order-flow-for-binance-perps-it-explains-the-bar-not-the-next-one-3fe7</guid>
      <description>&lt;p&gt;In a typical five minutes, the BTC perpetual on Binance prints close to 8,000 trades. Some are takers buying, some are takers selling, and the imbalance between them moves the price. If you want that order flow as a feature, you need it point in time. Each bar uses only the trades up to its end, by the exchange's clock. So how much does one bar's order flow tell you about the price, in that bar and in the next?&lt;/p&gt;

&lt;p&gt;I ran it on a month of 5-minute bars (May 2025, the free slice of our data, so you can rerun everything below without an API key). Flow pressure, the net share of taker volume that bought, has a rank IC of about 0.67 with the same bar's mid return. With the next bar's return the IC is about −0.025. That's a slight reversal, and it's too small to trade once you pay for the trades.&lt;/p&gt;

&lt;p&gt;Caveat: this is one month, one perp and one bar size. The next-bar effect is small, and it isn't stable within the month.&lt;/p&gt;

&lt;p&gt;We originally built Aperiodic for our own MFT stat arb prop trading, because crypto data is such a mess. (Full disclosure: the data here is ours.)&lt;/p&gt;

&lt;h2&gt;
  
  
  I. Point-in-time order flow
&lt;/h2&gt;

&lt;p&gt;Binance prints every trade with its aggressor side, so you know whether the taker bought or sold. Add up taker buys and taker sells per bar and you have order flow. Two details decide whether it's usable in a backtest:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Each trade goes into the bar its exchange timestamp falls in, and a bar never sees a trade printed after it closes.&lt;/li&gt;
&lt;li&gt;The price you measure the flow against is the mid at the end of the bar, from the order book. Trade prices bounce between the bid and the ask; the mid doesn't.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Our &lt;code&gt;flow&lt;/code&gt; dataset has 36 metrics per bar. They include taker buy and sell volume and counts, volume delta, flow entropy and a toxicity score, and the same split by small, medium and large orders. &lt;code&gt;flow_indices&lt;/code&gt; adds flow pressure (−100 when every taker sold, +100 when every taker bought). The mid comes from &lt;code&gt;l1_price&lt;/code&gt;. Fetching them takes a few lines:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="c1"&gt;# pip install "aperiodic[pandas]"&lt;/span&gt;
&lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="n"&gt;datetime&lt;/span&gt; &lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="n"&gt;date&lt;/span&gt;
&lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="n"&gt;aperiodic&lt;/span&gt; &lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="n"&gt;get_metrics&lt;/span&gt;

&lt;span class="n"&gt;kw&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kt"&gt;dict&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;exchange&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"binance-futures"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;symbol&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"perpetual-BTC-USDT:USDT"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;interval&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"5m"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
          &lt;span class="n"&gt;timestamp&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"exchange"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;start_date&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nf"&gt;date&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;2025&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;end_date&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nf"&gt;date&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;2025&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;31&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
          &lt;span class="n"&gt;preview&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="kc"&gt;True&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;output&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"pandas"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;show_progress&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="kc"&gt;False&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;  &lt;span class="c1"&gt;# the free slice, no API key&lt;/span&gt;

&lt;span class="n"&gt;flow&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;get_metrics&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;metric&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"flow"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="o"&gt;**&lt;/span&gt;&lt;span class="n"&gt;kw&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;            &lt;span class="c1"&gt;# taker volumes, counts, size buckets&lt;/span&gt;
&lt;span class="n"&gt;pressure&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;get_metrics&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;metric&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"flow_indices"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="o"&gt;**&lt;/span&gt;&lt;span class="n"&gt;kw&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;  &lt;span class="c1"&gt;# flow_pressure, conviction&lt;/span&gt;
&lt;span class="n"&gt;quotes&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;get_metrics&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;metric&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"l1_price"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="o"&gt;**&lt;/span&gt;&lt;span class="n"&gt;kw&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;      &lt;span class="c1"&gt;# best bid and ask, mid at the bar's end&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  II. The test
&lt;/h2&gt;

&lt;p&gt;I fixed the test before looking at any result. The sample is the BTC-USDT perp on Binance, 1 to 31 May 2025, in 5-minute bars (8,928 of them). For each bar I took three signals:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;flow pressure;&lt;/li&gt;
&lt;li&gt;net large-order flow: large taker buys minus large taker sells, as a share of all taker volume in the bar;&lt;/li&gt;
&lt;li&gt;net small-order flow, the same for small orders (the dataset's own size buckets).&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The returns are mid to mid, in basis points: the bar's own return (its closing mid against the previous one) and the next bar's. The statistic is the Spearman rank IC, with a plain t-statistic, since the bars don't overlap.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Signal&lt;/th&gt;
&lt;th&gt;IC, same bar&lt;/th&gt;
&lt;th&gt;t&lt;/th&gt;
&lt;th&gt;IC, next bar&lt;/th&gt;
&lt;th&gt;t&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Flow pressure&lt;/td&gt;
&lt;td&gt;0.671&lt;/td&gt;
&lt;td&gt;85.5&lt;/td&gt;
&lt;td&gt;−0.025&lt;/td&gt;
&lt;td&gt;−2.3&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Net large-order flow&lt;/td&gt;
&lt;td&gt;0.664&lt;/td&gt;
&lt;td&gt;84.0&lt;/td&gt;
&lt;td&gt;−0.025&lt;/td&gt;
&lt;td&gt;−2.3&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Net small-order flow&lt;/td&gt;
&lt;td&gt;0.186&lt;/td&gt;
&lt;td&gt;17.9&lt;/td&gt;
&lt;td&gt;−0.007&lt;/td&gt;
&lt;td&gt;−0.6&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;(8,927 pairs each.)&lt;/p&gt;

&lt;h2&gt;
  
  
  III. What the quintiles show
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fclpcgxgp8okk7jhl7cma.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fclpcgxgp8okk7jhl7cma.png" alt="Mean mid return of 5-minute BTC perp bars on Binance by quintile of taker flow pressure, May 2025: from about -9 bp to +10 bp in the same bar, but within 0.7 bp of zero in the next bar" width="800" height="450"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Sorting the bars into five groups by flow pressure makes the picture plain. In the bar itself, the mid moved about −9 bp in the most-selling fifth and about +10 bp in the most-buying fifth. In the next bar, every group sits within about 0.7 bp of zero, with no clean order: the second quintile is the highest, and the top quintile is slightly negative.&lt;/p&gt;

&lt;p&gt;Large orders carry almost all of the same-bar relationship (an IC of about 0.66, against about 0.19 for small orders). That fits the obvious mechanism, big takers move the price, though I haven't tested causality here.&lt;/p&gt;

&lt;p&gt;The flow itself persists a little: flow pressure has a lag-one rank autocorrelation of about 0.12. The price doesn't follow it. My best guess is that by the end of a 5-minute bar on BTC, the book has already absorbed the flow. What remains is a small overshoot that partly reverses.&lt;/p&gt;

&lt;h2&gt;
  
  
  IV. Where it breaks
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;The sample is short: one month of one perp, at one bar size.&lt;/li&gt;
&lt;li&gt;The next-bar IC isn't stable. It was about −0.018 (t −1.2) in the first half of May and about −0.032 (t −2.2) in the second.&lt;/li&gt;
&lt;li&gt;The same-bar IC isn't a signal. You only know a bar's flow once the bar is over.&lt;/li&gt;
&lt;li&gt;Costs decide the rest. A rule on this signal loses money once you pay the spread, slippage and fees, which is the subject of the next post.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Past results say nothing certain about future returns, and none of this is investment advice.&lt;/p&gt;

&lt;h2&gt;
  
  
  V. Reproduce it
&lt;/h2&gt;

&lt;p&gt;This prints the two headline numbers from the free slice:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="c1"&gt;# pip install "aperiodic[pandas]"&lt;/span&gt;
&lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="n"&gt;datetime&lt;/span&gt; &lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="n"&gt;date&lt;/span&gt;

&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="n"&gt;pandas&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="n"&gt;pd&lt;/span&gt;
&lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="n"&gt;aperiodic&lt;/span&gt; &lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="n"&gt;get_metrics&lt;/span&gt;

&lt;span class="n"&gt;kw&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kt"&gt;dict&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;exchange&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"binance-futures"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;symbol&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"perpetual-BTC-USDT:USDT"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;interval&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"5m"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
          &lt;span class="n"&gt;timestamp&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"exchange"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;start_date&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nf"&gt;date&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;2025&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;end_date&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nf"&gt;date&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;2025&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;31&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
          &lt;span class="n"&gt;preview&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="kc"&gt;True&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;output&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"pandas"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;show_progress&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="kc"&gt;False&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;  &lt;span class="c1"&gt;# the free slice, no API key&lt;/span&gt;

&lt;span class="n"&gt;flow&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;get_metrics&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;metric&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"flow_indices"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="o"&gt;**&lt;/span&gt;&lt;span class="n"&gt;kw&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;set_index&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"time"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;mid&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;get_metrics&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;metric&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"l1_price"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="o"&gt;**&lt;/span&gt;&lt;span class="n"&gt;kw&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;set_index&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"time"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"midprice"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;

&lt;span class="n"&gt;d&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;pd&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;DataFrame&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="s2"&gt;"flow"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;flow&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"flow_pressure"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;         &lt;span class="c1"&gt;# net share of taker volume that bought, -100 to +100&lt;/span&gt;
    &lt;span class="s2"&gt;"same"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;mid&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;pct_change&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;              &lt;span class="c1"&gt;# this bar's mid return&lt;/span&gt;
    &lt;span class="s2"&gt;"next"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;mid&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;pct_change&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;shift&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;    &lt;span class="c1"&gt;# the next bar's mid return&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;dropna&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;r&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;d&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;rank&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"rank IC, same bar:"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nb"&gt;round&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;r&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"flow"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;corr&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;r&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"same"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"rank IC, next bar:"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nb"&gt;round&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;r&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"flow"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;corr&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;r&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"next"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;rank IC, same bar: 0.671
rank IC, next bar: -0.025
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The free slice covers only this month. With an API key, the same calls reach other dates, OKX and Hyperliquid, and the tokenised stock perps (where the books are far thinner), as far as your plan goes. If you rerun it somewhere else, I'd love to see what you get.&lt;/p&gt;

&lt;p&gt;You can also pull the same data straight into an AI agent through our &lt;a href="https://aperiodic.io/mcp" rel="noopener noreferrer"&gt;MCP server&lt;/a&gt;, no key needed for the free slice.&lt;/p&gt;

&lt;p&gt;If you need help with data, feel free to reach out!&lt;/p&gt;

</description>
      <category>python</category>
      <category>datascience</category>
      <category>cryptocurrency</category>
      <category>fintech</category>
    </item>
  </channel>
</rss>
