[Python] BItUnix API Signature Error (10007) when Placing order

Discussão em 'Python' iniciado por Stack, Abril 11, 2025.

  1. Stack

    Stack Membro Participativo


    BitUnix Futures API – Signature Error (code 10007)
    ​

    I'm attempting to place a Futures order using BitUnix's REST API. Despite following the official documentation exactly, I consistently receive the error:

    {
    "code": 10007,
    "data": null,
    "msg": "Signature Error"
    }


    What I've done:


    1. Request URL and Method:
      POST https://fapi.bitunix.com/api/v1/futures/trade/place_order


    2. Headers:

      {
      "api-key": "my-api-key",
      "nonce": "random-hex-32-char",
      "timestamp": "in-milliseconds",
      "sign": "double-sha256 signature",
      "language": "en-US",
      "Content-Type": "application/json"
      }


      Payload (Minified):

      {
      "symbol": "BTCUSDT",
      "qty": "0.001",
      "side": "BUY",
      "tradeSide": "OPEN",
      "orderType": "MARKET"
      }


      Minimal Example:

      import hashlib, json, time, os, requests

      api_key = "your_api_key"
      secret_key = "your_secret_key"

      payload = {
      "symbol": "BTCUSDT",
      "qty": "0.001",
      "side": "BUY",
      "tradeSide": "OPEN",
      "orderType": "MARKET"
      }
      body = json.dumps(payload, separators=(",", ":"))

      nonce = os.urandom(16).hex()
      timestamp = str(int(time.time() * 1000))

      digest_input = nonce + timestamp + api_key + "" + body
      first_hash = hashlib.sha256(digest_input.encode()).hexdigest()
      signature = hashlib.sha256((first_hash + secret_key).encode()).hexdigest()

      headers = {
      "api-key": api_key,
      "nonce": nonce,
      "timestamp": timestamp,
      "sign": signature,
      "language": "en-US",
      "Content-Type": "application/json"
      }

      res = requests.post(
      "https://fapi.bitunix.com/api/v1/futures/trade/place_order",
      headers=headers,
      data=body
      )

      print("Status:", res.status_code)
      print("Response:", res.text)


      Official Documentation:
      https://openapidoc.bitunix.com/doc/common/introduction.html

    Continue reading...

Compartilhe esta Página