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_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/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..4f6e568 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" } } ``` diff --git a/artifacts/pysdk/grvt_raw_async.py b/artifacts/pysdk/grvt_raw_async.py index a8d2ab3..0e5cb75 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: diff --git a/artifacts/pysdk/grvt_raw_sync.py b/artifacts/pysdk/grvt_raw_sync.py index 1c2d137..166de01 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: diff --git a/artifacts/pysdk/grvt_raw_types.py b/artifacts/pysdk/grvt_raw_types.py index d2fbe54..55afdf1 100644 --- a/artifacts/pysdk/grvt_raw_types.py +++ b/artifacts/pysdk/grvt_raw_types.py @@ -674,8 +674,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 +798,40 @@ class ApiSetDeriskToMaintenanceMarginRatioResponse: 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..2fdbdf4 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 } ] }, @@ -4328,7 +4369,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 +4926,173 @@ "The response to set the derisk margin to maintenance margin ratio of a sub account" ] }, + { + "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,