MQuant Developers v1
Open MQuant

Authentication

Every request except GET /api/v1/time carries your key id and an HMAC-SHA256 signature. There are no bearer tokens and no sessions: each request proves on its own that it came from the holder of the secret, was made in the last few seconds and has not been seen before.

Credentials#

The desk issues credentials in pairs. The key id is public and travels with every request. The secret never leaves your servers: it is only the key for the HMAC.

ItemFormatLengthHow it is used
Live key idmq_live_pk_ + 22 characters33Sent in X-MQ-API-KEY on every request
Live secretmq_live_sk_ + 49 characters60Never sent. Used only as the HMAC key
Test key idmq_test_pk_ + 22 characters33Sent in X-MQ-API-KEY on every request
Test secretmq_test_sk_ + 49 characters60Never sent. Used only as the HMAC key
  • The last six characters of every key id and secret are a checksum, so a mistyped key is rejected straight away.
  • The secret is shown once, when the key is issued or rotated. Nobody at MQuant can read it back to you. If you lose it, ask the desk to rotate the key.
  • Each key has scopes: signals:write to send, test and cancel signals, and signals:read to read them back. GET /me works with either scope.
  • Each key has an expiry, 90 days by default and at most 365 days. GET /api/v1/me shows expires_at; after it, requests fail with 401 key_expired.
  • A trader can hold at most two active or suspended keys per mode. That leaves room to run a new key beside the old one while you switch over.

Request headers#

HeaderFormatExample
X-MQ-API-KEYYour key idmq_live_pk_…
X-MQ-TIMESTAMPUnix epoch time in milliseconds, exactly 13 digits1796184000000
X-MQ-NONCE16 to 64 characters from A-Z a-z 0-9 _ -, new for every request6f1c2a1e-8a4b-4c1f-9a3e-2b7d5c9e0f11
X-MQ-SIGNATURE64 hex characters: HMAC-SHA256 of the canonical string4f3288cd…eb0e

A POST with a body also needs Content-Type: application/json, optionally with ; charset=utf-8. Any other media type or charset returns 415 unsupported_media_type, and so does a Content-Encoding other than identity: do not compress request bodies. A cancel sent with no body needs no Content-Type.

Bodies are capped at 16,384 bytes (65,536 bytes for POST /signals/batch); larger bodies return 413 payload_too_large. A GET must not have a body (400 body_not_allowed).

The canonical string#

The signature is the HMAC-SHA256 of six values joined with a single line feed (\n, byte 0x0A). There is no trailing line feed.

Definition
canonical = METHOD + "\n" + PATH_WITH_QUERY + "\n" + TIMESTAMP + "\n" + NONCE + "\n" + KEY_ID + "\n" + BODY_SHA256_HEX
signature = lowercase_hex(HMAC_SHA256(key = secret_ascii_bytes, message = canonical_ascii_bytes))
  • METHOD: upper case, GET or POST.
  • PATH_WITH_QUERY: the request target exactly as you send it, starting at /api/v1, plus ? and the query string when there is one. MQuant signs the raw bytes it receives and never decodes or reorders the query, so sign the string you put on the wire, in the same order and with the same percent-encoding.
  • TIMESTAMP, NONCE and KEY_ID: the header values, exactly as sent.
  • BODY_SHA256_HEX: the lowercase hex SHA-256 of the raw body bytes. For an empty body it is always e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855.
  • The HMAC key is the whole 60-character secret, prefix included, as ASCII bytes.
  • Send the result as 64 hex characters. Lower case is conventional; upper case is accepted.

Worked example#

These inputs are for the documentation only and are not real credentials. Run your own signing code on them: if it prints the same body hash and signature, your signing is right. The body uses a fixed expiry date so that the signature never changes; do not send it as a real signal.

Method
POST
Path
/api/v1/signals
Timestamp
1796184000000
Nonce
6f1c2a1e-8a4b-4c1f-9a3e-2b7d5c9e0f11
Key id
mq_test_pk_Docs0Example0Key01tQIQ
Secret
mq_test_sk_DocsOnlyExampleSecretNeverUseThisValue123453XfwfW
Body, exact bytes
{"client_signal_id":"nifty-0001","exchange":"NFO","symbol":"NIFTY","instrument_type":"CE","expiry":"2026-12-29","strike":"24500","side":"BUY","lots":2,"order_type":"LIMIT","price":"112.50","product":"NRML","validity":"DAY","tag":"momo1"}
  1. Hash the body

    Take the exact bytes above (UTF-8, no added whitespace, no trailing newline) and compute SHA-256 as lowercase hex.

    Body SHA-256
    aeca1167ee27e92c043810b6c5dd20eda70395d6adc31b530df49d4f2bff58d6
  2. Build the canonical string

    Join the six values with \n. Here every line ends with a line feed except the last.

    Method
    POST
    Path with query
    /api/v1/signals
    Timestamp
    1796184000000
    Nonce
    6f1c2a1e-8a4b-4c1f-9a3e-2b7d5c9e0f11
    Key id
    mq_test_pk_Docs0Example0Key01tQIQ
    Body SHA-256
    aeca1167ee27e92c043810b6c5dd20eda70395d6adc31b530df49d4f2bff58d6
    Signature
    4f3288cd2ddecc0d5d2e692ae6081b02548a02eebc09be41b1d58d4071c2eb0e
  3. Sign it

    HMAC-SHA256 with the secret as the key and the canonical string as the message, both as ASCII bytes, written as lowercase hex.

    Signature
    4f3288cd2ddecc0d5d2e692ae6081b02548a02eebc09be41b1d58d4071c2eb0e
  4. Send the four headers

    On the wire
    POST /api/v1/signals HTTP/1.1
    Host: app.mquant.in
    Content-Type: application/json
    X-MQ-API-KEY: mq_test_pk_Docs0Example0Key01tQIQ
    X-MQ-TIMESTAMP: 1796184000000
    X-MQ-NONCE: 6f1c2a1e-8a4b-4c1f-9a3e-2b7d5c9e0f11
    X-MQ-SIGNATURE: 4f3288cd2ddecc0d5d2e692ae6081b02548a02eebc09be41b1d58d4071c2eb0e
    
    {"client_signal_id":"nifty-0001","exchange":"NFO","symbol":"NIFTY","instrument_type":"CE","expiry":"2026-12-29","strike":"24500","side":"BUY","lots":2,"order_type":"LIMIT","price":"112.50","product":"NRML","validity":"DAY","tag":"momo1"}

A second check, for a GET with a query string and an empty body, using the same timestamp, nonce and key:

Method
GET
Path with query
/api/v1/signals?status=received&limit=20
Timestamp
1796184000000
Nonce
6f1c2a1e-8a4b-4c1f-9a3e-2b7d5c9e0f11
Key id
mq_test_pk_Docs0Example0Key01tQIQ
Body SHA-256
e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855
Signature
17ecf98584ec8e9925783249e0e2dbd7ab1bae96f668e4d9e6b59e1713cd6545

To check your setup in one go, this short script must print the body hash and then the signature shown above:

Check your setup (Python)
import hashlib
import hmac

secret = "mq_test_sk_DocsOnlyExampleSecretNeverUseThisValue123453XfwfW"
body = b'{"client_signal_id":"nifty-0001","exchange":"NFO","symbol":"NIFTY","instrument_type":"CE","expiry":"2026-12-29","strike":"24500","side":"BUY","lots":2,"order_type":"LIMIT","price":"112.50","product":"NRML","validity":"DAY","tag":"momo1"}'
body_hash = hashlib.sha256(body).hexdigest()
canonical = "\n".join(["POST", "/api/v1/signals", "1796184000000",
                       "6f1c2a1e-8a4b-4c1f-9a3e-2b7d5c9e0f11",
                       "mq_test_pk_Docs0Example0Key01tQIQ", body_hash])
print(body_hash)
print(hmac.new(secret.encode("ascii"), canonical.encode("ascii"), hashlib.sha256).hexdigest())

Common mistakes#

  • Re-serialising JSON after signing. Build the body string once, hash it and send those same bytes. Many HTTP libraries re-encode a dict you hand them; pass the string or bytes instead.
  • Signing a different query string from the one you send. If your library sorts or re-encodes parameters, build the query yourself and pass the full URL.
  • Timestamps in seconds. MQuant wants 13-digit milliseconds. A 10-digit value fails with auth_headers_invalid.
  • Reusing a nonce on a retry. Every attempt needs a fresh timestamp, nonce and signature. Keep the same client_signal_id instead; that is what makes a retry safe.
  • Signing the full URL. Sign the path from /api/v1, not https://app.mquant.in/api/v1/….
  • A trailing slash. /api/v1/signals/ is a different path and returns 404 not_found.

Every signature failure gets the same 401 auth_failed response, whether the key id is unknown, the secret is wrong or the body was changed on the way. MQuant does not say which part was wrong. Debug against the worked example.

Clock and timestamps#

A request is accepted only when its timestamp is no more than 5,000 ms behind and no more than 1,000 ms ahead of the server clock. Outside that window you get 401 timestamp_out_of_window, and the message includes the server time in milliseconds.

  • Run NTP (chrony or systemd-timesyncd) on every machine that signs requests.
  • GET /api/v1/time needs no signature and returns server_time_ms, plus the current recv_window_ms and future_skew_ms. Read these values rather than hard-coding them.
  • If you cannot fix the clock, measure the offset: note your time before and after calling /time, take the midpoint, and add server_time_ms − midpoint to every timestamp. The Python and Node clients do this in sync_clock() / syncClock().
  • Sign immediately before you send. A request that sits in a queue for seconds can expire before it arrives.

Nonces#

  • 16 to 64 characters from A–Z a–z 0–9 _ -. A fresh UUIDv4 or 16 random bytes as hex is ideal.
  • Each nonce can be used once per key. MQuant remembers it for longer than the timestamp window, so a captured request cannot be replayed. A repeat returns 401 nonce_reused.
  • The nonce is recorded only after the signature checks out, so nobody else can use up your nonces.
  • Never derive the nonce from the signal or the clock alone. Two requests in the same millisecond must still have different nonces.

What the server checks, in order#

Checks run in this order, and the first failure decides the response. Knowing the order helps you read an error.

StepCheckFailure
1Per-IP request limit and any lockout or block on your address429 rate_limited, auth_locked, ip_temporarily_blocked
2API switched on503 api_disabled
3Body size, Content-Type, Content-Encoding, no body on GET413 payload_too_large, 415 unsupported_media_type, 400 body_not_allowed
4The four headers are present once each and well formed401 auth_headers_invalid
5Timestamp inside the window401 timestamp_out_of_window
6Key id and signature401 auth_failed
7Nonce not seen before401 nonce_reused
8Key and trader state401 key_expired, key_suspended, trader_inactive
9Caller IP on the allowlist403 ip_not_allowed
10Key has the scope the endpoint needs403 scope_denied
11Key not temporarily blocked429 key_temporarily_blocked
12Signal intake not paused (sending signals only)503 intake_paused
13Key, trader and desk rate limits429 rate_limited
14Body is strict JSON and the signal is valid, then risk caps400, 409 or 422, see Errors

IP allowlist#

Live keys accept requests only from the addresses on their allowlist. Anything else gets 403 ip_not_allowed, with your address in the message.

  • A live key needs 1 to 5 entries. Each is a public IPv4 or IPv6 address, or a CIDR range no wider than /24 (IPv4) or /56 (IPv6).
  • A test key may have an empty allowlist, which allows any address. If it has entries, they are enforced.
  • The desk changes allowlists for you. On a live key the list can change once every 7 days, in line with the exchange static-IP rule, so plan moves to new servers ahead.
  • The address that counts is the one MQuant sees: your NAT gateway or egress IP, not the private address of your server. GET /api/v1/me returns it as caller_ip.

Key rotation and expiry#

Rotation gives you a new secret for the same key id. Ask the desk for it on a schedule, when someone with access leaves, or at once if you think the secret has leaked.

  1. The desk rotates the key and hands you the new secret, shown once. The key id, limits, allowlist and your client_signal_id history do not change.
  2. For a grace period set by the desk (24 hours by default, at most 72 hours) both the old and the new secret are accepted. GET /api/v1/me shows the end of it in rotation_grace_until.
  3. Deploy the new secret to every machine and confirm with GET /api/v1/me.
  4. When the grace period ends, the old secret stops working. A rotation with no grace period switches at once.

Other key states you may meet: a suspended key returns 401 key_suspended until the desk resumes it. A revoked key is gone for good: its secret is erased, so its requests fail with 401 auth_failed. An expired key returns 401 key_expired; ask the desk for a new key before expires_at.

Security checklist#

  • Keep the secret on the server. Load it from a secrets manager or an environment variable. Never put it in source control, a browser, a mobile app, a spreadsheet, a chat message or a log line.
  • Do not log credentials. Log the X-Request-Id and your client_signal_id, not the signature or the secret. A signature is single-use but still tells an attacker about your traffic.
  • One key per system. Give each trading box its own key, so you can rotate or revoke one without stopping the others.
  • Use HTTPS and verify certificates. Never turn off certificate verification, even when testing.
  • Lock down the shell example. openssl -hmac takes the secret as a command-line argument, which other users on the same machine can see in the process list. Use it only on a single-user machine, or use the Python or Node client.
  • Least privilege. A monitoring job that only reads signals should have a key with signals:read only.
  • If a secret leaks, tell your MQuant desk contact at once. A revoke takes effect on the very next request.
MQuant is the platform of Sykes & Ray Equities. Questions go to your MQuant desk contact.