Skip to content

Commit 1aa9a59

Browse files
feat(api): add missing models, pagination impls
1 parent a2daaa3 commit 1aa9a59

40 files changed

Lines changed: 1452 additions & 897 deletions

.stats.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
configured_endpoints: 48
1+
configured_endpoints: 50
22
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/cryptech%2Fneptune-api-v2-3e68b318eeaab1241ee6ed696300829c9eae836a937905e7389788413f9daa8a.yml
33
openapi_spec_hash: b76569f104863b1e7b3c5271f53df840
4-
config_hash: fa0efc29593602eac57523d55bc83fa6
4+
config_hash: a6c5cf005205fb3c675ac298b416cf14

README.md

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,87 @@ Nested request parameters are [TypedDicts](https://docs.python.org/3/library/typ
9696

9797
Typed requests and responses provide autocomplete and documentation within your editor. If you would like to see type errors in VS Code to help catch bugs earlier, set `python.analysis.typeCheckingMode` to `basic`.
9898

99+
## Pagination
100+
101+
List methods in the Neptune API V2 API are paginated.
102+
103+
This library provides auto-paginating iterators with each list response, so you do not have to request successive pages manually:
104+
105+
```python
106+
from neptune_api_v2 import NeptuneAPIV2
107+
108+
client = NeptuneAPIV2()
109+
110+
all_assets = []
111+
# Automatically fetches more pages as needed.
112+
for asset in client.assets.get_price_history(
113+
end=0,
114+
period="h",
115+
start=0,
116+
):
117+
# Do something with asset here
118+
all_assets.append(asset)
119+
print(all_assets)
120+
```
121+
122+
Or, asynchronously:
123+
124+
```python
125+
import asyncio
126+
from neptune_api_v2 import AsyncNeptuneAPIV2
127+
128+
client = AsyncNeptuneAPIV2()
129+
130+
131+
async def main() -> None:
132+
all_assets = []
133+
# Iterate through items across all pages, issuing requests as needed.
134+
async for asset in client.assets.get_price_history(
135+
end=0,
136+
period="h",
137+
start=0,
138+
):
139+
all_assets.append(asset)
140+
print(all_assets)
141+
142+
143+
asyncio.run(main())
144+
```
145+
146+
Alternatively, you can use the `.has_next_page()`, `.next_page_info()`, or `.get_next_page()` methods for more granular control working with pages:
147+
148+
```python
149+
first_page = await client.assets.get_price_history(
150+
end=0,
151+
period="h",
152+
start=0,
153+
)
154+
if first_page.has_next_page():
155+
print(f"will fetch next page using these details: {first_page.next_page_info()}")
156+
next_page = await first_page.get_next_page()
157+
print(f"number of items we just fetched: {len(next_page.data.series)}")
158+
159+
# Remove `await` for non-async usage.
160+
```
161+
162+
Or just work directly with the returned data:
163+
164+
```python
165+
first_page = await client.assets.get_price_history(
166+
end=0,
167+
period="h",
168+
start=0,
169+
)
170+
171+
print(
172+
f"the current start offset for this page: {first_page.data.pagination.next_offset}"
173+
) # => "the current start offset for this page: 1"
174+
for asset in first_page.data.series:
175+
print(asset.asset)
176+
177+
# Remove `await` for non-async usage.
178+
```
179+
99180
## Handling errors
100181

101182
When the library is unable to connect to the API (for example, due to network connection problems or a timeout), a subclass of `neptune_api_v2.APIConnectionError` is raised.

api.md

Lines changed: 31 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ from neptune_api_v2.types import (
77
ErrorData,
88
ErrorDataVariants,
99
ErrorKind,
10+
ErrorResponse,
1011
ErrorScope,
1112
FieldValidationError,
1213
Interval,
@@ -42,15 +43,14 @@ from neptune_api_v2.types import (
4243
AssetRateHistory,
4344
AssetSpec,
4445
AssetListResponse,
45-
AssetGetPriceHistoryResponse,
4646
AssetListPricesResponse,
4747
)
4848
```
4949

5050
Methods:
5151

5252
- <code title="get /api/v1/assets">client.assets.<a href="./src/neptune_api_v2/resources/assets.py">list</a>() -> <a href="./src/neptune_api_v2/types/asset_list_response.py">AssetListResponse</a></code>
53-
- <code title="get /api/v1/assets/price-history">client.assets.<a href="./src/neptune_api_v2/resources/assets.py">get_price_history</a>(\*\*<a href="src/neptune_api_v2/types/asset_get_price_history_params.py">params</a>) -> <a href="./src/neptune_api_v2/types/asset_get_price_history_response.py">AssetGetPriceHistoryResponse</a></code>
53+
- <code title="get /api/v1/assets/price-history">client.assets.<a href="./src/neptune_api_v2/resources/assets.py">get_price_history</a>(\*\*<a href="src/neptune_api_v2/types/asset_get_price_history_params.py">params</a>) -> SyncIntervalMultiPage[Series]</code>
5454
- <code title="get /api/v1/assets/prices">client.assets.<a href="./src/neptune_api_v2/resources/assets.py">list_prices</a>(\*\*<a href="src/neptune_api_v2/types/asset_list_prices_params.py">params</a>) -> <a href="./src/neptune_api_v2/types/asset_list_prices_response.py">AssetListPricesResponse</a></code>
5555

5656
# Markets
@@ -87,32 +87,27 @@ from neptune_api_v2.types.markets import (
8787
LendMarketState,
8888
LendListResponse,
8989
LendGetByAssetResponse,
90-
LendGetRateHistoryResponse,
9190
)
9291
```
9392

9493
Methods:
9594

9695
- <code title="get /api/v1/markets/lend">client.markets.lend.<a href="./src/neptune_api_v2/resources/markets/lend.py">list</a>(\*\*<a href="src/neptune_api_v2/types/markets/lend_list_params.py">params</a>) -> <a href="./src/neptune_api_v2/types/markets/lend_list_response.py">LendListResponse</a></code>
9796
- <code title="get /api/v1/markets/lend/lookup">client.markets.lend.<a href="./src/neptune_api_v2/resources/markets/lend.py">get_by_asset</a>(\*\*<a href="src/neptune_api_v2/types/markets/lend_get_by_asset_params.py">params</a>) -> <a href="./src/neptune_api_v2/types/markets/lend_get_by_asset_response.py">LendGetByAssetResponse</a></code>
98-
- <code title="get /api/v1/markets/lend/rate-history">client.markets.lend.<a href="./src/neptune_api_v2/resources/markets/lend.py">get_rate_history</a>(\*\*<a href="src/neptune_api_v2/types/markets/lend_get_rate_history_params.py">params</a>) -> <a href="./src/neptune_api_v2/types/markets/lend_get_rate_history_response.py">LendGetRateHistoryResponse</a></code>
97+
- <code title="get /api/v1/markets/lend/rate-history">client.markets.lend.<a href="./src/neptune_api_v2/resources/markets/lend.py">get_rate_history</a>(\*\*<a href="src/neptune_api_v2/types/markets/lend_get_rate_history_params.py">params</a>) -> SyncIntervalMultiPage[Series]</code>
9998

10099
## Borrow
101100

102101
Types:
103102

104103
```python
105-
from neptune_api_v2.types.markets import (
106-
BorrowMarketOverview,
107-
BorrowGetOverviewResponse,
108-
BorrowGetRateHistoryResponse,
109-
)
104+
from neptune_api_v2.types.markets import BorrowMarketOverview, BorrowGetOverviewResponse
110105
```
111106

112107
Methods:
113108

114109
- <code title="get /api/v1/markets/borrow">client.markets.borrow.<a href="./src/neptune_api_v2/resources/markets/borrow/borrow.py">get_overview</a>(\*\*<a href="src/neptune_api_v2/types/markets/borrow_get_overview_params.py">params</a>) -> <a href="./src/neptune_api_v2/types/markets/borrow_get_overview_response.py">BorrowGetOverviewResponse</a></code>
115-
- <code title="get /api/v1/markets/borrow/rate-history">client.markets.borrow.<a href="./src/neptune_api_v2/resources/markets/borrow/borrow.py">get_rate_history</a>(\*\*<a href="src/neptune_api_v2/types/markets/borrow_get_rate_history_params.py">params</a>) -> <a href="./src/neptune_api_v2/types/markets/borrow_get_rate_history_response.py">BorrowGetRateHistoryResponse</a></code>
110+
- <code title="get /api/v1/markets/borrow/rate-history">client.markets.borrow.<a href="./src/neptune_api_v2/resources/markets/borrow/borrow.py">get_rate_history</a>(\*\*<a href="src/neptune_api_v2/types/markets/borrow_get_rate_history_params.py">params</a>) -> SyncIntervalMultiPage[Series]</code>
116111

117112
### Collaterals
118113

@@ -183,18 +178,12 @@ Methods:
183178
Types:
184179

185180
```python
186-
from neptune_api_v2.types import (
187-
EventAction,
188-
User,
189-
UserTx,
190-
UserGetTxHistoryResponse,
191-
UserGetUserResponse,
192-
)
181+
from neptune_api_v2.types import EventAction, User, UserTx, UserGetUserResponse
193182
```
194183

195184
Methods:
196185

197-
- <code title="get /api/v1/users/{address}/tx-history">client.user.<a href="./src/neptune_api_v2/resources/user/user.py">get_tx_history</a>(address, \*\*<a href="src/neptune_api_v2/types/user_get_tx_history_params.py">params</a>) -> <a href="./src/neptune_api_v2/types/user_get_tx_history_response.py">UserGetTxHistoryResponse</a></code>
186+
- <code title="get /api/v1/users/{address}/tx-history">client.user.<a href="./src/neptune_api_v2/resources/user/user.py">get_tx_history</a>(address, \*\*<a href="src/neptune_api_v2/types/user_get_tx_history_params.py">params</a>) -> <a href="./src/neptune_api_v2/types/user_tx.py">SyncTxHistoryPage[UserTx]</a></code>
198187
- <code title="get /api/v1/users/{address}/user">client.user.<a href="./src/neptune_api_v2/resources/user/user.py">get_user</a>(address, \*\*<a href="src/neptune_api_v2/types/user_get_user_params.py">params</a>) -> <a href="./src/neptune_api_v2/types/user_get_user_response.py">UserGetUserResponse</a></code>
199188

200189
## Market
@@ -223,7 +212,10 @@ Types:
223212

224213
```python
225214
from neptune_api_v2.types.user.market import (
215+
UserLendAssetPool,
226216
UserLendMarket,
217+
UserLendOriginAmounts,
218+
UserLendReceiptAmounts,
227219
LendListResponse,
228220
LendGetByAssetResponse,
229221
)
@@ -376,8 +368,8 @@ from neptune_api_v2.types.analytics.market import (
376368

377369
Methods:
378370

379-
- <code title="get /api/v1/analytics/market/history/loans-originated">client.analytics.market.history.<a href="./src/neptune_api_v2/resources/analytics/market/history.py">get_loans_originated</a>(\*\*<a href="src/neptune_api_v2/types/analytics/market/history_get_loans_originated_params.py">params</a>) -> <a href="./src/neptune_api_v2/types/analytics/market/history_get_loans_originated_response.py">HistoryGetLoansOriginatedResponse</a></code>
380-
- <code title="get /api/v1/analytics/market/history/loans-originated/by-asset">client.analytics.market.history.<a href="./src/neptune_api_v2/resources/analytics/market/history.py">get_loans_originated_by_asset</a>(\*\*<a href="src/neptune_api_v2/types/analytics/market/history_get_loans_originated_by_asset_params.py">params</a>) -> <a href="./src/neptune_api_v2/types/analytics/market/history_get_loans_originated_by_asset_response.py">HistoryGetLoansOriginatedByAssetResponse</a></code>
371+
- <code title="get /api/v1/analytics/market/history/loans-originated">client.analytics.market.history.<a href="./src/neptune_api_v2/resources/analytics/market/history.py">get_loans_originated</a>(\*\*<a href="src/neptune_api_v2/types/analytics/market/history_get_loans_originated_params.py">params</a>) -> <a href="./src/neptune_api_v2/types/analytics/market/history_get_loans_originated_response.py">SyncIntervalSinglePage[HistoryGetLoansOriginatedResponse]</a></code>
372+
- <code title="get /api/v1/analytics/market/history/loans-originated/by-asset">client.analytics.market.history.<a href="./src/neptune_api_v2/resources/analytics/market/history.py">get_loans_originated_by_asset</a>(\*\*<a href="src/neptune_api_v2/types/analytics/market/history_get_loans_originated_by_asset_params.py">params</a>) -> <a href="./src/neptune_api_v2/types/analytics/market/history_get_loans_originated_by_asset_response.py">SyncIntervalMultiPage[HistoryGetLoansOriginatedByAssetResponse]</a></code>
381373

382374
## Nept
383375

@@ -404,3 +396,22 @@ from neptune_api_v2.types.integrations import BantrGetTransactionsResponse
404396
Methods:
405397

406398
- <code title="get /api/v1/integrations/bantr/transactions">client.integrations.bantr.<a href="./src/neptune_api_v2/resources/integrations/bantr.py">get_transactions</a>(\*\*<a href="src/neptune_api_v2/types/integrations/bantr_get_transactions_params.py">params</a>) -> <a href="./src/neptune_api_v2/types/integrations/bantr_get_transactions_response.py">BantrGetTransactionsResponse</a></code>
399+
400+
# Swap
401+
402+
## Routes
403+
404+
Types:
405+
406+
```python
407+
from neptune_api_v2.types.swap import (
408+
SwapRouteTargetSet,
409+
RouteListAllResponse,
410+
RouteListByDenomResponse,
411+
)
412+
```
413+
414+
Methods:
415+
416+
- <code title="get /api/v1/swap/routes/all">client.swap.routes.<a href="./src/neptune_api_v2/resources/swap/routes.py">list_all</a>(\*\*<a href="src/neptune_api_v2/types/swap/route_list_all_params.py">params</a>) -> <a href="./src/neptune_api_v2/types/swap/route_list_all_response.py">RouteListAllResponse</a></code>
417+
- <code title="get /api/v1/swap/routes">client.swap.routes.<a href="./src/neptune_api_v2/resources/swap/routes.py">list_by_denom</a>(\*\*<a href="src/neptune_api_v2/types/swap/route_list_by_denom_params.py">params</a>) -> <a href="./src/neptune_api_v2/types/swap/route_list_by_denom_response.py">RouteListByDenomResponse</a></code>

src/neptune_api_v2/_client.py

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,11 @@
3131
)
3232

3333
if TYPE_CHECKING:
34-
from .resources import nept, user, assets, status, markets, analytics, integrations
34+
from .resources import nept, swap, user, assets, status, markets, analytics, integrations
3535
from .resources.nept import NeptResource, AsyncNeptResource
3636
from .resources.assets import AssetsResource, AsyncAssetsResource
3737
from .resources.status import StatusResource, AsyncStatusResource
38+
from .resources.swap.swap import SwapResource, AsyncSwapResource
3839
from .resources.user.user import UserResource, AsyncUserResource
3940
from .resources.markets.markets import MarketsResource, AsyncMarketsResource
4041
from .resources.analytics.analytics import AnalyticsResource, AsyncAnalyticsResource
@@ -136,6 +137,12 @@ def integrations(self) -> IntegrationsResource:
136137

137138
return IntegrationsResource(self)
138139

140+
@cached_property
141+
def swap(self) -> SwapResource:
142+
from .resources.swap import SwapResource
143+
144+
return SwapResource(self)
145+
139146
@cached_property
140147
def with_raw_response(self) -> NeptuneAPIV2WithRawResponse:
141148
return NeptuneAPIV2WithRawResponse(self)
@@ -325,6 +332,12 @@ def integrations(self) -> AsyncIntegrationsResource:
325332

326333
return AsyncIntegrationsResource(self)
327334

335+
@cached_property
336+
def swap(self) -> AsyncSwapResource:
337+
from .resources.swap import AsyncSwapResource
338+
339+
return AsyncSwapResource(self)
340+
328341
@cached_property
329342
def with_raw_response(self) -> AsyncNeptuneAPIV2WithRawResponse:
330343
return AsyncNeptuneAPIV2WithRawResponse(self)
@@ -478,6 +491,12 @@ def integrations(self) -> integrations.IntegrationsResourceWithRawResponse:
478491

479492
return IntegrationsResourceWithRawResponse(self._client.integrations)
480493

494+
@cached_property
495+
def swap(self) -> swap.SwapResourceWithRawResponse:
496+
from .resources.swap import SwapResourceWithRawResponse
497+
498+
return SwapResourceWithRawResponse(self._client.swap)
499+
481500

482501
class AsyncNeptuneAPIV2WithRawResponse:
483502
_client: AsyncNeptuneAPIV2
@@ -527,6 +546,12 @@ def integrations(self) -> integrations.AsyncIntegrationsResourceWithRawResponse:
527546

528547
return AsyncIntegrationsResourceWithRawResponse(self._client.integrations)
529548

549+
@cached_property
550+
def swap(self) -> swap.AsyncSwapResourceWithRawResponse:
551+
from .resources.swap import AsyncSwapResourceWithRawResponse
552+
553+
return AsyncSwapResourceWithRawResponse(self._client.swap)
554+
530555

531556
class NeptuneAPIV2WithStreamedResponse:
532557
_client: NeptuneAPIV2
@@ -576,6 +601,12 @@ def integrations(self) -> integrations.IntegrationsResourceWithStreamingResponse
576601

577602
return IntegrationsResourceWithStreamingResponse(self._client.integrations)
578603

604+
@cached_property
605+
def swap(self) -> swap.SwapResourceWithStreamingResponse:
606+
from .resources.swap import SwapResourceWithStreamingResponse
607+
608+
return SwapResourceWithStreamingResponse(self._client.swap)
609+
579610

580611
class AsyncNeptuneAPIV2WithStreamedResponse:
581612
_client: AsyncNeptuneAPIV2
@@ -625,6 +656,12 @@ def integrations(self) -> integrations.AsyncIntegrationsResourceWithStreamingRes
625656

626657
return AsyncIntegrationsResourceWithStreamingResponse(self._client.integrations)
627658

659+
@cached_property
660+
def swap(self) -> swap.AsyncSwapResourceWithStreamingResponse:
661+
from .resources.swap import AsyncSwapResourceWithStreamingResponse
662+
663+
return AsyncSwapResourceWithStreamingResponse(self._client.swap)
664+
628665

629666
Client = NeptuneAPIV2
630667

0 commit comments

Comments
 (0)