"""Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT."""

from .basesdk import BaseSDK
from ascend_sdk import utils
from ascend_sdk._hooks import HookContext
from ascend_sdk.models import components, errors, operations
from ascend_sdk.types import OptionalNullable, UNSET
from typing import Any, Optional, Union


class FixedIncomePricing(BaseSDK):
    def preview_order_cost(
        self,
        *,
        account_id: str,
        order_cost_preview_request_create: Union[
            components.OrderCostPreviewRequestCreate,
            components.OrderCostPreviewRequestCreateTypedDict,
        ],
        retries: OptionalNullable[utils.RetryConfig] = UNSET,
        server_url: Optional[str] = None,
        timeout_ms: Optional[int] = None,
    ) -> operations.OrderPriceServicePreviewOrderCostResponse:
        r"""Preview Order Cost

        Returns a calculation estimating the costs involved in ordering a given quantity of a Fixed Income asset at a specified limit price.

        :param account_id: The account id.
        :param order_cost_preview_request_create:
        :param retries: Override the default retry configuration for this method
        :param server_url: Override the default server URL for this method
        :param timeout_ms: Override the default request timeout configuration for this method in milliseconds
        """
        base_url = None
        url_variables = None
        if timeout_ms is None:
            timeout_ms = self.sdk_configuration.timeout_ms

        if server_url is not None:
            base_url = server_url

        request = operations.OrderPriceServicePreviewOrderCostRequest(
            account_id=account_id,
            order_cost_preview_request_create=utils.get_pydantic_model(
                order_cost_preview_request_create,
                components.OrderCostPreviewRequestCreate,
            ),
        )

        req = self.build_request(
            method="POST",
            path="/trading/v1/accounts/{account_id}/orders:previewOrderCost",
            base_url=base_url,
            url_variables=url_variables,
            request=request,
            request_body_required=True,
            request_has_path_params=True,
            request_has_query_params=True,
            user_agent_header="user-agent",
            accept_header_value="application/json",
            security=self.sdk_configuration.security,
            get_serialized_body=lambda: utils.serialize_request_body(
                request.order_cost_preview_request_create,
                False,
                False,
                "json",
                components.OrderCostPreviewRequestCreate,
            ),
            timeout_ms=timeout_ms,
        )

        if retries == UNSET:
            if self.sdk_configuration.retry_config is not UNSET:
                retries = self.sdk_configuration.retry_config

        retry_config = None
        if isinstance(retries, utils.RetryConfig):
            retry_config = (retries, ["429", "500", "502", "503", "504"])

        http_res = self.do_request(
            hook_ctx=HookContext(
                operation_id="OrderPriceService_PreviewOrderCost",
                oauth2_scopes=[],
                security_source=self.sdk_configuration.security,
            ),
            request=req,
            error_status_codes=["400", "401", "403", "4XX", "500", "503", "5XX"],
            retry_config=retry_config,
        )

        data: Any = None
        if utils.match_response(http_res, "200", "application/json"):
            return operations.OrderPriceServicePreviewOrderCostResponse(
                order_cost_preview_response=utils.unmarshal_json(
                    http_res.text, Optional[components.OrderCostPreviewResponse]
                ),
                http_meta=components.HTTPMetadata(request=req, response=http_res),
            )
        if utils.match_response(
            http_res, ["400", "401", "403", "500", "503"], "application/json"
        ):
            data = utils.unmarshal_json(http_res.text, errors.StatusData)
            raise errors.Status(data=data)
        if utils.match_response(http_res, ["4XX", "5XX"], "*"):
            raise errors.SDKError(
                "API error occurred", http_res.status_code, http_res.text, http_res
            )
        if utils.match_response(http_res, "default", "application/json"):
            return operations.OrderPriceServicePreviewOrderCostResponse(
                status=utils.unmarshal_json(http_res.text, Optional[components.Status]),
                http_meta=components.HTTPMetadata(request=req, response=http_res),
            )

        content_type = http_res.headers.get("Content-Type")
        raise errors.SDKError(
            f"Unexpected response received (code: {http_res.status_code}, type: {content_type})",
            http_res.status_code,
            http_res.text,
            http_res,
        )

    async def preview_order_cost_async(
        self,
        *,
        account_id: str,
        order_cost_preview_request_create: Union[
            components.OrderCostPreviewRequestCreate,
            components.OrderCostPreviewRequestCreateTypedDict,
        ],
        retries: OptionalNullable[utils.RetryConfig] = UNSET,
        server_url: Optional[str] = None,
        timeout_ms: Optional[int] = None,
    ) -> operations.OrderPriceServicePreviewOrderCostResponse:
        r"""Preview Order Cost

        Returns a calculation estimating the costs involved in ordering a given quantity of a Fixed Income asset at a specified limit price.

        :param account_id: The account id.
        :param order_cost_preview_request_create:
        :param retries: Override the default retry configuration for this method
        :param server_url: Override the default server URL for this method
        :param timeout_ms: Override the default request timeout configuration for this method in milliseconds
        """
        base_url = None
        url_variables = None
        if timeout_ms is None:
            timeout_ms = self.sdk_configuration.timeout_ms

        if server_url is not None:
            base_url = server_url

        request = operations.OrderPriceServicePreviewOrderCostRequest(
            account_id=account_id,
            order_cost_preview_request_create=utils.get_pydantic_model(
                order_cost_preview_request_create,
                components.OrderCostPreviewRequestCreate,
            ),
        )

        req = self.build_request_async(
            method="POST",
            path="/trading/v1/accounts/{account_id}/orders:previewOrderCost",
            base_url=base_url,
            url_variables=url_variables,
            request=request,
            request_body_required=True,
            request_has_path_params=True,
            request_has_query_params=True,
            user_agent_header="user-agent",
            accept_header_value="application/json",
            security=self.sdk_configuration.security,
            get_serialized_body=lambda: utils.serialize_request_body(
                request.order_cost_preview_request_create,
                False,
                False,
                "json",
                components.OrderCostPreviewRequestCreate,
            ),
            timeout_ms=timeout_ms,
        )

        if retries == UNSET:
            if self.sdk_configuration.retry_config is not UNSET:
                retries = self.sdk_configuration.retry_config

        retry_config = None
        if isinstance(retries, utils.RetryConfig):
            retry_config = (retries, ["429", "500", "502", "503", "504"])

        http_res = await self.do_request_async(
            hook_ctx=HookContext(
                operation_id="OrderPriceService_PreviewOrderCost",
                oauth2_scopes=[],
                security_source=self.sdk_configuration.security,
            ),
            request=req,
            error_status_codes=["400", "401", "403", "4XX", "500", "503", "5XX"],
            retry_config=retry_config,
        )

        data: Any = None
        if utils.match_response(http_res, "200", "application/json"):
            return operations.OrderPriceServicePreviewOrderCostResponse(
                order_cost_preview_response=utils.unmarshal_json(
                    http_res.text, Optional[components.OrderCostPreviewResponse]
                ),
                http_meta=components.HTTPMetadata(request=req, response=http_res),
            )
        if utils.match_response(
            http_res, ["400", "401", "403", "500", "503"], "application/json"
        ):
            data = utils.unmarshal_json(http_res.text, errors.StatusData)
            raise errors.Status(data=data)
        if utils.match_response(http_res, ["4XX", "5XX"], "*"):
            raise errors.SDKError(
                "API error occurred", http_res.status_code, http_res.text, http_res
            )
        if utils.match_response(http_res, "default", "application/json"):
            return operations.OrderPriceServicePreviewOrderCostResponse(
                status=utils.unmarshal_json(http_res.text, Optional[components.Status]),
                http_meta=components.HTTPMetadata(request=req, response=http_res),
            )

        content_type = http_res.headers.get("Content-Type")
        raise errors.SDKError(
            f"Unexpected response received (code: {http_res.status_code}, type: {content_type})",
            http_res.status_code,
            http_res.text,
            http_res,
        )

    def retrieve_quote(
        self,
        *,
        account_id: str,
        retrieve_quote_request_create: Union[
            components.RetrieveQuoteRequestCreate,
            components.RetrieveQuoteRequestCreateTypedDict,
        ],
        retries: OptionalNullable[utils.RetryConfig] = UNSET,
        server_url: Optional[str] = None,
        timeout_ms: Optional[int] = None,
    ) -> operations.OrderPriceServiceRetrieveQuoteResponse:
        r"""Retrieve Quote

        Returns quote information containing the best bid/ask for the given Fixed Income asset.

        :param account_id: The account id.
        :param retrieve_quote_request_create:
        :param retries: Override the default retry configuration for this method
        :param server_url: Override the default server URL for this method
        :param timeout_ms: Override the default request timeout configuration for this method in milliseconds
        """
        base_url = None
        url_variables = None
        if timeout_ms is None:
            timeout_ms = self.sdk_configuration.timeout_ms

        if server_url is not None:
            base_url = server_url

        request = operations.OrderPriceServiceRetrieveQuoteRequest(
            account_id=account_id,
            retrieve_quote_request_create=utils.get_pydantic_model(
                retrieve_quote_request_create, components.RetrieveQuoteRequestCreate
            ),
        )

        req = self.build_request(
            method="POST",
            path="/trading/v1/accounts/{account_id}/orders:retrieveAssetQuote",
            base_url=base_url,
            url_variables=url_variables,
            request=request,
            request_body_required=True,
            request_has_path_params=True,
            request_has_query_params=True,
            user_agent_header="user-agent",
            accept_header_value="application/json",
            security=self.sdk_configuration.security,
            get_serialized_body=lambda: utils.serialize_request_body(
                request.retrieve_quote_request_create,
                False,
                False,
                "json",
                components.RetrieveQuoteRequestCreate,
            ),
            timeout_ms=timeout_ms,
        )

        if retries == UNSET:
            if self.sdk_configuration.retry_config is not UNSET:
                retries = self.sdk_configuration.retry_config

        retry_config = None
        if isinstance(retries, utils.RetryConfig):
            retry_config = (retries, ["429", "500", "502", "503", "504"])

        http_res = self.do_request(
            hook_ctx=HookContext(
                operation_id="OrderPriceService_RetrieveQuote",
                oauth2_scopes=[],
                security_source=self.sdk_configuration.security,
            ),
            request=req,
            error_status_codes=["400", "401", "403", "4XX", "500", "503", "5XX"],
            retry_config=retry_config,
        )

        data: Any = None
        if utils.match_response(http_res, "200", "application/json"):
            return operations.OrderPriceServiceRetrieveQuoteResponse(
                retrieve_quote_response=utils.unmarshal_json(
                    http_res.text, Optional[components.RetrieveQuoteResponse]
                ),
                http_meta=components.HTTPMetadata(request=req, response=http_res),
            )
        if utils.match_response(
            http_res, ["400", "401", "403", "500", "503"], "application/json"
        ):
            data = utils.unmarshal_json(http_res.text, errors.StatusData)
            raise errors.Status(data=data)
        if utils.match_response(http_res, ["4XX", "5XX"], "*"):
            raise errors.SDKError(
                "API error occurred", http_res.status_code, http_res.text, http_res
            )
        if utils.match_response(http_res, "default", "application/json"):
            return operations.OrderPriceServiceRetrieveQuoteResponse(
                status=utils.unmarshal_json(http_res.text, Optional[components.Status]),
                http_meta=components.HTTPMetadata(request=req, response=http_res),
            )

        content_type = http_res.headers.get("Content-Type")
        raise errors.SDKError(
            f"Unexpected response received (code: {http_res.status_code}, type: {content_type})",
            http_res.status_code,
            http_res.text,
            http_res,
        )

    async def retrieve_quote_async(
        self,
        *,
        account_id: str,
        retrieve_quote_request_create: Union[
            components.RetrieveQuoteRequestCreate,
            components.RetrieveQuoteRequestCreateTypedDict,
        ],
        retries: OptionalNullable[utils.RetryConfig] = UNSET,
        server_url: Optional[str] = None,
        timeout_ms: Optional[int] = None,
    ) -> operations.OrderPriceServiceRetrieveQuoteResponse:
        r"""Retrieve Quote

        Returns quote information containing the best bid/ask for the given Fixed Income asset.

        :param account_id: The account id.
        :param retrieve_quote_request_create:
        :param retries: Override the default retry configuration for this method
        :param server_url: Override the default server URL for this method
        :param timeout_ms: Override the default request timeout configuration for this method in milliseconds
        """
        base_url = None
        url_variables = None
        if timeout_ms is None:
            timeout_ms = self.sdk_configuration.timeout_ms

        if server_url is not None:
            base_url = server_url

        request = operations.OrderPriceServiceRetrieveQuoteRequest(
            account_id=account_id,
            retrieve_quote_request_create=utils.get_pydantic_model(
                retrieve_quote_request_create, components.RetrieveQuoteRequestCreate
            ),
        )

        req = self.build_request_async(
            method="POST",
            path="/trading/v1/accounts/{account_id}/orders:retrieveAssetQuote",
            base_url=base_url,
            url_variables=url_variables,
            request=request,
            request_body_required=True,
            request_has_path_params=True,
            request_has_query_params=True,
            user_agent_header="user-agent",
            accept_header_value="application/json",
            security=self.sdk_configuration.security,
            get_serialized_body=lambda: utils.serialize_request_body(
                request.retrieve_quote_request_create,
                False,
                False,
                "json",
                components.RetrieveQuoteRequestCreate,
            ),
            timeout_ms=timeout_ms,
        )

        if retries == UNSET:
            if self.sdk_configuration.retry_config is not UNSET:
                retries = self.sdk_configuration.retry_config

        retry_config = None
        if isinstance(retries, utils.RetryConfig):
            retry_config = (retries, ["429", "500", "502", "503", "504"])

        http_res = await self.do_request_async(
            hook_ctx=HookContext(
                operation_id="OrderPriceService_RetrieveQuote",
                oauth2_scopes=[],
                security_source=self.sdk_configuration.security,
            ),
            request=req,
            error_status_codes=["400", "401", "403", "4XX", "500", "503", "5XX"],
            retry_config=retry_config,
        )

        data: Any = None
        if utils.match_response(http_res, "200", "application/json"):
            return operations.OrderPriceServiceRetrieveQuoteResponse(
                retrieve_quote_response=utils.unmarshal_json(
                    http_res.text, Optional[components.RetrieveQuoteResponse]
                ),
                http_meta=components.HTTPMetadata(request=req, response=http_res),
            )
        if utils.match_response(
            http_res, ["400", "401", "403", "500", "503"], "application/json"
        ):
            data = utils.unmarshal_json(http_res.text, errors.StatusData)
            raise errors.Status(data=data)
        if utils.match_response(http_res, ["4XX", "5XX"], "*"):
            raise errors.SDKError(
                "API error occurred", http_res.status_code, http_res.text, http_res
            )
        if utils.match_response(http_res, "default", "application/json"):
            return operations.OrderPriceServiceRetrieveQuoteResponse(
                status=utils.unmarshal_json(http_res.text, Optional[components.Status]),
                http_meta=components.HTTPMetadata(request=req, response=http_res),
            )

        content_type = http_res.headers.get("Content-Type")
        raise errors.SDKError(
            f"Unexpected response received (code: {http_res.status_code}, type: {content_type})",
            http_res.status_code,
            http_res.text,
            http_res,
        )

    def retrieve_fixed_income_marks(
        self,
        *,
        correspondent_id: str,
        retrieve_fixed_income_marks_request_create: Union[
            components.RetrieveFixedIncomeMarksRequestCreate,
            components.RetrieveFixedIncomeMarksRequestCreateTypedDict,
        ],
        retries: OptionalNullable[utils.RetryConfig] = UNSET,
        server_url: Optional[str] = None,
        timeout_ms: Optional[int] = None,
    ) -> operations.OrderPriceServiceRetrieveFixedIncomeMarksResponse:
        r"""Retrieve Fixed Income Marks

        Returns marks for a specified set of Fixed Income assets (up to 100 per request)

        :param correspondent_id: The correspondent id.
        :param retrieve_fixed_income_marks_request_create:
        :param retries: Override the default retry configuration for this method
        :param server_url: Override the default server URL for this method
        :param timeout_ms: Override the default request timeout configuration for this method in milliseconds
        """
        base_url = None
        url_variables = None
        if timeout_ms is None:
            timeout_ms = self.sdk_configuration.timeout_ms

        if server_url is not None:
            base_url = server_url

        request = operations.OrderPriceServiceRetrieveFixedIncomeMarksRequest(
            correspondent_id=correspondent_id,
            retrieve_fixed_income_marks_request_create=utils.get_pydantic_model(
                retrieve_fixed_income_marks_request_create,
                components.RetrieveFixedIncomeMarksRequestCreate,
            ),
        )

        req = self.build_request(
            method="POST",
            path="/trading/v1/correspondents/{correspondent_id}/prices:retrieveFixedIncomeMarks",
            base_url=base_url,
            url_variables=url_variables,
            request=request,
            request_body_required=True,
            request_has_path_params=True,
            request_has_query_params=True,
            user_agent_header="user-agent",
            accept_header_value="application/json",
            security=self.sdk_configuration.security,
            get_serialized_body=lambda: utils.serialize_request_body(
                request.retrieve_fixed_income_marks_request_create,
                False,
                False,
                "json",
                components.RetrieveFixedIncomeMarksRequestCreate,
            ),
            timeout_ms=timeout_ms,
        )

        if retries == UNSET:
            if self.sdk_configuration.retry_config is not UNSET:
                retries = self.sdk_configuration.retry_config

        retry_config = None
        if isinstance(retries, utils.RetryConfig):
            retry_config = (retries, ["429", "500", "502", "503", "504"])

        http_res = self.do_request(
            hook_ctx=HookContext(
                operation_id="OrderPriceService_RetrieveFixedIncomeMarks",
                oauth2_scopes=[],
                security_source=self.sdk_configuration.security,
            ),
            request=req,
            error_status_codes=["400", "401", "403", "4XX", "500", "503", "5XX"],
            retry_config=retry_config,
        )

        data: Any = None
        if utils.match_response(http_res, "200", "application/json"):
            return operations.OrderPriceServiceRetrieveFixedIncomeMarksResponse(
                retrieve_fixed_income_marks_response=utils.unmarshal_json(
                    http_res.text, Optional[components.RetrieveFixedIncomeMarksResponse]
                ),
                http_meta=components.HTTPMetadata(request=req, response=http_res),
            )
        if utils.match_response(
            http_res, ["400", "401", "403", "500", "503"], "application/json"
        ):
            data = utils.unmarshal_json(http_res.text, errors.StatusData)
            raise errors.Status(data=data)
        if utils.match_response(http_res, ["4XX", "5XX"], "*"):
            raise errors.SDKError(
                "API error occurred", http_res.status_code, http_res.text, http_res
            )
        if utils.match_response(http_res, "default", "application/json"):
            return operations.OrderPriceServiceRetrieveFixedIncomeMarksResponse(
                status=utils.unmarshal_json(http_res.text, Optional[components.Status]),
                http_meta=components.HTTPMetadata(request=req, response=http_res),
            )

        content_type = http_res.headers.get("Content-Type")
        raise errors.SDKError(
            f"Unexpected response received (code: {http_res.status_code}, type: {content_type})",
            http_res.status_code,
            http_res.text,
            http_res,
        )

    async def retrieve_fixed_income_marks_async(
        self,
        *,
        correspondent_id: str,
        retrieve_fixed_income_marks_request_create: Union[
            components.RetrieveFixedIncomeMarksRequestCreate,
            components.RetrieveFixedIncomeMarksRequestCreateTypedDict,
        ],
        retries: OptionalNullable[utils.RetryConfig] = UNSET,
        server_url: Optional[str] = None,
        timeout_ms: Optional[int] = None,
    ) -> operations.OrderPriceServiceRetrieveFixedIncomeMarksResponse:
        r"""Retrieve Fixed Income Marks

        Returns marks for a specified set of Fixed Income assets (up to 100 per request)

        :param correspondent_id: The correspondent id.
        :param retrieve_fixed_income_marks_request_create:
        :param retries: Override the default retry configuration for this method
        :param server_url: Override the default server URL for this method
        :param timeout_ms: Override the default request timeout configuration for this method in milliseconds
        """
        base_url = None
        url_variables = None
        if timeout_ms is None:
            timeout_ms = self.sdk_configuration.timeout_ms

        if server_url is not None:
            base_url = server_url

        request = operations.OrderPriceServiceRetrieveFixedIncomeMarksRequest(
            correspondent_id=correspondent_id,
            retrieve_fixed_income_marks_request_create=utils.get_pydantic_model(
                retrieve_fixed_income_marks_request_create,
                components.RetrieveFixedIncomeMarksRequestCreate,
            ),
        )

        req = self.build_request_async(
            method="POST",
            path="/trading/v1/correspondents/{correspondent_id}/prices:retrieveFixedIncomeMarks",
            base_url=base_url,
            url_variables=url_variables,
            request=request,
            request_body_required=True,
            request_has_path_params=True,
            request_has_query_params=True,
            user_agent_header="user-agent",
            accept_header_value="application/json",
            security=self.sdk_configuration.security,
            get_serialized_body=lambda: utils.serialize_request_body(
                request.retrieve_fixed_income_marks_request_create,
                False,
                False,
                "json",
                components.RetrieveFixedIncomeMarksRequestCreate,
            ),
            timeout_ms=timeout_ms,
        )

        if retries == UNSET:
            if self.sdk_configuration.retry_config is not UNSET:
                retries = self.sdk_configuration.retry_config

        retry_config = None
        if isinstance(retries, utils.RetryConfig):
            retry_config = (retries, ["429", "500", "502", "503", "504"])

        http_res = await self.do_request_async(
            hook_ctx=HookContext(
                operation_id="OrderPriceService_RetrieveFixedIncomeMarks",
                oauth2_scopes=[],
                security_source=self.sdk_configuration.security,
            ),
            request=req,
            error_status_codes=["400", "401", "403", "4XX", "500", "503", "5XX"],
            retry_config=retry_config,
        )

        data: Any = None
        if utils.match_response(http_res, "200", "application/json"):
            return operations.OrderPriceServiceRetrieveFixedIncomeMarksResponse(
                retrieve_fixed_income_marks_response=utils.unmarshal_json(
                    http_res.text, Optional[components.RetrieveFixedIncomeMarksResponse]
                ),
                http_meta=components.HTTPMetadata(request=req, response=http_res),
            )
        if utils.match_response(
            http_res, ["400", "401", "403", "500", "503"], "application/json"
        ):
            data = utils.unmarshal_json(http_res.text, errors.StatusData)
            raise errors.Status(data=data)
        if utils.match_response(http_res, ["4XX", "5XX"], "*"):
            raise errors.SDKError(
                "API error occurred", http_res.status_code, http_res.text, http_res
            )
        if utils.match_response(http_res, "default", "application/json"):
            return operations.OrderPriceServiceRetrieveFixedIncomeMarksResponse(
                status=utils.unmarshal_json(http_res.text, Optional[components.Status]),
                http_meta=components.HTTPMetadata(request=req, response=http_res),
            )

        content_type = http_res.headers.get("Content-Type")
        raise errors.SDKError(
            f"Unexpected response received (code: {http_res.status_code}, type: {content_type})",
            http_res.status_code,
            http_res.text,
            http_res,
        )
