<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Bitnxs Blog]]></title><description><![CDATA[Bitnxs Blog]]></description><link>https://bitnxs.hashnode.dev</link><generator>RSS for Node</generator><lastBuildDate>Fri, 20 Nov 2026 14:33:26 GMT</lastBuildDate><atom:link href="https://bitnxs.hashnode.dev/rss.xml" rel="self" type="application/rss+xml"/><language><![CDATA[en]]></language><ttl>60</ttl><item><title><![CDATA[Reading perpetual futures market data from the Bitnxs REST API]]></title><description><![CDATA[Prices, funding, order book and candles from one public endpoint, plus a 44-line Python monitor]]></description><link>https://bitnxs.hashnode.dev/reading-perpetual-futures-market-data-from-the-bitnxs-rest-api</link><guid isPermaLink="true">https://bitnxs.hashnode.dev/reading-perpetual-futures-market-data-from-the-bitnxs-rest-api</guid><category><![CDATA[Python]]></category><category><![CDATA[APIs]]></category><category><![CDATA[Cryptocurrency]]></category><category><![CDATA[Web3]]></category><dc:creator><![CDATA[Bitnxs Team]]></dc:creator><pubDate>Fri, 20 Nov 2026 12:37:20 GMT</pubDate><content:encoded><![CDATA[<p><em>Written by the Bitnxs team. Bitnxs is a DEX for USDC-margined perpetuals on BTC, ETH and SOL, and this post covers its public read API.</em></p>
<p>If you want market data from Bitnxs, you don't need an account, a wallet or a key. All public reads go to a single endpoint, and the request body says what you want. This post goes through the calls we use most for prices, funding, the order book and candles, then puts them together into a small monitor you can leave running in a terminal.</p>
<p>Every request and response shape here was checked against the live API on November 20, 2026. The reference lives at <a href="https://docs.bitnxs.com/api/info-queries/">docs.bitnxs.com/api</a>.</p>
<h2>The one endpoint</h2>
<pre><code>POST https://api.bitnxs.com/info
Content-Type: application/json

{"type": "&lt;query&gt;", ...}
</code></pre>
<p>Three things trip people up:</p>
<ol>
<li><code>Content-Type: application/json</code> is required. Leave it off and you get HTTP 415.</li>
<li>Send a custom <code>User-Agent</code>. Python's default urllib agent gets HTTP 403.</li>
<li>Errors are plain text (400 or 422), not JSON, so don't blindly <code>json.loads</code> an error body.</li>
</ol>
<p>Numbers come back as decimal strings and timestamps are UTC milliseconds. Reads aren't rate-limited, but please keep it to one or two requests a second.</p>
<p>A quick test with curl:</p>
<pre><code class="language-bash">curl -s -X POST https://api.bitnxs.com/info \
  -H 'Content-Type: application/json' -H 'User-Agent: my-monitor/0.1' \
  -d '{"type":"allMids"}'
</code></pre>
<pre><code class="language-json">{"BTC":"61656.66","ETH":"1746.83","SOL":"71.94"}
</code></pre>
<h2>What's listed: <code>meta</code></h2>
<pre><code class="language-json">{"type": "meta"}
</code></pre>
<p>The response has an <code>assetToId</code> map (<code>{"BTC":1,"ETH":2,"SOL":3}</code>) and a <code>universe</code> array with each market's settings, including <code>maxLeverage</code> (50 for BTC and ETH, 20 for SOL). Call this first. If you ask about a coin that isn't listed, you get a response full of zeros rather than an error, which is an easy way to end up charting nonsense.</p>
<h2>Price and funding: <code>marketSummary</code></h2>
<pre><code class="language-json">{"type": "marketSummary", "coin": "BTC"}
</code></pre>
<p>One coin per call. A trimmed response:</p>
<pre><code class="language-json">{
  "coin": "BTC",
  "markPrice": "61705.92",
  "indexPrice": "61701.78",
  "change24hAbs": "-1055.68",
  "change24hPct": "-1.68",
  "fundingRate": "0.0076",
  "fundingIsEstimated": false,
  "nextFundingSeconds": 2195
}
</code></pre>
<p><code>fundingRate</code> is a percent per hour, because Bitnxs settles funding hourly. <code>0.0076</code> means 0.0076% per hour. Multiply by 8,760 if you want a yearly equivalent for comparison. <code>nextFundingSeconds</code> counts down to the next hourly settlement. The response also carries open interest and 24h volume in USD if you need them.</p>
<p><code>allMids</code> gives you a price for every market in one call, which is cheaper when that's all you need.</p>
<h2>Order book: <code>l2Book</code></h2>
<pre><code class="language-json">{"type": "l2Book", "coin": "ETH"}
</code></pre>
<p>You get <code>bids</code> and <code>asks</code>, each a list of <code>[price, size]</code> pairs with size in the coin. Best bid is <code>bids[0]</code> and best ask is <code>asks[0]</code>. There's also a <code>levels</code> field you can ignore. A spread in basis points is one line:</p>
<pre><code class="language-python">spread_bps = (ask - bid) / ((ask + bid) / 2) * 1e4
</code></pre>
<h2>Candles: <code>candleSnapshot</code></h2>
<pre><code class="language-json">{
  "type": "candleSnapshot",
  "req": {"coin": "BTC", "interval": "1h",
          "startTime": 1795087200000, "endTime": 1795173600000}
}
</code></pre>
<p>Both times are required, as integer milliseconds. Use camelCase <code>startTime</code> and <code>endTime</code>; that's what the server accepts in our tests. Supported intervals are 1m, 3m, 5m, 15m, 30m, 1h, 2h, 4h, 6h, 8h, 12h, 1d, 3d, 1w and 1mo. If you typo the interval you silently get 5m candles, so double-check.</p>
<p>Each candle looks like this:</p>
<pre><code class="language-json">{"t":1795161600000,"o":"61759.79","h":"61974.1","l":"61626.26","c":"61746.28","v":"0.3641","q":"22512.421959"}
</code></pre>
<p><code>v</code> is volume in the coin and <code>q</code> is in USD. Candles come oldest first, and the last one is still forming. Daily candles open at 00:00 UTC.</p>
<h2>Two more you'll want</h2>
<ul>
<li><code>{"type":"fundingHistory","coin":"ETH"}</code> returns the last 168 hourly funding rates (one week), oldest first. It ignores time parameters.</li>
<li><code>{"type":"feeSchedule"}</code> returns fees in basis points. The default tier shows <code>maker_fee_bps: 2</code> and <code>taker_fee_bps: 5</code>, which is 0.02% maker and 0.05% taker.</li>
</ul>
<p><code>recentTrades</code> exists too (<code>limit</code> is required, max 500), and there's a WebSocket at <code>wss://api.bitnxs.com/ws</code> for streaming mids, trades and book snapshots. One gotcha: the WebSocket candle channel doesn't respond, so fetch candles over REST.</p>
<h2>Build a small monitor</h2>
<p>Here's the whole thing. It uses only the standard library. Every 60 seconds it checks each listed market and prints the mark price, the 24h high-low range from hourly candles, the current funding rate and minutes to the next settlement. It flags anything past three thresholds you set.</p>
<pre><code class="language-python">import json, time, urllib.request

API = "https://api.bitnxs.com/info"
HEADERS = {"Content-Type": "application/json", "User-Agent": "bitnxs-monitor/0.1"}

def info(body):
    req = urllib.request.Request(API, json.dumps(body).encode(), HEADERS)
    with urllib.request.urlopen(req, timeout=15) as r:
        return json.loads(r.read())

FUNDING_MAX = 0.02   # percent per hour
MOVE_MAX = 3.0       # 24h change, percent
SPREAD_MAX = 10.0    # basis points

def check(coin):
    s = info({"type": "marketSummary", "coin": coin})
    book = info({"type": "l2Book", "coin": coin})
    now = int(time.time() * 1000)
    candles = info({"type": "candleSnapshot", "req": {
        "coin": coin, "interval": "1h",
        "startTime": now - 24 * 3600 * 1000, "endTime": now}})
    bid, ask = float(book["bids"][0][0]), float(book["asks"][0][0])
    spread_bps = (ask - bid) / ((ask + bid) / 2) * 1e4
    hi = max(float(c["h"]) for c in candles)
    lo = min(float(c["l"]) for c in candles)
    funding = float(s["fundingRate"])
    move = float(s["change24hPct"])
    alerts = []
    if abs(funding) &gt; FUNDING_MAX:
        alerts.append(f"funding {funding:.4f}%/h")
    if abs(move) &gt; MOVE_MAX:
        alerts.append(f"24h move {move:+.2f}%")
    if spread_bps &gt; SPREAD_MAX:
        alerts.append(f"spread {spread_bps:.1f}bp")
    print(f"{coin}: mark {float(s['markPrice']):,.2f}  24h range {lo:,.2f}-{hi:,.2f}  "
          f"funding {funding:.4f}%/h  next in {s['nextFundingSeconds'] // 60} min  "
          + ("ALERT: " + ", ".join(alerts) if alerts else "ok"))

coins = list(info({"type": "meta"})["assetToId"])
while True:
    for c in coins:
        check(c)
        time.sleep(1)
    time.sleep(60)
</code></pre>
<p>Run it with unbuffered output so lines show up immediately:</p>
<pre><code class="language-bash">python3 -u monitor.py
</code></pre>
<p>Output from a run on November 20, 2026, around 11:25 UTC:</p>
<pre><code>BTC: mark 61,700.70  24h range 61,246.53-64,004.14  funding 0.0076%/h  next in 34 min  ok
ETH: mark 1,749.27  24h range 1,718.24-1,815.18  funding 0.0100%/h  next in 34 min  ok
SOL: mark 71.95  24h range 71.59-75.50  funding 0.0100%/h  next in 34 min  ok
</code></pre>
<p>The thresholds are placeholders. Set them to whatever is useful to you. Some ideas for taking it further:</p>
<ul>
<li>Send alerts to a Slack or Telegram webhook instead of printing, and only when something changes state, so you don't get the same alert every minute.</li>
<li>Add <code>fundingHistory</code> and compare the current rate with the week's average.</li>
<li>Swap polling for the WebSocket <code>allMids</code> subscription if you want prices faster than once a minute.</li>
<li>Handle errors. As written, one failed request stops the loop. Wrap <code>check()</code> in a try/except and log the plain-text error body.</li>
</ul>
<h2>Where this stops</h2>
<p>Everything above is public and read-only. Account data (balances, positions, open orders) and anything that places orders needs a session signed by your wallet or an API key you create in the web app. The <a href="https://docs.bitnxs.com/api/authentication/">authentication docs</a> cover that flow. If you'd rather not write it yourself, our open-source Grok Bot template at <a href="https://github.com/Bitnxs-Labs/bitnxs-grokbot">github.com/Bitnxs-Labs/bitnxs-grokbot</a> has a stdlib-only <code>snapshot.py</code> that does a similar read-only check.</p>
<p>If you go on to trade, keep the risks in view. Leveraged perpetuals can lose your whole margin, and a monitor that flags a number says nothing about whether a trade is a good idea. Nothing here is investment advice, and we don't promise any outcome. Bitnxs isn't available in restricted regions, including the United States, Canada, the United Kingdom and Mainland China. Withdrawals go through a review of about 5 minutes and may be held or rejected.</p>
<p>The markets and the trading page are at <a href="https://www.bitnxs.com">www.bitnxs.com</a>, and the rest of the API reference is at <a href="https://docs.bitnxs.com/api/">docs.bitnxs.com</a>.</p>
]]></content:encoded></item></channel></rss>