From 3692f0bc52e5d959764b6a5eb2e3dd405678f4f3 Mon Sep 17 00:00:00 2001 From: keithang-grvt Date: Fri, 28 Nov 2025 12:13:06 +0800 Subject: [PATCH] [RFC] Update API docs and specs --- artifacts/apidocs/market_data_api.md | 294 +++++ .../schemas/aggregated_account_summary.md | 5 +- ...pi_add_isolated_position_margin_request.md | 19 + ...i_add_isolated_position_margin_response.md | 6 + ...api_aggregated_account_summary_response.md | 5 +- .../schemas/api_get_margin_rules_request.md | 6 + .../schemas/api_get_margin_rules_response.md | 18 + ..._account_position_margin_config_request.md | 24 + ...account_position_margin_config_response.md | 6 + .../apidocs/schemas/position_margin_type.md | 4 + artifacts/apidocs/schemas/risk_bracket.md | 10 + artifacts/apidocs/trading_api.md | 1050 ++++++++++++++++- artifacts/pysdk/grvt_raw_async.py | 32 + artifacts/pysdk/grvt_raw_sync.py | 30 + artifacts/pysdk/grvt_raw_types.py | 92 +- src/codegen/apispec.json | 563 ++++++++- 16 files changed, 2158 insertions(+), 6 deletions(-) create mode 100644 artifacts/apidocs/schemas/api_add_isolated_position_margin_request.md create mode 100644 artifacts/apidocs/schemas/api_add_isolated_position_margin_response.md create mode 100644 artifacts/apidocs/schemas/api_get_margin_rules_request.md create mode 100644 artifacts/apidocs/schemas/api_get_margin_rules_response.md create mode 100644 artifacts/apidocs/schemas/api_set_sub_account_position_margin_config_request.md create mode 100644 artifacts/apidocs/schemas/api_set_sub_account_position_margin_config_response.md create mode 100644 artifacts/apidocs/schemas/position_margin_type.md create mode 100644 artifacts/apidocs/schemas/risk_bracket.md diff --git a/artifacts/apidocs/market_data_api.md b/artifacts/apidocs/market_data_api.md index d78e338..34ed711 100644 --- a/artifacts/apidocs/market_data_api.md +++ b/artifacts/apidocs/market_data_api.md @@ -1258,6 +1258,300 @@ LITE ENDPOINT: lite/v1/currency ```
+### Get Margin Rules +``` +FULL ENDPOINT: full/v1/margin_rules +LITE ENDPOINT: lite/v1/margin_rules +``` + +=== "Request" +
+ -8<- "docs/schemas/api_get_margin_rules_request.md" +
+
+ !!! question "Query" + **Full Request** + ``` { .json .copy } + { + "instrument": "BTC_USDT_Perp" + } + ``` + **Lite Request** + ``` { .json .copy } + { + "i": "BTC_USDT_Perp" + } + ``` +
+=== "Response" +
+ -8<- "docs/schemas/api_get_margin_rules_response.md" +
+
+ !!! success + **Full Response** + ``` { .json .copy } + { + "instrument": "BTC_USDT_Perp", + "max_position_size": "100.0", + "risk_brackets": [{ + "tier": 1, + "notional_floor": "0", + "notional_cap": "600000", + "maintenance_margin_rate": "0.01", + "initial_margin_rate": "0.02", + "max_leverage": 50, + "cumulative_maintenance_amount": "0" + }] + } + ``` + **Lite Response** + ``` { .json .copy } + { + "i": "BTC_USDT_Perp", + "mp": "100.0", + "rb": [{ + "t": 1, + "nf": "0", + "nc": "600000", + "mm": "0.01", + "im": "0.02", + "ml": 50, + "cm": "0" + }] + } + ``` +
+=== "Errors" +
+ !!! info "Error Codes" + |Code|HttpStatus| Description | + |-|-|-| + |1002|500|Internal Server Error| + |1003|400|Request could not be processed due to malformed syntax| + |3000|400|Instrument is invalid| + |1004|404|Data Not Found| + |1006|429|You have surpassed the allocated rate limit for your tier| +
+
+ !!! failure + **Full Error Response** + ``` { .json .copy } + { + "request_id":1, + "code":1002, + "message":"Internal Server Error", + "status":500 + } + ``` + **Lite Error Response** + ``` { .json .copy } + { + "ri":1, + "c":1002, + "m":"Internal Server Error", + "s":500 + } + ``` +
+=== "Try it out" + === "DEV" +
+ !!! example "REST Full" + ``` { .bash .copy } + curl --location 'https://market-data.dev.gravitymarkets.io/full/v1/margin_rules' \ + --data '{ + "instrument": "BTC_USDT_Perp" + } + ' + ``` + !!! example "JSONRPC Full" + ``` { .bash .copy } + wscat -c "wss://market-data.dev.gravitymarkets.io/ws/full" \ + -x ' + { + "jsonrpc": "2.0", + "method": "v1/margin_rules", + "params": { + "instrument": "BTC_USDT_Perp" + }, + "id": 123 + } + ' -w 360 + ``` +
+
+ !!! example "REST Lite" + ``` { .bash .copy } + curl --location 'https://market-data.dev.gravitymarkets.io/lite/v1/margin_rules' \ + --data '{ + "i": "BTC_USDT_Perp" + } + ' + ``` + !!! example "JSONRPC Lite" + ``` { .bash .copy } + wscat -c "wss://market-data.dev.gravitymarkets.io/ws/lite" \ + -x ' + { + "j": "2.0", + "m": "v1/margin_rules", + "p": { + "i": "BTC_USDT_Perp" + }, + "i": 123 + } + ' -w 360 + ``` +
+ === "STAGING" +
+ !!! example "REST Full" + ``` { .bash .copy } + curl --location 'https://market-data.staging.gravitymarkets.io/full/v1/margin_rules' \ + --data '{ + "instrument": "BTC_USDT_Perp" + } + ' + ``` + !!! example "JSONRPC Full" + ``` { .bash .copy } + wscat -c "wss://market-data.staging.gravitymarkets.io/ws/full" \ + -x ' + { + "jsonrpc": "2.0", + "method": "v1/margin_rules", + "params": { + "instrument": "BTC_USDT_Perp" + }, + "id": 123 + } + ' -w 360 + ``` +
+
+ !!! example "REST Lite" + ``` { .bash .copy } + curl --location 'https://market-data.staging.gravitymarkets.io/lite/v1/margin_rules' \ + --data '{ + "i": "BTC_USDT_Perp" + } + ' + ``` + !!! example "JSONRPC Lite" + ``` { .bash .copy } + wscat -c "wss://market-data.staging.gravitymarkets.io/ws/lite" \ + -x ' + { + "j": "2.0", + "m": "v1/margin_rules", + "p": { + "i": "BTC_USDT_Perp" + }, + "i": 123 + } + ' -w 360 + ``` +
+ === "TESTNET" +
+ !!! example "REST Full" + ``` { .bash .copy } + curl --location 'https://market-data.testnet.grvt.io/full/v1/margin_rules' \ + --data '{ + "instrument": "BTC_USDT_Perp" + } + ' + ``` + !!! example "JSONRPC Full" + ``` { .bash .copy } + wscat -c "wss://market-data.testnet.grvt.io/ws/full" \ + -x ' + { + "jsonrpc": "2.0", + "method": "v1/margin_rules", + "params": { + "instrument": "BTC_USDT_Perp" + }, + "id": 123 + } + ' -w 360 + ``` +
+
+ !!! example "REST Lite" + ``` { .bash .copy } + curl --location 'https://market-data.testnet.grvt.io/lite/v1/margin_rules' \ + --data '{ + "i": "BTC_USDT_Perp" + } + ' + ``` + !!! example "JSONRPC Lite" + ``` { .bash .copy } + wscat -c "wss://market-data.testnet.grvt.io/ws/lite" \ + -x ' + { + "j": "2.0", + "m": "v1/margin_rules", + "p": { + "i": "BTC_USDT_Perp" + }, + "i": 123 + } + ' -w 360 + ``` +
+ === "PROD" +
+ !!! example "REST Full" + ``` { .bash .copy } + curl --location 'https://market-data.grvt.io/full/v1/margin_rules' \ + --data '{ + "instrument": "BTC_USDT_Perp" + } + ' + ``` + !!! example "JSONRPC Full" + ``` { .bash .copy } + wscat -c "wss://market-data.grvt.io/ws/full" \ + -x ' + { + "jsonrpc": "2.0", + "method": "v1/margin_rules", + "params": { + "instrument": "BTC_USDT_Perp" + }, + "id": 123 + } + ' -w 360 + ``` +
+
+ !!! example "REST Lite" + ``` { .bash .copy } + curl --location 'https://market-data.grvt.io/lite/v1/margin_rules' \ + --data '{ + "i": "BTC_USDT_Perp" + } + ' + ``` + !!! example "JSONRPC Lite" + ``` { .bash .copy } + wscat -c "wss://market-data.grvt.io/ws/lite" \ + -x ' + { + "j": "2.0", + "m": "v1/margin_rules", + "p": { + "i": "BTC_USDT_Perp" + }, + "i": 123 + } + ' -w 360 + ``` +
+
## Ticker ### Mini Ticker ``` diff --git a/artifacts/apidocs/schemas/aggregated_account_summary.md b/artifacts/apidocs/schemas/aggregated_account_summary.md index 59e3433..3934344 100644 --- a/artifacts/apidocs/schemas/aggregated_account_summary.md +++ b/artifacts/apidocs/schemas/aggregated_account_summary.md @@ -5,7 +5,10 @@ |total_equity
`te` |string|True|Total equity of the main (+ sub) account, denominated in USD| |spot_balances
`sb` |[SpotBalance]|True|The list of spot assets owned by this main (+ sub) account, and their balances| |vault_investments
`vi` |[VaultInvestment]|True|The list of vault investments held by this main account| - |total_sub_account_balance
`ts` |string|True|Total balance of the sub accounts, denominated in USD| + |total_sub_account_balance
`ts` |string|True|Deprecated: Use totalSubAccountEquity instead| + |total_sub_account_equity
`ts1` |string|True|Total equity of the sub accounts, denominated in USD| + |total_vault_investments_balance
`tv` |string|True|Total amount of the vault investments, denominated in USD| + |total_sub_account_available_balance
`ts2` |string|True|Total available balance of the main account, denominated in USD| ??? info "[SpotBalance](/../../schemas/spot_balance)" |Name
`Lite`|Type|Required
`Default`| Description | |-|-|-|-| diff --git a/artifacts/apidocs/schemas/api_add_isolated_position_margin_request.md b/artifacts/apidocs/schemas/api_add_isolated_position_margin_request.md new file mode 100644 index 0000000..2a14591 --- /dev/null +++ b/artifacts/apidocs/schemas/api_add_isolated_position_margin_request.md @@ -0,0 +1,19 @@ +!!! info "[ApiAddIsolatedPositionMarginRequest](/../../schemas/api_add_isolated_position_margin_request)" + The request to add margin to a isolated position
+ + |Name
`Lite`|Type|Required
`Default`| Description | + |-|-|-|-| + |sub_account_id
`sa` |string|True|The sub account ID to add isolated margin in or remove margin from| + |instrument
`i` |string|True|The instrument to add margin into, or remove margin from| + |amount
`a` |string|True|The amount of margin to add to the position, positive to add, negative to remove, expressed in quote asset decimal units| + |signature
`s` |Signature|True|The signature of this operation| + ??? info "[Signature](/../../schemas/signature)" + |Name
`Lite`|Type|Required
`Default`| Description | + |-|-|-|-| + |signer
`s` |string|True|The address (public key) of the wallet signing the payload| + |r
`r` |string|True|Signature R| + |s
`s1` |string|True|Signature S| + |v
`v` |integer|True|Signature V| + |expiration
`e` |string|True|Timestamp after which this signature expires, expressed in unix nanoseconds. Must be capped at 30 days| + |nonce
`n` |integer|True|Users can randomly generate this value, used as a signature deconflicting key.
ie. You can send the same exact instruction twice with different nonces.
When the same nonce is used, the same payload will generate the same signature.
Our system will consider the payload a duplicate, and ignore it.| + |chain_id
`ci` |string|True|Chain ID used in EIP-712 domain. Zero value fallbacks to GRVT Chain ID.| diff --git a/artifacts/apidocs/schemas/api_add_isolated_position_margin_response.md b/artifacts/apidocs/schemas/api_add_isolated_position_margin_response.md new file mode 100644 index 0000000..e8d806b --- /dev/null +++ b/artifacts/apidocs/schemas/api_add_isolated_position_margin_response.md @@ -0,0 +1,6 @@ +!!! info "[ApiAddIsolatedPositionMarginResponse](/../../schemas/api_add_isolated_position_margin_response)" + The response to add margin to a isolated position
+ + |Name
`Lite`|Type|Required
`Default`| Description | + |-|-|-|-| + |success
`s` |boolean|True|Whether the margin mode and leverage was set successfully| diff --git a/artifacts/apidocs/schemas/api_aggregated_account_summary_response.md b/artifacts/apidocs/schemas/api_aggregated_account_summary_response.md index f3a6e7d..c19e0de 100644 --- a/artifacts/apidocs/schemas/api_aggregated_account_summary_response.md +++ b/artifacts/apidocs/schemas/api_aggregated_account_summary_response.md @@ -11,7 +11,10 @@ |total_equity
`te` |string|True|Total equity of the main (+ sub) account, denominated in USD| |spot_balances
`sb` |[SpotBalance]|True|The list of spot assets owned by this main (+ sub) account, and their balances| |vault_investments
`vi` |[VaultInvestment]|True|The list of vault investments held by this main account| - |total_sub_account_balance
`ts` |string|True|Total balance of the sub accounts, denominated in USD| + |total_sub_account_balance
`ts` |string|True|Deprecated: Use totalSubAccountEquity instead| + |total_sub_account_equity
`ts1` |string|True|Total equity of the sub accounts, denominated in USD| + |total_vault_investments_balance
`tv` |string|True|Total amount of the vault investments, denominated in USD| + |total_sub_account_available_balance
`ts2` |string|True|Total available balance of the main account, denominated in USD| ??? info "[SpotBalance](/../../schemas/spot_balance)" |Name
`Lite`|Type|Required
`Default`| Description | |-|-|-|-| diff --git a/artifacts/apidocs/schemas/api_get_margin_rules_request.md b/artifacts/apidocs/schemas/api_get_margin_rules_request.md new file mode 100644 index 0000000..37555ca --- /dev/null +++ b/artifacts/apidocs/schemas/api_get_margin_rules_request.md @@ -0,0 +1,6 @@ +!!! info "[ApiGetMarginRulesRequest](/../../schemas/api_get_margin_rules_request)" + API request payload to get margin rules for a particular instrument
+ + |Name
`Lite`|Type|Required
`Default`| Description | + |-|-|-|-| + |instrument
`i` |string|True|The instrument to query margin rules for| diff --git a/artifacts/apidocs/schemas/api_get_margin_rules_response.md b/artifacts/apidocs/schemas/api_get_margin_rules_response.md new file mode 100644 index 0000000..639d311 --- /dev/null +++ b/artifacts/apidocs/schemas/api_get_margin_rules_response.md @@ -0,0 +1,18 @@ +!!! info "[ApiGetMarginRulesResponse](/../../schemas/api_get_margin_rules_response)" + API response payload for margin rules of a particular instrument
+ + |Name
`Lite`|Type|Required
`Default`| Description | + |-|-|-|-| + |instrument
`i` |string|True|The instrument name| + |max_position_size
`mp` |string|True|The maximum position size, expressed in base asset decimal units| + |risk_brackets
`rb` |[RiskBracket]|True|List of risk brackets defining margin requirements at different notional tiers| + ??? info "[RiskBracket](/../../schemas/risk_bracket)" + |Name
`Lite`|Type|Required
`Default`| Description | + |-|-|-|-| + |tier
`t` |integer|True|1-indexed tier number| + |notional_floor
`nf` |string|True|Lower bound of notional value (inclusive) in quote currency| + |notional_cap
`nc` |string|True|Upper bound of notional value (exclusive) in quote currency, empty for last tier| + |maintenance_margin_rate
`mm` |string|True|Maintenance margin rate as a decimal (e.g., '0.01' for 1%)| + |initial_margin_rate
`im` |string|True|Initial margin rate as a decimal (e.g., '0.02' for 2%)| + |max_leverage
`ml` |integer|True|Maximum leverage allowed at this tier (floor of 1 / initial_margin_rate)| + |cumulative_maintenance_amount
`cm` |string|True|Cumulative maintenance margin amount in quote currency| diff --git a/artifacts/apidocs/schemas/api_set_sub_account_position_margin_config_request.md b/artifacts/apidocs/schemas/api_set_sub_account_position_margin_config_request.md new file mode 100644 index 0000000..3a4ad21 --- /dev/null +++ b/artifacts/apidocs/schemas/api_set_sub_account_position_margin_config_request.md @@ -0,0 +1,24 @@ +!!! info "[ApiSetSubAccountPositionMarginConfigRequest](/../../schemas/api_set_sub_account_position_margin_config_request)" + Sets the margin type and leverage configuration for a specific position (instrument) within a sub account.

This configuration is applied per-instrument, allowing different margin settings for different positions.

+ + |Name
`Lite`|Type|Required
`Default`| Description | + |-|-|-|-| + |sub_account_id
`sa` |string|True|The sub account ID to set the margin type and leverage for| + |instrument
`i` |string|True|The instrument of the position to set the margin type and leverage for| + |margin_type
`mt` |PositionMarginType|True|The margin type to set for the position| + |leverage
`l` |string|True|The leverage to set for the position| + |signature
`s` |Signature|True|The signature of this operation| + ??? info "[PositionMarginType](/../../schemas/position_margin_type)" + |Value| Description | + |-|-| + |`CROSS` = 2|Cross Margin Mode: uses all available funds in your account as collateral across all cross margin positions| + ??? info "[Signature](/../../schemas/signature)" + |Name
`Lite`|Type|Required
`Default`| Description | + |-|-|-|-| + |signer
`s` |string|True|The address (public key) of the wallet signing the payload| + |r
`r` |string|True|Signature R| + |s
`s1` |string|True|Signature S| + |v
`v` |integer|True|Signature V| + |expiration
`e` |string|True|Timestamp after which this signature expires, expressed in unix nanoseconds. Must be capped at 30 days| + |nonce
`n` |integer|True|Users can randomly generate this value, used as a signature deconflicting key.
ie. You can send the same exact instruction twice with different nonces.
When the same nonce is used, the same payload will generate the same signature.
Our system will consider the payload a duplicate, and ignore it.| + |chain_id
`ci` |string|True|Chain ID used in EIP-712 domain. Zero value fallbacks to GRVT Chain ID.| diff --git a/artifacts/apidocs/schemas/api_set_sub_account_position_margin_config_response.md b/artifacts/apidocs/schemas/api_set_sub_account_position_margin_config_response.md new file mode 100644 index 0000000..a766cfa --- /dev/null +++ b/artifacts/apidocs/schemas/api_set_sub_account_position_margin_config_response.md @@ -0,0 +1,6 @@ +!!! info "[ApiSetSubAccountPositionMarginConfigResponse](/../../schemas/api_set_sub_account_position_margin_config_response)" + The response to set the margin type and leverage for a position
+ + |Name
`Lite`|Type|Required
`Default`| Description | + |-|-|-|-| + |ack
`a` |boolean|True|Whether the margin type and leverage was acked| diff --git a/artifacts/apidocs/schemas/position_margin_type.md b/artifacts/apidocs/schemas/position_margin_type.md new file mode 100644 index 0000000..f268122 --- /dev/null +++ b/artifacts/apidocs/schemas/position_margin_type.md @@ -0,0 +1,4 @@ +!!! info "[PositionMarginType](/../../schemas/position_margin_type)" + |Value| Description | + |-|-| + |`CROSS` = 2|Cross Margin Mode: uses all available funds in your account as collateral across all cross margin positions| diff --git a/artifacts/apidocs/schemas/risk_bracket.md b/artifacts/apidocs/schemas/risk_bracket.md new file mode 100644 index 0000000..ab13f94 --- /dev/null +++ b/artifacts/apidocs/schemas/risk_bracket.md @@ -0,0 +1,10 @@ +!!! info "[RiskBracket](/../../schemas/risk_bracket)" + |Name
`Lite`|Type|Required
`Default`| Description | + |-|-|-|-| + |tier
`t` |integer|True|1-indexed tier number| + |notional_floor
`nf` |string|True|Lower bound of notional value (inclusive) in quote currency| + |notional_cap
`nc` |string|True|Upper bound of notional value (exclusive) in quote currency, empty for last tier| + |maintenance_margin_rate
`mm` |string|True|Maintenance margin rate as a decimal (e.g., '0.01' for 1%)| + |initial_margin_rate
`im` |string|True|Initial margin rate as a decimal (e.g., '0.02' for 2%)| + |max_leverage
`ml` |integer|True|Maximum leverage allowed at this tier (floor of 1 / initial_margin_rate)| + |cumulative_maintenance_amount
`cm` |string|True|Cumulative maintenance margin amount in quote currency| diff --git a/artifacts/apidocs/trading_api.md b/artifacts/apidocs/trading_api.md index a3a48b3..51be3b8 100644 --- a/artifacts/apidocs/trading_api.md +++ b/artifacts/apidocs/trading_api.md @@ -261,6 +261,7 @@ LITE ENDPOINT: lite/v1/create_order |3006|500|Instrument's quote currency does not have a valid balance decimal configuration| |2400|400|Reduce only order with no position| |2401|400|Reduce only order must not increase position size| + |2402|400|Reduce only order size exceeds maximum allowed value|
!!! failure @@ -8184,7 +8185,10 @@ LITE ENDPOINT: lite/v1/aggregated_account_summary "num_lp_tokens": 1000000, "share_price": 1000000 }], - "total_sub_account_balance": "3945034.23" + "total_sub_account_balance": "3945034.23", + "total_sub_account_equity": "3945034.23", + "total_vault_investments_balance": "3945034.23", + "total_sub_account_available_balance": "3945034.23" } } ``` @@ -8204,7 +8208,10 @@ LITE ENDPOINT: lite/v1/aggregated_account_summary "nl": 1000000, "sp": 1000000 }], - "ts": "3945034.23" + "ts": "3945034.23", + "ts1": "3945034.23", + "tv": "3945034.23", + "ts2": "3945034.23" } } ``` @@ -12885,3 +12892,1042 @@ LITE ENDPOINT: lite/v1/vault_manager_investor_history ```

+## Margin +### Set Position Margin Config +``` +FULL ENDPOINT: full/v1/set_position_margin_config +LITE ENDPOINT: lite/v1/set_position_margin_config +``` + +=== "Request" +
+ -8<- "docs/schemas/api_set_sub_account_position_margin_config_request.md" +
+
+ !!! question "Query" + **Full Request** + ``` { .json .copy } + { + "sub_account_id": "'$GRVT_SUB_ACCOUNT_ID'", + "instrument": "BTC_USDT_Perp", + "margin_type": "CROSS", + "leverage": "1.5", + "signature": { + "signer": "0xc73c0c2538fd9b833d20933ccc88fdaa74fcb0d0", + "r": "0xb788d96fee91c7cdc35918e0441b756d4000ec1d07d900c73347d9abbc20acc8", + "s": "0x3d786193125f7c29c958647da64d0e2875ece2c3f845a591bdd7dae8c475e26d", + "v": 28, + "expiration": "1697788800000000000", + "nonce": 1234567890, + "chain_id": "325" + } + } + ``` + **Lite Request** + ``` { .json .copy } + { + "sa": "'$GRVT_SUB_ACCOUNT_ID'", + "i": "BTC_USDT_Perp", + "mt": "CROSS", + "l": "1.5", + "s": { + "s": "0xc73c0c2538fd9b833d20933ccc88fdaa74fcb0d0", + "r": "0xb788d96fee91c7cdc35918e0441b756d4000ec1d07d900c73347d9abbc20acc8", + "s1": "0x3d786193125f7c29c958647da64d0e2875ece2c3f845a591bdd7dae8c475e26d", + "v": 28, + "e": "1697788800000000000", + "n": 1234567890, + "ci": "325" + } + } + ``` +
+=== "Response" +
+ -8<- "docs/schemas/api_set_sub_account_position_margin_config_response.md" +
+
+ !!! success + **Full Response** + ``` { .json .copy } + { + "ack": "true" + } + ``` + **Lite Response** + ``` { .json .copy } + { + "a": "true" + } + ``` +
+=== "Errors" +
+ !!! info "Error Codes" + |Code|HttpStatus| Description | + |-|-|-| + |1000|401|You need to authenticate prior to using this functionality| + |1001|403|You are not authorized to access this functionality| + |1002|500|Internal Server Error| + |1003|400|Request could not be processed due to malformed syntax| + |1006|429|You have surpassed the allocated rate limit for your tier| + |1004|404|Data Not Found| + |2102|400|Margin type change failed, has open position for this instrument| + |2103|400|Margin type change failed, has open orders for this instrument| + |2101|400|Vaults cannot configure leverage| + |2104|400|Margin type not supported| + |2105|400|Margin type change failed| +
+
+ !!! failure + **Full Error Response** + ``` { .json .copy } + { + "request_id":1, + "code":1000, + "message":"You need to authenticate prior to using this functionality", + "status":401 + } + ``` + **Lite Error Response** + ``` { .json .copy } + { + "ri":1, + "c":1000, + "m":"You need to authenticate prior to using this functionality", + "s":401 + } + ``` +
+=== "Try it out" + -8<- "sections/auth_closed.md" + === "DEV" +
+ !!! example "REST Full" + ``` { .bash .copy } + curl --location 'https://trades.dev.gravitymarkets.io/full/v1/set_position_margin_config' \ + --header "Cookie: $GRVT_COOKIE" \ + --header "X-Grvt-Account-Id: $GRVT_ACCOUNT_ID" \ + --data '{ + "sub_account_id": "'$GRVT_SUB_ACCOUNT_ID'", + "instrument": "BTC_USDT_Perp", + "margin_type": "CROSS", + "leverage": "1.5", + "signature": { + "signer": "0xc73c0c2538fd9b833d20933ccc88fdaa74fcb0d0", + "r": "0xb788d96fee91c7cdc35918e0441b756d4000ec1d07d900c73347d9abbc20acc8", + "s": "0x3d786193125f7c29c958647da64d0e2875ece2c3f845a591bdd7dae8c475e26d", + "v": 28, + "expiration": "1697788800000000000", + "nonce": 1234567890, + "chain_id": "325" + } + } + ' + ``` + !!! example "JSONRPC Full" + ``` { .bash .copy } + wscat -c "wss://trades.dev.gravitymarkets.io/ws/full" \ + -H "Cookie: $GRVT_COOKIE" \ + -H "X-Grvt-Account-Id: $GRVT_ACCOUNT_ID" \ + -x ' + { + "jsonrpc": "2.0", + "method": "v1/set_position_margin_config", + "params": { + "sub_account_id": "'$GRVT_SUB_ACCOUNT_ID'", + "instrument": "BTC_USDT_Perp", + "margin_type": "CROSS", + "leverage": "1.5", + "signature": { + "signer": "0xc73c0c2538fd9b833d20933ccc88fdaa74fcb0d0", + "r": "0xb788d96fee91c7cdc35918e0441b756d4000ec1d07d900c73347d9abbc20acc8", + "s": "0x3d786193125f7c29c958647da64d0e2875ece2c3f845a591bdd7dae8c475e26d", + "v": 28, + "expiration": "1697788800000000000", + "nonce": 1234567890, + "chain_id": "325" + } + }, + "id": 123 + } + ' -w 360 + ``` +
+
+ !!! example "REST Lite" + ``` { .bash .copy } + curl --location 'https://trades.dev.gravitymarkets.io/lite/v1/set_position_margin_config' \ + --header "Cookie: $GRVT_COOKIE" \ + --header "X-Grvt-Account-Id: $GRVT_ACCOUNT_ID" \ + --data '{ + "sa": "'$GRVT_SUB_ACCOUNT_ID'", + "i": "BTC_USDT_Perp", + "mt": "CROSS", + "l": "1.5", + "s": { + "s": "0xc73c0c2538fd9b833d20933ccc88fdaa74fcb0d0", + "r": "0xb788d96fee91c7cdc35918e0441b756d4000ec1d07d900c73347d9abbc20acc8", + "s1": "0x3d786193125f7c29c958647da64d0e2875ece2c3f845a591bdd7dae8c475e26d", + "v": 28, + "e": "1697788800000000000", + "n": 1234567890, + "ci": "325" + } + } + ' + ``` + !!! example "JSONRPC Lite" + ``` { .bash .copy } + wscat -c "wss://trades.dev.gravitymarkets.io/ws/lite" \ + -H "Cookie: $GRVT_COOKIE" \ + -H "X-Grvt-Account-Id: $GRVT_ACCOUNT_ID" \ + -x ' + { + "j": "2.0", + "m": "v1/set_position_margin_config", + "p": { + "sa": "'$GRVT_SUB_ACCOUNT_ID'", + "i": "BTC_USDT_Perp", + "mt": "CROSS", + "l": "1.5", + "s": { + "s": "0xc73c0c2538fd9b833d20933ccc88fdaa74fcb0d0", + "r": "0xb788d96fee91c7cdc35918e0441b756d4000ec1d07d900c73347d9abbc20acc8", + "s1": "0x3d786193125f7c29c958647da64d0e2875ece2c3f845a591bdd7dae8c475e26d", + "v": 28, + "e": "1697788800000000000", + "n": 1234567890, + "ci": "325" + } + }, + "i": 123 + } + ' -w 360 + ``` +
+ === "STAGING" +
+ !!! example "REST Full" + ``` { .bash .copy } + curl --location 'https://trades.staging.gravitymarkets.io/full/v1/set_position_margin_config' \ + --header "Cookie: $GRVT_COOKIE" \ + --header "X-Grvt-Account-Id: $GRVT_ACCOUNT_ID" \ + --data '{ + "sub_account_id": "'$GRVT_SUB_ACCOUNT_ID'", + "instrument": "BTC_USDT_Perp", + "margin_type": "CROSS", + "leverage": "1.5", + "signature": { + "signer": "0xc73c0c2538fd9b833d20933ccc88fdaa74fcb0d0", + "r": "0xb788d96fee91c7cdc35918e0441b756d4000ec1d07d900c73347d9abbc20acc8", + "s": "0x3d786193125f7c29c958647da64d0e2875ece2c3f845a591bdd7dae8c475e26d", + "v": 28, + "expiration": "1697788800000000000", + "nonce": 1234567890, + "chain_id": "325" + } + } + ' + ``` + !!! example "JSONRPC Full" + ``` { .bash .copy } + wscat -c "wss://trades.staging.gravitymarkets.io/ws/full" \ + -H "Cookie: $GRVT_COOKIE" \ + -H "X-Grvt-Account-Id: $GRVT_ACCOUNT_ID" \ + -x ' + { + "jsonrpc": "2.0", + "method": "v1/set_position_margin_config", + "params": { + "sub_account_id": "'$GRVT_SUB_ACCOUNT_ID'", + "instrument": "BTC_USDT_Perp", + "margin_type": "CROSS", + "leverage": "1.5", + "signature": { + "signer": "0xc73c0c2538fd9b833d20933ccc88fdaa74fcb0d0", + "r": "0xb788d96fee91c7cdc35918e0441b756d4000ec1d07d900c73347d9abbc20acc8", + "s": "0x3d786193125f7c29c958647da64d0e2875ece2c3f845a591bdd7dae8c475e26d", + "v": 28, + "expiration": "1697788800000000000", + "nonce": 1234567890, + "chain_id": "325" + } + }, + "id": 123 + } + ' -w 360 + ``` +
+
+ !!! example "REST Lite" + ``` { .bash .copy } + curl --location 'https://trades.staging.gravitymarkets.io/lite/v1/set_position_margin_config' \ + --header "Cookie: $GRVT_COOKIE" \ + --header "X-Grvt-Account-Id: $GRVT_ACCOUNT_ID" \ + --data '{ + "sa": "'$GRVT_SUB_ACCOUNT_ID'", + "i": "BTC_USDT_Perp", + "mt": "CROSS", + "l": "1.5", + "s": { + "s": "0xc73c0c2538fd9b833d20933ccc88fdaa74fcb0d0", + "r": "0xb788d96fee91c7cdc35918e0441b756d4000ec1d07d900c73347d9abbc20acc8", + "s1": "0x3d786193125f7c29c958647da64d0e2875ece2c3f845a591bdd7dae8c475e26d", + "v": 28, + "e": "1697788800000000000", + "n": 1234567890, + "ci": "325" + } + } + ' + ``` + !!! example "JSONRPC Lite" + ``` { .bash .copy } + wscat -c "wss://trades.staging.gravitymarkets.io/ws/lite" \ + -H "Cookie: $GRVT_COOKIE" \ + -H "X-Grvt-Account-Id: $GRVT_ACCOUNT_ID" \ + -x ' + { + "j": "2.0", + "m": "v1/set_position_margin_config", + "p": { + "sa": "'$GRVT_SUB_ACCOUNT_ID'", + "i": "BTC_USDT_Perp", + "mt": "CROSS", + "l": "1.5", + "s": { + "s": "0xc73c0c2538fd9b833d20933ccc88fdaa74fcb0d0", + "r": "0xb788d96fee91c7cdc35918e0441b756d4000ec1d07d900c73347d9abbc20acc8", + "s1": "0x3d786193125f7c29c958647da64d0e2875ece2c3f845a591bdd7dae8c475e26d", + "v": 28, + "e": "1697788800000000000", + "n": 1234567890, + "ci": "325" + } + }, + "i": 123 + } + ' -w 360 + ``` +
+ === "TESTNET" +
+ !!! example "REST Full" + ``` { .bash .copy } + curl --location 'https://trades.testnet.grvt.io/full/v1/set_position_margin_config' \ + --header "Cookie: $GRVT_COOKIE" \ + --header "X-Grvt-Account-Id: $GRVT_ACCOUNT_ID" \ + --data '{ + "sub_account_id": "'$GRVT_SUB_ACCOUNT_ID'", + "instrument": "BTC_USDT_Perp", + "margin_type": "CROSS", + "leverage": "1.5", + "signature": { + "signer": "0xc73c0c2538fd9b833d20933ccc88fdaa74fcb0d0", + "r": "0xb788d96fee91c7cdc35918e0441b756d4000ec1d07d900c73347d9abbc20acc8", + "s": "0x3d786193125f7c29c958647da64d0e2875ece2c3f845a591bdd7dae8c475e26d", + "v": 28, + "expiration": "1697788800000000000", + "nonce": 1234567890, + "chain_id": "325" + } + } + ' + ``` + !!! example "JSONRPC Full" + ``` { .bash .copy } + wscat -c "wss://trades.testnet.grvt.io/ws/full" \ + -H "Cookie: $GRVT_COOKIE" \ + -H "X-Grvt-Account-Id: $GRVT_ACCOUNT_ID" \ + -x ' + { + "jsonrpc": "2.0", + "method": "v1/set_position_margin_config", + "params": { + "sub_account_id": "'$GRVT_SUB_ACCOUNT_ID'", + "instrument": "BTC_USDT_Perp", + "margin_type": "CROSS", + "leverage": "1.5", + "signature": { + "signer": "0xc73c0c2538fd9b833d20933ccc88fdaa74fcb0d0", + "r": "0xb788d96fee91c7cdc35918e0441b756d4000ec1d07d900c73347d9abbc20acc8", + "s": "0x3d786193125f7c29c958647da64d0e2875ece2c3f845a591bdd7dae8c475e26d", + "v": 28, + "expiration": "1697788800000000000", + "nonce": 1234567890, + "chain_id": "325" + } + }, + "id": 123 + } + ' -w 360 + ``` +
+
+ !!! example "REST Lite" + ``` { .bash .copy } + curl --location 'https://trades.testnet.grvt.io/lite/v1/set_position_margin_config' \ + --header "Cookie: $GRVT_COOKIE" \ + --header "X-Grvt-Account-Id: $GRVT_ACCOUNT_ID" \ + --data '{ + "sa": "'$GRVT_SUB_ACCOUNT_ID'", + "i": "BTC_USDT_Perp", + "mt": "CROSS", + "l": "1.5", + "s": { + "s": "0xc73c0c2538fd9b833d20933ccc88fdaa74fcb0d0", + "r": "0xb788d96fee91c7cdc35918e0441b756d4000ec1d07d900c73347d9abbc20acc8", + "s1": "0x3d786193125f7c29c958647da64d0e2875ece2c3f845a591bdd7dae8c475e26d", + "v": 28, + "e": "1697788800000000000", + "n": 1234567890, + "ci": "325" + } + } + ' + ``` + !!! example "JSONRPC Lite" + ``` { .bash .copy } + wscat -c "wss://trades.testnet.grvt.io/ws/lite" \ + -H "Cookie: $GRVT_COOKIE" \ + -H "X-Grvt-Account-Id: $GRVT_ACCOUNT_ID" \ + -x ' + { + "j": "2.0", + "m": "v1/set_position_margin_config", + "p": { + "sa": "'$GRVT_SUB_ACCOUNT_ID'", + "i": "BTC_USDT_Perp", + "mt": "CROSS", + "l": "1.5", + "s": { + "s": "0xc73c0c2538fd9b833d20933ccc88fdaa74fcb0d0", + "r": "0xb788d96fee91c7cdc35918e0441b756d4000ec1d07d900c73347d9abbc20acc8", + "s1": "0x3d786193125f7c29c958647da64d0e2875ece2c3f845a591bdd7dae8c475e26d", + "v": 28, + "e": "1697788800000000000", + "n": 1234567890, + "ci": "325" + } + }, + "i": 123 + } + ' -w 360 + ``` +
+ === "PROD" +
+ !!! example "REST Full" + ``` { .bash .copy } + curl --location 'https://trades.grvt.io/full/v1/set_position_margin_config' \ + --header "Cookie: $GRVT_COOKIE" \ + --header "X-Grvt-Account-Id: $GRVT_ACCOUNT_ID" \ + --data '{ + "sub_account_id": "'$GRVT_SUB_ACCOUNT_ID'", + "instrument": "BTC_USDT_Perp", + "margin_type": "CROSS", + "leverage": "1.5", + "signature": { + "signer": "0xc73c0c2538fd9b833d20933ccc88fdaa74fcb0d0", + "r": "0xb788d96fee91c7cdc35918e0441b756d4000ec1d07d900c73347d9abbc20acc8", + "s": "0x3d786193125f7c29c958647da64d0e2875ece2c3f845a591bdd7dae8c475e26d", + "v": 28, + "expiration": "1697788800000000000", + "nonce": 1234567890, + "chain_id": "325" + } + } + ' + ``` + !!! example "JSONRPC Full" + ``` { .bash .copy } + wscat -c "wss://trades.grvt.io/ws/full" \ + -H "Cookie: $GRVT_COOKIE" \ + -H "X-Grvt-Account-Id: $GRVT_ACCOUNT_ID" \ + -x ' + { + "jsonrpc": "2.0", + "method": "v1/set_position_margin_config", + "params": { + "sub_account_id": "'$GRVT_SUB_ACCOUNT_ID'", + "instrument": "BTC_USDT_Perp", + "margin_type": "CROSS", + "leverage": "1.5", + "signature": { + "signer": "0xc73c0c2538fd9b833d20933ccc88fdaa74fcb0d0", + "r": "0xb788d96fee91c7cdc35918e0441b756d4000ec1d07d900c73347d9abbc20acc8", + "s": "0x3d786193125f7c29c958647da64d0e2875ece2c3f845a591bdd7dae8c475e26d", + "v": 28, + "expiration": "1697788800000000000", + "nonce": 1234567890, + "chain_id": "325" + } + }, + "id": 123 + } + ' -w 360 + ``` +
+
+ !!! example "REST Lite" + ``` { .bash .copy } + curl --location 'https://trades.grvt.io/lite/v1/set_position_margin_config' \ + --header "Cookie: $GRVT_COOKIE" \ + --header "X-Grvt-Account-Id: $GRVT_ACCOUNT_ID" \ + --data '{ + "sa": "'$GRVT_SUB_ACCOUNT_ID'", + "i": "BTC_USDT_Perp", + "mt": "CROSS", + "l": "1.5", + "s": { + "s": "0xc73c0c2538fd9b833d20933ccc88fdaa74fcb0d0", + "r": "0xb788d96fee91c7cdc35918e0441b756d4000ec1d07d900c73347d9abbc20acc8", + "s1": "0x3d786193125f7c29c958647da64d0e2875ece2c3f845a591bdd7dae8c475e26d", + "v": 28, + "e": "1697788800000000000", + "n": 1234567890, + "ci": "325" + } + } + ' + ``` + !!! example "JSONRPC Lite" + ``` { .bash .copy } + wscat -c "wss://trades.grvt.io/ws/lite" \ + -H "Cookie: $GRVT_COOKIE" \ + -H "X-Grvt-Account-Id: $GRVT_ACCOUNT_ID" \ + -x ' + { + "j": "2.0", + "m": "v1/set_position_margin_config", + "p": { + "sa": "'$GRVT_SUB_ACCOUNT_ID'", + "i": "BTC_USDT_Perp", + "mt": "CROSS", + "l": "1.5", + "s": { + "s": "0xc73c0c2538fd9b833d20933ccc88fdaa74fcb0d0", + "r": "0xb788d96fee91c7cdc35918e0441b756d4000ec1d07d900c73347d9abbc20acc8", + "s1": "0x3d786193125f7c29c958647da64d0e2875ece2c3f845a591bdd7dae8c475e26d", + "v": 28, + "e": "1697788800000000000", + "n": 1234567890, + "ci": "325" + } + }, + "i": 123 + } + ' -w 360 + ``` +
+
+### Add Isolated Position Margin +``` +FULL ENDPOINT: full/v1/add_isolated_position_margin +LITE ENDPOINT: lite/v1/add_isolated_position_margin +``` + +=== "Request" +
+ -8<- "docs/schemas/api_add_isolated_position_margin_request.md" +
+
+ !!! question "Query" + **Full Request** + ``` { .json .copy } + { + "sub_account_id": "'$GRVT_SUB_ACCOUNT_ID'", + "instrument": "BTC_USDT_Perp", + "amount": "123456.78", + "signature": { + "signer": "0xc73c0c2538fd9b833d20933ccc88fdaa74fcb0d0", + "r": "0xb788d96fee91c7cdc35918e0441b756d4000ec1d07d900c73347d9abbc20acc8", + "s": "0x3d786193125f7c29c958647da64d0e2875ece2c3f845a591bdd7dae8c475e26d", + "v": 28, + "expiration": "1697788800000000000", + "nonce": 1234567890, + "chain_id": "325" + } + } + ``` + **Lite Request** + ``` { .json .copy } + { + "sa": "'$GRVT_SUB_ACCOUNT_ID'", + "i": "BTC_USDT_Perp", + "a": "123456.78", + "s": { + "s": "0xc73c0c2538fd9b833d20933ccc88fdaa74fcb0d0", + "r": "0xb788d96fee91c7cdc35918e0441b756d4000ec1d07d900c73347d9abbc20acc8", + "s1": "0x3d786193125f7c29c958647da64d0e2875ece2c3f845a591bdd7dae8c475e26d", + "v": 28, + "e": "1697788800000000000", + "n": 1234567890, + "ci": "325" + } + } + ``` +
+=== "Response" +
+ -8<- "docs/schemas/api_add_isolated_position_margin_response.md" +
+
+ !!! success + **Full Response** + ``` { .json .copy } + { + "success": "true" + } + ``` + **Lite Response** + ``` { .json .copy } + { + "s": "true" + } + ``` +
+=== "Errors" +
+ !!! info "Error Codes" + |Code|HttpStatus| Description | + |-|-|-| + |1000|401|You need to authenticate prior to using this functionality| + |1001|403|You are not authorized to access this functionality| + |1002|500|Internal Server Error| + |1003|400|Request could not be processed due to malformed syntax| + |1006|429|You have surpassed the allocated rate limit for your tier| + |1004|404|Data Not Found| + |7450|400|Add margin failed| + |7451|400|Add margin to empty position| + |7452|400|Add margin to non isolated position| +
+
+ !!! failure + **Full Error Response** + ``` { .json .copy } + { + "request_id":1, + "code":1000, + "message":"You need to authenticate prior to using this functionality", + "status":401 + } + ``` + **Lite Error Response** + ``` { .json .copy } + { + "ri":1, + "c":1000, + "m":"You need to authenticate prior to using this functionality", + "s":401 + } + ``` +
+=== "Try it out" + -8<- "sections/auth_closed.md" + === "DEV" +
+ !!! example "REST Full" + ``` { .bash .copy } + curl --location 'https://trades.dev.gravitymarkets.io/full/v1/add_isolated_position_margin' \ + --header "Cookie: $GRVT_COOKIE" \ + --header "X-Grvt-Account-Id: $GRVT_ACCOUNT_ID" \ + --data '{ + "sub_account_id": "'$GRVT_SUB_ACCOUNT_ID'", + "instrument": "BTC_USDT_Perp", + "amount": "123456.78", + "signature": { + "signer": "0xc73c0c2538fd9b833d20933ccc88fdaa74fcb0d0", + "r": "0xb788d96fee91c7cdc35918e0441b756d4000ec1d07d900c73347d9abbc20acc8", + "s": "0x3d786193125f7c29c958647da64d0e2875ece2c3f845a591bdd7dae8c475e26d", + "v": 28, + "expiration": "1697788800000000000", + "nonce": 1234567890, + "chain_id": "325" + } + } + ' + ``` + !!! example "JSONRPC Full" + ``` { .bash .copy } + wscat -c "wss://trades.dev.gravitymarkets.io/ws/full" \ + -H "Cookie: $GRVT_COOKIE" \ + -H "X-Grvt-Account-Id: $GRVT_ACCOUNT_ID" \ + -x ' + { + "jsonrpc": "2.0", + "method": "v1/add_isolated_position_margin", + "params": { + "sub_account_id": "'$GRVT_SUB_ACCOUNT_ID'", + "instrument": "BTC_USDT_Perp", + "amount": "123456.78", + "signature": { + "signer": "0xc73c0c2538fd9b833d20933ccc88fdaa74fcb0d0", + "r": "0xb788d96fee91c7cdc35918e0441b756d4000ec1d07d900c73347d9abbc20acc8", + "s": "0x3d786193125f7c29c958647da64d0e2875ece2c3f845a591bdd7dae8c475e26d", + "v": 28, + "expiration": "1697788800000000000", + "nonce": 1234567890, + "chain_id": "325" + } + }, + "id": 123 + } + ' -w 360 + ``` +
+
+ !!! example "REST Lite" + ``` { .bash .copy } + curl --location 'https://trades.dev.gravitymarkets.io/lite/v1/add_isolated_position_margin' \ + --header "Cookie: $GRVT_COOKIE" \ + --header "X-Grvt-Account-Id: $GRVT_ACCOUNT_ID" \ + --data '{ + "sa": "'$GRVT_SUB_ACCOUNT_ID'", + "i": "BTC_USDT_Perp", + "a": "123456.78", + "s": { + "s": "0xc73c0c2538fd9b833d20933ccc88fdaa74fcb0d0", + "r": "0xb788d96fee91c7cdc35918e0441b756d4000ec1d07d900c73347d9abbc20acc8", + "s1": "0x3d786193125f7c29c958647da64d0e2875ece2c3f845a591bdd7dae8c475e26d", + "v": 28, + "e": "1697788800000000000", + "n": 1234567890, + "ci": "325" + } + } + ' + ``` + !!! example "JSONRPC Lite" + ``` { .bash .copy } + wscat -c "wss://trades.dev.gravitymarkets.io/ws/lite" \ + -H "Cookie: $GRVT_COOKIE" \ + -H "X-Grvt-Account-Id: $GRVT_ACCOUNT_ID" \ + -x ' + { + "j": "2.0", + "m": "v1/add_isolated_position_margin", + "p": { + "sa": "'$GRVT_SUB_ACCOUNT_ID'", + "i": "BTC_USDT_Perp", + "a": "123456.78", + "s": { + "s": "0xc73c0c2538fd9b833d20933ccc88fdaa74fcb0d0", + "r": "0xb788d96fee91c7cdc35918e0441b756d4000ec1d07d900c73347d9abbc20acc8", + "s1": "0x3d786193125f7c29c958647da64d0e2875ece2c3f845a591bdd7dae8c475e26d", + "v": 28, + "e": "1697788800000000000", + "n": 1234567890, + "ci": "325" + } + }, + "i": 123 + } + ' -w 360 + ``` +
+ === "STAGING" +
+ !!! example "REST Full" + ``` { .bash .copy } + curl --location 'https://trades.staging.gravitymarkets.io/full/v1/add_isolated_position_margin' \ + --header "Cookie: $GRVT_COOKIE" \ + --header "X-Grvt-Account-Id: $GRVT_ACCOUNT_ID" \ + --data '{ + "sub_account_id": "'$GRVT_SUB_ACCOUNT_ID'", + "instrument": "BTC_USDT_Perp", + "amount": "123456.78", + "signature": { + "signer": "0xc73c0c2538fd9b833d20933ccc88fdaa74fcb0d0", + "r": "0xb788d96fee91c7cdc35918e0441b756d4000ec1d07d900c73347d9abbc20acc8", + "s": "0x3d786193125f7c29c958647da64d0e2875ece2c3f845a591bdd7dae8c475e26d", + "v": 28, + "expiration": "1697788800000000000", + "nonce": 1234567890, + "chain_id": "325" + } + } + ' + ``` + !!! example "JSONRPC Full" + ``` { .bash .copy } + wscat -c "wss://trades.staging.gravitymarkets.io/ws/full" \ + -H "Cookie: $GRVT_COOKIE" \ + -H "X-Grvt-Account-Id: $GRVT_ACCOUNT_ID" \ + -x ' + { + "jsonrpc": "2.0", + "method": "v1/add_isolated_position_margin", + "params": { + "sub_account_id": "'$GRVT_SUB_ACCOUNT_ID'", + "instrument": "BTC_USDT_Perp", + "amount": "123456.78", + "signature": { + "signer": "0xc73c0c2538fd9b833d20933ccc88fdaa74fcb0d0", + "r": "0xb788d96fee91c7cdc35918e0441b756d4000ec1d07d900c73347d9abbc20acc8", + "s": "0x3d786193125f7c29c958647da64d0e2875ece2c3f845a591bdd7dae8c475e26d", + "v": 28, + "expiration": "1697788800000000000", + "nonce": 1234567890, + "chain_id": "325" + } + }, + "id": 123 + } + ' -w 360 + ``` +
+
+ !!! example "REST Lite" + ``` { .bash .copy } + curl --location 'https://trades.staging.gravitymarkets.io/lite/v1/add_isolated_position_margin' \ + --header "Cookie: $GRVT_COOKIE" \ + --header "X-Grvt-Account-Id: $GRVT_ACCOUNT_ID" \ + --data '{ + "sa": "'$GRVT_SUB_ACCOUNT_ID'", + "i": "BTC_USDT_Perp", + "a": "123456.78", + "s": { + "s": "0xc73c0c2538fd9b833d20933ccc88fdaa74fcb0d0", + "r": "0xb788d96fee91c7cdc35918e0441b756d4000ec1d07d900c73347d9abbc20acc8", + "s1": "0x3d786193125f7c29c958647da64d0e2875ece2c3f845a591bdd7dae8c475e26d", + "v": 28, + "e": "1697788800000000000", + "n": 1234567890, + "ci": "325" + } + } + ' + ``` + !!! example "JSONRPC Lite" + ``` { .bash .copy } + wscat -c "wss://trades.staging.gravitymarkets.io/ws/lite" \ + -H "Cookie: $GRVT_COOKIE" \ + -H "X-Grvt-Account-Id: $GRVT_ACCOUNT_ID" \ + -x ' + { + "j": "2.0", + "m": "v1/add_isolated_position_margin", + "p": { + "sa": "'$GRVT_SUB_ACCOUNT_ID'", + "i": "BTC_USDT_Perp", + "a": "123456.78", + "s": { + "s": "0xc73c0c2538fd9b833d20933ccc88fdaa74fcb0d0", + "r": "0xb788d96fee91c7cdc35918e0441b756d4000ec1d07d900c73347d9abbc20acc8", + "s1": "0x3d786193125f7c29c958647da64d0e2875ece2c3f845a591bdd7dae8c475e26d", + "v": 28, + "e": "1697788800000000000", + "n": 1234567890, + "ci": "325" + } + }, + "i": 123 + } + ' -w 360 + ``` +
+ === "TESTNET" +
+ !!! example "REST Full" + ``` { .bash .copy } + curl --location 'https://trades.testnet.grvt.io/full/v1/add_isolated_position_margin' \ + --header "Cookie: $GRVT_COOKIE" \ + --header "X-Grvt-Account-Id: $GRVT_ACCOUNT_ID" \ + --data '{ + "sub_account_id": "'$GRVT_SUB_ACCOUNT_ID'", + "instrument": "BTC_USDT_Perp", + "amount": "123456.78", + "signature": { + "signer": "0xc73c0c2538fd9b833d20933ccc88fdaa74fcb0d0", + "r": "0xb788d96fee91c7cdc35918e0441b756d4000ec1d07d900c73347d9abbc20acc8", + "s": "0x3d786193125f7c29c958647da64d0e2875ece2c3f845a591bdd7dae8c475e26d", + "v": 28, + "expiration": "1697788800000000000", + "nonce": 1234567890, + "chain_id": "325" + } + } + ' + ``` + !!! example "JSONRPC Full" + ``` { .bash .copy } + wscat -c "wss://trades.testnet.grvt.io/ws/full" \ + -H "Cookie: $GRVT_COOKIE" \ + -H "X-Grvt-Account-Id: $GRVT_ACCOUNT_ID" \ + -x ' + { + "jsonrpc": "2.0", + "method": "v1/add_isolated_position_margin", + "params": { + "sub_account_id": "'$GRVT_SUB_ACCOUNT_ID'", + "instrument": "BTC_USDT_Perp", + "amount": "123456.78", + "signature": { + "signer": "0xc73c0c2538fd9b833d20933ccc88fdaa74fcb0d0", + "r": "0xb788d96fee91c7cdc35918e0441b756d4000ec1d07d900c73347d9abbc20acc8", + "s": "0x3d786193125f7c29c958647da64d0e2875ece2c3f845a591bdd7dae8c475e26d", + "v": 28, + "expiration": "1697788800000000000", + "nonce": 1234567890, + "chain_id": "325" + } + }, + "id": 123 + } + ' -w 360 + ``` +
+
+ !!! example "REST Lite" + ``` { .bash .copy } + curl --location 'https://trades.testnet.grvt.io/lite/v1/add_isolated_position_margin' \ + --header "Cookie: $GRVT_COOKIE" \ + --header "X-Grvt-Account-Id: $GRVT_ACCOUNT_ID" \ + --data '{ + "sa": "'$GRVT_SUB_ACCOUNT_ID'", + "i": "BTC_USDT_Perp", + "a": "123456.78", + "s": { + "s": "0xc73c0c2538fd9b833d20933ccc88fdaa74fcb0d0", + "r": "0xb788d96fee91c7cdc35918e0441b756d4000ec1d07d900c73347d9abbc20acc8", + "s1": "0x3d786193125f7c29c958647da64d0e2875ece2c3f845a591bdd7dae8c475e26d", + "v": 28, + "e": "1697788800000000000", + "n": 1234567890, + "ci": "325" + } + } + ' + ``` + !!! example "JSONRPC Lite" + ``` { .bash .copy } + wscat -c "wss://trades.testnet.grvt.io/ws/lite" \ + -H "Cookie: $GRVT_COOKIE" \ + -H "X-Grvt-Account-Id: $GRVT_ACCOUNT_ID" \ + -x ' + { + "j": "2.0", + "m": "v1/add_isolated_position_margin", + "p": { + "sa": "'$GRVT_SUB_ACCOUNT_ID'", + "i": "BTC_USDT_Perp", + "a": "123456.78", + "s": { + "s": "0xc73c0c2538fd9b833d20933ccc88fdaa74fcb0d0", + "r": "0xb788d96fee91c7cdc35918e0441b756d4000ec1d07d900c73347d9abbc20acc8", + "s1": "0x3d786193125f7c29c958647da64d0e2875ece2c3f845a591bdd7dae8c475e26d", + "v": 28, + "e": "1697788800000000000", + "n": 1234567890, + "ci": "325" + } + }, + "i": 123 + } + ' -w 360 + ``` +
+ === "PROD" +
+ !!! example "REST Full" + ``` { .bash .copy } + curl --location 'https://trades.grvt.io/full/v1/add_isolated_position_margin' \ + --header "Cookie: $GRVT_COOKIE" \ + --header "X-Grvt-Account-Id: $GRVT_ACCOUNT_ID" \ + --data '{ + "sub_account_id": "'$GRVT_SUB_ACCOUNT_ID'", + "instrument": "BTC_USDT_Perp", + "amount": "123456.78", + "signature": { + "signer": "0xc73c0c2538fd9b833d20933ccc88fdaa74fcb0d0", + "r": "0xb788d96fee91c7cdc35918e0441b756d4000ec1d07d900c73347d9abbc20acc8", + "s": "0x3d786193125f7c29c958647da64d0e2875ece2c3f845a591bdd7dae8c475e26d", + "v": 28, + "expiration": "1697788800000000000", + "nonce": 1234567890, + "chain_id": "325" + } + } + ' + ``` + !!! example "JSONRPC Full" + ``` { .bash .copy } + wscat -c "wss://trades.grvt.io/ws/full" \ + -H "Cookie: $GRVT_COOKIE" \ + -H "X-Grvt-Account-Id: $GRVT_ACCOUNT_ID" \ + -x ' + { + "jsonrpc": "2.0", + "method": "v1/add_isolated_position_margin", + "params": { + "sub_account_id": "'$GRVT_SUB_ACCOUNT_ID'", + "instrument": "BTC_USDT_Perp", + "amount": "123456.78", + "signature": { + "signer": "0xc73c0c2538fd9b833d20933ccc88fdaa74fcb0d0", + "r": "0xb788d96fee91c7cdc35918e0441b756d4000ec1d07d900c73347d9abbc20acc8", + "s": "0x3d786193125f7c29c958647da64d0e2875ece2c3f845a591bdd7dae8c475e26d", + "v": 28, + "expiration": "1697788800000000000", + "nonce": 1234567890, + "chain_id": "325" + } + }, + "id": 123 + } + ' -w 360 + ``` +
+
+ !!! example "REST Lite" + ``` { .bash .copy } + curl --location 'https://trades.grvt.io/lite/v1/add_isolated_position_margin' \ + --header "Cookie: $GRVT_COOKIE" \ + --header "X-Grvt-Account-Id: $GRVT_ACCOUNT_ID" \ + --data '{ + "sa": "'$GRVT_SUB_ACCOUNT_ID'", + "i": "BTC_USDT_Perp", + "a": "123456.78", + "s": { + "s": "0xc73c0c2538fd9b833d20933ccc88fdaa74fcb0d0", + "r": "0xb788d96fee91c7cdc35918e0441b756d4000ec1d07d900c73347d9abbc20acc8", + "s1": "0x3d786193125f7c29c958647da64d0e2875ece2c3f845a591bdd7dae8c475e26d", + "v": 28, + "e": "1697788800000000000", + "n": 1234567890, + "ci": "325" + } + } + ' + ``` + !!! example "JSONRPC Lite" + ``` { .bash .copy } + wscat -c "wss://trades.grvt.io/ws/lite" \ + -H "Cookie: $GRVT_COOKIE" \ + -H "X-Grvt-Account-Id: $GRVT_ACCOUNT_ID" \ + -x ' + { + "j": "2.0", + "m": "v1/add_isolated_position_margin", + "p": { + "sa": "'$GRVT_SUB_ACCOUNT_ID'", + "i": "BTC_USDT_Perp", + "a": "123456.78", + "s": { + "s": "0xc73c0c2538fd9b833d20933ccc88fdaa74fcb0d0", + "r": "0xb788d96fee91c7cdc35918e0441b756d4000ec1d07d900c73347d9abbc20acc8", + "s1": "0x3d786193125f7c29c958647da64d0e2875ece2c3f845a591bdd7dae8c475e26d", + "v": 28, + "e": "1697788800000000000", + "n": 1234567890, + "ci": "325" + } + }, + "i": 123 + } + ' -w 360 + ``` +
+
diff --git a/artifacts/pysdk/grvt_raw_async.py b/artifacts/pysdk/grvt_raw_async.py index a8d2ab3..c1f63dc 100644 --- a/artifacts/pysdk/grvt_raw_async.py +++ b/artifacts/pysdk/grvt_raw_async.py @@ -48,6 +48,14 @@ async def get_currency_v1( return GrvtError(**resp) return from_dict(types.ApiGetCurrencyResponse, resp, Config(cast=[Enum])) + async def get_margin_rules_v1( + self, req: types.ApiGetMarginRulesRequest + ) -> types.ApiGetMarginRulesResponse | GrvtError: + resp = await self._post(False, self.md_rpc + "/full/v1/margin_rules", req) + if resp.get("code"): + return GrvtError(**resp) + return from_dict(types.ApiGetMarginRulesResponse, resp, Config(cast=[Enum])) + async def mini_ticker_v1( self, req: types.ApiMiniTickerRequest ) -> types.ApiMiniTickerResponse | GrvtError: @@ -363,3 +371,27 @@ async def vault_manager_investment_history_v1( return from_dict( types.ApiQueryVaultManagerInvestorHistoryResponse, resp, Config(cast=[Enum]) ) + + async def set_position_margin_config_v1( + self, req: types.ApiSetSubAccountPositionMarginConfigRequest + ) -> types.ApiSetSubAccountPositionMarginConfigResponse | GrvtError: + resp = await self._post( + True, self.td_rpc + "/full/v1/set_position_margin_config", req + ) + if resp.get("code"): + return GrvtError(**resp) + return from_dict( + types.ApiSetSubAccountPositionMarginConfigResponse, resp, Config(cast=[Enum]) + ) + + async def add_isolated_position_margin_v1( + self, req: types.ApiAddIsolatedPositionMarginRequest + ) -> types.ApiAddIsolatedPositionMarginResponse | GrvtError: + resp = await self._post( + True, self.td_rpc + "/full/v1/add_isolated_position_margin", req + ) + if resp.get("code"): + return GrvtError(**resp) + return from_dict( + types.ApiAddIsolatedPositionMarginResponse, resp, Config(cast=[Enum]) + ) diff --git a/artifacts/pysdk/grvt_raw_sync.py b/artifacts/pysdk/grvt_raw_sync.py index 1c2d137..75b898e 100644 --- a/artifacts/pysdk/grvt_raw_sync.py +++ b/artifacts/pysdk/grvt_raw_sync.py @@ -48,6 +48,14 @@ def get_currency_v1( return GrvtError(**resp) return from_dict(types.ApiGetCurrencyResponse, resp, Config(cast=[Enum])) + def get_margin_rules_v1( + self, req: types.ApiGetMarginRulesRequest + ) -> types.ApiGetMarginRulesResponse | GrvtError: + resp = self._post(False, self.md_rpc + "/full/v1/margin_rules", req) + if resp.get("code"): + return GrvtError(**resp) + return from_dict(types.ApiGetMarginRulesResponse, resp, Config(cast=[Enum])) + def mini_ticker_v1( self, req: types.ApiMiniTickerRequest ) -> types.ApiMiniTickerResponse | GrvtError: @@ -349,3 +357,25 @@ def vault_manager_investment_history_v1( return from_dict( types.ApiQueryVaultManagerInvestorHistoryResponse, resp, Config(cast=[Enum]) ) + + def set_position_margin_config_v1( + self, req: types.ApiSetSubAccountPositionMarginConfigRequest + ) -> types.ApiSetSubAccountPositionMarginConfigResponse | GrvtError: + resp = self._post(True, self.td_rpc + "/full/v1/set_position_margin_config", req) + if resp.get("code"): + return GrvtError(**resp) + return from_dict( + types.ApiSetSubAccountPositionMarginConfigResponse, resp, Config(cast=[Enum]) + ) + + def add_isolated_position_margin_v1( + self, req: types.ApiAddIsolatedPositionMarginRequest + ) -> types.ApiAddIsolatedPositionMarginResponse | GrvtError: + resp = self._post( + True, self.td_rpc + "/full/v1/add_isolated_position_margin", req + ) + if resp.get("code"): + return GrvtError(**resp) + return from_dict( + types.ApiAddIsolatedPositionMarginResponse, resp, Config(cast=[Enum]) + ) diff --git a/artifacts/pysdk/grvt_raw_types.py b/artifacts/pysdk/grvt_raw_types.py index d2fbe54..df9a9da 100644 --- a/artifacts/pysdk/grvt_raw_types.py +++ b/artifacts/pysdk/grvt_raw_types.py @@ -213,6 +213,11 @@ class OrderStatus(Enum): CANCELLED = "CANCELLED" +class PositionMarginType(Enum): + # Cross Margin Mode: uses all available funds in your account as collateral across all cross margin positions + CROSS = "CROSS" + + class TimeInForce(Enum): """ | | Must Fill All | Can Fill Partial | @@ -674,8 +679,14 @@ class AggregatedAccountSummary: spot_balances: list[SpotBalance] # The list of vault investments held by this main account vault_investments: list[VaultInvestment] - # Total balance of the sub accounts, denominated in USD + # Deprecated: Use totalSubAccountEquity instead total_sub_account_balance: str + # Total equity of the sub accounts, denominated in USD + total_sub_account_equity: str + # Total amount of the vault investments, denominated in USD + total_vault_investments_balance: str + # Total available balance of the main account, denominated in USD + total_sub_account_available_balance: str @dataclass @@ -792,6 +803,85 @@ class ApiSetDeriskToMaintenanceMarginRatioResponse: success: bool +@dataclass +class ApiSetSubAccountPositionMarginConfigRequest: + """ + Sets the margin type and leverage configuration for a specific position (instrument) within a sub account. + + This configuration is applied per-instrument, allowing different margin settings for different positions. + + """ + + # The sub account ID to set the margin type and leverage for + sub_account_id: str + # The instrument of the position to set the margin type and leverage for + instrument: str + # The margin type to set for the position + margin_type: PositionMarginType + # The leverage to set for the position + leverage: str + # The signature of this operation + signature: Signature + + +@dataclass +class ApiSetSubAccountPositionMarginConfigResponse: + # Whether the margin type and leverage was acked + ack: bool + + +@dataclass +class ApiAddIsolatedPositionMarginRequest: + # The sub account ID to add isolated margin in or remove margin from + sub_account_id: str + # The instrument to add margin into, or remove margin from + instrument: str + # The amount of margin to add to the position, positive to add, negative to remove, expressed in quote asset decimal units + amount: str + # The signature of this operation + signature: Signature + + +@dataclass +class ApiAddIsolatedPositionMarginResponse: + # Whether the margin mode and leverage was set successfully + success: bool + + +@dataclass +class ApiGetMarginRulesRequest: + # The instrument to query margin rules for + instrument: str + + +@dataclass +class RiskBracket: + # 1-indexed tier number + tier: int + # Lower bound of notional value (inclusive) in quote currency + notional_floor: str + # Upper bound of notional value (exclusive) in quote currency, empty for last tier + notional_cap: str + # Maintenance margin rate as a decimal (e.g., '0.01' for 1%) + maintenance_margin_rate: str + # Initial margin rate as a decimal (e.g., '0.02' for 2%) + initial_margin_rate: str + # Maximum leverage allowed at this tier (floor of 1 / initial_margin_rate) + max_leverage: int + # Cumulative maintenance margin amount in quote currency + cumulative_maintenance_amount: str + + +@dataclass +class ApiGetMarginRulesResponse: + # The instrument name + instrument: str + # The maximum position size, expressed in base asset decimal units + max_position_size: str + # List of risk brackets defining margin requirements at different notional tiers + risk_brackets: list[RiskBracket] + + @dataclass class JSONRPCRequest: """ diff --git a/src/codegen/apispec.json b/src/codegen/apispec.json index 25d0a0a..afabbae 100644 --- a/src/codegen/apispec.json +++ b/src/codegen/apispec.json @@ -135,6 +135,42 @@ } ] }, + { + "namespace": "Instrument", + "name": "RPCGetMarginRulesV1", + "version": 1, + "route": "/margin_rules", + "auth_required": false, + "request": "ApiGetMarginRulesRequest", + "response": "ApiGetMarginRulesResponse", + "on_request_errors": [ + { + "code": 1002, + "message": "Internal Server Error", + "status": 500 + }, + { + "code": 1003, + "message": "Request could not be processed due to malformed syntax", + "status": 400 + }, + { + "code": 3000, + "message": "Instrument is invalid", + "status": 400 + }, + { + "code": 1004, + "message": "Data Not Found", + "status": 404 + }, + { + "code": 1006, + "message": "You have surpassed the allocated rate limit for your tier", + "status": 429 + } + ] + }, { "namespace": "Ticker", "name": "RPCMiniTickerV1", @@ -1020,6 +1056,11 @@ "code": 2401, "message": "Reduce only order must not increase position size", "status": 400 + }, + { + "code": 2402, + "message": "Reduce only order size exceeds maximum allowed value", + "status": 400 } ] }, @@ -2425,6 +2466,128 @@ "status": 401 } ] + }, + { + "namespace": "Margin", + "name": "RPCSetPositionMarginConfigV1", + "version": 1, + "route": "/set_position_margin_config", + "auth_required": true, + "request": "ApiSetSubAccountPositionMarginConfigRequest", + "response": "ApiSetSubAccountPositionMarginConfigResponse", + "on_request_errors": [ + { + "code": 1000, + "message": "You need to authenticate prior to using this functionality", + "status": 401 + }, + { + "code": 1001, + "message": "You are not authorized to access this functionality", + "status": 403 + }, + { + "code": 1002, + "message": "Internal Server Error", + "status": 500 + }, + { + "code": 1003, + "message": "Request could not be processed due to malformed syntax", + "status": 400 + }, + { + "code": 1006, + "message": "You have surpassed the allocated rate limit for your tier", + "status": 429 + }, + { + "code": 1004, + "message": "Data Not Found", + "status": 404 + }, + { + "code": 2102, + "message": "Margin type change failed, has open position for this instrument", + "status": 400 + }, + { + "code": 2103, + "message": "Margin type change failed, has open orders for this instrument", + "status": 400 + }, + { + "code": 2101, + "message": "Vaults cannot configure leverage", + "status": 400 + }, + { + "code": 2104, + "message": "Margin type not supported", + "status": 400 + }, + { + "code": 2105, + "message": "Margin type change failed", + "status": 400 + } + ] + }, + { + "namespace": "Margin", + "name": "RPCAddIsolatedPositionMarginV1", + "version": 1, + "route": "/add_isolated_position_margin", + "auth_required": true, + "request": "ApiAddIsolatedPositionMarginRequest", + "response": "ApiAddIsolatedPositionMarginResponse", + "on_request_errors": [ + { + "code": 1000, + "message": "You need to authenticate prior to using this functionality", + "status": 401 + }, + { + "code": 1001, + "message": "You are not authorized to access this functionality", + "status": 403 + }, + { + "code": 1002, + "message": "Internal Server Error", + "status": 500 + }, + { + "code": 1003, + "message": "Request could not be processed due to malformed syntax", + "status": 400 + }, + { + "code": 1006, + "message": "You have surpassed the allocated rate limit for your tier", + "status": 429 + }, + { + "code": 1004, + "message": "Data Not Found", + "status": 404 + }, + { + "code": 7450, + "message": "Add margin failed", + "status": 400 + }, + { + "code": 7451, + "message": "Add margin to empty position", + "status": 400 + }, + { + "code": 7452, + "message": "Add margin to non isolated position", + "status": 400 + } + ] } ], "streams": [ @@ -4328,7 +4491,46 @@ "optional": false, "example": "'3945034.23'", "comment": [ - "Total balance of the sub accounts, denominated in USD" + "Deprecated: Use totalSubAccountEquity instead" + ] + }, + { + "name": "total_sub_account_equity", + "lite_name": "ts1", + "semantic_type": "string", + "json_type": "string", + "index": 5, + "array_depth": 0, + "optional": false, + "example": "'3945034.23'", + "comment": [ + "Total equity of the sub accounts, denominated in USD" + ] + }, + { + "name": "total_vault_investments_balance", + "lite_name": "tv", + "semantic_type": "string", + "json_type": "string", + "index": 6, + "array_depth": 0, + "optional": false, + "example": "'3945034.23'", + "comment": [ + "Total amount of the vault investments, denominated in USD" + ] + }, + { + "name": "total_sub_account_available_balance", + "lite_name": "ts2", + "semantic_type": "string", + "json_type": "string", + "index": 7, + "array_depth": 0, + "optional": false, + "example": "'3945034.23'", + "comment": [ + "Total available balance of the main account, denominated in USD" ] } ], @@ -4846,6 +5048,352 @@ "The response to set the derisk margin to maintenance margin ratio of a sub account" ] }, + { + "name": "ApiSetSubAccountPositionMarginConfigRequest", + "is_root": true, + "fields": [ + { + "name": "sub_account_id", + "lite_name": "sa", + "semantic_type": "uint64", + "json_type": "string", + "index": 0, + "array_depth": 0, + "optional": false, + "example": "'$GRVT_SUB_ACCOUNT_ID'", + "comment": [ + "The sub account ID to set the margin type and leverage for" + ] + }, + { + "name": "instrument", + "lite_name": "i", + "semantic_type": "asset", + "json_type": "string", + "index": 1, + "array_depth": 0, + "optional": false, + "example": "'BTC_USDT_Perp'", + "comment": [ + "The instrument of the position to set the margin type and leverage for" + ] + }, + { + "name": "margin_type", + "lite_name": "mt", + "semantic_type": "PositionMarginType", + "json_type": "PositionMarginType", + "index": 2, + "array_depth": 0, + "optional": false, + "comment": [ + "The margin type to set for the position" + ] + }, + { + "name": "leverage", + "lite_name": "l", + "semantic_type": "string", + "json_type": "string", + "index": 3, + "array_depth": 0, + "optional": false, + "example": "'1.5'", + "comment": [ + "The leverage to set for the position" + ] + }, + { + "name": "signature", + "lite_name": "s", + "semantic_type": "Signature", + "json_type": "Signature", + "index": 4, + "array_depth": 0, + "optional": false, + "comment": [ + "The signature of this operation" + ] + } + ], + "comment": [ + "Sets the margin type and leverage configuration for a specific position (instrument) within a sub account.", + "", + "This configuration is applied per-instrument, allowing different margin settings for different positions.", + "" + ] + }, + { + "name": "ApiSetSubAccountPositionMarginConfigResponse", + "is_root": true, + "fields": [ + { + "name": "ack", + "lite_name": "a", + "semantic_type": "bool", + "json_type": "boolean", + "index": 0, + "array_depth": 0, + "optional": false, + "example": "'true'", + "comment": [ + "Whether the margin type and leverage was acked" + ] + } + ], + "comment": [ + "The response to set the margin type and leverage for a position" + ] + }, + { + "name": "ApiAddIsolatedPositionMarginRequest", + "is_root": true, + "fields": [ + { + "name": "sub_account_id", + "lite_name": "sa", + "semantic_type": "uint64", + "json_type": "string", + "index": 0, + "array_depth": 0, + "optional": false, + "example": "'$GRVT_SUB_ACCOUNT_ID'", + "comment": [ + "The sub account ID to add isolated margin in or remove margin from" + ] + }, + { + "name": "instrument", + "lite_name": "i", + "semantic_type": "asset", + "json_type": "string", + "index": 1, + "array_depth": 0, + "optional": false, + "example": "'BTC_USDT_Perp'", + "comment": [ + "The instrument to add margin into, or remove margin from" + ] + }, + { + "name": "amount", + "lite_name": "a", + "semantic_type": "string", + "json_type": "string", + "index": 2, + "array_depth": 0, + "optional": false, + "example": "'123456.78'", + "comment": [ + "The amount of margin to add to the position, positive to add, negative to remove, expressed in quote asset decimal units" + ] + }, + { + "name": "signature", + "lite_name": "s", + "semantic_type": "Signature", + "json_type": "Signature", + "index": 3, + "array_depth": 0, + "optional": false, + "comment": [ + "The signature of this operation" + ] + } + ], + "comment": [ + "The request to add margin to a isolated position" + ] + }, + { + "name": "ApiAddIsolatedPositionMarginResponse", + "is_root": true, + "fields": [ + { + "name": "success", + "lite_name": "s", + "semantic_type": "bool", + "json_type": "boolean", + "index": 0, + "array_depth": 0, + "optional": false, + "example": "'true'", + "comment": [ + "Whether the margin mode and leverage was set successfully" + ] + } + ], + "comment": [ + "The response to add margin to a isolated position" + ] + }, + { + "name": "ApiGetMarginRulesRequest", + "is_root": true, + "fields": [ + { + "name": "instrument", + "lite_name": "i", + "semantic_type": "asset", + "json_type": "string", + "index": 0, + "array_depth": 0, + "optional": false, + "example": "'BTC_USDT_Perp'", + "comment": [ + "The instrument to query margin rules for" + ] + } + ], + "comment": [ + "API request payload to get margin rules for a particular instrument" + ] + }, + { + "name": "RiskBracket", + "is_root": false, + "fields": [ + { + "name": "tier", + "lite_name": "t", + "semantic_type": "uint32", + "json_type": "integer", + "index": 0, + "array_depth": 0, + "optional": false, + "example": "1", + "comment": [ + "1-indexed tier number" + ] + }, + { + "name": "notional_floor", + "lite_name": "nf", + "semantic_type": "string", + "json_type": "string", + "index": 1, + "array_depth": 0, + "optional": false, + "example": "'0'", + "comment": [ + "Lower bound of notional value (inclusive) in quote currency" + ] + }, + { + "name": "notional_cap", + "lite_name": "nc", + "semantic_type": "string", + "json_type": "string", + "index": 2, + "array_depth": 0, + "optional": false, + "example": "'600000'", + "comment": [ + "Upper bound of notional value (exclusive) in quote currency, empty for last tier" + ] + }, + { + "name": "maintenance_margin_rate", + "lite_name": "mm", + "semantic_type": "string", + "json_type": "string", + "index": 3, + "array_depth": 0, + "optional": false, + "example": "'0.01'", + "comment": [ + "Maintenance margin rate as a decimal (e.g., '0.01' for 1%)" + ] + }, + { + "name": "initial_margin_rate", + "lite_name": "im", + "semantic_type": "string", + "json_type": "string", + "index": 4, + "array_depth": 0, + "optional": false, + "example": "'0.02'", + "comment": [ + "Initial margin rate as a decimal (e.g., '0.02' for 2%)" + ] + }, + { + "name": "max_leverage", + "lite_name": "ml", + "semantic_type": "uint32", + "json_type": "integer", + "index": 5, + "array_depth": 0, + "optional": false, + "example": "50", + "comment": [ + "Maximum leverage allowed at this tier (floor of 1 / initial_margin_rate)" + ] + }, + { + "name": "cumulative_maintenance_amount", + "lite_name": "cm", + "semantic_type": "string", + "json_type": "string", + "index": 6, + "array_depth": 0, + "optional": false, + "example": "'0'", + "comment": [ + "Cumulative maintenance margin amount in quote currency" + ] + } + ], + "comment": [] + }, + { + "name": "ApiGetMarginRulesResponse", + "is_root": true, + "fields": [ + { + "name": "instrument", + "lite_name": "i", + "semantic_type": "asset", + "json_type": "string", + "index": 0, + "array_depth": 0, + "optional": false, + "example": "'BTC_USDT_Perp'", + "comment": [ + "The instrument name" + ] + }, + { + "name": "max_position_size", + "lite_name": "mp", + "semantic_type": "string", + "json_type": "string", + "index": 1, + "array_depth": 0, + "optional": false, + "example": "'100.0'", + "comment": [ + "The maximum position size, expressed in base asset decimal units" + ] + }, + { + "name": "risk_brackets", + "lite_name": "rb", + "semantic_type": "RiskBracket", + "json_type": "RiskBracket", + "index": 2, + "array_depth": 1, + "optional": false, + "comment": [ + "List of risk brackets defining margin requirements at different notional tiers" + ] + } + ], + "comment": [ + "API response payload for margin rules of a particular instrument" + ] + }, { "name": "JSONRPCRequest", "is_root": true, @@ -13029,6 +13577,19 @@ ], "comment": [] }, + { + "name": "PositionMarginType", + "values": [ + { + "name": "CROSS", + "value": 2, + "comment": [ + "Cross Margin Mode: uses all available funds in your account as collateral across all cross margin positions" + ] + } + ], + "comment": [] + }, { "name": "TimeInForce", "values": [