diff --git a/examples/get_set_maker_only_api_keys.py b/examples/get_set_maker_only_api_keys.py new file mode 100644 index 0000000..494cff0 --- /dev/null +++ b/examples/get_set_maker_only_api_keys.py @@ -0,0 +1,51 @@ +import asyncio, json, lighter +from utils import default_example_setup + +async def main(): + client, api_client, _ = default_example_setup() + auth_token, err = client.create_auth_token_with_expiry() + assert err is None + + # set_maker_only_api_keys replaces the full set of maker-only API key indexes for the account. + # Pass "[]" to clear all maker-only restrictions on the account + # For set_maker_only_api_keys you can call this endpoint only once per hour + # Indexes must be >= 4 e.g [4, 5, 6] + + account_api = lighter.AccountApi(api_client) + + resp = await account_api.set_maker_only_api_keys( + account_index=client.account_index, + api_key_indexes=json.dumps([4, 5, 6]), + authorization=auth_token, + ) + print("set:", resp) + + await asyncio.sleep(1) + + resp = await account_api.get_maker_only_api_keys( + account_index=client.account_index, + authorization=auth_token, + ) + print("get:", resp) + + # clear maker only restrictions + resp = await account_api.set_maker_only_api_keys( + account_index=client.account_index, + api_key_indexes=json.dumps([]), + authorization=auth_token, + ) + print("set:", resp) + await asyncio.sleep(1) + + resp = await account_api.get_maker_only_api_keys( + account_index=client.account_index, + authorization=auth_token, + ) + print("get:", resp) + + + await client.close() + await api_client.close() + +if __name__ == "__main__": + asyncio.run(main()) diff --git a/lighter/__init__.py b/lighter/__init__.py index 2264126..1d1b810 100644 --- a/lighter/__init__.py +++ b/lighter/__init__.py @@ -203,5 +203,10 @@ from lighter.models.withdraw_history import WithdrawHistory from lighter.models.withdraw_history_item import WithdrawHistoryItem from lighter.models.zk_lighter_info import ZkLighterInfo +from lighter.models.resp_get_maker_only_api_keys import RespGetMakerOnlyApiKeys +from lighter.models.resp_set_maker_only_api_keys import RespSetMakerOnlyApiKeys +from lighter.models.req_get_partner_stats import ReqGetPartnerStats +from lighter.models.req_get_maker_only_api_keys import ReqGetMakerOnlyApiKeys +from lighter.models.partner_stats import PartnerStats from lighter.ws_client import WsClient from lighter.signer_client import SignerClient, create_api_key \ No newline at end of file diff --git a/lighter/api/account_api.py b/lighter/api/account_api.py index dd17c6e..901b1fb 100644 --- a/lighter/api/account_api.py +++ b/lighter/api/account_api.py @@ -33,6 +33,7 @@ from lighter.models.resp_get_lease_options import RespGetLeaseOptions from lighter.models.resp_get_leases import RespGetLeases from lighter.models.resp_get_maker_only_api_keys import RespGetMakerOnlyApiKeys +from lighter.models.resp_set_maker_only_api_keys import RespSetMakerOnlyApiKeys from lighter.models.resp_post_api_token import RespPostApiToken from lighter.models.resp_public_pools_metadata import RespPublicPoolsMetadata from lighter.models.resp_revoke_api_token import RespRevokeApiToken @@ -2425,7 +2426,308 @@ def _get_maker_only_api_keys_serialize( _request_auth=_request_auth ) + @validate_call + async def set_maker_only_api_keys( + self, + authorization: StrictStr, + account_index: StrictInt, + api_key_indexes: Annotated[StrictStr, Field( + description="JSON array string of API key indexes, e.g. \\\"[4,5]\\\". Use [] to clear all maker-only restrictions.")], + _request_timeout: Union[ + None, + Annotated[StrictFloat, Field(gt=0)], + Tuple[ + Annotated[StrictFloat, Field(gt=0)], + Annotated[StrictFloat, Field(gt=0)] + ] + ] = None, + _request_auth: Optional[Dict[StrictStr, Any]] = None, + _content_type: Optional[StrictStr] = None, + _headers: Optional[Dict[StrictStr, Any]] = None, + _host_index: Annotated[StrictInt, Field(ge=0, le=0)] = 0, + ) -> RespSetMakerOnlyApiKeys: + """setMakerOnlyApiKeys + + Set maker-only API key indexes. This replaces the current list; pass all indexes you want marked as maker-only. Pass [] to clear all maker-only restrictions. + + :param authorization: (required) + :type authorization: str + :param account_index: (required) + :type account_index: int + :param api_key_indexes: JSON array string of API key indexes, e.g. \\\"[4,5]\\\". Use [] to clear all maker-only restrictions. (required) + :type api_key_indexes: str + :param _request_timeout: timeout setting for this request. If one + number provided, it will be total request + timeout. It can also be a pair (tuple) of + (connection, read) timeouts. + :type _request_timeout: int, tuple(int, int), optional + :param _request_auth: set to override the auth_settings for an a single + request; this effectively ignores the + authentication in the spec for a single request. + :type _request_auth: dict, optional + :param _content_type: force content-type for the request. + :type _content_type: str, Optional + :param _headers: set to override the headers for a single + request; this effectively ignores the headers + in the spec for a single request. + :type _headers: dict, optional + :param _host_index: set to override the host_index for a single + request; this effectively ignores the host_index + in the spec for a single request. + :type _host_index: int, optional + :return: Returns the result object. + """ # noqa: E501 + + _param = self._set_maker_only_api_keys_serialize( + authorization=authorization, + account_index=account_index, + api_key_indexes=api_key_indexes, + _request_auth=_request_auth, + _content_type=_content_type, + _headers=_headers, + _host_index=_host_index + ) + + _response_types_map: Dict[str, Optional[str]] = { + '200': "RespSetMakerOnlyApiKeys", + '400': "ResultCode", + } + response_data = await self.api_client.call_api( + *_param, + _request_timeout=_request_timeout + ) + await response_data.read() + return self.api_client.response_deserialize( + response_data=response_data, + response_types_map=_response_types_map, + ).data + + @validate_call + async def set_maker_only_api_keys_with_http_info( + self, + authorization: StrictStr, + account_index: StrictInt, + api_key_indexes: Annotated[StrictStr, Field( + description="JSON array string of API key indexes, e.g. \\\"[4,5]\\\". Use [] to clear all maker-only restrictions.")], + _request_timeout: Union[ + None, + Annotated[StrictFloat, Field(gt=0)], + Tuple[ + Annotated[StrictFloat, Field(gt=0)], + Annotated[StrictFloat, Field(gt=0)] + ] + ] = None, + _request_auth: Optional[Dict[StrictStr, Any]] = None, + _content_type: Optional[StrictStr] = None, + _headers: Optional[Dict[StrictStr, Any]] = None, + _host_index: Annotated[StrictInt, Field(ge=0, le=0)] = 0, + ) -> ApiResponse[RespSetMakerOnlyApiKeys]: + """setMakerOnlyApiKeys + + Set maker-only API key indexes. This replaces the current list; pass all indexes you want marked as maker-only. Pass [] to clear all maker-only restrictions. + + :param authorization: (required) + :type authorization: str + :param account_index: (required) + :type account_index: int + :param api_key_indexes: JSON array string of API key indexes, e.g. \\\"[4,5]\\\". Use [] to clear all maker-only restrictions. (required) + :type api_key_indexes: str + :param _request_timeout: timeout setting for this request. If one + number provided, it will be total request + timeout. It can also be a pair (tuple) of + (connection, read) timeouts. + :type _request_timeout: int, tuple(int, int), optional + :param _request_auth: set to override the auth_settings for an a single + request; this effectively ignores the + authentication in the spec for a single request. + :type _request_auth: dict, optional + :param _content_type: force content-type for the request. + :type _content_type: str, Optional + :param _headers: set to override the headers for a single + request; this effectively ignores the headers + in the spec for a single request. + :type _headers: dict, optional + :param _host_index: set to override the host_index for a single + request; this effectively ignores the host_index + in the spec for a single request. + :type _host_index: int, optional + :return: Returns the result object. + """ # noqa: E501 + + _param = self._set_maker_only_api_keys_serialize( + authorization=authorization, + account_index=account_index, + api_key_indexes=api_key_indexes, + _request_auth=_request_auth, + _content_type=_content_type, + _headers=_headers, + _host_index=_host_index + ) + + _response_types_map: Dict[str, Optional[str]] = { + '200': "RespSetMakerOnlyApiKeys", + '400': "ResultCode", + } + response_data = await self.api_client.call_api( + *_param, + _request_timeout=_request_timeout + ) + await response_data.read() + return self.api_client.response_deserialize( + response_data=response_data, + response_types_map=_response_types_map, + ) + + @validate_call + async def set_maker_only_api_keys_without_preload_content( + self, + authorization: StrictStr, + account_index: StrictInt, + api_key_indexes: Annotated[StrictStr, Field( + description="JSON array string of API key indexes, e.g. \\\"[4,5]\\\". Use [] to clear all maker-only restrictions.")], + _request_timeout: Union[ + None, + Annotated[StrictFloat, Field(gt=0)], + Tuple[ + Annotated[StrictFloat, Field(gt=0)], + Annotated[StrictFloat, Field(gt=0)] + ] + ] = None, + _request_auth: Optional[Dict[StrictStr, Any]] = None, + _content_type: Optional[StrictStr] = None, + _headers: Optional[Dict[StrictStr, Any]] = None, + _host_index: Annotated[StrictInt, Field(ge=0, le=0)] = 0, + ) -> RESTResponseType: + """setMakerOnlyApiKeys + Set maker-only API key indexes. This replaces the current list; pass all indexes you want marked as maker-only. Pass [] to clear all maker-only restrictions. + + :param authorization: (required) + :type authorization: str + :param account_index: (required) + :type account_index: int + :param api_key_indexes: JSON array string of API key indexes, e.g. \\\"[4,5]\\\". Use [] to clear all maker-only restrictions. (required) + :type api_key_indexes: str + :param _request_timeout: timeout setting for this request. If one + number provided, it will be total request + timeout. It can also be a pair (tuple) of + (connection, read) timeouts. + :type _request_timeout: int, tuple(int, int), optional + :param _request_auth: set to override the auth_settings for an a single + request; this effectively ignores the + authentication in the spec for a single request. + :type _request_auth: dict, optional + :param _content_type: force content-type for the request. + :type _content_type: str, Optional + :param _headers: set to override the headers for a single + request; this effectively ignores the headers + in the spec for a single request. + :type _headers: dict, optional + :param _host_index: set to override the host_index for a single + request; this effectively ignores the host_index + in the spec for a single request. + :type _host_index: int, optional + :return: Returns the result object. + """ # noqa: E501 + + _param = self._set_maker_only_api_keys_serialize( + authorization=authorization, + account_index=account_index, + api_key_indexes=api_key_indexes, + _request_auth=_request_auth, + _content_type=_content_type, + _headers=_headers, + _host_index=_host_index + ) + + _response_types_map: Dict[str, Optional[str]] = { + '200': "RespSetMakerOnlyApiKeys", + '400': "ResultCode", + } + response_data = await self.api_client.call_api( + *_param, + _request_timeout=_request_timeout + ) + return response_data.response + + def _set_maker_only_api_keys_serialize( + self, + authorization, + account_index, + api_key_indexes, + _request_auth, + _content_type, + _headers, + _host_index, + ) -> RequestSerialized: + + _host = None + + _collection_formats: Dict[str, str] = { + } + + _path_params: Dict[str, str] = {} + _query_params: List[Tuple[str, str]] = [] + _header_params: Dict[str, Optional[str]] = _headers or {} + _form_params: List[Tuple[str, str]] = [] + _files: Dict[ + str, Union[str, bytes, List[str], List[bytes], List[Tuple[str, bytes]]] + ] = {} + _body_params: Optional[bytes] = None + + # process the path parameters + # process the query parameters + # process the header parameters + if authorization is not None: + _header_params['authorization'] = authorization + # process the form parameters + if account_index is not None: + _form_params.append(('account_index', account_index)) + if api_key_indexes is not None: + _form_params.append(('api_key_indexes', api_key_indexes)) + # process the body parameter + + # set the HTTP header `Accept` + if 'Accept' not in _header_params: + _header_params['Accept'] = self.api_client.select_header_accept( + [ + 'application/json' + ] + ) + + # set the HTTP header `Content-Type` + if _content_type: + _header_params['Content-Type'] = _content_type + else: + _default_content_type = ( + self.api_client.select_header_content_type( + [ + 'application/x-www-form-urlencoded', + 'multipart/form-data' + ] + ) + ) + if _default_content_type is not None: + _header_params['Content-Type'] = _default_content_type + + # authentication setting + _auth_settings: List[str] = [ + ] + + return self.api_client.param_serialize( + method='POST', + resource_path='/api/v1/setMakerOnlyApiKeys', + path_params=_path_params, + query_params=_query_params, + header_params=_header_params, + body=_body_params, + post_params=_form_params, + files=_files, + auth_settings=_auth_settings, + collection_formats=_collection_formats, + _host=_host, + _request_auth=_request_auth + ) async def l1_metadata(