Exchange API Reference
Programmatic access to the CXM cryptocurrency exchange over GraphQL.
Get a Bearer Token
Obtain a JWT that you can pass as Authorization: Bearer <token> on every request in this document, and to enable the Try It action on each endpoint below. Tokens are short-lived; refresh by signing in again. Don't have an API key? Create one in your CXM account settings.
Introduction
The CXM API is a GraphQL API. All requests are sent as POST to the /graphql endpoint of the appropriate host with a JSON body containing query and variables, and an Authorization: Bearer <token> header.
Hosts
https://api.cxm.io/graphql for derivatives, account balances, and API key management.
GraphQL subscriptions are delivered over WebSocket on the same host with the wss:// scheme. See the WebSocket transport guide and the Subscriptions group below.
Request shape
POST /graphql HTTP/1.1
Host: api.cxm.io
Authorization: Bearer <token>
Content-Type: application/json
{
"query": "query { instruments { instrument_id name } }",
"variables": {}
}
Errors
GraphQL errors are returned in the errors array of the response body with HTTP status 200. Network and auth errors return non-200 statuses.
Accounts & Balances
Read wallet balances and ledger entries for the authenticated user.
query accounts_balances Read current balances per currency (free, total, exposed, margin exposure).
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
wallet_id |
String |
optional | Wallet ID (optional) |
Response
| Field | Type | Description |
|---|---|---|
currency_id |
String |
Currency ID |
total_balance |
Float |
Total balance |
free_balance |
Float |
Available balance for trading |
GraphQL Operation
query accounts_balances($wallet_id: String) {
accounts_balances(wallet_id: $wallet_id) {
currency_id total_balance exposed_balance margin_exposure free_balance
}
}
Code Examples
curl -X POST 'https://api.cxm.io/graphql' \
-H 'Authorization: Bearer YOUR_TOKEN' \
-H 'Content-Type: application/json' \
-d '{"query":"query accounts_balances($wallet_id: String) { accounts_balances(wallet_id: $wallet_id) { currency_id total_balance exposed_balance margin_exposure free_balance } }","variables":{}}'
import requests
url = "https://api.cxm.io/graphql"
headers = {
"Authorization": "Bearer YOUR_TOKEN",
"Content-Type": "application/json",
}
payload = {
"query": """query accounts_balances($wallet_id: String) { accounts_balances(wallet_id: $wallet_id) { currency_id total_balance exposed_balance margin_exposure free_balance } }""",
"variables": {},
}
response = requests.post(url, json=payload, headers=headers)
print(response.json())
const response = await fetch("https://api.cxm.io/graphql", {
method: "POST",
headers: {
"Authorization": `Bearer ${YOUR_TOKEN}`,
"Content-Type": "application/json",
},
body: JSON.stringify({
query: `query accounts_balances($wallet_id: String) { accounts_balances(wallet_id: $wallet_id) { currency_id total_balance exposed_balance margin_exposure free_balance } }`,
variables: {},
}),
});
const data = await response.json();
console.log(data);Try It
query account_transactions Read account ledger (trades, fees, deposits, withdrawals, transfers).
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
wallet_id |
String! |
required | Wallet ID |
currency_id |
String |
optional | Filter by currency |
pager |
PagerInput |
optional | Pagination parameters |
dateRange |
DateRangeInput |
optional | Date range filter |
Response
| Field | Type | Description |
|---|---|---|
account_transaction_id |
String |
Transaction ID |
type |
AccountTransactionType |
Transaction type (trade, deposit, withdrawal, etc.) |
GraphQL Operation
query account_transactions($wallet_id: String!, $currency_id: String, $pager: PagerInput, $dateRange: DateRangeInput) {
account_transactions(wallet_id: $wallet_id, currency_id: $currency_id, pager: $pager, dateRange: $dateRange) {
account_transaction_id currency_id type amount post_balance created_at_iso
}
}
Code Examples
curl -X POST 'https://api.cxm.io/graphql' \
-H 'Authorization: Bearer YOUR_TOKEN' \
-H 'Content-Type: application/json' \
-d '{"query":"query account_transactions($wallet_id: String!, $currency_id: String, $pager: PagerInput, $dateRange: DateRangeInput) { account_transactions(wallet_id: $wallet_id, currency_id: $currency_id, pager: $pager, dateRange: $dateRange) { account_transaction_id currency_id type amount post_balance created_at_iso } }","variables":{"wallet_id":"wallet-123"}}'
import requests
url = "https://api.cxm.io/graphql"
headers = {
"Authorization": "Bearer YOUR_TOKEN",
"Content-Type": "application/json",
}
payload = {
"query": """query account_transactions($wallet_id: String!, $currency_id: String, $pager: PagerInput, $dateRange: DateRangeInput) { account_transactions(wallet_id: $wallet_id, currency_id: $currency_id, pager: $pager, dateRange: $dateRange) { account_transaction_id currency_id type amount post_balance created_at_iso } }""",
"variables": {
"wallet_id": "wallet-123"
},
}
response = requests.post(url, json=payload, headers=headers)
print(response.json())
const response = await fetch("https://api.cxm.io/graphql", {
method: "POST",
headers: {
"Authorization": `Bearer ${YOUR_TOKEN}`,
"Content-Type": "application/json",
},
body: JSON.stringify({
query: `query account_transactions($wallet_id: String!, $currency_id: String, $pager: PagerInput, $dateRange: DateRangeInput) { account_transactions(wallet_id: $wallet_id, currency_id: $currency_id, pager: $pager, dateRange: $dateRange) { account_transaction_id currency_id type amount post_balance created_at_iso } }`,
variables: {
"wallet_id": "wallet-123"
},
}),
});
const data = await response.json();
console.log(data);Try It
API Keys
Create and manage API keys for programmatic access to the exchange.
API key permissions
When creating a key with create_api_key (or editing one with update_api_key), the permissions argument accepts values from the enum below. Pass the exact lowercase string in the array. For example, ["accounts_balances", "create_derivatives_order", "cancel_derivatives_order"]. Grant only the permissions the key actually needs; an unauthenticated call to a permission the key does not hold returns a GraphQL error.
The group marked conditional appears on a key only when derivatives are enabled for the user's account.
Accounts and balances
| Permission | Description |
|---|---|
accounts_balances | Read current balances per currency (free, total, exposed, margin exposure). |
daily_balances_report | Read end-of-day balance snapshots / history. |
account_transactions | Read account ledger (trades, fees, deposits, withdrawals, transfers). |
accounts | List the user's accounts and metadata. |
API keys
| Permission | Description |
|---|---|
create_api_key | Create new API keys. |
update_api_key | Rename, expire, enable/disable, change permissions of existing keys. |
delete_api_key | Revoke API keys. |
Derivatives (conditional: only when derivatives are enabled for the user)
| Permission | Description |
|---|---|
derivatives_instruments | List perpetual swap contracts. |
open_derivatives_orders | List currently open margin orders. |
closed_derivatives_orders | List filled / cancelled margin orders. |
create_derivatives_order | Place a margin / perpetual order. |
cancel_derivatives_order | Cancel a margin order. |
estimate_derivatives_order | Preview a margin order before placing. |
open_derivatives_positions | List currently open margin positions. |
closed_derivatives_positions | List historical (closed) margin positions. |
update_open_derivatives_position | Adjust take-profit / stop-loss / margin on an open position. |
derivatives_funding_history | Read funding fees paid / earned over time. |
mutation create_api_key Create new API keys.
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
name |
String |
optional | Descriptive name for the API key |
expires_at |
String! |
required | Expiration date in ISO 8601 format |
is_active |
ToggleSwitch! |
required | Enable or disable the key immediately |
ip_address |
[String!] |
optional | IP addresses allowed to use this key |
permissions |
[Permission!]! |
required | List of permissions (READ, TRADE, WITHDRAW, etc.) |
type |
ApiKeyTypes! |
required | Type of API key (SPOT, MARGIN, etc.) |
hmac_required |
ToggleSwitch! |
required | Require HMAC signature for requests |
Response
| Field | Type | Description |
|---|---|---|
api_key_id |
String |
Newly created API key (public key) |
api_key_secret |
String |
API key secret (shown only once, store securely) |
GraphQL Operation
mutation create_api_key($name: String, $expires_at: String!, $is_active: ToggleSwitch!, $ip_address: [String!], $permissions: [Permission!]!, $type: ApiKeyTypes!, $hmac_required: ToggleSwitch!) {
create_api_key(name: $name, expires_at: $expires_at, is_active: $is_active, ip_address: $ip_address, permissions: $permissions, type: $type, hmac_required: $hmac_required) {
api_key_id api_key_secret
}
}
Code Examples
curl -X POST 'https://api.cxm.io/graphql' \
-H 'Authorization: Bearer YOUR_TOKEN' \
-H 'Content-Type: application/json' \
-d '{"query":"mutation create_api_key($name: String, $expires_at: String!, $is_active: ToggleSwitch!, $ip_address: [String!], $permissions: [Permission!]!, $type: ApiKeyTypes!, $hmac_required: ToggleSwitch!) { create_api_key(name: $name, expires_at: $expires_at, is_active: $is_active, ip_address: $ip_address, permissions: $permissions, type: $type, hmac_required: $hmac_required) { api_key_id api_key_secret } }","variables":{"name":"Trading Bot","expires_at":"2025-12-31T23:59:59Z","is_active":"ON","permissions":["READ","TRADE"],"type":"SPOT","hmac_required":"ON"}}'
import requests
url = "https://api.cxm.io/graphql"
headers = {
"Authorization": "Bearer YOUR_TOKEN",
"Content-Type": "application/json",
}
payload = {
"query": """mutation create_api_key($name: String, $expires_at: String!, $is_active: ToggleSwitch!, $ip_address: [String!], $permissions: [Permission!]!, $type: ApiKeyTypes!, $hmac_required: ToggleSwitch!) { create_api_key(name: $name, expires_at: $expires_at, is_active: $is_active, ip_address: $ip_address, permissions: $permissions, type: $type, hmac_required: $hmac_required) { api_key_id api_key_secret } }""",
"variables": {
"name": "Trading Bot",
"expires_at": "2025-12-31T23:59:59Z",
"is_active": "ON",
"permissions": [
"READ",
"TRADE"
],
"type": "SPOT",
"hmac_required": "ON"
},
}
response = requests.post(url, json=payload, headers=headers)
print(response.json())
const response = await fetch("https://api.cxm.io/graphql", {
method: "POST",
headers: {
"Authorization": `Bearer ${YOUR_TOKEN}`,
"Content-Type": "application/json",
},
body: JSON.stringify({
query: `mutation create_api_key($name: String, $expires_at: String!, $is_active: ToggleSwitch!, $ip_address: [String!], $permissions: [Permission!]!, $type: ApiKeyTypes!, $hmac_required: ToggleSwitch!) { create_api_key(name: $name, expires_at: $expires_at, is_active: $is_active, ip_address: $ip_address, permissions: $permissions, type: $type, hmac_required: $hmac_required) { api_key_id api_key_secret } }`,
variables: {
"name": "Trading Bot",
"expires_at": "2025-12-31T23:59:59Z",
"is_active": "ON",
"permissions": [
"READ",
"TRADE"
],
"type": "SPOT",
"hmac_required": "ON"
},
}),
});
const data = await response.json();
console.log(data);Try It
mutation update_api_key Rename, expire, enable/disable, change permissions of existing keys.
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
api_key_id |
String! |
required | ID of the API key to update |
name |
String |
optional | New descriptive name |
expires_at |
String |
optional | New expiration date |
is_active |
ToggleSwitch |
optional | Enable or disable the key |
ip_address |
[String!] |
optional | New IP whitelist |
permissions |
[Permission!] |
optional | Updated permissions |
hmac_required |
ToggleSwitch! |
required | Require HMAC signature |
GraphQL Operation
mutation update_api_key($api_key_id: String!, $name: String, $expires_at: String, $is_active: ToggleSwitch, $ip_address: [String!], $permissions: [Permission!], $hmac_required: ToggleSwitch!) {
update_api_key(api_key_id: $api_key_id, name: $name, expires_at: $expires_at, is_active: $is_active, ip_address: $ip_address, permissions: $permissions, hmac_required: $hmac_required)
}
Code Examples
curl -X POST 'https://api.cxm.io/graphql' \
-H 'Authorization: Bearer YOUR_TOKEN' \
-H 'Content-Type: application/json' \
-d '{"query":"mutation update_api_key($api_key_id: String!, $name: String, $expires_at: String, $is_active: ToggleSwitch, $ip_address: [String!], $permissions: [Permission!], $hmac_required: ToggleSwitch!) { update_api_key(api_key_id: $api_key_id, name: $name, expires_at: $expires_at, is_active: $is_active, ip_address: $ip_address, permissions: $permissions, hmac_required: $hmac_required) }","variables":{"api_key_id":"key123","name":"Updated Name","is_active":"OFF","hmac_required":"ON"}}'
import requests
url = "https://api.cxm.io/graphql"
headers = {
"Authorization": "Bearer YOUR_TOKEN",
"Content-Type": "application/json",
}
payload = {
"query": """mutation update_api_key($api_key_id: String!, $name: String, $expires_at: String, $is_active: ToggleSwitch, $ip_address: [String!], $permissions: [Permission!], $hmac_required: ToggleSwitch!) { update_api_key(api_key_id: $api_key_id, name: $name, expires_at: $expires_at, is_active: $is_active, ip_address: $ip_address, permissions: $permissions, hmac_required: $hmac_required) }""",
"variables": {
"api_key_id": "key123",
"name": "Updated Name",
"is_active": "OFF",
"hmac_required": "ON"
},
}
response = requests.post(url, json=payload, headers=headers)
print(response.json())
const response = await fetch("https://api.cxm.io/graphql", {
method: "POST",
headers: {
"Authorization": `Bearer ${YOUR_TOKEN}`,
"Content-Type": "application/json",
},
body: JSON.stringify({
query: `mutation update_api_key($api_key_id: String!, $name: String, $expires_at: String, $is_active: ToggleSwitch, $ip_address: [String!], $permissions: [Permission!], $hmac_required: ToggleSwitch!) { update_api_key(api_key_id: $api_key_id, name: $name, expires_at: $expires_at, is_active: $is_active, ip_address: $ip_address, permissions: $permissions, hmac_required: $hmac_required) }`,
variables: {
"api_key_id": "key123",
"name": "Updated Name",
"is_active": "OFF",
"hmac_required": "ON"
},
}),
});
const data = await response.json();
console.log(data);Try It
mutation delete_api_key Revoke API keys.
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
api_key_id |
String! |
required | ID of the API key to delete |
GraphQL Operation
mutation delete_api_key($api_key_id: String!) {
delete_api_key(api_key_id: $api_key_id)
}
Code Examples
curl -X POST 'https://api.cxm.io/graphql' \
-H 'Authorization: Bearer YOUR_TOKEN' \
-H 'Content-Type: application/json' \
-d '{"query":"mutation delete_api_key($api_key_id: String!) { delete_api_key(api_key_id: $api_key_id) }","variables":{"api_key_id":"key123"}}'
import requests
url = "https://api.cxm.io/graphql"
headers = {
"Authorization": "Bearer YOUR_TOKEN",
"Content-Type": "application/json",
}
payload = {
"query": """mutation delete_api_key($api_key_id: String!) { delete_api_key(api_key_id: $api_key_id) }""",
"variables": {
"api_key_id": "key123"
},
}
response = requests.post(url, json=payload, headers=headers)
print(response.json())
const response = await fetch("https://api.cxm.io/graphql", {
method: "POST",
headers: {
"Authorization": `Bearer ${YOUR_TOKEN}`,
"Content-Type": "application/json",
},
body: JSON.stringify({
query: `mutation delete_api_key($api_key_id: String!) { delete_api_key(api_key_id: $api_key_id) }`,
variables: {
"api_key_id": "key123"
},
}),
});
const data = await response.json();
console.log(data);Try It
Subscriptions
Real-time GraphQL subscriptions delivered over a WebSocket connection. Subscribe once, receive a stream of next messages until you unsubscribe or the server closes the channel.
WebSocket transport
Subscriptions use the graphql-ws protocol over secure WebSocket (wss://).
Endpoint
wss://api.cxm.io/graphql for all derivatives subscriptions.
Authentication
Send your bearer token in connectionParams on the initial connection_init frame. Do not use an HTTP Authorization header (browsers cannot set headers on WebSocket handshakes). The server reads the authorization field from connectionParams:
{
"type": "connection_init",
"payload": {
"authorization": "Bearer <JWT_TOKEN>"
}
}
The server replies with {"type": "connection_ack"} when authentication succeeds.
Opening a subscription
After connection_ack, send a subscribe frame with a unique id you choose; every next message the server sends back will carry that same id:
{
"type": "subscribe",
"id": "1",
"payload": {
"query": "subscription instrument_price($instrument_id: String) { instrument_price(instrument_id: $instrument_id) { instrument_id ask bid price_24h_change ts_iso } }",
"variables": { "instrument_id": "BTC-USDT" }
}
}
Each update arrives as a next frame:
{
"type": "next",
"id": "1",
"payload": { "data": { "instrument_price": { "instrument_id": "BTC-USDT", "ask": 43210.5, "bid": 43208.0, "price_24h_change": 1.23, "ts_iso": "2026-04-08T12:00:00Z" } } }
}
The server signals end-of-stream with {"type": "complete", "id": "1"}; an error frame with the same shape is sent if the subscription fails. To stop receiving updates yourself, send {"type": "complete", "id": "1"}.
Keeping the connection open
The graphql-ws protocol carries its own keepalive: the server periodically sends a ping frame and the client must reply with a pong. Every compliant graphql-ws client library handles this for you; if you implement the protocol by hand, mirror every ping with a pong within a few seconds, otherwise the server will close the connection.
WebSocket connections will still drop occasionally, whether from transient network issues, load-balancer rotations, or an expired bearer token. The recommended pattern is to let the client library reconnect automatically and re-issue every active subscription on the new connection. The reference client we ship in cointrader_v4 uses these settings:
import { createClient } from "graphql-ws";
const client = createClient({
url: "wss://api.cxm.io/graphql",
connectionParams: { authorization: `Bearer ${token}` },
shouldRetry: () => true,
retryAttempts: 8,
});
client.subscribe(
{
query: `subscription instrument_price($instrument_id: String) {
instrument_price(instrument_id: $instrument_id) { instrument_id ask bid price_24h_change ts_iso }
}`,
variables: { instrument_id: "BTC-USDT" },
},
{
next: (msg) => console.log(msg.data),
error: (err) => console.error(err),
complete: () => console.log("server closed the stream"),
}
);
shouldRetry: () => true with retryAttempts: 8 means the library will reconnect up to eight times after a drop, with exponential backoff between attempts; after a successful reconnect it automatically re-issues every active subscribe. If your token has expired by then, refresh it (re-run Get a Bearer Token) and update connectionParams before reconnecting.
Operational tips:
- One connection per host. Multiplex many subscriptions on the same WebSocket instead of opening a connection per subscription. The
idfield on every frame keeps streams separated. - Refresh the token before it expires. Bearer tokens are short-lived; reconnect with a fresh token rather than letting the connection close on auth failure.
- Resume cleanly. When reconnecting, snapshot the latest state via the equivalent query (e.g. call
open_ordersafter reconnectingall_orders) so you do not miss updates that occurred while disconnected.
subscription margin_orderbook Real-time perpetual-contract order book.
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
instrument_id | String! | required | Perpetual contract symbol (e.g. BTC-PERP). |
Each update
| Field | Type | Description |
|---|---|---|
instrument_id | String | Instrument the update applies to. |
buy | [OrderbookLevel] | Bid side, an array of { quantity, price }. |
sell | [OrderbookLevel] | Ask side, an array of { quantity, price }. |
GraphQL Operation
subscription margin_orderbook($instrument_id: String!) {
margin_orderbook(instrument_id: $instrument_id) {
instrument_id
buy { quantity price }
sell { quantity price }
}
}
subscription margin_instrument_price_bar Real-time OHLC candle stream for a perpetual contract.
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
instrument_id | String! | required | Perpetual contract symbol. |
periodicity | MarginInstrumentHistoryPeriodicity! | required | Bar interval (e.g. 1m, 5m, 1h, 1d). |
Each update
| Field | Type | Description |
|---|---|---|
margin_instrument_id | String | Contract this bar applies to. |
open | Float | Open price. |
high | Float | High price. |
low | Float | Low price. |
close | Float | Close price. |
updated_at_iso | String | Bar timestamp (ISO-8601). |
GraphQL Operation
subscription margin_instrument_price_bar($instrument_id: String!, $periodicity: MarginInstrumentHistoryPeriodicity!) {
margin_instrument_price_bar(instrument_id: $instrument_id, periodicity: $periodicity) {
margin_instrument_id open high low close updated_at_iso
}
}
subscription margin_order_update Real-time status updates for the user's margin orders.
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
wallet_id | String | optional | Restrict updates to a single margin wallet. |
Each update
| Field | Type | Description |
|---|---|---|
margin_order_id | ID | The order whose state changed. |
margin_position_id | ID | Linked position, if any. |
instrument_id | String | Contract symbol. |
side | String | Buy / sell side. |
type | String | Order type (market, limit, stop, …). |
status | String | New order status. |
quantity | Float | Order quantity. |
executed_quantity | Float | Quantity filled so far. |
price | Float | Order price. |
limit_price | Float | Limit / stop price. |
leverage | Float | Leverage applied. |
stop_loss | Float | Stop-loss price. |
take_profit | Float | Take-profit price. |
fee_amount | Float | Fee charged so far. |
time_in_force | String | TIF (GTC, IOC, FOK, …). |
updated_at_iso | String | Update timestamp (ISO-8601). |
wallet_id | String | Wallet the order belongs to. |
GraphQL Operation
subscription margin_order_update($wallet_id: String) {
margin_order_update(wallet_id: $wallet_id) {
margin_order_id margin_position_id instrument_id side type status
leverage quantity executed_quantity price limit_price
stop_loss take_profit fee_amount time_in_force
updated_at_iso wallet_id
}
}
subscription open_margin_position_update Real-time updates for the user's open margin positions (P&L, exit price, margin).
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
wallet_id | String | optional | Restrict updates to a single margin wallet. |
Each update
| Field | Type | Description |
|---|---|---|
margin_position_id | ID | Position the update applies to. |
instrument_id | String | Contract symbol. |
side | String | Long / short. |
amount | Float | Current position size. |
leverage | Float | Leverage on the position. |
entry_price | Float | Average entry price. |
exit_price | Float | Realised exit price (for closed legs). |
pnl | Float | Unrealised P&L. |
total_pnl | Float | Realised + unrealised P&L. |
margin | Float | Margin allocated to the position. |
margin_currency_id | String | Currency of the margin. |
funding_fee_amount | Float | Funding fee paid / received. |
stop_loss | Float | Stop-loss price. |
take_profit | Float | Take-profit price. |
close_reason | String | Close reason text (when closing). |
close_reason_code | String | Close reason machine code. |
updated_at_iso | String | Update timestamp (ISO-8601). |
wallet_id | String | Wallet the position belongs to. |
GraphQL Operation
subscription open_margin_position_update($wallet_id: String) {
open_margin_position_update(wallet_id: $wallet_id) {
margin_position_id instrument_id side
amount leverage entry_price exit_price
pnl total_pnl margin margin_currency_id
funding_fee_amount stop_loss take_profit
close_reason close_reason_code
updated_at_iso wallet_id
}
}
subscription user_balance_position Real-time margin account balance, equity, and risk metrics.
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
wallet_id | String | optional | Restrict updates to a single margin wallet. |
Each update
| Field | Type | Description |
|---|---|---|
free_balance | Float | Available balance. |
equity | Float | Total equity (balance + unrealised P&L). |
currently_used_margin | Float | Margin currently locked by open positions. |
margin_call_left_margin | Float | Margin remaining before margin call. |
liquidation_left_margin | Float | Margin remaining before liquidation. |
margin_ratio_percentage | Float | Current margin ratio %. |
risk_level | String | Risk-level classification. |
pnl | Float | Unrealised P&L. |
total_pnl | Float | Realised + unrealised P&L. |
unsettled_balance | Float | Balance pending settlement. |
GraphQL Operation
subscription user_balance_position($wallet_id: String) {
user_balance_position(wallet_id: $wallet_id) {
free_balance equity
currently_used_margin margin_call_left_margin liquidation_left_margin
margin_ratio_percentage risk_level
pnl total_pnl unsettled_balance
}
}
subscription margin_user_update Margin notifications: margin calls, liquidation warnings, trading-status changes.
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
wallet_id | String | optional | Restrict notifications to a single margin wallet. |
Each update
| Field | Type | Description |
|---|---|---|
notification.title | String | Notification title. |
notification.body | String | Notification message. |
notification.trigger | String | Trigger type (e.g. margin_call, margin_liquidation). |
GraphQL Operation
subscription margin_user_update($wallet_id: String) {
margin_user_update(wallet_id: $wallet_id) {
notification { title body trigger }
}
}
Derivatives
Optional group: only available if derivatives are enabled for the account. Scope names use the "derivatives_" prefix; the corresponding GraphQL operations are named with the "margin_" prefix.
query derivatives_instruments List perpetual swap contracts.
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
is_active |
ToggleSwitch! |
optional | Filter active instruments only |
pager |
PagerInput |
optional | Pagination parameters (limit, offset) |
Response
| Field | Type | Description |
|---|---|---|
margin_instrument_id |
String |
Unique instrument identifier |
name |
String |
Instrument display name (e.g., BTC-PERP) |
price |
Object |
Current bid/ask pricing |
long_funding_rate |
Float |
Funding rate for long positions |
short_funding_rate |
Float |
Funding rate for short positions |
GraphQL Operation
query margin_instruments($is_active: ToggleSwitch!, $pager: PagerInput) {
margin_instruments(is_active: $is_active, pager: $pager) {
margin_instrument_id name base_currency_id quote_currency_id min_leverage max_leverage min_quantity max_quantity long_funding_rate short_funding_rate price_24h_change price_decimals quantity_decimals price_24h_low price_24h_high is_trading_on market_status margin_instrument_strategy_is_active margin_instrument_strategy_id class lot_size step_size cross_quote_price close_only base_currency {
currency_id precision is_active
}
quote_currency {
currency_id precision is_active
}
price {
margin_instrument_id ask bid updated_at
}
funding_data {
rate_type next_funding_date long_funding_rate short_funding_rate multiplier period
}
meta market_hours {
custom_periods {
end_time name start_time
}
general_rules {
days end_time is_active start_time
}
holidays {
end_time name start_time
}
}
}
}
Code Examples
curl -X POST 'https://api.cxm.io/graphql' \
-H 'Authorization: Bearer YOUR_TOKEN' \
-H 'Content-Type: application/json' \
-d '{"query":"query margin_instruments($is_active: ToggleSwitch!, $pager: PagerInput) { margin_instruments(is_active: $is_active, pager: $pager) { margin_instrument_id name base_currency_id quote_currency_id min_leverage max_leverage min_quantity max_quantity long_funding_rate short_funding_rate price_24h_change price_decimals quantity_decimals price_24h_low price_24h_high is_trading_on market_status margin_instrument_strategy_is_active margin_instrument_strategy_id class lot_size step_size cross_quote_price close_only base_currency { currency_id precision is_active } quote_currency { currency_id precision is_active } price { margin_instrument_id ask bid updated_at } funding_data { rate_type next_funding_date long_funding_rate short_funding_rate multiplier period } meta market_hours { custom_periods { end_time name start_time } general_rules { days end_time is_active start_time } holidays { end_time name start_time } } } }","variables":{"is_active":"On","pager":{"limit":1000,"offset":0}}}'
import requests
url = "https://api.cxm.io/graphql"
headers = {
"Authorization": "Bearer YOUR_TOKEN",
"Content-Type": "application/json",
}
payload = {
"query": """query margin_instruments($is_active: ToggleSwitch!, $pager: PagerInput) { margin_instruments(is_active: $is_active, pager: $pager) { margin_instrument_id name base_currency_id quote_currency_id min_leverage max_leverage min_quantity max_quantity long_funding_rate short_funding_rate price_24h_change price_decimals quantity_decimals price_24h_low price_24h_high is_trading_on market_status margin_instrument_strategy_is_active margin_instrument_strategy_id class lot_size step_size cross_quote_price close_only base_currency { currency_id precision is_active } quote_currency { currency_id precision is_active } price { margin_instrument_id ask bid updated_at } funding_data { rate_type next_funding_date long_funding_rate short_funding_rate multiplier period } meta market_hours { custom_periods { end_time name start_time } general_rules { days end_time is_active start_time } holidays { end_time name start_time } } } }""",
"variables": {
"is_active": "On",
"pager": {
"limit": 1000,
"offset": 0
}
},
}
response = requests.post(url, json=payload, headers=headers)
print(response.json())
const response = await fetch("https://api.cxm.io/graphql", {
method: "POST",
headers: {
"Authorization": `Bearer ${YOUR_TOKEN}`,
"Content-Type": "application/json",
},
body: JSON.stringify({
query: `query margin_instruments($is_active: ToggleSwitch!, $pager: PagerInput) { margin_instruments(is_active: $is_active, pager: $pager) { margin_instrument_id name base_currency_id quote_currency_id min_leverage max_leverage min_quantity max_quantity long_funding_rate short_funding_rate price_24h_change price_decimals quantity_decimals price_24h_low price_24h_high is_trading_on market_status margin_instrument_strategy_is_active margin_instrument_strategy_id class lot_size step_size cross_quote_price close_only base_currency { currency_id precision is_active } quote_currency { currency_id precision is_active } price { margin_instrument_id ask bid updated_at } funding_data { rate_type next_funding_date long_funding_rate short_funding_rate multiplier period } meta market_hours { custom_periods { end_time name start_time } general_rules { days end_time is_active start_time } holidays { end_time name start_time } } } }`,
variables: {
"is_active": "On",
"pager": {
"limit": 1000,
"offset": 0
}
},
}),
});
const data = await response.json();
console.log(data);Try It
query open_derivatives_orders List currently open margin orders.
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
search |
String |
optional | Search by order ID or instrument |
pager |
PagerInput |
optional | Pagination |
sort |
SortInput |
optional | Sort field and direction |
user_id |
String |
optional | Filter by user ID |
dateRange |
DateRangeInput |
optional | Time range filter |
side |
MarginPositionSide |
optional | buy or sell |
status |
MarginOrderStatus |
optional | open, completed, cancelled, etc. |
time_in_force |
MarginOrderTimeInForce |
optional | GTC, IOC, FOK, etc. |
type |
MarginOrderType |
optional | market or limit |
instrument_id |
String |
optional | Single instrument filter |
instruments_ids |
[String!] |
optional | Multiple instrument IDs |
wallet_id |
String |
optional | Filter by wallet |
Response
| Field | Type | Description |
|---|---|---|
margin_order_id |
ID |
Order unique identifier |
status |
String |
Order status: open, completed, cancelled |
side |
String |
buy or sell |
type |
String |
market or limit |
leverage |
Int |
Leverage multiplier |
quantity |
Float |
Order size |
fee_amount |
Float |
Trading fee charged |
GraphQL Operation
query open_margin_orders($search: String, $pager: PagerInput, $sort: SortInput, $user_id: String, $dateRange: DateRangeInput, $side: MarginPositionSide, $status: MarginOrderStatus, $time_in_force: MarginOrderTimeInForce, $type: MarginOrderType, $instrument_id: String, $instruments_ids: [String!], $wallet_id: String) {
open_margin_orders(search: $search, pager: $pager, sort: $sort, user_id: $user_id, dateRange: $dateRange, side: $side, status: $status, time_in_force: $time_in_force, type: $type, instrument_id: $instrument_id, instruments_ids: $instruments_ids, wallet_id: $wallet_id) {
margin_order_id margin_position_id user_id instrument_id side type status leverage quantity price limit_price message created_at_timestamp stop_loss take_profit ask bid executed_quantity fee_amount time_in_force expires_at_iso updated_at_iso cross_quote_price wallet_id margin_instrument {
base_currency_id quote_currency_id name price_decimals quantity_decimals min_leverage max_leverage min_quantity max_quantity cross_quote_price close_only quote_currency {
precision
}
base_currency {
precision
}
price {
ask bid
}
margin_instrument_strategy_is_active lot_size step_size class margin_instrument_id is_trading_on market_status
}
}
}
Code Examples
curl -X POST 'https://api.cxm.io/graphql' \
-H 'Authorization: Bearer YOUR_TOKEN' \
-H 'Content-Type: application/json' \
-d '{"query":"query open_margin_orders($search: String, $pager: PagerInput, $sort: SortInput, $user_id: String, $dateRange: DateRangeInput, $side: MarginPositionSide, $status: MarginOrderStatus, $time_in_force: MarginOrderTimeInForce, $type: MarginOrderType, $instrument_id: String, $instruments_ids: [String!], $wallet_id: String) { open_margin_orders(search: $search, pager: $pager, sort: $sort, user_id: $user_id, dateRange: $dateRange, side: $side, status: $status, time_in_force: $time_in_force, type: $type, instrument_id: $instrument_id, instruments_ids: $instruments_ids, wallet_id: $wallet_id) { margin_order_id margin_position_id user_id instrument_id side type status leverage quantity price limit_price message created_at_timestamp stop_loss take_profit ask bid executed_quantity fee_amount time_in_force expires_at_iso updated_at_iso cross_quote_price wallet_id margin_instrument { base_currency_id quote_currency_id name price_decimals quantity_decimals min_leverage max_leverage min_quantity max_quantity cross_quote_price close_only quote_currency { precision } base_currency { precision } price { ask bid } margin_instrument_strategy_is_active lot_size step_size class margin_instrument_id is_trading_on market_status } } }","variables":{"user_id":"user123","side":"buy","status":"open","pager":{"limit":50,"offset":0}}}'
import requests
url = "https://api.cxm.io/graphql"
headers = {
"Authorization": "Bearer YOUR_TOKEN",
"Content-Type": "application/json",
}
payload = {
"query": """query open_margin_orders($search: String, $pager: PagerInput, $sort: SortInput, $user_id: String, $dateRange: DateRangeInput, $side: MarginPositionSide, $status: MarginOrderStatus, $time_in_force: MarginOrderTimeInForce, $type: MarginOrderType, $instrument_id: String, $instruments_ids: [String!], $wallet_id: String) { open_margin_orders(search: $search, pager: $pager, sort: $sort, user_id: $user_id, dateRange: $dateRange, side: $side, status: $status, time_in_force: $time_in_force, type: $type, instrument_id: $instrument_id, instruments_ids: $instruments_ids, wallet_id: $wallet_id) { margin_order_id margin_position_id user_id instrument_id side type status leverage quantity price limit_price message created_at_timestamp stop_loss take_profit ask bid executed_quantity fee_amount time_in_force expires_at_iso updated_at_iso cross_quote_price wallet_id margin_instrument { base_currency_id quote_currency_id name price_decimals quantity_decimals min_leverage max_leverage min_quantity max_quantity cross_quote_price close_only quote_currency { precision } base_currency { precision } price { ask bid } margin_instrument_strategy_is_active lot_size step_size class margin_instrument_id is_trading_on market_status } } }""",
"variables": {
"user_id": "user123",
"side": "buy",
"status": "open",
"pager": {
"limit": 50,
"offset": 0
}
},
}
response = requests.post(url, json=payload, headers=headers)
print(response.json())
const response = await fetch("https://api.cxm.io/graphql", {
method: "POST",
headers: {
"Authorization": `Bearer ${YOUR_TOKEN}`,
"Content-Type": "application/json",
},
body: JSON.stringify({
query: `query open_margin_orders($search: String, $pager: PagerInput, $sort: SortInput, $user_id: String, $dateRange: DateRangeInput, $side: MarginPositionSide, $status: MarginOrderStatus, $time_in_force: MarginOrderTimeInForce, $type: MarginOrderType, $instrument_id: String, $instruments_ids: [String!], $wallet_id: String) { open_margin_orders(search: $search, pager: $pager, sort: $sort, user_id: $user_id, dateRange: $dateRange, side: $side, status: $status, time_in_force: $time_in_force, type: $type, instrument_id: $instrument_id, instruments_ids: $instruments_ids, wallet_id: $wallet_id) { margin_order_id margin_position_id user_id instrument_id side type status leverage quantity price limit_price message created_at_timestamp stop_loss take_profit ask bid executed_quantity fee_amount time_in_force expires_at_iso updated_at_iso cross_quote_price wallet_id margin_instrument { base_currency_id quote_currency_id name price_decimals quantity_decimals min_leverage max_leverage min_quantity max_quantity cross_quote_price close_only quote_currency { precision } base_currency { precision } price { ask bid } margin_instrument_strategy_is_active lot_size step_size class margin_instrument_id is_trading_on market_status } } }`,
variables: {
"user_id": "user123",
"side": "buy",
"status": "open",
"pager": {
"limit": 50,
"offset": 0
}
},
}),
});
const data = await response.json();
console.log(data);Try It
query closed_derivatives_orders List filled / cancelled margin orders.
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
search |
String |
optional | Search by ID |
pager |
PagerInput |
optional | Pagination |
sort |
SortInput |
optional | Sort parameters |
user_id |
String |
optional | User filter |
dateRange |
DateRangeInput |
optional | Time range |
side |
MarginPositionSide |
optional | buy or sell |
status |
MarginOrderStatus |
optional | completed, cancelled, rejected |
time_in_force |
MarginOrderTimeInForce |
optional | GTC, IOC, FOK |
type |
MarginOrderType |
optional | market or limit |
instrument_id |
String |
optional | Single instrument |
instruments_ids |
[String!] |
optional | Multiple instruments |
wallet_id |
String |
optional | Wallet filter |
Response
| Field | Type | Description |
|---|---|---|
margin_order_id |
ID |
Order ID |
status |
String |
Final status |
executed_quantity |
Float |
Amount actually filled |
value |
Float |
Total notional value |
fee_amount |
Float |
Trading fees |
GraphQL Operation
query closed_margin_orders($search: String, $pager: PagerInput, $sort: SortInput, $user_id: String, $dateRange: DateRangeInput, $side: MarginPositionSide, $status: MarginOrderStatus, $time_in_force: MarginOrderTimeInForce, $type: MarginOrderType, $instrument_id: String, $instruments_ids: [String!], $wallet_id: String) {
closed_margin_orders(search: $search, pager: $pager, sort: $sort, user_id: $user_id, dateRange: $dateRange, side: $side, status: $status, time_in_force: $time_in_force, type: $type, instrument_id: $instrument_id, instruments_ids: $instruments_ids, wallet_id: $wallet_id) {
margin_order_id margin_position_id user_id instrument_id side type status leverage quantity price limit_price message created_at_timestamp stop_loss take_profit ask bid executed_quantity fee_amount time_in_force expires_at_iso updated_at_iso cross_quote_price wallet_id value margin_instrument {
base_currency_id quote_currency_id name price_decimals quantity_decimals min_leverage max_leverage min_quantity max_quantity cross_quote_price close_only quote_currency {
precision
}
base_currency {
precision
}
price {
ask bid
}
margin_instrument_strategy_is_active lot_size step_size class margin_instrument_id is_trading_on market_status
}
}
}
Code Examples
curl -X POST 'https://api.cxm.io/graphql' \
-H 'Authorization: Bearer YOUR_TOKEN' \
-H 'Content-Type: application/json' \
-d '{"query":"query closed_margin_orders($search: String, $pager: PagerInput, $sort: SortInput, $user_id: String, $dateRange: DateRangeInput, $side: MarginPositionSide, $status: MarginOrderStatus, $time_in_force: MarginOrderTimeInForce, $type: MarginOrderType, $instrument_id: String, $instruments_ids: [String!], $wallet_id: String) { closed_margin_orders(search: $search, pager: $pager, sort: $sort, user_id: $user_id, dateRange: $dateRange, side: $side, status: $status, time_in_force: $time_in_force, type: $type, instrument_id: $instrument_id, instruments_ids: $instruments_ids, wallet_id: $wallet_id) { margin_order_id margin_position_id user_id instrument_id side type status leverage quantity price limit_price message created_at_timestamp stop_loss take_profit ask bid executed_quantity fee_amount time_in_force expires_at_iso updated_at_iso cross_quote_price wallet_id value margin_instrument { base_currency_id quote_currency_id name price_decimals quantity_decimals min_leverage max_leverage min_quantity max_quantity cross_quote_price close_only quote_currency { precision } base_currency { precision } price { ask bid } margin_instrument_strategy_is_active lot_size step_size class margin_instrument_id is_trading_on market_status } } }","variables":{"user_id":"user123","status":"completed","pager":{"limit":50,"offset":0}}}'
import requests
url = "https://api.cxm.io/graphql"
headers = {
"Authorization": "Bearer YOUR_TOKEN",
"Content-Type": "application/json",
}
payload = {
"query": """query closed_margin_orders($search: String, $pager: PagerInput, $sort: SortInput, $user_id: String, $dateRange: DateRangeInput, $side: MarginPositionSide, $status: MarginOrderStatus, $time_in_force: MarginOrderTimeInForce, $type: MarginOrderType, $instrument_id: String, $instruments_ids: [String!], $wallet_id: String) { closed_margin_orders(search: $search, pager: $pager, sort: $sort, user_id: $user_id, dateRange: $dateRange, side: $side, status: $status, time_in_force: $time_in_force, type: $type, instrument_id: $instrument_id, instruments_ids: $instruments_ids, wallet_id: $wallet_id) { margin_order_id margin_position_id user_id instrument_id side type status leverage quantity price limit_price message created_at_timestamp stop_loss take_profit ask bid executed_quantity fee_amount time_in_force expires_at_iso updated_at_iso cross_quote_price wallet_id value margin_instrument { base_currency_id quote_currency_id name price_decimals quantity_decimals min_leverage max_leverage min_quantity max_quantity cross_quote_price close_only quote_currency { precision } base_currency { precision } price { ask bid } margin_instrument_strategy_is_active lot_size step_size class margin_instrument_id is_trading_on market_status } } }""",
"variables": {
"user_id": "user123",
"status": "completed",
"pager": {
"limit": 50,
"offset": 0
}
},
}
response = requests.post(url, json=payload, headers=headers)
print(response.json())
const response = await fetch("https://api.cxm.io/graphql", {
method: "POST",
headers: {
"Authorization": `Bearer ${YOUR_TOKEN}`,
"Content-Type": "application/json",
},
body: JSON.stringify({
query: `query closed_margin_orders($search: String, $pager: PagerInput, $sort: SortInput, $user_id: String, $dateRange: DateRangeInput, $side: MarginPositionSide, $status: MarginOrderStatus, $time_in_force: MarginOrderTimeInForce, $type: MarginOrderType, $instrument_id: String, $instruments_ids: [String!], $wallet_id: String) { closed_margin_orders(search: $search, pager: $pager, sort: $sort, user_id: $user_id, dateRange: $dateRange, side: $side, status: $status, time_in_force: $time_in_force, type: $type, instrument_id: $instrument_id, instruments_ids: $instruments_ids, wallet_id: $wallet_id) { margin_order_id margin_position_id user_id instrument_id side type status leverage quantity price limit_price message created_at_timestamp stop_loss take_profit ask bid executed_quantity fee_amount time_in_force expires_at_iso updated_at_iso cross_quote_price wallet_id value margin_instrument { base_currency_id quote_currency_id name price_decimals quantity_decimals min_leverage max_leverage min_quantity max_quantity cross_quote_price close_only quote_currency { precision } base_currency { precision } price { ask bid } margin_instrument_strategy_is_active lot_size step_size class margin_instrument_id is_trading_on market_status } } }`,
variables: {
"user_id": "user123",
"status": "completed",
"pager": {
"limit": 50,
"offset": 0
}
},
}),
});
const data = await response.json();
console.log(data);Try It
mutation create_derivatives_order Place a margin / perpetual order.
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
instrument_id |
String! |
required | Perpetual contract symbol |
side |
MarginPositionSide! |
required | buy (long) or sell (short) |
type |
MarginOrderType! |
required | market or limit |
leverage |
Int! |
required | Leverage multiplier |
quantity |
Float! |
required | Order size |
price |
Float |
optional | Limit price (required for limit orders) |
stop_loss |
Float |
optional | Stop loss trigger price |
take_profit |
Float |
optional | Take profit target price |
expires_at |
String |
optional | Order expiry ISO timestamp |
time_in_force |
MarginOrderTimeInForce! |
optional | GTC, IOC, FOK |
all_in |
ToggleSwitch |
optional | Use all available margin |
wallet_id |
String |
optional | Target wallet |
Response
| Field | Type | Description |
|---|---|---|
margin_order_id |
ID |
ID of the created order |
GraphQL Operation
mutation create_margin_order($instrument_id: String!, $side: MarginPositionSide!, $type: MarginOrderType!, $leverage: Int!, $quantity: Float!, $price: Float, $stop_loss: Float, $take_profit: Float, $expires_at: String, $time_in_force: MarginOrderTimeInForce!, $all_in: ToggleSwitch, $wallet_id: String) {
create_margin_order(instrument_id: $instrument_id, side: $side, type: $type, leverage: $leverage, quantity: $quantity, price: $price, stop_loss: $stop_loss, take_profit: $take_profit, expires_at: $expires_at, time_in_force: $time_in_force, all_in: $all_in, wallet_id: $wallet_id) {
margin_order_id
}
}
Code Examples
curl -X POST 'https://api.cxm.io/graphql' \
-H 'Authorization: Bearer YOUR_TOKEN' \
-H 'Content-Type: application/json' \
-d '{"query":"mutation create_margin_order($instrument_id: String!, $side: MarginPositionSide!, $type: MarginOrderType!, $leverage: Int!, $quantity: Float!, $price: Float, $stop_loss: Float, $take_profit: Float, $expires_at: String, $time_in_force: MarginOrderTimeInForce!, $all_in: ToggleSwitch, $wallet_id: String) { create_margin_order(instrument_id: $instrument_id, side: $side, type: $type, leverage: $leverage, quantity: $quantity, price: $price, stop_loss: $stop_loss, take_profit: $take_profit, expires_at: $expires_at, time_in_force: $time_in_force, all_in: $all_in, wallet_id: $wallet_id) { margin_order_id } }","variables":{"instrument_id":"BTC-PERP","side":"buy","type":"market","leverage":10,"quantity":1}}'
import requests
url = "https://api.cxm.io/graphql"
headers = {
"Authorization": "Bearer YOUR_TOKEN",
"Content-Type": "application/json",
}
payload = {
"query": """mutation create_margin_order($instrument_id: String!, $side: MarginPositionSide!, $type: MarginOrderType!, $leverage: Int!, $quantity: Float!, $price: Float, $stop_loss: Float, $take_profit: Float, $expires_at: String, $time_in_force: MarginOrderTimeInForce!, $all_in: ToggleSwitch, $wallet_id: String) { create_margin_order(instrument_id: $instrument_id, side: $side, type: $type, leverage: $leverage, quantity: $quantity, price: $price, stop_loss: $stop_loss, take_profit: $take_profit, expires_at: $expires_at, time_in_force: $time_in_force, all_in: $all_in, wallet_id: $wallet_id) { margin_order_id } }""",
"variables": {
"instrument_id": "BTC-PERP",
"side": "buy",
"type": "market",
"leverage": 10,
"quantity": 1
},
}
response = requests.post(url, json=payload, headers=headers)
print(response.json())
const response = await fetch("https://api.cxm.io/graphql", {
method: "POST",
headers: {
"Authorization": `Bearer ${YOUR_TOKEN}`,
"Content-Type": "application/json",
},
body: JSON.stringify({
query: `mutation create_margin_order($instrument_id: String!, $side: MarginPositionSide!, $type: MarginOrderType!, $leverage: Int!, $quantity: Float!, $price: Float, $stop_loss: Float, $take_profit: Float, $expires_at: String, $time_in_force: MarginOrderTimeInForce!, $all_in: ToggleSwitch, $wallet_id: String) { create_margin_order(instrument_id: $instrument_id, side: $side, type: $type, leverage: $leverage, quantity: $quantity, price: $price, stop_loss: $stop_loss, take_profit: $take_profit, expires_at: $expires_at, time_in_force: $time_in_force, all_in: $all_in, wallet_id: $wallet_id) { margin_order_id } }`,
variables: {
"instrument_id": "BTC-PERP",
"side": "buy",
"type": "market",
"leverage": 10,
"quantity": 1
},
}),
});
const data = await response.json();
console.log(data);Try It
mutation cancel_derivatives_order Cancel a margin order.
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
margin_order_id |
String! |
required | Order ID to cancel |
GraphQL Operation
mutation cancel_margin_order($margin_order_id: String!) {
cancel_margin_order(margin_order_id: $margin_order_id)
}
Code Examples
curl -X POST 'https://api.cxm.io/graphql' \
-H 'Authorization: Bearer YOUR_TOKEN' \
-H 'Content-Type: application/json' \
-d '{"query":"mutation cancel_margin_order($margin_order_id: String!) { cancel_margin_order(margin_order_id: $margin_order_id) }","variables":{"margin_order_id":"order123"}}'
import requests
url = "https://api.cxm.io/graphql"
headers = {
"Authorization": "Bearer YOUR_TOKEN",
"Content-Type": "application/json",
}
payload = {
"query": """mutation cancel_margin_order($margin_order_id: String!) { cancel_margin_order(margin_order_id: $margin_order_id) }""",
"variables": {
"margin_order_id": "order123"
},
}
response = requests.post(url, json=payload, headers=headers)
print(response.json())
const response = await fetch("https://api.cxm.io/graphql", {
method: "POST",
headers: {
"Authorization": `Bearer ${YOUR_TOKEN}`,
"Content-Type": "application/json",
},
body: JSON.stringify({
query: `mutation cancel_margin_order($margin_order_id: String!) { cancel_margin_order(margin_order_id: $margin_order_id) }`,
variables: {
"margin_order_id": "order123"
},
}),
});
const data = await response.json();
console.log(data);Try It
query estimate_derivatives_order Preview a margin order before placing.
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
instrument_id |
String! |
required | Perpetual contract symbol |
quantity |
Float! |
required | Position size to estimate |
leverage |
Int! |
required | Leverage multiplier (min 1) |
side |
MarginPositionSide! |
required | long or short |
limit_price |
Float |
optional | Target entry price for limit orders |
use_cached_price |
ToggleSwitch |
optional | Use cached price data |
wallet_id |
String |
optional | Specific wallet to estimate for |
Response
| Field | Type | Description |
|---|---|---|
order_required_margin |
Float |
Margin needed to place order |
fee |
Float |
Total trading fee |
order_value |
Float |
Notional order value |
order_available_margin |
Float |
Available margin after trade |
max_position_size_base |
Float |
Maximum position size allowed |
GraphQL Operation
query estimate_margin_user_position($instrument_id: String!, $quantity: Float!, $leverage: Int!, $side: MarginPositionSide!, $limit_price: Float, $use_cached_price: ToggleSwitch, $wallet_id: String) {
estimate_margin_user_position(instrument_id: $instrument_id, quantity: $quantity, leverage: $leverage, side: $side, limit_price: $limit_price, use_cached_price: $use_cached_price, wallet_id: $wallet_id) {
order_required_margin fee order_available_margin order_value max_position_size_base min_position_size_base fees_breakdown {
fee value source
}
}
}
Code Examples
curl -X POST 'https://api.cxm.io/graphql' \
-H 'Authorization: Bearer YOUR_TOKEN' \
-H 'Content-Type: application/json' \
-d '{"query":"query estimate_margin_user_position($instrument_id: String!, $quantity: Float!, $leverage: Int!, $side: MarginPositionSide!, $limit_price: Float, $use_cached_price: ToggleSwitch, $wallet_id: String) { estimate_margin_user_position(instrument_id: $instrument_id, quantity: $quantity, leverage: $leverage, side: $side, limit_price: $limit_price, use_cached_price: $use_cached_price, wallet_id: $wallet_id) { order_required_margin fee order_available_margin order_value max_position_size_base min_position_size_base fees_breakdown { fee value source } } }","variables":{"instrument_id":"BTC-PERP","quantity":1,"leverage":10,"side":"long"}}'
import requests
url = "https://api.cxm.io/graphql"
headers = {
"Authorization": "Bearer YOUR_TOKEN",
"Content-Type": "application/json",
}
payload = {
"query": """query estimate_margin_user_position($instrument_id: String!, $quantity: Float!, $leverage: Int!, $side: MarginPositionSide!, $limit_price: Float, $use_cached_price: ToggleSwitch, $wallet_id: String) { estimate_margin_user_position(instrument_id: $instrument_id, quantity: $quantity, leverage: $leverage, side: $side, limit_price: $limit_price, use_cached_price: $use_cached_price, wallet_id: $wallet_id) { order_required_margin fee order_available_margin order_value max_position_size_base min_position_size_base fees_breakdown { fee value source } } }""",
"variables": {
"instrument_id": "BTC-PERP",
"quantity": 1,
"leverage": 10,
"side": "long"
},
}
response = requests.post(url, json=payload, headers=headers)
print(response.json())
const response = await fetch("https://api.cxm.io/graphql", {
method: "POST",
headers: {
"Authorization": `Bearer ${YOUR_TOKEN}`,
"Content-Type": "application/json",
},
body: JSON.stringify({
query: `query estimate_margin_user_position($instrument_id: String!, $quantity: Float!, $leverage: Int!, $side: MarginPositionSide!, $limit_price: Float, $use_cached_price: ToggleSwitch, $wallet_id: String) { estimate_margin_user_position(instrument_id: $instrument_id, quantity: $quantity, leverage: $leverage, side: $side, limit_price: $limit_price, use_cached_price: $use_cached_price, wallet_id: $wallet_id) { order_required_margin fee order_available_margin order_value max_position_size_base min_position_size_base fees_breakdown { fee value source } } }`,
variables: {
"instrument_id": "BTC-PERP",
"quantity": 1,
"leverage": 10,
"side": "long"
},
}),
});
const data = await response.json();
console.log(data);Try It
query open_derivatives_positions List currently open margin positions.
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
search |
String |
optional | Search by position ID |
pager |
PagerInput |
optional | Pagination |
sort |
SortInput |
optional | Sort parameters |
user_id |
String |
optional | User filter |
dateRange |
DateRangeInput |
optional | Date range |
side |
MarginPositionSide |
optional | long or short |
instrument_id |
String |
optional | Single instrument |
instruments_ids |
[String!] |
optional | Multiple instruments |
wallet_id |
String |
optional | Wallet filter |
Response
| Field | Type | Description |
|---|---|---|
margin_position_id |
ID |
Position unique ID |
side |
String |
long or short |
amount |
Float |
Position size in base asset |
entry_price |
Float |
Average entry price |
pnl |
Float |
Unrealized P&L |
leverage |
Int |
Current leverage |
funding_fee_amount |
Float |
Accrued funding fees |
GraphQL Operation
query open_margin_positions($search: String, $pager: PagerInput, $sort: SortInput, $user_id: String, $dateRange: DateRangeInput, $side: MarginPositionSide, $instrument_id: String, $instruments_ids: [String!], $wallet_id: String) {
open_margin_positions(search: $search, pager: $pager, sort: $sort, user_id: $user_id, dateRange: $dateRange, side: $side, instrument_id: $instrument_id, instruments_ids: $instruments_ids, wallet_id: $wallet_id) {
margin_position_id instrument_id user_id side leverage amount value funding_fee_amount entry_price start_price_ts end_price_ts start_ask_price start_bid_price duration end_ask_price pnl stop_loss take_profit start_ts_timestamp close_reason updated_at_iso wallet_id margin_currency_id exit_price margin total_pnl cross_quote_price end_bid_price close_reason_code margin_instrument {
base_currency_id quote_currency_id name price_decimals quantity_decimals min_quantity min_leverage max_leverage is_trading_on class margin_instrument_id market_status cross_quote_price close_only quote_currency {
precision
}
base_currency {
precision
}
price {
ask bid
}
margin_instrument_strategy_is_active lot_size step_size
}
}
}
Code Examples
curl -X POST 'https://api.cxm.io/graphql' \
-H 'Authorization: Bearer YOUR_TOKEN' \
-H 'Content-Type: application/json' \
-d '{"query":"query open_margin_positions($search: String, $pager: PagerInput, $sort: SortInput, $user_id: String, $dateRange: DateRangeInput, $side: MarginPositionSide, $instrument_id: String, $instruments_ids: [String!], $wallet_id: String) { open_margin_positions(search: $search, pager: $pager, sort: $sort, user_id: $user_id, dateRange: $dateRange, side: $side, instrument_id: $instrument_id, instruments_ids: $instruments_ids, wallet_id: $wallet_id) { margin_position_id instrument_id user_id side leverage amount value funding_fee_amount entry_price start_price_ts end_price_ts start_ask_price start_bid_price duration end_ask_price pnl stop_loss take_profit start_ts_timestamp close_reason updated_at_iso wallet_id margin_currency_id exit_price margin total_pnl cross_quote_price end_bid_price close_reason_code margin_instrument { base_currency_id quote_currency_id name price_decimals quantity_decimals min_quantity min_leverage max_leverage is_trading_on class margin_instrument_id market_status cross_quote_price close_only quote_currency { precision } base_currency { precision } price { ask bid } margin_instrument_strategy_is_active lot_size step_size } } }","variables":{"user_id":"user123","side":"long","pager":{"limit":50,"offset":0}}}'
import requests
url = "https://api.cxm.io/graphql"
headers = {
"Authorization": "Bearer YOUR_TOKEN",
"Content-Type": "application/json",
}
payload = {
"query": """query open_margin_positions($search: String, $pager: PagerInput, $sort: SortInput, $user_id: String, $dateRange: DateRangeInput, $side: MarginPositionSide, $instrument_id: String, $instruments_ids: [String!], $wallet_id: String) { open_margin_positions(search: $search, pager: $pager, sort: $sort, user_id: $user_id, dateRange: $dateRange, side: $side, instrument_id: $instrument_id, instruments_ids: $instruments_ids, wallet_id: $wallet_id) { margin_position_id instrument_id user_id side leverage amount value funding_fee_amount entry_price start_price_ts end_price_ts start_ask_price start_bid_price duration end_ask_price pnl stop_loss take_profit start_ts_timestamp close_reason updated_at_iso wallet_id margin_currency_id exit_price margin total_pnl cross_quote_price end_bid_price close_reason_code margin_instrument { base_currency_id quote_currency_id name price_decimals quantity_decimals min_quantity min_leverage max_leverage is_trading_on class margin_instrument_id market_status cross_quote_price close_only quote_currency { precision } base_currency { precision } price { ask bid } margin_instrument_strategy_is_active lot_size step_size } } }""",
"variables": {
"user_id": "user123",
"side": "long",
"pager": {
"limit": 50,
"offset": 0
}
},
}
response = requests.post(url, json=payload, headers=headers)
print(response.json())
const response = await fetch("https://api.cxm.io/graphql", {
method: "POST",
headers: {
"Authorization": `Bearer ${YOUR_TOKEN}`,
"Content-Type": "application/json",
},
body: JSON.stringify({
query: `query open_margin_positions($search: String, $pager: PagerInput, $sort: SortInput, $user_id: String, $dateRange: DateRangeInput, $side: MarginPositionSide, $instrument_id: String, $instruments_ids: [String!], $wallet_id: String) { open_margin_positions(search: $search, pager: $pager, sort: $sort, user_id: $user_id, dateRange: $dateRange, side: $side, instrument_id: $instrument_id, instruments_ids: $instruments_ids, wallet_id: $wallet_id) { margin_position_id instrument_id user_id side leverage amount value funding_fee_amount entry_price start_price_ts end_price_ts start_ask_price start_bid_price duration end_ask_price pnl stop_loss take_profit start_ts_timestamp close_reason updated_at_iso wallet_id margin_currency_id exit_price margin total_pnl cross_quote_price end_bid_price close_reason_code margin_instrument { base_currency_id quote_currency_id name price_decimals quantity_decimals min_quantity min_leverage max_leverage is_trading_on class margin_instrument_id market_status cross_quote_price close_only quote_currency { precision } base_currency { precision } price { ask bid } margin_instrument_strategy_is_active lot_size step_size } } }`,
variables: {
"user_id": "user123",
"side": "long",
"pager": {
"limit": 50,
"offset": 0
}
},
}),
});
const data = await response.json();
console.log(data);Try It
query closed_derivatives_positions List historical (closed) margin positions.
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
search |
String |
optional | Search by ID |
pager |
PagerInput |
optional | Pagination |
sort |
SortInput |
optional | Sort parameters |
user_id |
String |
optional | User filter |
dateRange |
DateRangeInput |
optional | Time range |
side |
MarginPositionSide |
optional | long or short |
instrument_id |
String |
optional | Single instrument |
instruments_ids |
[String!] |
optional | Multiple instruments |
wallet_id |
String |
optional | Wallet filter |
Response
| Field | Type | Description |
|---|---|---|
margin_position_id |
ID |
Position ID |
exit_price |
Float |
Closing price |
pnl |
Float |
Realized P&L |
close_reason |
String |
Why position closed |
end_ts_iso |
DateTime |
Close timestamp |
GraphQL Operation
query closed_margin_positions($search: String, $pager: PagerInput, $sort: SortInput, $user_id: String, $dateRange: DateRangeInput, $side: MarginPositionSide, $instrument_id: String, $instruments_ids: [String!], $wallet_id: String) {
closed_margin_positions(search: $search, pager: $pager, sort: $sort, user_id: $user_id, dateRange: $dateRange, side: $side, instrument_id: $instrument_id, instruments_ids: $instruments_ids, wallet_id: $wallet_id) {
margin_position_id instrument_id user_id side leverage amount value funding_fee_amount entry_price start_price_ts end_price_ts start_ask_price start_bid_price duration end_ask_price pnl stop_loss take_profit start_ts_timestamp close_reason updated_at_iso wallet_id margin_currency_id exit_price margin total_pnl cross_quote_price end_bid_price close_reason_code end_ts_iso margin_instrument {
base_currency_id quote_currency_id name price_decimals quantity_decimals min_quantity min_leverage max_leverage is_trading_on class margin_instrument_id market_status cross_quote_price close_only quote_currency {
precision
}
base_currency {
precision
}
price {
ask bid
}
margin_instrument_strategy_is_active lot_size step_size
}
}
}
Code Examples
curl -X POST 'https://api.cxm.io/graphql' \
-H 'Authorization: Bearer YOUR_TOKEN' \
-H 'Content-Type: application/json' \
-d '{"query":"query closed_margin_positions($search: String, $pager: PagerInput, $sort: SortInput, $user_id: String, $dateRange: DateRangeInput, $side: MarginPositionSide, $instrument_id: String, $instruments_ids: [String!], $wallet_id: String) { closed_margin_positions(search: $search, pager: $pager, sort: $sort, user_id: $user_id, dateRange: $dateRange, side: $side, instrument_id: $instrument_id, instruments_ids: $instruments_ids, wallet_id: $wallet_id) { margin_position_id instrument_id user_id side leverage amount value funding_fee_amount entry_price start_price_ts end_price_ts start_ask_price start_bid_price duration end_ask_price pnl stop_loss take_profit start_ts_timestamp close_reason updated_at_iso wallet_id margin_currency_id exit_price margin total_pnl cross_quote_price end_bid_price close_reason_code end_ts_iso margin_instrument { base_currency_id quote_currency_id name price_decimals quantity_decimals min_quantity min_leverage max_leverage is_trading_on class margin_instrument_id market_status cross_quote_price close_only quote_currency { precision } base_currency { precision } price { ask bid } margin_instrument_strategy_is_active lot_size step_size } } }","variables":{"user_id":"user123","side":"long","pager":{"limit":50,"offset":0}}}'
import requests
url = "https://api.cxm.io/graphql"
headers = {
"Authorization": "Bearer YOUR_TOKEN",
"Content-Type": "application/json",
}
payload = {
"query": """query closed_margin_positions($search: String, $pager: PagerInput, $sort: SortInput, $user_id: String, $dateRange: DateRangeInput, $side: MarginPositionSide, $instrument_id: String, $instruments_ids: [String!], $wallet_id: String) { closed_margin_positions(search: $search, pager: $pager, sort: $sort, user_id: $user_id, dateRange: $dateRange, side: $side, instrument_id: $instrument_id, instruments_ids: $instruments_ids, wallet_id: $wallet_id) { margin_position_id instrument_id user_id side leverage amount value funding_fee_amount entry_price start_price_ts end_price_ts start_ask_price start_bid_price duration end_ask_price pnl stop_loss take_profit start_ts_timestamp close_reason updated_at_iso wallet_id margin_currency_id exit_price margin total_pnl cross_quote_price end_bid_price close_reason_code end_ts_iso margin_instrument { base_currency_id quote_currency_id name price_decimals quantity_decimals min_quantity min_leverage max_leverage is_trading_on class margin_instrument_id market_status cross_quote_price close_only quote_currency { precision } base_currency { precision } price { ask bid } margin_instrument_strategy_is_active lot_size step_size } } }""",
"variables": {
"user_id": "user123",
"side": "long",
"pager": {
"limit": 50,
"offset": 0
}
},
}
response = requests.post(url, json=payload, headers=headers)
print(response.json())
const response = await fetch("https://api.cxm.io/graphql", {
method: "POST",
headers: {
"Authorization": `Bearer ${YOUR_TOKEN}`,
"Content-Type": "application/json",
},
body: JSON.stringify({
query: `query closed_margin_positions($search: String, $pager: PagerInput, $sort: SortInput, $user_id: String, $dateRange: DateRangeInput, $side: MarginPositionSide, $instrument_id: String, $instruments_ids: [String!], $wallet_id: String) { closed_margin_positions(search: $search, pager: $pager, sort: $sort, user_id: $user_id, dateRange: $dateRange, side: $side, instrument_id: $instrument_id, instruments_ids: $instruments_ids, wallet_id: $wallet_id) { margin_position_id instrument_id user_id side leverage amount value funding_fee_amount entry_price start_price_ts end_price_ts start_ask_price start_bid_price duration end_ask_price pnl stop_loss take_profit start_ts_timestamp close_reason updated_at_iso wallet_id margin_currency_id exit_price margin total_pnl cross_quote_price end_bid_price close_reason_code end_ts_iso margin_instrument { base_currency_id quote_currency_id name price_decimals quantity_decimals min_quantity min_leverage max_leverage is_trading_on class margin_instrument_id market_status cross_quote_price close_only quote_currency { precision } base_currency { precision } price { ask bid } margin_instrument_strategy_is_active lot_size step_size } } }`,
variables: {
"user_id": "user123",
"side": "long",
"pager": {
"limit": 50,
"offset": 0
}
},
}),
});
const data = await response.json();
console.log(data);Try It
mutation update_open_derivatives_position Adjust take-profit / stop-loss / margin on an open position.
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
margin_position_id |
String! |
required | Position ID to update |
leverage |
Int! |
required | New leverage |
stop_loss |
Float |
optional | Stop loss trigger price |
take_profit |
Float |
optional | Take profit target price |
Response
| Field | Type | Description |
|---|---|---|
margin_position_id |
ID |
Updated position ID |
GraphQL Operation
mutation update_open_margin_position($margin_position_id: String!, $leverage: Int!, $stop_loss: Float, $take_profit: Float) {
update_open_margin_position(margin_position_id: $margin_position_id, leverage: $leverage, stop_loss: $stop_loss, take_profit: $take_profit) {
margin_position_id
}
}
Code Examples
curl -X POST 'https://api.cxm.io/graphql' \
-H 'Authorization: Bearer YOUR_TOKEN' \
-H 'Content-Type: application/json' \
-d '{"query":"mutation update_open_margin_position($margin_position_id: String!, $leverage: Int!, $stop_loss: Float, $take_profit: Float) { update_open_margin_position(margin_position_id: $margin_position_id, leverage: $leverage, stop_loss: $stop_loss, take_profit: $take_profit) { margin_position_id } }","variables":{"margin_position_id":"pos123","leverage":15,"stop_loss":40000,"take_profit":45000}}'
import requests
url = "https://api.cxm.io/graphql"
headers = {
"Authorization": "Bearer YOUR_TOKEN",
"Content-Type": "application/json",
}
payload = {
"query": """mutation update_open_margin_position($margin_position_id: String!, $leverage: Int!, $stop_loss: Float, $take_profit: Float) { update_open_margin_position(margin_position_id: $margin_position_id, leverage: $leverage, stop_loss: $stop_loss, take_profit: $take_profit) { margin_position_id } }""",
"variables": {
"margin_position_id": "pos123",
"leverage": 15,
"stop_loss": 40000,
"take_profit": 45000
},
}
response = requests.post(url, json=payload, headers=headers)
print(response.json())
const response = await fetch("https://api.cxm.io/graphql", {
method: "POST",
headers: {
"Authorization": `Bearer ${YOUR_TOKEN}`,
"Content-Type": "application/json",
},
body: JSON.stringify({
query: `mutation update_open_margin_position($margin_position_id: String!, $leverage: Int!, $stop_loss: Float, $take_profit: Float) { update_open_margin_position(margin_position_id: $margin_position_id, leverage: $leverage, stop_loss: $stop_loss, take_profit: $take_profit) { margin_position_id } }`,
variables: {
"margin_position_id": "pos123",
"leverage": 15,
"stop_loss": 40000,
"take_profit": 45000
},
}),
});
const data = await response.json();
console.log(data);Try It
query derivatives_funding_history Read funding fees paid / earned over time.
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
sort |
SortInput |
optional | Sort field and direction |
pager |
PagerInput |
optional | Pagination |
dateRange |
DateRangeInput |
optional | Date range filter |
margin_position_id |
String |
optional | Filter by specific position |
wallet_id |
String |
optional | Wallet filter |
Response
| Field | Type | Description |
|---|---|---|
margin_position_id |
ID |
Position ID |
amount |
Float |
Funding fee paid/received |
rate |
Float |
Funding rate at time of charge |
updated_at_iso |
DateTime |
Fee calculation time |
rate_type |
String |
financing or funding |
GraphQL Operation
query margin_funding_fees($sort: SortInput, $pager: PagerInput, $dateRange: DateRangeInput, $margin_position_id: String, $wallet_id: String) {
margin_funding_fees(sort: $sort, pager: $pager, dateRange: $dateRange, margin_position_id: $margin_position_id, wallet_id: $wallet_id) {
amount updated_at_iso margin_position_id position_size rate currency_id rate_type
}
}
Code Examples
curl -X POST 'https://api.cxm.io/graphql' \
-H 'Authorization: Bearer YOUR_TOKEN' \
-H 'Content-Type: application/json' \
-d '{"query":"query margin_funding_fees($sort: SortInput, $pager: PagerInput, $dateRange: DateRangeInput, $margin_position_id: String, $wallet_id: String) { margin_funding_fees(sort: $sort, pager: $pager, dateRange: $dateRange, margin_position_id: $margin_position_id, wallet_id: $wallet_id) { amount updated_at_iso margin_position_id position_size rate currency_id rate_type } }","variables":{"wallet_id":"wallet123","pager":{"limit":100,"offset":0}}}'
import requests
url = "https://api.cxm.io/graphql"
headers = {
"Authorization": "Bearer YOUR_TOKEN",
"Content-Type": "application/json",
}
payload = {
"query": """query margin_funding_fees($sort: SortInput, $pager: PagerInput, $dateRange: DateRangeInput, $margin_position_id: String, $wallet_id: String) { margin_funding_fees(sort: $sort, pager: $pager, dateRange: $dateRange, margin_position_id: $margin_position_id, wallet_id: $wallet_id) { amount updated_at_iso margin_position_id position_size rate currency_id rate_type } }""",
"variables": {
"wallet_id": "wallet123",
"pager": {
"limit": 100,
"offset": 0
}
},
}
response = requests.post(url, json=payload, headers=headers)
print(response.json())
const response = await fetch("https://api.cxm.io/graphql", {
method: "POST",
headers: {
"Authorization": `Bearer ${YOUR_TOKEN}`,
"Content-Type": "application/json",
},
body: JSON.stringify({
query: `query margin_funding_fees($sort: SortInput, $pager: PagerInput, $dateRange: DateRangeInput, $margin_position_id: String, $wallet_id: String) { margin_funding_fees(sort: $sort, pager: $pager, dateRange: $dateRange, margin_position_id: $margin_position_id, wallet_id: $wallet_id) { amount updated_at_iso margin_position_id position_size rate currency_id rate_type } }`,
variables: {
"wallet_id": "wallet123",
"pager": {
"limit": 100,
"offset": 0
}
},
}),
});
const data = await response.json();
console.log(data);