XTS-compatible API
If your trading code talks to a Symphony XTS Interactive API today, through the Python XTConnect SDK, the Node xts-interactive-api SDK or plain REST, it can talk to MQuant. Change the root URL, appKey and secretKey; the endpoints, function names, field names and replies stay the same.
Orders you place are stored as signals for the Sykes & Ray desk. Nothing is sent to an exchange or a broker by the API. Trades, positions and holdings are always empty.
The three changes#
| Setting | At your XTS broker | At MQuant |
|---|---|---|
| Root URL | https://xts.your-broker.example | https://app.mquant.in/api/v1 |
appKey | Your broker app key | Your MQuant key id: mq_live_pk_… or mq_test_pk_… |
secretKey | Your broker secret key | Your MQuant secret: mq_live_sk_… or mq_test_sk_… |
source | WEBAPI | Unchanged. Any XTS source is accepted; it defaults to WEBAPI. |
Before and after code for Python, Node.js and curl is in Switching from XTS on the overview. Every endpoint, with its SDK function, is in the XTS API reference.
Ask your MQuant desk contact for a key. Start with a test key: test orders are kept apart from live ones and can never be accepted by the desk. Live keys need an IP allowlist of 1 to 5 static public addresses.
Root URL for each client#
| Client | Set the root to | Requests go to |
|---|---|---|
| Plain REST, curl, any HTTP library | https://app.mquant.in/api/v1 | https://app.mquant.in/api/v1/interactive/… |
Node xts-interactive-api 3.x (new XTSInteractive(url)) | https://app.mquant.in/api/v1 | https://app.mquant.in/api/v1/interactive/… |
Python XTConnect (XTSConnect(appKey, secretKey, source, root=…)) | https://app.mquant.in/api/v1 | https://app.mquant.in/interactive/…, which MQuant serves as the same API |
The Python SDK builds every URL with urljoin(root, "/interactive/…"), which drops the path of the root, so it calls https://app.mquant.in/interactive/… whatever root you give it. MQuant answers there with the same API, so root="https://app.mquant.in/api/v1" and root="https://app.mquant.in" both work.
XTConnect reads config.ini from the working directory when it is imported, and fails without it. If you pass root= to XTSConnect you only need the file to exist; if you rely on its default root, change it:
[user]
source=WEBAPI
[SSL]
disable_ssl=False
[root_url]
root=https://app.mquant.in/api/v1
broadcastMode=FullLogging in and sessions#
POST /interactive/user/sessionwithappKey,secretKeyandsource, as JSON or as a form. The reply carriesresult.tokenandresult.userID(MQfollowed by your trader number, for exampleMQ12).- Send the token in the
authorizationheader on every other call, as XTS does. A leadingBeareris accepted too. DELETE /interactive/user/sessionends the session.
| Rule | MQuant |
|---|---|
| Token | mq_xts_ followed by 64 letters and digits. MQuant stores only a hash of it. |
| Lifetime | Until the next midnight IST, or the key's expiry if that is sooner. A token from yesterday gets Invalid Token. |
| Sessions per key | Up to 3. A fourth login ends the oldest session, so up to three processes can share one key. |
| Ends early when | You log out, or the desk suspends, revokes or rotates the key, or deactivates your trader account. |
| Wrong credentials | 400 e-user-0001 "Invalid appKey or secretKey", the same for every cause. 20 failed logins or signatures in 15 minutes lock your IP for 15 minutes. |
| IP allowlist | Checked at login and on every call. Live keys must have one. |
| Scopes | signals:write to place, modify and cancel; signals:read for the order book and history. Any key can log in and read the profile, balance, trades, positions and holdings. |
When a call answers 400 with "description": "Invalid Token", log in again and repeat the call. Both SDKs already treat this reply as an expired session.
Orders are signals#
MQuant does not route orders to an exchange. An order you place is stored as a signal for the Sykes & Ray desk, which reviews it and decides what happens to it. The same signal is visible through the signed signals API and to the desk.
- AppOrderID is a number MQuant assigns, 1,000,000,000 or more, unique and increasing within MQuant. Use it to modify, cancel and read the order, as with XTS.
- orderUniqueIdentifier is your tag. It is echoed back and stored as the signal's
tag. - Safe retries. Within 10 seconds, an identical order with the same
orderUniqueIdentifieris treated as a retry: you get the first order's AppOrderID back with the headerIdempotent-Replayed: true, and nothing new is stored. To send two identical orders back to back on purpose, give them differentorderUniqueIdentifiervalues. Orders without one are never treated as retries. - The order book lists today's orders (since midnight IST) placed through this interface by your trader, in the key's mode, oldest first. Order history works for any of your AppOrderIDs.
- Orders show the desk's view in two extra fields on every row:
MQuantStatus(the signal status) andMQuantSignalID.
Order fields#
Place (POST /interactive/orders) takes the XTS fields below. Values are matched without regard to case, and numeric strings are accepted where a number is expected. Any other field is a Bad Request.
| XTS field | Accepted values | Stored on the signal as |
|---|---|---|
exchangeSegment | Required. NSECM, NSEFO, BSECM, BSEFO, MCXFO, or the codes 1, 2, 11, 12, 51 (number or string), any case. | exchange: NSE, NFO, BSE, BFO, MCX |
exchangeInstrumentID | Required. The exchange token, as a number or a digit string of up to 15 digits. | symbol, instrument_type, expiry, strike, from the instrument master |
productType | Required. MIS (1), NRML (2), CNC (4). CO, BO and MTF are not supported. CNC only on NSECM and BSECM. | product. NRML on NSECM or BSECM is stored as CNC; the order book still shows NRML. |
orderType | Required. MARKET (1), LIMIT (2), STOPMARKET (4), STOPLIMIT (8), any case, so Limit and StopLimit work. | order_type: MARKET, LIMIT, SL-M, SL |
orderSide | Required. BUY or SELL. | side |
timeInForce | Required. DAY (1) or IOC (4). GTC, GTD, EOS, COL and GTDYS are not supported. | validity |
orderQuantity | Required. Whole number, at least 1, in units (shares or contracts). On NSEFO, BSEFO and MCXFO it must be a multiple of the lot size. | quantity |
disclosedQuantity | Optional, default 0. Not more than orderQuantity. | Kept with the order |
limitPrice | Number or decimal string, 0 or more, at most 2 decimals, a multiple of the tick size. 0 means not set. Required (above 0) for LIMIT and STOPLIMIT; ignored for MARKET and STOPMARKET. | price |
stopPrice | As limitPrice. Required (above 0) for STOPLIMIT and STOPMARKET; ignored for MARKET and LIMIT. | trigger_price |
orderUniqueIdentifier | Optional. 1 to 20 characters of A-Z a-z 0-9 _ -. Echoed back on every reply and row. | tag |
apiOrderSource | Optional. Up to 40 printable characters. | Kept with the order; shown as ApiOrderSource |
clientID | Optional. Leave it out, or send your userID. undefined and null count as absent. | Not stored |
algoID, algoCategory, isProOrder | Accepted and ignored. | Not stored |
Modify takes the same values under the XTS modified… names, plus appOrderID. The segment, instrument and side of an order cannot change.
Enum values#
| Field | XTS value | MQuant signal value |
|---|---|---|
productType | MIS / NRML / CNC | MIS / NRML on F&O, CNC on cash / CNC |
orderType | MARKET / LIMIT / STOPMARKET / STOPLIMIT | MARKET / LIMIT / SL-M / SL |
orderSide | BUY / SELL | BUY / SELL |
timeInForce | DAY / IOC | DAY / IOC |
dayOrNet | DayWise / NetWise (also DAY, NET, 1, 2) | Positions are always empty |
Order book OrderType | Market / Limit / StopMarket / StopLimit | XTS response casing |
Exchange segments#
| exchangeSegment | Code | Signal exchange | Instruments | Status |
|---|---|---|---|---|
NSECM | 1 | NSE | Equity (series EQ, BE, BZ, SM, ST, IV, RR) | Supported |
NSEFO | 2 | NFO | Index and stock futures and options | Supported |
BSECM | 11 | BSE | Equity (every group except F, G and SPOT) | Supported |
BSEFO | 12 | BFO | Futures and options | Supported |
MCXFO | 51 | MCX | Commodity futures and options | Accepted, but fails with e-instrument-0003 until MQuant has an MCX instrument master |
NSECD, BSECD, NCDEX | 3, 13, 21 | Currency and NCDEX | Not supported: e-instrument-0002 |
Instrument ids#
exchangeInstrumentIDis the exchange token. It is the same at every XTS broker (NSECM 2885 is RELIANCE everywhere), so keep getting it from your broker's XTS market data API or instrument master.- MQuant looks the id up in its own copy of the exchange instrument master to find the symbol, expiry, strike, option type, lot size and tick size. An id it cannot find gives
e-instrument-0001; a contract listed today may not be there yet. - Expired contracts give
e-instrument-0004. Debt, government securities and index rows givee-instrument-0002. - Quantities are units, as at XTS brokers: one lot of a NIFTY option with lot size 65 is
orderQuantity: 65.
Order statuses#
Nothing executes, so no order is ever Filled, PartiallyFilled, Expired or PendingNew. CumulativeQuantity is always 0 and OrderAverageTradedPrice is always "0".
| Signal status | OrderStatus | Open? | Modify | Cancel |
|---|---|---|---|---|
received | New, or Replaced after a modify | Yes | Yes | Becomes cancelled |
accepted | New, or Replaced if modified before | Yes | No: e-orders-0003 | Becomes cancelled |
mapped (reserved) | New / Replaced | Yes | No | Becomes cancel_requested |
cancel_requested | PendingCancel | No | No | Success, unchanged |
cancelled | Cancelled | No | No | e-orders-0003 |
rejected | Rejected, with the desk's reason in CancelRejectReason | No | No | e-orders-0003 |
- Modify works only while the signal is
received, before the desk has acted on it. It records a new revision, and the history shows aReplacedrow. - Cancel and cancel all work while new orders are paused by the desk. Cancel all affects today's open orders placed through this interface, in one segment, and for one instrument unless
exchangeInstrumentIDis 0. - Orders do not expire at the end of the day in v1.
Response envelope#
Every reply under /interactive/ is JSON with type, code, description and result, as XTS sends it. Successes are always HTTP 200.
{"type": "success", "code": "s-orders-0001", "description": "Request sent", "result": {
"AppOrderID": 1000000017, "OrderUniqueIdentifier": "reliance1", "ClientID": "MQ12",
"MQuantSignalID": "sig_9f2c4e1a7b3d5f60a1b2c3d4", "MQuantWarnings": []
}}{"type": "error", "code": "e-orders-0001", "description": "Bad Request", "result": {"errors": [
{"field": ["limitPrice"], "messages": ["limitPrice is required for LIMIT and STOPLIMIT orders"], "location": "body"}
]}}"Invalid Token"and"Bad Request"are sent exactly as XTS sends them, because the Python SDK matches them to raiseXTSTokenExceptionandXTSInputException.result.errorsnames fields by their XTS names (orderQuantity,limitPrice,modifiedLimitPrice…).- Fields MQuant adds always start with
MQuant, so they cannot clash with XTS fields. Ignore them if you do not need them. - Every reply has an
X-Request-Idheader. Quote it to the desk.
{"type": "error", "code": "e-session-0007", "description": "Invalid Token", "result": {}}Error codes#
| code | HTTP | description | When | What to do |
|---|---|---|---|---|
e-session-0007 | 400 | Invalid Token | The token is missing, malformed, unknown, expired (after midnight IST), logged out, or its key was suspended, revoked or rotated. | Log in again. The SDKs raise XTSTokenException (Python) or return the error (Node). |
e-user-0001 | 400 | Invalid appKey or secretKey | Login failed. The same reply for an unknown key id, a wrong secret or a typo, on purpose. | Check the two values. 20 failures in 15 minutes lock your IP for 15 minutes. |
e-user-0002 | 429 | Too many failed logins, try later | Your IP is locked after repeated failed logins or failed signatures. | Wait Retry-After seconds and fix the credentials. |
e-user-0003 | 400 | API key is revoked / has expired / is suspended, or Trader is not active | The secret was right but the key or the trader cannot be used. | Contact your MQuant desk contact. |
e-user-0004 | 400 | Bad Request | The login body could not be read, or source is not an XTS source. | Send appKey, secretKey and source as JSON or as a form. |
e-user-0005 | 403 | Requests from <ip> are not allowed for this key | The request came from an address outside the key's allowlist. | Send from an allowlisted address, or ask the desk to change the allowlist. |
e-user-0006 | 400 | clientID does not belong to this session | A clientID other than your userID was sent. | Leave clientID out, or send your userID. |
e-user-0007 | 403 | This key does not have the scope this endpoint needs | Placing, modifying and cancelling need signals:write; the order book and history need signals:read. | Use a key with the right scope. |
e-orders-0001 | 400 | Bad Request | An order field failed validation. result.errors lists every problem by XTS field name. | Fix each listed field. |
e-orders-0002 | 400 | Order not found | No order with that appOrderID for your trader and key mode. | Check the id and that you use a key of the same mode (live or test). |
e-orders-0003 | 400 | Order is not open | Modify of an order that is no longer received, or cancel of a cancelled or rejected order. result.MQuantStatus gives the current status. | Read the order history. |
e-orders-0004 | 400 | Order exceeds this key's risk limits | orderQuantity or the order value is above a risk cap on the key. | Reduce the size, or ask the desk to review the cap. |
e-orders-0005 | 400 | Duplicate order is still being processed, retry | An identical retry arrived while the first copy was still being stored. | Retry after a moment; you get the first order back. |
e-portfolio-0001 | 400 | Bad Request | dayOrNet is missing or not DayWise / NetWise. | Send dayOrNet. |
e-instrument-0001 | 400 | Instrument not found | The exchangeInstrumentID is not in MQuant's copy of the instrument master for that segment. | Check the segment and the id. A contract listed today may not be there yet. |
e-instrument-0002 | 400 | Instrument not supported by MQuant | NSECD, BSECD or NCDEX, a debt, government-security or index row, or an unusable master row. | Trade a supported instrument. |
e-instrument-0003 | 400 | Instrument master unavailable | MQuant has no instrument master for the segment yet (MCXFO today). | Use another segment, or ask the desk. |
e-instrument-0004 | 400 | Contract has expired | The contract's expiry date is before today (IST). | Use a current contract. |
e-request-0001 | 404 | Not found | The path ends with a slash. | Remove the trailing slash. |
e-request-0002 | 405 | Method not allowed | Wrong HTTP method for a supported path. Allow lists the right ones. | Use the method from the reference. |
e-request-0003 | 413 | Payload too large | The body is over its limit: 4,096 bytes for login and cancel all, 8,192 for place and modify. | Send a smaller body. |
e-request-0004 | 400 | Bad Request | The body is not a JSON object, has a duplicate key, NaN, an exponent number, or is compressed. | Build the body with a JSON library and do not compress it. |
e-mquant-0001 | 400 | Not supported by MQuant | A part of XTS that MQuant does not provide: bracket, cover, convert, square-off, GTT, spread, margin, exchange messages and status, the socket. | See What MQuant does not provide. |
e-rate-0001 | 429 | Rate limit exceeded. Retry after <n> s | A rate limit was hit. Retry-After says how long to wait. | Wait and retry. See Rate limits. |
e-rate-0002 | 429 | IP temporarily blocked | Your IP hit limits repeatedly. | Stop until Retry-After has passed, then slow down. |
e-rate-0003 | 429 | Key temporarily blocked | The key hit its limits repeatedly. | Stop until Retry-After has passed, then slow down. |
e-mquant-0005 | 500 | Internal error. Quote X-Request-Id <req_…> to the desk. | Something failed on our side. | Retry with backoff. Read the order book before resending an order. |
e-mquant-0002 | 503 | The MQuant API is switched off | The API is off for maintenance. | Retry later. |
e-mquant-0003 | 503 | Order intake is paused by the desk | New orders and modifications are paused. Reads and cancels still work. | Retry later. |
e-mquant-0004 | 503 | Service temporarily unavailable, retry later | A dependency is down. | Retry with backoff. |
Rate limits#
| Endpoints | Counts as | Limit |
|---|---|---|
| Login | Login | 30 per minute per IP before the secret is checked; 2 per second, 20 per minute and 200 per day per key after |
| Place, modify, cancel, cancel all | Write, 1 each | Your key's write limits (default 10 per second, 400 per minute, 5,000 per day), shared with POST /api/v1/signals |
| Profile, balance, enums, order book, history, trades, positions, holdings | Read, 1 each | Your key's read limits (default 10 per second, 300 per minute), shared with the signed API |
| Logout | None | Per-IP limits only |
XTS and the signed API share the same buckets, so the exchange ceiling of 10 orders per second holds across both. A 429 carries Retry-After. Rate limit headers are described in Rate limits.
What MQuant does not provide#
- Market data API (
/apimarketdata/…: quotes, subscriptions, instrument master, OHLC, search). Keep using your broker's XTS market data API for prices and instrument ids. - Interactive socket (socket.io order, trade and position events). You do not need it for any REST call; poll the order book or order history instead.
- Host lookup. Set the root URL directly.
- Bracket and cover orders, position conversion, square-off, GTT, spread and AMO orders, margin calculation, exchange status and exchange messages. They return
e-mquant-0001"Not supported by MQuant". - Segments NSECD, BSECD and NCDEX. MCXFO until MQuant has its instrument master.
- Fills, trades, positions, holdings and money. The trade book, positions and holdings are always empty, and the balance is always zero.
- Browser use. There are no CORS headers.
SDK notes#
Python XTConnect#
- Check
response["type"]on every reply. XTConnect returns error replies as dicts, except "Invalid Token" and "Bad Request", which it raises. - XTConnect's wrappers catch their own exceptions and then fail with
UnboundLocalError. This is the same with any XTS broker. Wrap calls and log in again on any exception from a call made with an old token. get_dealerposition_daywiseandget_dealerposition_netwisebuild their URL without a leading slash. If you call them, useroot="https://app.mquant.in".- MQuant answers
isInvestorClient: true, so XTConnect never sendsclientID.
Node xts-interactive-api#
- The SDK sends
clientID=undefinedwhen you pass noclientID; MQuant treats that as absent. - Version 3.0.3 has no cancel-all function. Call
POST /interactive/orders/cancelalldirectly if you need it. - Do not create
XTSInteractiveWS: there is no socket.
Plain REST in Python#
No SDK needed. Set MQ_API_KEY and MQ_API_SECRET in the environment and run:
import os
import requests
ROOT = "https://app.mquant.in/api/v1"
session = requests.Session()
login = session.post(ROOT + "/interactive/user/session", timeout=10, json={
"appKey": os.environ["MQ_API_KEY"],
"secretKey": os.environ["MQ_API_SECRET"],
"source": "WEBAPI",
}).json()
if login["type"] != "success":
raise SystemExit(login["code"] + " " + login["description"])
session.headers["authorization"] = login["result"]["token"]
order = session.post(ROOT + "/interactive/orders", timeout=10, json={
"exchangeSegment": "NSEFO",
"exchangeInstrumentID": 63624,
"productType": "NRML",
"orderType": "LIMIT",
"orderSide": "BUY",
"timeInForce": "DAY",
"disclosedQuantity": 0,
"orderQuantity": 65,
"limitPrice": 112.5,
"stopPrice": 0,
"orderUniqueIdentifier": "nifty1",
"apiOrderSource": "WEBAPI",
}).json()
print(order["type"], order["code"], order["result"])
app_order_id = order["result"]["AppOrderID"]
history = session.get(ROOT + "/interactive/orders", params={"appOrderID": app_order_id}, timeout=10).json()
print([row["OrderStatus"] for row in history["result"]])
cancel = session.delete(ROOT + "/interactive/orders", params={"appOrderID": app_order_id}, timeout=10).json()
print(cancel["type"], cancel["result"])
session.delete(ROOT + "/interactive/user/session", timeout=10)Security#
XTS-style authentication is a bearer token, with no signature on each request. MQuant limits the risk: live keys must have an IP allowlist, tokens are stored only as hashes, every token ends at midnight IST, a key has at most three sessions, and suspending, revoking or rotating a key ends its sessions at once. If you want every request signed, use the signed signals API with the same key.