Skip to content

Commit 9d71f0b

Browse files
feat(api): disable series pagn, update example requests
1 parent 1aa9a59 commit 9d71f0b

18 files changed

Lines changed: 316 additions & 185 deletions

File tree

.stats.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
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: a6c5cf005205fb3c675ac298b416cf14
4+
config_hash: c289d0e2a34fb50fdbd02ca21400d3cd

README.md

Lines changed: 56 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,11 @@ from neptune_api_v2 import NeptuneAPIV2
3232

3333
client = NeptuneAPIV2()
3434

35-
response = client.status.check_health()
36-
print(response.status)
35+
response = client.markets.get_overview(
36+
with_text=True,
37+
with_value=True,
38+
)
39+
print(response.data)
3740
```
3841

3942
## Async usage
@@ -48,8 +51,11 @@ client = AsyncNeptuneAPIV2()
4851

4952

5053
async def main() -> None:
51-
response = await client.status.check_health()
52-
print(response.status)
54+
response = await client.markets.get_overview(
55+
with_text=True,
56+
with_value=True,
57+
)
58+
print(response.data)
5359

5460

5561
asyncio.run(main())
@@ -80,8 +86,11 @@ async def main() -> None:
8086
async with AsyncNeptuneAPIV2(
8187
http_client=DefaultAioHttpClient(),
8288
) as client:
83-
response = await client.status.check_health()
84-
print(response.status)
89+
response = await client.markets.get_overview(
90+
with_text=True,
91+
with_value=True,
92+
)
93+
print(response.data)
8594

8695

8796
asyncio.run(main())
@@ -107,16 +116,14 @@ from neptune_api_v2 import NeptuneAPIV2
107116

108117
client = NeptuneAPIV2()
109118

110-
all_assets = []
119+
all_users = []
111120
# Automatically fetches more pages as needed.
112-
for asset in client.assets.get_price_history(
113-
end=0,
114-
period="h",
115-
start=0,
121+
for user in client.user.get_tx_history(
122+
address="injvalcons1a03k0ztfyjnd70apawva003pkh0adqmau0a9q0",
116123
):
117-
# Do something with asset here
118-
all_assets.append(asset)
119-
print(all_assets)
124+
# Do something with user here
125+
all_users.append(user)
126+
print(all_users)
120127
```
121128

122129
Or, asynchronously:
@@ -129,15 +136,13 @@ client = AsyncNeptuneAPIV2()
129136

130137

131138
async def main() -> None:
132-
all_assets = []
139+
all_users = []
133140
# 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,
141+
async for user in client.user.get_tx_history(
142+
address="injvalcons1a03k0ztfyjnd70apawva003pkh0adqmau0a9q0",
138143
):
139-
all_assets.append(asset)
140-
print(all_assets)
144+
all_users.append(user)
145+
print(all_users)
141146

142147

143148
asyncio.run(main())
@@ -146,33 +151,27 @@ asyncio.run(main())
146151
Alternatively, you can use the `.has_next_page()`, `.next_page_info()`, or `.get_next_page()` methods for more granular control working with pages:
147152

148153
```python
149-
first_page = await client.assets.get_price_history(
150-
end=0,
151-
period="h",
152-
start=0,
154+
first_page = await client.user.get_tx_history(
155+
address="injvalcons1a03k0ztfyjnd70apawva003pkh0adqmau0a9q0",
153156
)
154157
if first_page.has_next_page():
155158
print(f"will fetch next page using these details: {first_page.next_page_info()}")
156159
next_page = await first_page.get_next_page()
157-
print(f"number of items we just fetched: {len(next_page.data.series)}")
160+
print(f"number of items we just fetched: {len(next_page.data)}")
158161

159162
# Remove `await` for non-async usage.
160163
```
161164

162165
Or just work directly with the returned data:
163166

164167
```python
165-
first_page = await client.assets.get_price_history(
166-
end=0,
167-
period="h",
168-
start=0,
168+
first_page = await client.user.get_tx_history(
169+
address="injvalcons1a03k0ztfyjnd70apawva003pkh0adqmau0a9q0",
169170
)
170171

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)
172+
print(f"next page cursor: {first_page.prev_event_uuid}") # => "next page cursor: ..."
173+
for user in first_page.data:
174+
print(user.event_uuid)
176175

177176
# Remove `await` for non-async usage.
178177
```
@@ -193,7 +192,10 @@ from neptune_api_v2 import NeptuneAPIV2
193192
client = NeptuneAPIV2()
194193

195194
try:
196-
client.status.check_health()
195+
client.markets.get_overview(
196+
with_text=True,
197+
with_value=True,
198+
)
197199
except neptune_api_v2.APIConnectionError as e:
198200
print("The server could not be reached")
199201
print(e.__cause__) # an underlying Exception, likely raised within httpx.
@@ -236,7 +238,10 @@ client = NeptuneAPIV2(
236238
)
237239

238240
# Or, configure per-request:
239-
client.with_options(max_retries=5).status.check_health()
241+
client.with_options(max_retries=5).markets.get_overview(
242+
with_text=True,
243+
with_value=True,
244+
)
240245
```
241246

242247
### Timeouts
@@ -259,7 +264,10 @@ client = NeptuneAPIV2(
259264
)
260265

261266
# Override per-request:
262-
client.with_options(timeout=5.0).status.check_health()
267+
client.with_options(timeout=5.0).markets.get_overview(
268+
with_text=True,
269+
with_value=True,
270+
)
263271
```
264272

265273
On timeout, an `APITimeoutError` is thrown.
@@ -300,11 +308,14 @@ The "raw" Response object can be accessed by prefixing `.with_raw_response.` to
300308
from neptune_api_v2 import NeptuneAPIV2
301309

302310
client = NeptuneAPIV2()
303-
response = client.status.with_raw_response.check_health()
311+
response = client.markets.with_raw_response.get_overview(
312+
with_text=True,
313+
with_value=True,
314+
)
304315
print(response.headers.get('X-My-Header'))
305316

306-
status = response.parse() # get the object that `status.check_health()` would have returned
307-
print(status.status)
317+
market = response.parse() # get the object that `markets.get_overview()` would have returned
318+
print(market.data)
308319
```
309320

310321
These methods return an [`APIResponse`](https://github.com/cryptechdev/neptune-api-v2-python/tree/main/src/neptune_api_v2/_response.py) object.
@@ -318,7 +329,10 @@ The above interface eagerly reads the full response body when you make the reque
318329
To stream the response body, use `.with_streaming_response` instead, which requires a context manager and only reads the response body once you call `.read()`, `.text()`, `.json()`, `.iter_bytes()`, `.iter_text()`, `.iter_lines()` or `.parse()`. In the async client, these are async methods.
319330

320331
```python
321-
with client.status.with_streaming_response.check_health() as response:
332+
with client.markets.with_streaming_response.get_overview(
333+
with_text=True,
334+
with_value=True,
335+
) as response:
322336
print(response.headers.get("X-My-Header"))
323337

324338
for line in response.iter_lines():

api.md

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,14 +43,15 @@ from neptune_api_v2.types import (
4343
AssetRateHistory,
4444
AssetSpec,
4545
AssetListResponse,
46+
AssetGetPriceHistoryResponse,
4647
AssetListPricesResponse,
4748
)
4849
```
4950

5051
Methods:
5152

5253
- <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>) -> SyncIntervalMultiPage[Series]</code>
54+
- <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>
5455
- <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>
5556

5657
# Markets
@@ -87,27 +88,32 @@ from neptune_api_v2.types.markets import (
8788
LendMarketState,
8889
LendListResponse,
8990
LendGetByAssetResponse,
91+
LendGetRateHistoryResponse,
9092
)
9193
```
9294

9395
Methods:
9496

9597
- <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>
9698
- <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>
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>
99+
- <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>
98100

99101
## Borrow
100102

101103
Types:
102104

103105
```python
104-
from neptune_api_v2.types.markets import BorrowMarketOverview, BorrowGetOverviewResponse
106+
from neptune_api_v2.types.markets import (
107+
BorrowMarketOverview,
108+
BorrowGetOverviewResponse,
109+
BorrowGetRateHistoryResponse,
110+
)
105111
```
106112

107113
Methods:
108114

109115
- <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>
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>
116+
- <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>
111117

112118
### Collaterals
113119

@@ -369,7 +375,7 @@ from neptune_api_v2.types.analytics.market import (
369375
Methods:
370376

371377
- <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>
378+
- <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>
373379

374380
## Nept
375381

src/neptune_api_v2/resources/analytics/market/history.py

Lines changed: 10 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
from ....types import IntervalUnit
1010
from ...._types import Body, Omit, Query, Headers, NotGiven, omit, not_given
11-
from ...._utils import maybe_transform
11+
from ...._utils import maybe_transform, async_maybe_transform
1212
from ...._compat import cached_property
1313
from ...._resource import SyncAPIResource, AsyncAPIResource
1414
from ...._response import (
@@ -17,12 +17,7 @@
1717
async_to_raw_response_wrapper,
1818
async_to_streamed_response_wrapper,
1919
)
20-
from ....pagination import (
21-
SyncIntervalMultiPage,
22-
AsyncIntervalMultiPage,
23-
SyncIntervalSinglePage,
24-
AsyncIntervalSinglePage,
25-
)
20+
from ....pagination import SyncIntervalSinglePage, AsyncIntervalSinglePage
2621
from ...._base_client import AsyncPaginator, make_request_options
2722
from ....types.interval_unit import IntervalUnit
2823
from ....types.analytics.market import history_get_loans_originated_params, history_get_loans_originated_by_asset_params
@@ -155,7 +150,7 @@ def get_loans_originated_by_asset(
155150
extra_query: Query | None = None,
156151
extra_body: Body | None = None,
157152
timeout: float | httpx.Timeout | None | NotGiven = not_given,
158-
) -> SyncIntervalMultiPage[HistoryGetLoansOriginatedByAssetResponse]:
153+
) -> HistoryGetLoansOriginatedByAssetResponse:
159154
"""
160155
Get cumulative lending value history assets
161156
@@ -205,9 +200,8 @@ def get_loans_originated_by_asset(
205200
206201
timeout: Override the client-level default timeout for this request, in seconds
207202
"""
208-
return self._get_api_list(
203+
return self._get(
209204
"/api/v1/analytics/market/history/loans-originated/by-asset",
210-
page=SyncIntervalMultiPage[HistoryGetLoansOriginatedByAssetResponse],
211205
options=make_request_options(
212206
extra_headers=extra_headers,
213207
extra_query=extra_query,
@@ -226,7 +220,7 @@ def get_loans_originated_by_asset(
226220
history_get_loans_originated_by_asset_params.HistoryGetLoansOriginatedByAssetParams,
227221
),
228222
),
229-
model=HistoryGetLoansOriginatedByAssetResponse,
223+
cast_to=HistoryGetLoansOriginatedByAssetResponse,
230224
)
231225

232226

@@ -335,7 +329,7 @@ def get_loans_originated(
335329
model=HistoryGetLoansOriginatedResponse,
336330
)
337331

338-
def get_loans_originated_by_asset(
332+
async def get_loans_originated_by_asset(
339333
self,
340334
*,
341335
end: int,
@@ -351,9 +345,7 @@ def get_loans_originated_by_asset(
351345
extra_query: Query | None = None,
352346
extra_body: Body | None = None,
353347
timeout: float | httpx.Timeout | None | NotGiven = not_given,
354-
) -> AsyncPaginator[
355-
HistoryGetLoansOriginatedByAssetResponse, AsyncIntervalMultiPage[HistoryGetLoansOriginatedByAssetResponse]
356-
]:
348+
) -> HistoryGetLoansOriginatedByAssetResponse:
357349
"""
358350
Get cumulative lending value history assets
359351
@@ -403,15 +395,14 @@ def get_loans_originated_by_asset(
403395
404396
timeout: Override the client-level default timeout for this request, in seconds
405397
"""
406-
return self._get_api_list(
398+
return await self._get(
407399
"/api/v1/analytics/market/history/loans-originated/by-asset",
408-
page=AsyncIntervalMultiPage[HistoryGetLoansOriginatedByAssetResponse],
409400
options=make_request_options(
410401
extra_headers=extra_headers,
411402
extra_query=extra_query,
412403
extra_body=extra_body,
413404
timeout=timeout,
414-
query=maybe_transform(
405+
query=await async_maybe_transform(
415406
{
416407
"end": end,
417408
"period": period,
@@ -424,7 +415,7 @@ def get_loans_originated_by_asset(
424415
history_get_loans_originated_by_asset_params.HistoryGetLoansOriginatedByAssetParams,
425416
),
426417
),
427-
model=HistoryGetLoansOriginatedByAssetResponse,
418+
cast_to=HistoryGetLoansOriginatedByAssetResponse,
428419
)
429420

430421

0 commit comments

Comments
 (0)