DEVELOPER SNIPPETS
Sample Code & Integration Guides
Ready-to-run examples demonstrating how to poll worker telemetry, handle automatic failovers, listen to real-time share submissions, and export pool earnings.
Python 3
asyncio + aiohttp Monitor Worker Hashrate & Alert on Offline Rigs
This script fetches active workers for a payout wallet, compares effective hashrate against nominal values, and prints alerts when a rig drops offline.
import asyncio
import aiohttp
POOL_API = "https://api.hashce.io/v2"
WALLET = "bc1q87x9p3c8e54u2nmf60ykv9qzw09m7dlaeq0042"
async def check_workers():
async with aiohttp.ClientSession() as session:
async with session.get(f"{POOL_API}/miner/{WALLET}/workers") as resp:
data = await resp.json()
for worker in data.get("workers", []):
w_id = worker["worker_id"]
eff_th = worker["effective_hashrate_ths"]
status = worker["status"]
if status != "online" or eff_th < 100.0:
print(f"[ALERT] Worker {w_id} is degraded! Status: {status}, Hash: {eff_th} TH/s")
else:
print(f"[OK] {w_id}: {eff_th:.1f} TH/s (Valid: {worker['shares_valid']})")
if __name__ == "__main__":
asyncio.run(check_workers()) Rust
tokio + hashce-stratum-v2 Stratum V2 Noise Handshake (Tokio)
Establishes an encrypted Noise Protocol (NX) channel with the hash_ce Stratum V2 Anycast server.
use tokio::net::TcpStream;
use hashce_stratum_v2::codec::{FramedStream, Message};
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let stream = TcpStream::connect("na.stratum.hashce.io:3334").await?;
let mut framed = FramedStream::new(stream);
// Perform Noise handshake with pool public authority key
framed.init_noise_handshake().await?;
println!("Stratum V2 encrypted channel established!");
// Open standard mining channel
let channel_req = Message::OpenStandardMiningChannel {
user_name: "bc1q87x9p3c8e54u2nmf60ykv9qzw09m7dlaeq0042.farm1".into(),
nominal_hash_rate: 234_000_000_000_000.0,
};
framed.send(channel_req).await?;
Ok(())
} Bash / cURL
jq + curl Daily Hashrate & Payout CSV Export
Export historical payouts and transaction hashes to an accounting-ready CSV format.
#!/usr/bin/env bash WALLET="bc1q87x9p3c8e54u2nmf60ykv9qzw09m7dlaeq0042" echo "payout_id,amount_sats,txid,date" > payouts.csv curl -s "https://api.hashce.io/v2/miner/$WALLET/payouts" \ | jq -r '.payouts[] | [.payout_id, .amount_sats, .txid, .settled_at] | @csv' \ >> payouts.csv echo "Exported $(wc -l < payouts.csv) entries to payouts.csv"
Looking for the complete API reference?
Explore all query parameters, error schemas, and WebSocket message types.