REST · HMAC-signed

One key.
Spot and futures.

mSamex exposes both matching engines under a single API key. Sign the request once, hit either base URL.

Spothttps://api.msamex.com/api/v2/spot
Futureshttps://api.msamex.com/api/v2/futures
135futures markets
70spot markets
0.020%maker
0.055%taker

Get a key

Four steps. The whole thing takes about two minutes, and step 1 is not optional.

1

Enable two-factor authentication

Key creation is gated on 2FA server-side. Without an authenticator app on your account the request fails with 400 resource.api_key.2fa_disabled — from the website and from a direct API call alike. There is no way around it, by design: a key can place orders with your money.

2

Open your account's API keys

Go to Account → API keys and choose to create a new key. You will be asked for the six-digit code from your authenticator.

3

Copy the secret — it is shown once

You get two values: an access key (the kid) and a secret. The kid stays visible in your account; the secret is displayed exactly once and never again. Copy the whole string — a half-copied secret produces authz.invalid_signature on every request and is indistinguishable from a wrong signing implementation.

4

Verify it before you build on it

Sign one request and check the status. A 200 here means your signing is correct; anything else is worth fixing now rather than mid-integration.

Authentication#

Every authenticated request carries three headers. The signature is an HMAC-SHA256 of nonce + kid — the concatenation, in that order, with no separator. Not the body, not the path, not the method.

HeaderValue
X-Auth-ApikeyYour access key (kid).
X-Auth-NonceCurrent UTC time in milliseconds.
X-Auth-SignatureHMAC-SHA256(secret, nonce + kid), lowercase hex.
Nonce is milliseconds

Date.now() in JavaScript is already correct. time.time() in Python returns seconds and must be multiplied by 1000. A nonce in seconds returns authz.nonce_expired — the same error as a genuinely stale nonce.

The nonce rule

The nonce must be within 5,000 ms of server time, in either direction (GET /api/v2/spot/public/timestamp). Every request needs a new nonce, retries included: a nonce that was already used can be refused with 401 authz.nonce_replayed. To retry an order safely, send it again with the same client_order_id and a new nonce. The signature covers only nonce + kid, not the path or the body, so keep the three headers out of logs and proxies.

Porting

This is the standard HMAC scheme used across most exchange APIs. Bots written against a comparable exchange port with minimal changes — swap the base URL and keys.

Rate limits#

Limits apply per account holder: all your API keys, your web and app sessions and your futures sub-accounts share one budget. More keys do not give more capacity.

WhatLimit
Futures order actions: place, cancel, cancel all, batch (each order in a batch counts), sub-account create / rename / transfer / close5 per second sustained, bursts up to 20 (default tier)
Higher order-rate tierUp to 20 per second, bursts up to 80, assigned to an account holder on request (contact support)
Futures lookups: GET /orders/{id}, GET /orders?client_order_id=, GET /trades?order_id=10 per second, bursts up to 40
Futures batch sizeUp to 20 orders per call
Other futures reads (account, order and trade lists, positions)Not counted in the order budget
Spot APIA per-account limit is being introduced. Treat 429 as a signal to back off.coming

Over the limit, futures answers 429 with Retry-After: 1 and {"error":"…","retriable":true,"code":"rate_limited"}. Nothing was placed: wait and resend. Every order-action answer carries X-RateLimit-Limit (bucket size), X-RateLimit-Remaining and X-RateLimit-Reset (seconds until the bucket is full again).

Errors#

How to read a futures answer. Futures error bodies are {"error":"<text>","code":"<code>"}: branch on code, it is stable; the text may change. Spot error bodies are {"errors":["<code>"]}, for example market.account.insufficient_balance, market.order.insufficient_market_liquidity, market.order.invalid_volume_or_price, market.order.create_error, market.order.invalid_client_order_id.

StatusMeaningWhat to do
200Done. A futures create answer already carries the final state for market, ioc and fok.—
422Refused, nothing placed: balance or margin, lot size, too large, leverage over the tier, reduce-only would increase, post-only would cross, FOK not fillable, market not active, invalid field.Fix the request. One exception: code client_order_id_in_flight means a copy with the same client_order_id is being placed right now; retry it to receive the order.
409in_progress: a transfer with this client_transfer_id is still being processed (Retry-After: 1).Retry: the answer will be the original transfer.
503{"retriable":true} + Retry-After: 1: a temporary condition, refused before the order was written.Wait and resend.
429Rate limit, nothing placed (Retry-After: 1).Wait and resend.
500, gateway timeout, no answerOutcome unknown.Resend with the same client_order_id. If the order exists you get the original back (200) and nothing new is placed. Ids are kept for 30 days. Spot works the same way: the repeat returns the original order with "duplicate": true.
codeStatusMeaning
insufficient_balance, insufficient_margin422Not enough free balance or margin.
quantity_below_minimum, quantity_above_maximum422Size outside the lot / limits; market orders above max_market_order_qty too.
leverage_exceeds_limit422Leverage above the tier for that size.
post_only_rejected, fok_cancelled, reduce_only_rejected422The order flag could not be honoured; nothing placed.
margin_mode_locked422Margin mode cannot change with an open position.
invalid_request422A field is missing or wrong (the text says which).
client_order_id_in_flight422Retry: a copy is being placed.
transfer_failed422The transfer was refused or failed.
market_not_found, order_not_found, position_not_found404Unknown, or not yours.
in_progress409Keyed transfer still processing; retry.
rate_limited429Over the limit; retry after Retry-After.
engine_reloading, dependency_unavailable503Temporary; nothing placed; retry.
internal_error500Outcome unknown: resend with the same client_order_id.

Bodies as returned:

StatusBodyCause
401{"error":"Missing Authorization header"}No auth headers sent.
401{"errors":["authz.invalid_signature"]}Signed the wrong string, or the secret does not match this key (copied incompletely). Sign nonce + kid only.
401{"errors":["authz.nonce_expired"]}See the nonce trap below.
401{"errors":["authz.nonce_replayed"]}This nonce was already used. Sign every request, retries included, with a new nonce.
401{"errors":["authz.unexistent_apikey"]}kid not recognised.
403ForbiddenA path no API key may use (see Key permissions).
404{"error":"Market 'xxx' not found"}Unknown market id.
422Failed to deserializeWrong field name or type.
401{"errors":["authz.invalid_permission"]}The path is not open to API keys.
400{"errors":["resource.api_key.2fa_disabled"]}Account has no 2FA. Keys require it.
The nonce_expired trap

A nonce in seconds returns exactly the same error as a stale nonce. If you see nonce_expired, check the unit before you check the clock. Compare against GET /api/v2/spot/public/timestamp — the server's current time, no auth required.

The margin_mode trap

POST /api/v2/futures/margin_mode expects the field mode, not margin_mode. Sending margin_mode returns 422. Some older spec material documents the other name; the spec is wrong and the engine is right.

Key permissions#

Every API key has the same permissions, enforced at the gateway: trade and read. It can read balances, orders, trades and positions, place and cancel spot and futures orders, set futures leverage and margin mode, and move funds between your own spot and futures wallets and your own futures sub-accounts.

It cannot: withdraw, add or change withdrawal addresses (beneficiaries), send internal transfers to another user, manage API keys, or obtain a session token. Those paths answer 403 to any request carrying an API key. A leaked key can trade; it cannot move funds off the platform.

Key info

GET /api/v2/apikey/info, signed like any request, returns the key's kid, your uid, permissions (allowed and blocked actions), ip_allowlist (enabled, mode, cidrs, your_ip, your_ip_allowed), the nonce rule and server_time_ms. It never returns a token.

IP allowlist (optional)

Off by default: a key without one works from any address, exactly as before. On request, support sets a list of addresses or ranges for one key, usually in watch mode first, then enforced. An enforced key used from any other address is refused before anything runs: 403 {"errors":["authz.ip_not_allowed"],"your_ip":"…"}. It applies to REST and to the private WebSocket.

  • Creating a key requires two-factor authentication on the account.
  • If a key is exposed, disable it immediately — it can still trade until you do.
  • Keys are created and revoked in the web app only, never through the API.

Order types#

Futures: field order_type, all types below. Spot: field ord_type, limit or market only. reduce_only is a separate boolean on futures orders and never increases a position. Positions are one-way (net) per market.

order_typeTriggerBecomes
limit—Rests at price.
market—Executes immediately at the best available price.
stop_marketstop_price touchedA market order. Fills, at whatever the market is.
stop_limitstop_price touchedA limit order at price. It rests — it may not fill at all if the market runs through your price.
take_profit_marketstop_price touched (in profit)A market order.
take_profit_limitstop_price touched (in profit)A limit order at price. Same resting caveat as stop_limit.
trailing_stopmark moves trail_amount against youA market order. Tracks the mark price only.
ioc—Fills what it can immediately, the remainder is cancelled. With a price it fills only up to that price: this is the protected market order.
fok—Fills completely at once or is refused with 422; nothing rests.
Price protection

Every taker sweep (market, ioc, fok) stops at 10% from the mark price. A market order larger than the market's maximum market-order size is refused with 422 ("use a limit order"); the maximum is max_market_order_qty in GET /api/v2/futures/public/markets/{id}.

stop_limit is not protection

A stop that becomes a limit order only protects you if the market trades at your limit. In a fast move it can be skipped entirely. Use stop_market when you need the position closed.

Statuses#

ObjectValues
Futures orderpending, open, partially_filled, filled, cancelled, rejected, trigger_pending
Futures positionopen, closed, liquidating, adl
Spot orderpending, wait (resting), done, cancel, reject, trigger_wait
Spot create answers pending

Spot matching is asynchronous: POST /api/v2/spot/market/orders saves the order and answers with "state":"pending". Read the result with GET /api/v2/spot/market/orders/{id} (or /market/orders/client/{client_order_id}) a few hundred milliseconds later. Futures is different: the create answer is final and carries avg_fill_price.

Order lookup and history#

FuturesSpot
One orderGET /orders/{id} (the UUID; 404 order_not_found if it is not yours) or GET /orders?client_order_id= (0 or 1 order; other filters ignored). Read limit 10/s, bursts 40.GET /market/orders/{id} (numeric id or uuid), GET /market/orders/client/{client_order_id} or GET /market/orders?client_order_id=. Includes avg_price, executed_volume and the fills.
Paginglimit (up to 1000, default 100) + offset, newest first. total in the answer is the number of rows in this page.limit (1–1000, default 100) + page (from 1), order_by asc|desc on the last update.
Time windowfrom (inclusive) and to (exclusive), Unix milliseconds, on orders and trades.time_from and time_to, Unix seconds, on orders and trades.
Fill priceavg_fill_price in the create answer and on every order read. Fills of one order: GET /trades?order_id=.avg_price on the order; fills with fee_amount and fee_currency.
Statements and statuscoming

Account statement endpoints (a full ledger of transfers, fees, funding and realized PnL for reconciliation) and a platform status endpoint.

Transfers and sub-accounts#

POST /api/v2/futures/transfer with {"direction":"spot_to_futures"|"futures_to_spot","currency":"usdt","amount":"100"} moves funds between your own spot and futures wallets and answers {"transfer_id":…,"futures_balance_after":"…"}. Main account only. Send client_transfer_id (1–128 printable characters, unique per account) and a retry is safe: the same key for the same transfer returns the original answer with "replay": true and moves nothing; the same key for a different transfer is refused (422 invalid_request); while the original is still processing you get 409 in_progress (retry); if the original failed, send a new key.

Futures sub-accounts: GET / POST /api/v2/futures/accounts lists and creates them. Select one on any futures call with the header X-Account-Id: <id>; without it a call acts on your main account. Move funds between your own accounts with POST /api/v2/futures/accounts/transfer {"from":"main"|id,"to":"main"|id,"amount":"…","currency":"usdt","client_transfer_id":"…"}; a retry with the same client_transfer_id returns the original move.

WebSocket#

Public streams: wss://ws.msamex.com/api/v2/ranger/public?stream=btcusdt-perp.ob-snap&stream=btcusdt-perp.ob-inc&stream=btcusdt-perp.ticker&stream=btcusdt-perp.trades. Messages arrive as {"<stream>":{…}}. No key is needed. From a server or a bot, send no Origin header: an Origin from another site is refused with 403 Forbidden.

StreamContent
<market>.ob-snapThe full book (up to 50 levels a side) every second, with sequence.
<market>.ob-incChanged levels only, every 250 ms, with sequence. A quantity of "0" removes the level.
<market>.tickermark_price, index_price, last, timestamp. Funding is on REST: GET /api/v2/futures/public/markets/{id}/ticker has funding_rate and next_funding_time (ms); history at /api/v2/futures/public/funding_rate_history.
<market>.tradesEvery trade as it happens, with its exact time; good for 1-second candles. Futures (btcusdt-perp.trades): one message per trade with id, price, quantity, maker_side, is_liquidation and created_at (UTC, RFC 3339, nanoseconds). Spot (btcusdt.trades): {"trades":[…]} with tid, price, amount, taker_type and date (Unix seconds).
Keeping a local book

Build the book from an ob-snap. Apply an ob-inc only if its sequence is higher than your book's. Sequences are not consecutive (one increment can cover several changes), so a gap is normal. After a reconnect, or when in doubt, wait for the next ob-snap (at most one second) and replace the book.

Private streams with an API key

Connect to wss://ws.msamex.com/api/v2/ranger/private?stream=futures_order&stream=futures_position&stream=futures_balance (spot: order, trade) with the three X-Auth-* headers on the upgrade request, signed as for REST (an Authorization header is not needed: the gateway authorizes the upgrade), and no Origin header. wss://api.msamex.com/api/v2/ranger/private works the same way. The answer {"success":{"message":"subscribed","streams":[…]}} lists the private streams you got; an empty list means the key was not accepted. Reconnect at least every 60 minutes with a fresh signature.

Public#

No authentication. Rate-limited per IP.

Futures#

Base /api/v2/futures. Authenticated. Leverage up to 1000× (500× on BTC, 12 leverage tiers — see the note below).

Spot#

Base /api/v2/spot. Authenticated.

Copied