You are working on a Python Bitunix futures order bot. Your task is to inspect the existing bot and tests, validate the inputs below, fix the bot when necessary, and prepare or submit exactly one Bitunix futures order. ==================== INPUTS ==================== Create a local .env file using these values. The API credentials must be filled in locally with a current matching Bitunix API key and secret. Never place real credentials in this prompt. BITUNIX_API_KEY=REPLACE_LOCALLY BITUNIX_API_SECRET=REPLACE_LOCALLY SYMBOL=BTCUSDT SIDE=LONG LEVERAGE=30 ENTRY_PRICE=57000 STOP_LOSS=55000 TAKE_PROFIT=63000 USDT_COST=10 REAL=yes # Use a new unique value for every separately authorized order. Never reuse one # that may already have been submitted. ORDER_INTENT_ID=REPLACE_WITH_NEW_UNIQUE_VALUE ================ INPUT DEFINITIONS ============= - SIDE must be LONG or SHORT. - ENTRY_PRICE is the limit-entry price in USDT. - USDT_COST is the initial margin/collateral, not leveraged position value. - Target position notional = USDT_COST * LEVERAGE. - Raw base quantity = target position notional / ENTRY_PRICE. - Round quantity DOWN to the contract's current basePrecision. Never round up. - Also report actual order notional = rounded quantity * ENTRY_PRICE. - Use Decimal for every monetary, price, quantity, risk, and precision calculation. Do not use float. - REAL must be exactly yes or no, case-insensitive. - REAL=no means validation-only. Do not send any authenticated request that changes account state, leverage, margin mode, or orders. - REAL=yes authorizes exactly one live order only after every mandatory validation passes. Never save an API key or secret in Python/PHP source, README files, logs, command history, test output, responses, or version control. Put .env in .gitignore before creating it. Redact credentials from all output. If credentials are missing, placeholders, or rejected, stop without placing an order. ================ DOCUMENTATION ================= Use the current official Bitunix documentation and official demo. Do not guess endpoints, parameters, signing, precision, or behavior. Documentation home: https://www.bitunix.com/api-docs/ Authentication/signing: https://www.bitunix.com/api-docs/futures/common/sign.html Official API demo repository: https://github.com/BitunixOfficial/open-api Trading-pair configuration: https://www.bitunix.com/api-docs/futures/market/get_trading_pairs.html Account information: https://www.bitunix.com/api-docs/futures/account/get_single_account.html Change leverage: https://www.bitunix.com/api-docs/futures/account/change_leverage.html Place order with attached TP/SL: https://www.bitunix.com/api-docs/futures/trade/place_order.html Pending orders: https://www.bitunix.com/api-docs/futures/trade/get_pending_orders.html Base URL: https://fapi.bitunix.com ================ EXACT SIGNING REQUIREMENTS ================= Match Bitunix's official demo and the known-good PHP implementation exactly: 1. Generate nonce as a 32-character random hexadecimal string (UUID4 without hyphens is acceptable). 2. timestamp is the current Unix epoch time in milliseconds as a string. 3. For GET signing, sort query parameters by key in ascending ASCII order, then concatenate each key directly with its value. Do not include '=', '&', spaces, URL encoding, or the request path in the signed query string. Example: {"marginCoin":"USDT"} signs as marginCoinUSDT. 4. The actual GET URL must still use normal URL query encoding, for example ?marginCoin=USDT. 5. For POST signing, query string is empty unless the URL actually contains query parameters. 6. Serialize the POST body once to JSON. Use that exact serialized byte sequence both in the signature and the HTTP request body. Do not sign one JSON representation and send another. Compact JSON with no spaces is preferred. 7. digest = SHA256_HEX(nonce + timestamp + apiKey + signedQueryString + exactBodyString) 8. sign = SHA256_HEX(digest + secretKey) 9. Send these headers on every authenticated GET and POST, preserving the documented names: - api-key - nonce - timestamp - sign - Content-Type: application/json - language: en-US 10. Prefer Python requests, matching Bitunix's official Python demo. Do not print request headers because they contain credentials/signatures. 11. Treat only Bitunix code 0 as success. Preserve the returned numeric code and message in redacted errors; do not silently reinterpret a contradictory code/message. Before any mutation, make one authenticated read-only account request to verify signing and credentials. If it fails, stop. Never test signing using leverage/order endpoints. Important response-shape compatibility: Bitunix may return GET /api/v1/futures/account data either as a JSON object or as a one-element array containing that object. Normalize both forms. Never blindly use data[0]. Reject empty arrays, multi-item arrays, null, or other unexpected shapes. ================ REQUIRED WORKFLOW ============= 1. Read the existing bot and all tests before editing. 2. Review the current official documentation and official demo. 3. Add .env to .gitignore before saving credentials. Never reveal credentials. 4. Parse and validate all numeric inputs with Decimal. Reject non-finite and non-positive values. 5. Validate price relationships: - LONG: STOP_LOSS < ENTRY_PRICE < TAKE_PROFIT. - SHORT: TAKE_PROFIT < ENTRY_PRICE < STOP_LOSS. 6. Fetch current public trading-pair configuration and ticker before any authenticated mutation. Confirm: - Symbol exists and symbolStatus is OPEN. - isApiSupported is true. - Requested leverage is within current min/max limits. - Rounded-down quantity meets minTradeVolume and maxLimitOrderVolume. - Entry, stop, and take-profit prices satisfy current quote precision. - Entry satisfies current Bitunix price-protection rules using the current mark price and priceProtectScope. 7. Run automated tests before live execution. Tests must mock all authenticated requests and must never place orders or change account state. 8. Perform one authenticated read-only account request. Normalize object/list response shapes as described above. Read positionMode and available equity safely. 9. Show a concise summary with mode, side, symbol, leverage, entry, SL, TP, USDT_COST, target leveraged notional, actual rounded notional, rounded quantity, estimated SL loss, estimated TP profit, and reward/risk. Never show credentials. 10. Warn if estimated SL loss exceeds 1% of available futures equity. Warn if liquidation may occur before the stop. State that stop triggers and market exits do not guarantee a fill price. 11. If REAL=no, stop after validation/summary and state that no authenticated mutation or order was sent. 12. If REAL=yes, enforce durable idempotency before mutation: - Build a clientId from ORDER_INTENT_ID or persist the generated clientId to a local state file before the first live mutation. - Before placing, query pending and history/order-detail endpoints by clientId when supported. - If the clientId already exists, report that order and do not submit another. - If local state says submission may already have occurred, query first and never blindly place again. 13. Submit exactly one live order: - Change leverage to LEVERAGE for SYMBOL with the official endpoint. - Do not change margin mode or position mode. - Use LIMIT at ENTRY_PRICE. - LONG uses side BUY and tradeSide OPEN; SHORT uses side SELL and tradeSide OPEN. - Respect the account's ONE_WAY or HEDGE position mode. Do not assume a position mode. - Use GTC. - Set reduceOnly=false. - Attach TP and SL to the same entry order. - Use tpStopType=MARK_PRICE, tpOrderType=MARKET, slStopType=MARK_PRICE, slOrderType=MARKET. - Do not include tpOrderPrice/slOrderPrice for MARKET exits. 14. Never automatically retry the place-order POST after a timeout, connection loss, invalid JSON, or any ambiguous response. Query by the already-persisted clientId/orderId first so a network problem cannot create a duplicate. 15. On code 0, print returned orderId and clientId, then query and report the matching pending order. A pending query returning zero records may mean the order filled quickly; query official order detail/history before declaring failure. Do not place another order. 16. If validation, authentication, leverage change, or order placement fails, stop and report the redacted error. Do not weaken safeguards, substitute another order, or retry blindly. 17. Once a live order has been accepted, do not run the bot again with REAL=yes unless the user explicitly authorizes a separate additional order with a new ORDER_INTENT_ID. Do not use TradingView MCP or other MCP trading tools for this task. REAL=yes authorizes only the one order described by the current inputs and ORDER_INTENT_ID after mandatory validation. It does not authorize additional orders, blind retries, unrelated account changes, transfers, cancellations, or credential disclosure. At the end, report exactly what happened and show how to run the bot. Clearly warn that rerunning with REAL=yes can place another live order unless the idempotency guard recognizes the same ORDER_INTENT_ID.