<?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: Bitnxs</title>
    <description>The latest articles on DEV Community by Bitnxs (@bitnxs).</description>
    <link>https://dev.to/bitnxs</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%2F4255712%2F038e0582-3213-4a60-a952-e8b4dce42a70.png</url>
      <title>DEV Community: Bitnxs</title>
      <link>https://dev.to/bitnxs</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/bitnxs"/>
    <language>en</language>
    <item>
      <title>Run perp market checks with the open-source Bitnxs Grok Bot template</title>
      <dc:creator>Bitnxs</dc:creator>
      <pubDate>Fri, 20 Nov 2026 12:44:04 +0000</pubDate>
      <link>https://dev.to/bitnxs/run-perp-market-checks-with-the-open-source-bitnxs-grok-bot-template-1pli</link>
      <guid>https://dev.to/bitnxs/run-perp-market-checks-with-the-open-source-bitnxs-grok-bot-template-1pli</guid>
      <description>&lt;p&gt;&lt;em&gt;Written by the Bitnxs team. We build Bitnxs, a DEX for USDC-margined perpetual futures, and we maintain the template covered here.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;We open-sourced a Grok Bot template for Bitnxs under the MIT license. It's small on purpose: three skill files and two Python scripts. This post walks through what's in it, how to run the market checks locally, and how the agent side fits together. Everything below was run against the live API while writing.&lt;/p&gt;

&lt;p&gt;Quick context if you haven't seen Bitnxs: it lists USDC-margined perpetuals on BTC, ETH and SOL. Max leverage is 50x on BTC and ETH and 20x on SOL, funding is paid hourly, and fees are 0.02% maker and 0.05% taker. You can trade in the web app at &lt;a href="https://www.bitnxs.com" rel="noopener noreferrer"&gt;www.bitnxs.com&lt;/a&gt; or through the API documented at &lt;a href="https://docs.bitnxs.com/api/" rel="noopener noreferrer"&gt;docs.bitnxs.com&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Get the repo
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git clone https://github.com/Bitnxs-Labs/bitnxs-grokbot
&lt;span class="nb"&gt;cd&lt;/span&gt; bitnxs-grokbot
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The layout:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;LICENSE
README.md
scripts/snapshot.py
scripts/trade_min.py
skills/bitnxs-getting-started/SKILL.md
skills/bitnxs-market-brief/SKILL.md
skills/bitnxs-trading/SKILL.md
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The skills are Markdown instructions the agent reads. The scripts are what it actually runs. You can use the scripts without any agent at all, which is the easiest way to see what the bot sees.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 1: a read-only market snapshot
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;snapshot.py&lt;/code&gt; uses only the Python standard library and needs no API key.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;python3 scripts/snapshot.py            &lt;span class="c"&gt;# every listed market&lt;/span&gt;
python3 scripts/snapshot.py BTC ETH    &lt;span class="c"&gt;# just these&lt;/span&gt;
python3 scripts/snapshot.py --json     &lt;span class="c"&gt;# machine-readable rows&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The table has one row per coin: mark price, 24h change, funding per hour, the yearly equivalent of that funding rate, open interest, 24h volume and best bid/ask spread in basis points. The last line tells you how many minutes until the next hourly funding.&lt;/p&gt;

&lt;p&gt;Under the hood it's a handful of POSTs to one endpoint:&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="no"&gt;BASE&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"https://api.bitnxs.com"&lt;/span&gt;

&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;info&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;body&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;retries&lt;/span&gt;&lt;span class="o"&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="n"&gt;data&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;json&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;dumps&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;body&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;encode&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;req&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;urllib&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;request&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Request&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;"{BASE}/info"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;data&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;data&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;method&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"POST"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
                                 &lt;span class="n"&gt;headers&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="s2"&gt;"Content-Type"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"application/json"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
                                          &lt;span class="s2"&gt;"User-Agent"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"bitnxs-snapshot/1.0"&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="p"&gt;.&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The script calls &lt;code&gt;meta&lt;/code&gt; to get the listed coins, &lt;code&gt;allMids&lt;/code&gt; for prices, then &lt;code&gt;marketSummary&lt;/code&gt; and &lt;code&gt;l2Book&lt;/code&gt; per coin. Two details we learned the hard way and baked in:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Set a User-Agent.&lt;/strong&gt; Python's default urllib User-Agent gets an HTTP 403. Any custom string works.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Check &lt;code&gt;meta&lt;/code&gt; before asking about a coin.&lt;/strong&gt; Unknown coins return a summary full of zeros instead of an error, so the script checks &lt;code&gt;assetToId&lt;/code&gt; first and marks anything else as "not listed".&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Funding comes back as a percent per hour. &lt;code&gt;0.0100&lt;/code&gt; means 0.01% per hour, so the script multiplies by 24 × 365 to show a yearly figure. That's an annualized rate for comparison, not a forecast of anything.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 2: how the agent uses it
&lt;/h2&gt;

&lt;p&gt;The template has three skills.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;code&gt;bitnxs-getting-started&lt;/code&gt;&lt;/strong&gt; runs the first conversation. It sends a live snapshot right away, then asks which coins you care about, whether you want a regular brief and when, and what alert thresholds you want (a price level, a 24h move beyond some percent, funding above or below a rate). It saves those to memory and creates one routine for the brief and one for alerts. The alert routine stays quiet when nothing crossed.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;code&gt;bitnxs-market-brief&lt;/code&gt;&lt;/strong&gt; is read-only. It never places orders and never needs a key. It's also where we wrote down API quirks so the agent doesn't have to rediscover them. A few from the file:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Every public read is &lt;code&gt;POST https://api.bitnxs.com/info&lt;/code&gt; with &lt;code&gt;{"type": ...}&lt;/code&gt;. Without &lt;code&gt;Content-Type: application/json&lt;/code&gt; you get HTTP 415.&lt;/li&gt;
&lt;li&gt;Numbers are decimal strings, timestamps are UTC milliseconds, and errors come back as plain text, not JSON.&lt;/li&gt;
&lt;li&gt;Candles need both &lt;code&gt;startTime&lt;/code&gt; and &lt;code&gt;endTime&lt;/code&gt; as integer milliseconds, camelCase. An unknown interval silently falls back to 5m.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;recentTrades&lt;/code&gt; requires &lt;code&gt;limit&lt;/code&gt; (max 500).&lt;/li&gt;
&lt;li&gt;There's no public liquidation feed. If someone asks for liquidation levels, the skill only offers a clearly labeled estimate.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;If you write your own agent for any API, this kind of file pays off. The model stops guessing parameter names, and you stop debugging the same 415.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;code&gt;bitnxs-trading&lt;/code&gt;&lt;/strong&gt; is the part that touches an account. It covers placing, modifying and cancelling orders, changing leverage and setting TP/SL. It only works once you've created your own API key under More &amp;gt; API Keys in the web app, and the template collects that key through a masked secret field, not in chat.&lt;/p&gt;

&lt;p&gt;To try it, the README has an "Import Bitnxs Bot" button for Grok Bot. Importing starts the getting-started conversation.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 3: the trading script, without sending anything
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;trade_min.py&lt;/code&gt; is the minimal trading client the trading skill relies on. It needs one dependency:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;python3 -m venv .venv
.venv/bin/pip install &lt;span class="s2"&gt;"eth-account&amp;gt;=0.13"&lt;/span&gt;
.venv/bin/python scripts/trade_min.py selftest
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;selftest&lt;/code&gt; runs offline. It signs a sample challenge with a throwaway key, recovers the address and checks decimal formatting. You should see &lt;code&gt;selftest ok&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;The subcommands are &lt;code&gt;account&lt;/code&gt;, &lt;code&gt;place&lt;/code&gt;, &lt;code&gt;cancel&lt;/code&gt;, &lt;code&gt;cancel-all&lt;/code&gt;, &lt;code&gt;leverage&lt;/code&gt;, &lt;code&gt;tpsl&lt;/code&gt;, &lt;code&gt;cancel-trigger&lt;/code&gt; and &lt;code&gt;selftest&lt;/code&gt;. For real use it reads &lt;code&gt;BITNXS_API_KEY&lt;/code&gt; and &lt;code&gt;BITNXS_USER&lt;/code&gt; (your main wallet address) from the environment. The global flags go before the subcommand:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="kd"&gt;export&lt;/span&gt; &lt;span class="nv"&gt;BITNXS_USER&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;0xYourMainWallet
&lt;span class="kd"&gt;export&lt;/span&gt; &lt;span class="nv"&gt;BITNXS_API_KEY&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;0xYourApiKey
.venv/bin/python scripts/trade_min.py --dry-run place BTC buy 0.001 --price 50000
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;With &lt;code&gt;--dry-run&lt;/code&gt; the script prints the order body it would send to &lt;code&gt;/session/order&lt;/code&gt; and stops there:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;
 &lt;span class="nl"&gt;"POST /session/order"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;"sessionId"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"&amp;lt;sessionId&amp;gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nl"&gt;"asset"&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="nl"&gt;"isBuy"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nl"&gt;"limitPx"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"50000"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nl"&gt;"sz"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"0.001"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nl"&gt;"reduceOnly"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nl"&gt;"orderType"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nl"&gt;"type"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"limit"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nl"&gt;"tif"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"Gtc"&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;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Without &lt;code&gt;--dry-run&lt;/code&gt; or &lt;code&gt;--yes&lt;/code&gt;, any write command exits with &lt;code&gt;live request: add --yes or --dry-run&lt;/code&gt;. That guard exists because there is no testnet. Anything sent with &lt;code&gt;--yes&lt;/code&gt; is a real order on a real account.&lt;/p&gt;

&lt;p&gt;How auth works, briefly: the API key is a delegate signing key derived from your wallet. The client calls &lt;code&gt;/session/start&lt;/code&gt;, signs the returned challenge with the key (raw keccak, not personal_sign), sends it to &lt;code&gt;/session/complete&lt;/code&gt;, and gets a &lt;code&gt;sessionId&lt;/code&gt; for the order calls. There are no bearer tokens or HMAC secrets. The &lt;a href="https://docs.bitnxs.com/api/" rel="noopener noreferrer"&gt;API overview&lt;/a&gt; has the full flow in Python, and the script revokes its session when it's done.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 4: wire it into your own agent
&lt;/h2&gt;

&lt;p&gt;You don't need Grok Bot to reuse any of this. The pattern is portable:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Give the model a read-only tool that returns the snapshot JSON (&lt;code&gt;snapshot.py --json&lt;/code&gt;).&lt;/li&gt;
&lt;li&gt;Put the API rules in the system prompt or a skill file, like &lt;code&gt;bitnxs-market-brief&lt;/code&gt; does.&lt;/li&gt;
&lt;li&gt;Keep anything that writes to an account behind a separate tool with a dry-run path, and keep scheduled routines read-only. The template's routines never place trades.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Bitnxs also has its own experimental agent panel in the web app at bitnxs.com/#/agent, which works with any OpenAI-compatible endpoint. The &lt;a href="https://docs.bitnxs.com/ai-agent/" rel="noopener noreferrer"&gt;AI Agent docs&lt;/a&gt; cover what it can and can't do. It's a different thing from this template, but the same idea.&lt;/p&gt;

&lt;h2&gt;
  
  
  Before you trade
&lt;/h2&gt;

&lt;p&gt;Perpetual futures with leverage can lose your entire margin, quickly. An agent doesn't change that, and a confident-sounding model is not evidence of a good trade. Nothing here is investment advice, and we don't promise any result from using the template. Bitnxs is not available in restricted regions, including the United States, Canada, the United Kingdom and Mainland China; the full list is in the &lt;a href="https://docs.bitnxs.com/legal/terms/" rel="noopener noreferrer"&gt;Terms&lt;/a&gt;. Withdrawals go through a review of about 5 minutes and may be held or rejected.&lt;/p&gt;

&lt;p&gt;Issues and pull requests are welcome on &lt;a href="https://github.com/Bitnxs-Labs/bitnxs-grokbot" rel="noopener noreferrer"&gt;GitHub&lt;/a&gt;. If you want to look at the markets first, &lt;a href="https://www.bitnxs.com" rel="noopener noreferrer"&gt;www.bitnxs.com&lt;/a&gt; has the trading page.&lt;/p&gt;

</description>
      <category>opensource</category>
      <category>ai</category>
      <category>python</category>
      <category>tutorial</category>
    </item>
  </channel>
</rss>
