โ† All Interactive Demos

๐Ÿค– ASTRA Crypto Trading Agent โ€” Demo โ†” Live Adapter & Replit Audit Workbench

Zero-Rebuild Binance USDโ“ˆ-M Futures Adapter Pattern ยท Exact LOT_SIZE/PRICE_FILTER Normalizer ยท Pre-Trade Risk Gate ยท Replit Codebase Audit.

BINANCE_DEMO_TESTNET https://testnet.binancefuture.com | WS: wss://stream.binancefuture.com/ws

Adapter Pattern Active: Strategy, Feature Engine & Risk Gate remain 100% untouched when toggling Demo โ†” Live credentials.

PASS โœ…Pre-Trade Risk Gate Verdict
0.037 BTCNormalized LOT_SIZE Qty
$3,496.50Position Notional & Eff. Lev
$349.65Initial Margin (ISOLATED)
astra-demo-btc-...Idempotent newClientOrderId

๐Ÿ“ Position-Sizing, Leverage & Exchange Filter Normalizer

Raw Unrounded Qty: โ€” Normalized Entry/SL: โ€”
All 5 Pre-Trade Risk & Exchange Filter Gates Passed.

๐Ÿ“œ Live ASTRA Signal โ†’ Risk Gate โ†’ Binance Execution Log

Simulated L2 Order-Book Top-of-Book Snapshot

Symbol Best Bid Best Ask OBI Imbalance Regime Signal

๐Ÿ” Initial-Stage Replit Python Codebase Audit & Hardening Checklist

Toggle items below to inspect critical failure modes commonly found in early Replit crypto bots and our exact Python fixes.

Readiness Score: 6 / 6 (100%)

๐Ÿ Clean Python 3.11 Exchange Adapter + Decimal Filter Normalizer

Drop-in modular architecture for your Replit workspace: switch `ASTRA_ENV=testnet` โ†” `ASTRA_ENV=live` via Replit Secrets with zero strategy edits.

from dataclasses import dataclass
from decimal import Decimal, ROUND_DOWN
import hashlib, hmac, os, time
from typing import Literal

EnvMode = Literal["testnet", "live"]

@dataclass(frozen=True)
class BinanceFuturesConfig:
    mode: EnvMode
    rest_base: str
    ws_base: str
    api_key: str
    api_secret: str

    @classmethod
    def from_replit_secrets(cls) -> "BinanceFuturesConfig":
        mode: EnvMode = "live" if os.getenv("ASTRA_ENV", "testnet").lower() == "live" else "testnet"
        if mode == "live":
            if os.getenv("ASTRA_LIVE_ARMED") != "true":
                raise RuntimeError("Refusing LIVE mainnet boot: set ASTRA_LIVE_ARMED=true explicitly.")
            return cls(
                mode="live",
                rest_base="https://fapi.binance.com",
                ws_base="wss://fstream.binance.com/ws",
                api_key=os.environ["BINANCE_LIVE_API_KEY"].strip(),
                api_secret=os.environ["BINANCE_LIVE_API_SECRET"].strip(),
            )
        return cls(
            mode="testnet",
            rest_base="https://testnet.binancefuture.com",
            ws_base="wss://stream.binancefuture.com/ws",
            api_key=os.environ["BINANCE_TESTNET_API_KEY"].strip(),
            api_secret=os.environ["BINANCE_TESTNET_API_SECRET"].strip(),
        )

def normalize_step(value: Decimal, step: Decimal) -> Decimal:
    """Prevents Binance -1111 Precision & Filter failure: LOT_SIZE / PRICE_FILTER."""
    return (value // step) * step.quantize(step, rounding=ROUND_DOWN)

def deterministic_client_order_id(mode: str, symbol: str, side: str, signal_ts_bucket: int) -> str:
    digest = hashlib.sha256(f"{mode}:{symbol}:{side}:{signal_ts_bucket}".encode()).hexdigest()[:10]
    return f"astra-{mode[:4]}-{symbol.lower()}-{digest}"