Skip to content

Commit

Permalink
feat(api): enable inventories endpoint (#54)
Browse files Browse the repository at this point in the history
  • Loading branch information
stainless-app[bot] authored and stainless-bot committed Oct 25, 2024
1 parent f14d0e1 commit 8fc74d6
Show file tree
Hide file tree
Showing 19 changed files with 408 additions and 19 deletions.
2 changes: 1 addition & 1 deletion .stats.yml
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
configured_endpoints: 29
configured_endpoints: 30
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/clear-street%2Fstudio-sdk-468b5da24bbf73b3a3861d44c5a8051fe6c55a6ec64c5c6f2d45f22c76bf35b2.yml
12 changes: 12 additions & 0 deletions api.md
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,18 @@ Methods:

- <code title="get /accounts/{account_id}/holdings">client.accounts.holdings.<a href="./src/studio_sdk/resources/accounts/holdings.py">list</a>(account_id, \*\*<a href="src/studio_sdk/types/accounts/holding_list_params.py">params</a>) -> <a href="./src/studio_sdk/types/accounts/holding_list_response.py">HoldingListResponse</a></code>

## Inventories

Types:

```python
from studio_sdk.types.accounts import InventoryRetrieveResponse
```

Methods:

- <code title="get /accounts/{account_id}/inventories/{symbol}">client.accounts.inventories.<a href="./src/studio_sdk/resources/accounts/inventories.py">retrieve</a>(symbol, \*, account_id) -> <a href="./src/studio_sdk/types/accounts/inventory_retrieve_response.py">InventoryRetrieveResponse</a></code>

# Instruments

Types:
Expand Down
8 changes: 2 additions & 6 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,11 @@ format = { chain = [
"format:ruff",
"format:docs",
"fix:ruff",
# run formatting again to fix any inconsistencies when imports are stripped
"format:ruff",
]}
"format:black" = "black ."
"format:docs" = "python scripts/utils/ruffen-docs.py README.md api.md"
"format:ruff" = "ruff format"
"format:isort" = "isort ."

"lint" = { chain = [
"check:ruff",
Expand Down Expand Up @@ -125,10 +125,6 @@ path = "README.md"
pattern = '\[(.+?)\]\(((?!https?://)\S+?)\)'
replacement = '[\1](https://github.com/clear-street/studio-sdk-python/tree/main/\g<2>)'

[tool.black]
line-length = 120
target-version = ["py37"]

[tool.pytest.ini_options]
testpaths = ["tests"]
addopts = "--tb=short"
Expand Down
2 changes: 1 addition & 1 deletion requirements-dev.lock
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ pytz==2023.3.post1
# via dirty-equals
respx==0.20.2
rich==13.7.1
ruff==0.6.5
ruff==0.6.9
setuptools==68.2.2
# via nodeenv
six==1.16.0
Expand Down
11 changes: 9 additions & 2 deletions src/studio_sdk/_base_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,12 @@ def __init__(
self.url = url
self.params = params

@override
def __repr__(self) -> str:
if self.url:
return f"{self.__class__.__name__}(url={self.url})"
return f"{self.__class__.__name__}(params={self.params})"


class BasePage(GenericModel, Generic[_T]):
"""
Expand Down Expand Up @@ -689,7 +695,8 @@ def _calculate_retry_timeout(
if retry_after is not None and 0 < retry_after <= 60:
return retry_after

nb_retries = max_retries - remaining_retries
# Also cap retry count to 1000 to avoid any potential overflows with `pow`
nb_retries = min(max_retries - remaining_retries, 1000)

# Apply exponential backoff, but not more than the max.
sleep_seconds = min(INITIAL_RETRY_DELAY * pow(2.0, nb_retries), MAX_RETRY_DELAY)
Expand Down Expand Up @@ -1568,7 +1575,7 @@ async def _request(
except Exception as err:
log.debug("Encountered Exception", exc_info=True)

if retries_taken > 0:
if remaining_retries > 0:
return await self._retry_request(
input_options,
cast_to,
Expand Down
14 changes: 14 additions & 0 deletions src/studio_sdk/resources/accounts/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,14 @@
BulkOrdersResourceWithStreamingResponse,
AsyncBulkOrdersResourceWithStreamingResponse,
)
from .inventories import (
InventoriesResource,
AsyncInventoriesResource,
InventoriesResourceWithRawResponse,
AsyncInventoriesResourceWithRawResponse,
InventoriesResourceWithStreamingResponse,
AsyncInventoriesResourceWithStreamingResponse,
)
from .pnl_details import (
PnlDetailsResource,
AsyncPnlDetailsResource,
Expand Down Expand Up @@ -150,6 +158,12 @@
"AsyncHoldingsResourceWithRawResponse",
"HoldingsResourceWithStreamingResponse",
"AsyncHoldingsResourceWithStreamingResponse",
"InventoriesResource",
"AsyncInventoriesResource",
"InventoriesResourceWithRawResponse",
"AsyncInventoriesResourceWithRawResponse",
"InventoriesResourceWithStreamingResponse",
"AsyncInventoriesResourceWithStreamingResponse",
"AccountsResource",
"AsyncAccountsResource",
"AccountsResourceWithRawResponse",
Expand Down
32 changes: 32 additions & 0 deletions src/studio_sdk/resources/accounts/accounts.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,14 @@
BulkOrdersResourceWithStreamingResponse,
AsyncBulkOrdersResourceWithStreamingResponse,
)
from .inventories import (
InventoriesResource,
AsyncInventoriesResource,
InventoriesResourceWithRawResponse,
AsyncInventoriesResourceWithRawResponse,
InventoriesResourceWithStreamingResponse,
AsyncInventoriesResourceWithStreamingResponse,
)
from .pnl_details import (
PnlDetailsResource,
AsyncPnlDetailsResource,
Expand Down Expand Up @@ -141,6 +149,10 @@ def pnl_sums(self) -> PnlSumsResource:
def holdings(self) -> HoldingsResource:
return HoldingsResource(self._client)

@cached_property
def inventories(self) -> InventoriesResource:
return InventoriesResource(self._client)

@cached_property
def with_raw_response(self) -> AccountsResourceWithRawResponse:
"""
Expand Down Expand Up @@ -256,6 +268,10 @@ def pnl_sums(self) -> AsyncPnlSumsResource:
def holdings(self) -> AsyncHoldingsResource:
return AsyncHoldingsResource(self._client)

@cached_property
def inventories(self) -> AsyncInventoriesResource:
return AsyncInventoriesResource(self._client)

@cached_property
def with_raw_response(self) -> AsyncAccountsResourceWithRawResponse:
"""
Expand Down Expand Up @@ -381,6 +397,10 @@ def pnl_sums(self) -> PnlSumsResourceWithRawResponse:
def holdings(self) -> HoldingsResourceWithRawResponse:
return HoldingsResourceWithRawResponse(self._accounts.holdings)

@cached_property
def inventories(self) -> InventoriesResourceWithRawResponse:
return InventoriesResourceWithRawResponse(self._accounts.inventories)


class AsyncAccountsResourceWithRawResponse:
def __init__(self, accounts: AsyncAccountsResource) -> None:
Expand Down Expand Up @@ -433,6 +453,10 @@ def pnl_sums(self) -> AsyncPnlSumsResourceWithRawResponse:
def holdings(self) -> AsyncHoldingsResourceWithRawResponse:
return AsyncHoldingsResourceWithRawResponse(self._accounts.holdings)

@cached_property
def inventories(self) -> AsyncInventoriesResourceWithRawResponse:
return AsyncInventoriesResourceWithRawResponse(self._accounts.inventories)


class AccountsResourceWithStreamingResponse:
def __init__(self, accounts: AccountsResource) -> None:
Expand Down Expand Up @@ -485,6 +509,10 @@ def pnl_sums(self) -> PnlSumsResourceWithStreamingResponse:
def holdings(self) -> HoldingsResourceWithStreamingResponse:
return HoldingsResourceWithStreamingResponse(self._accounts.holdings)

@cached_property
def inventories(self) -> InventoriesResourceWithStreamingResponse:
return InventoriesResourceWithStreamingResponse(self._accounts.inventories)


class AsyncAccountsResourceWithStreamingResponse:
def __init__(self, accounts: AsyncAccountsResource) -> None:
Expand Down Expand Up @@ -536,3 +564,7 @@ def pnl_sums(self) -> AsyncPnlSumsResourceWithStreamingResponse:
@cached_property
def holdings(self) -> AsyncHoldingsResourceWithStreamingResponse:
return AsyncHoldingsResourceWithStreamingResponse(self._accounts.holdings)

@cached_property
def inventories(self) -> AsyncInventoriesResourceWithStreamingResponse:
return AsyncInventoriesResourceWithStreamingResponse(self._accounts.inventories)
173 changes: 173 additions & 0 deletions src/studio_sdk/resources/accounts/inventories.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,173 @@
# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.

from __future__ import annotations

import httpx

from ..._types import NOT_GIVEN, Body, Query, Headers, NotGiven
from ..._compat import cached_property
from ..._resource import SyncAPIResource, AsyncAPIResource
from ..._response import (
to_raw_response_wrapper,
to_streamed_response_wrapper,
async_to_raw_response_wrapper,
async_to_streamed_response_wrapper,
)
from ..._base_client import make_request_options
from ...types.accounts.inventory_retrieve_response import InventoryRetrieveResponse

__all__ = ["InventoriesResource", "AsyncInventoriesResource"]


class InventoriesResource(SyncAPIResource):
@cached_property
def with_raw_response(self) -> InventoriesResourceWithRawResponse:
"""
This property can be used as a prefix for any HTTP method call to return the
the raw response object instead of the parsed content.
For more information, see https://www.github.com/clear-street/studio-sdk-python#accessing-raw-response-data-eg-headers
"""
return InventoriesResourceWithRawResponse(self)

@cached_property
def with_streaming_response(self) -> InventoriesResourceWithStreamingResponse:
"""
An alternative to `.with_raw_response` that doesn't eagerly read the response body.
For more information, see https://www.github.com/clear-street/studio-sdk-python#with_streaming_response
"""
return InventoriesResourceWithStreamingResponse(self)

def retrieve(
self,
symbol: str,
*,
account_id: str,
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
# The extra values given here take precedence over values defined on the client or passed to this method.
extra_headers: Headers | None = None,
extra_query: Query | None = None,
extra_body: Body | None = None,
timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN,
) -> InventoryRetrieveResponse:
"""
Get located inventory for a symbol.
Args:
account_id: Account ID for the account.
extra_headers: Send extra headers
extra_query: Add additional query parameters to the request
extra_body: Add additional JSON properties to the request
timeout: Override the client-level default timeout for this request, in seconds
"""
if not account_id:
raise ValueError(f"Expected a non-empty value for `account_id` but received {account_id!r}")
if not symbol:
raise ValueError(f"Expected a non-empty value for `symbol` but received {symbol!r}")
return self._get(
f"/accounts/{account_id}/inventories/{symbol}",
options=make_request_options(
extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
),
cast_to=InventoryRetrieveResponse,
)


class AsyncInventoriesResource(AsyncAPIResource):
@cached_property
def with_raw_response(self) -> AsyncInventoriesResourceWithRawResponse:
"""
This property can be used as a prefix for any HTTP method call to return the
the raw response object instead of the parsed content.
For more information, see https://www.github.com/clear-street/studio-sdk-python#accessing-raw-response-data-eg-headers
"""
return AsyncInventoriesResourceWithRawResponse(self)

@cached_property
def with_streaming_response(self) -> AsyncInventoriesResourceWithStreamingResponse:
"""
An alternative to `.with_raw_response` that doesn't eagerly read the response body.
For more information, see https://www.github.com/clear-street/studio-sdk-python#with_streaming_response
"""
return AsyncInventoriesResourceWithStreamingResponse(self)

async def retrieve(
self,
symbol: str,
*,
account_id: str,
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
# The extra values given here take precedence over values defined on the client or passed to this method.
extra_headers: Headers | None = None,
extra_query: Query | None = None,
extra_body: Body | None = None,
timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN,
) -> InventoryRetrieveResponse:
"""
Get located inventory for a symbol.
Args:
account_id: Account ID for the account.
extra_headers: Send extra headers
extra_query: Add additional query parameters to the request
extra_body: Add additional JSON properties to the request
timeout: Override the client-level default timeout for this request, in seconds
"""
if not account_id:
raise ValueError(f"Expected a non-empty value for `account_id` but received {account_id!r}")
if not symbol:
raise ValueError(f"Expected a non-empty value for `symbol` but received {symbol!r}")
return await self._get(
f"/accounts/{account_id}/inventories/{symbol}",
options=make_request_options(
extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
),
cast_to=InventoryRetrieveResponse,
)


class InventoriesResourceWithRawResponse:
def __init__(self, inventories: InventoriesResource) -> None:
self._inventories = inventories

self.retrieve = to_raw_response_wrapper(
inventories.retrieve,
)


class AsyncInventoriesResourceWithRawResponse:
def __init__(self, inventories: AsyncInventoriesResource) -> None:
self._inventories = inventories

self.retrieve = async_to_raw_response_wrapper(
inventories.retrieve,
)


class InventoriesResourceWithStreamingResponse:
def __init__(self, inventories: InventoriesResource) -> None:
self._inventories = inventories

self.retrieve = to_streamed_response_wrapper(
inventories.retrieve,
)


class AsyncInventoriesResourceWithStreamingResponse:
def __init__(self, inventories: AsyncInventoriesResource) -> None:
self._inventories = inventories

self.retrieve = async_to_streamed_response_wrapper(
inventories.retrieve,
)
1 change: 0 additions & 1 deletion src/studio_sdk/types/account.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.



from .._models import BaseModel

__all__ = ["Account"]
Expand Down
1 change: 1 addition & 0 deletions src/studio_sdk/types/accounts/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,4 @@
from .locate_order_create_params import LocateOrderCreateParams as LocateOrderCreateParams
from .locate_order_list_response import LocateOrderListResponse as LocateOrderListResponse
from .locate_order_update_params import LocateOrderUpdateParams as LocateOrderUpdateParams
from .inventory_retrieve_response import InventoryRetrieveResponse as InventoryRetrieveResponse
Loading

0 comments on commit 8fc74d6

Please sign in to comment.