squidlor 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- squidlor-0.1.0/.github/workflows/publish.yml +30 -0
- squidlor-0.1.0/.gitignore +7 -0
- squidlor-0.1.0/LICENSE +21 -0
- squidlor-0.1.0/PKG-INFO +326 -0
- squidlor-0.1.0/README.md +294 -0
- squidlor-0.1.0/examples/quickstart.py +48 -0
- squidlor-0.1.0/pyproject.toml +64 -0
- squidlor-0.1.0/src/squidlor/__init__.py +54 -0
- squidlor-0.1.0/src/squidlor/client.py +1140 -0
- squidlor-0.1.0/src/squidlor/errors.py +96 -0
- squidlor-0.1.0/src/squidlor/models.py +1062 -0
- squidlor-0.1.0/src/squidlor/py.typed +0 -0
- squidlor-0.1.0/tests/__init__.py +0 -0
- squidlor-0.1.0/tests/conftest.py +420 -0
- squidlor-0.1.0/tests/test_async.py +50 -0
- squidlor-0.1.0/tests/test_client.py +391 -0
- squidlor-0.1.0/tests/test_errors.py +128 -0
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
name: Publish to PyPI
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
release:
|
|
5
|
+
types: [published]
|
|
6
|
+
|
|
7
|
+
jobs:
|
|
8
|
+
publish:
|
|
9
|
+
name: Build and publish to PyPI
|
|
10
|
+
runs-on: ubuntu-latest
|
|
11
|
+
environment: pypi
|
|
12
|
+
permissions:
|
|
13
|
+
id-token: write
|
|
14
|
+
steps:
|
|
15
|
+
- name: Check out the repository
|
|
16
|
+
uses: actions/checkout@v4
|
|
17
|
+
|
|
18
|
+
- name: Set up Python
|
|
19
|
+
uses: actions/setup-python@v5
|
|
20
|
+
with:
|
|
21
|
+
python-version: "3.x"
|
|
22
|
+
|
|
23
|
+
- name: Install build tooling
|
|
24
|
+
run: python -m pip install --upgrade build
|
|
25
|
+
|
|
26
|
+
- name: Build the package
|
|
27
|
+
run: python -m build
|
|
28
|
+
|
|
29
|
+
- name: Publish to PyPI
|
|
30
|
+
uses: pypa/gh-action-pypi-publish@release/v1
|
squidlor-0.1.0/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 squidlor-python contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
squidlor-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,326 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: squidlor
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Python client for the Squidlor oracle REST API: on-chain price feeds, history, audit trails, provider scorecards, realtime prices and the daily price book.
|
|
5
|
+
Project-URL: Homepage, https://squidlor.com
|
|
6
|
+
Project-URL: Documentation, https://docs.squidlor.com/api
|
|
7
|
+
Project-URL: API reference, https://api.squidlor.com/aggregator/openapi.json
|
|
8
|
+
Author: squidlor-python contributors
|
|
9
|
+
License: MIT
|
|
10
|
+
License-File: LICENSE
|
|
11
|
+
Keywords: api client,arc,defi,oracle,price feeds,squidlor
|
|
12
|
+
Classifier: Development Status :: 4 - Beta
|
|
13
|
+
Classifier: Intended Audience :: Developers
|
|
14
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
15
|
+
Classifier: Programming Language :: Python :: 3
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
21
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
22
|
+
Classifier: Typing :: Typed
|
|
23
|
+
Requires-Python: >=3.9
|
|
24
|
+
Requires-Dist: httpx>=0.24
|
|
25
|
+
Provides-Extra: dev
|
|
26
|
+
Requires-Dist: build>=1.0; extra == 'dev'
|
|
27
|
+
Requires-Dist: pytest>=7; extra == 'dev'
|
|
28
|
+
Requires-Dist: respx>=0.20; extra == 'dev'
|
|
29
|
+
Requires-Dist: ruff>=0.4; extra == 'dev'
|
|
30
|
+
Requires-Dist: twine>=4.0; extra == 'dev'
|
|
31
|
+
Description-Content-Type: text/markdown
|
|
32
|
+
|
|
33
|
+
# squidlor — Python client for the Squidlor REST API
|
|
34
|
+
|
|
35
|
+
A typed Python client for the [Squidlor](https://squidlor.com) Aggregator
|
|
36
|
+
REST API: the on-chain oracle state of the Squidlor price feeds, exposed as
|
|
37
|
+
JSON over HTTPS.
|
|
38
|
+
|
|
39
|
+
Squidlor is a price-oracle network. Every price this client returns from the
|
|
40
|
+
feeds endpoints is derived from a live read of an on-chain `Aggregator`
|
|
41
|
+
contract — the same value a smart contract would have read at that moment —
|
|
42
|
+
plus the recorded history, per-source audit trail and provider scorecards
|
|
43
|
+
that the chain itself does not store.
|
|
44
|
+
|
|
45
|
+
- **Docs:** https://docs.squidlor.com/api
|
|
46
|
+
- **Machine-readable spec (OpenAPI 3.1):** https://api.squidlor.com/aggregator/openapi.json
|
|
47
|
+
- **License:** MIT
|
|
48
|
+
|
|
49
|
+
> **Never use this API as the price input to on-chain logic.** It is an
|
|
50
|
+
> HTTP endpoint: responses are cached for ~10 seconds and can be
|
|
51
|
+
> intercepted, none of which is true of an `eth_call`. For contracts, read
|
|
52
|
+
> the aggregator directly. This client is for dashboards, bots, analytics
|
|
53
|
+
> and agents.
|
|
54
|
+
|
|
55
|
+
## Installation
|
|
56
|
+
|
|
57
|
+
```bash
|
|
58
|
+
pip install squidlor
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
Requires Python 3.9+. The only runtime dependency is
|
|
62
|
+
[`httpx`](https://www.python-httpx.org/).
|
|
63
|
+
|
|
64
|
+
## Quick start
|
|
65
|
+
|
|
66
|
+
No API key is needed to start — the data is public on-chain state.
|
|
67
|
+
|
|
68
|
+
```python
|
|
69
|
+
from squidlor import SquidlorClient
|
|
70
|
+
|
|
71
|
+
with SquidlorClient() as client:
|
|
72
|
+
# Just the number: the on-chain median for a pair.
|
|
73
|
+
value = client.get_value("BTC/USD")
|
|
74
|
+
print(value.value, value.healthy_count, value.updated_at)
|
|
75
|
+
# Decimal('41652.6') 1 1796474967
|
|
76
|
+
|
|
77
|
+
# Every feed on the chain (Arc by default), with live medians.
|
|
78
|
+
for feed in client.list_feeds().feeds:
|
|
79
|
+
print(feed.pair, feed.median, feed.healthy_count, "/", feed.total_sources)
|
|
80
|
+
|
|
81
|
+
# Full state of one feed, including every source behind the median.
|
|
82
|
+
feed = client.get_feed("BTC/USD")
|
|
83
|
+
for source in feed.sources:
|
|
84
|
+
print(source.name, source.price, "stale:", source.is_stale)
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
Pairs are written `BTC/USD` (the client converts them to the `BTC_USD`
|
|
88
|
+
path form for you) and are case-insensitive. Prices the API returns as
|
|
89
|
+
decimal strings are exposed as `decimal.Decimal` — no float precision loss.
|
|
90
|
+
|
|
91
|
+
### With an API key
|
|
92
|
+
|
|
93
|
+
A key raises your rate limits and unlocks per-project usage stats. Get one
|
|
94
|
+
(free) at [build.squidlor.com](https://build.squidlor.com).
|
|
95
|
+
|
|
96
|
+
```python
|
|
97
|
+
client = SquidlorClient(api_key="sq_live_...")
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
| Tier | Requests/minute | History lookback |
|
|
101
|
+
|-------------|-----------------|------------------|
|
|
102
|
+
| No key | 30 (per IP) | 30 days |
|
|
103
|
+
| Free key | 300 | 30 days |
|
|
104
|
+
| Pro | 3,000 | unlimited |
|
|
105
|
+
|
|
106
|
+
After every call, `client.last_response` holds the rate-limit headers of
|
|
107
|
+
the most recent response (`rate_limit`, `rate_remaining`, `tier`,
|
|
108
|
+
`history_clamped`, …), so you can see which tier you were billed against
|
|
109
|
+
and whether a history window was clamped to your plan's lookback.
|
|
110
|
+
|
|
111
|
+
### Async
|
|
112
|
+
|
|
113
|
+
Every method also exists on `AsyncSquidlorClient` with the same signature:
|
|
114
|
+
|
|
115
|
+
```python
|
|
116
|
+
import asyncio
|
|
117
|
+
from squidlor import AsyncSquidlorClient
|
|
118
|
+
|
|
119
|
+
async def main():
|
|
120
|
+
async with AsyncSquidlorClient() as client:
|
|
121
|
+
value = await client.get_value("ETH/USD")
|
|
122
|
+
print(value.value)
|
|
123
|
+
|
|
124
|
+
asyncio.run(main())
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
## What you can read
|
|
128
|
+
|
|
129
|
+
### Feeds — on-chain aggregator state
|
|
130
|
+
|
|
131
|
+
```python
|
|
132
|
+
client.list_feeds() # every feed on a chain
|
|
133
|
+
client.list_feeds(5042) # chain by slug or numeric id
|
|
134
|
+
client.get_feed("BTC/USD") # full state, incl. every source
|
|
135
|
+
client.get_value("BTC/USD") # just the number
|
|
136
|
+
client.get_constituents("NVDA/USD") # live quotes behind the equity leg
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
`get_constituents` is for USD equity pairs only. It returns both the stored
|
|
140
|
+
on-chain leg and a live recomputation (`live_off_chain_median`) — what
|
|
141
|
+
Squidlor *would* publish right now. The live figure is **not** the on-chain
|
|
142
|
+
number and must never be substituted for it; the API repeats this in the
|
|
143
|
+
`warning` field of every response, and the model carries it through.
|
|
144
|
+
|
|
145
|
+
A feed whose aggregate cannot currently be read (too few healthy sources)
|
|
146
|
+
still appears in `list_feeds`, with `peek_error` set and `median` absent;
|
|
147
|
+
`get_value` raises `ServiceUnavailableError` instead. Always check the
|
|
148
|
+
status first — never treat a missing value as zero.
|
|
149
|
+
|
|
150
|
+
### History, candles and the audit trail
|
|
151
|
+
|
|
152
|
+
These are served from the recorded rounds, so they need a deployment with
|
|
153
|
+
history enabled (the production one has it). On the anonymous and free
|
|
154
|
+
tiers the window is clamped to 30 days — not rejected: you get the data
|
|
155
|
+
plus `X-History-Clamped: true`, visible as
|
|
156
|
+
`client.last_response.history_clamped`.
|
|
157
|
+
|
|
158
|
+
```python
|
|
159
|
+
history = client.get_history("BTC/USD", interval="1h", limit=100)
|
|
160
|
+
for point in history.points: # oldest-first
|
|
161
|
+
print(point.ts, point.median)
|
|
162
|
+
|
|
163
|
+
candles = client.get_ohlc("BTC/USD", interval="1h")
|
|
164
|
+
for candle in candles.candles:
|
|
165
|
+
print(candle.t, candle.open, candle.high, candle.low, candle.close)
|
|
166
|
+
|
|
167
|
+
# The audit trail: every source's price at each sampled round, its
|
|
168
|
+
# deviation from the median in basis points, and its staleness flag.
|
|
169
|
+
audit = client.get_audit("BTC/USD", flagged=True) # only anomalous rounds
|
|
170
|
+
for round_ in audit.rounds: # newest-first
|
|
171
|
+
print(round_.ts, round_.median, round_.flag_reasons)
|
|
172
|
+
```
|
|
173
|
+
|
|
174
|
+
`from_` / `to` accept unix seconds, unix milliseconds, ISO-8601 strings or
|
|
175
|
+
`datetime` objects.
|
|
176
|
+
|
|
177
|
+
### Point-in-time reads and proofs
|
|
178
|
+
|
|
179
|
+
```python
|
|
180
|
+
at = client.get_price_at("BTC/USD", at=1785973410, tolerance=300)
|
|
181
|
+
print(at.offset_seconds) # how far the observation sits
|
|
182
|
+
print(at.observation.median) # ...and what every source said
|
|
183
|
+
|
|
184
|
+
proof = client.get_price_proof("BTC/USD", at=1785973410)
|
|
185
|
+
print(proof.root, proof.leaf, proof.proof) # verify inclusion yourself
|
|
186
|
+
```
|
|
187
|
+
|
|
188
|
+
Recording is sampled, so an exact-timestamp answer does not exist and the
|
|
189
|
+
endpoint never pretends it does: you get the nearest observation with its
|
|
190
|
+
distance attached. Outside `tolerance` the API answers 404
|
|
191
|
+
`NO_OBSERVATION`. Proofs are anchored per closed period; an observation in
|
|
192
|
+
the still-open period is not provable yet, and the endpoint says so rather
|
|
193
|
+
than returning an unproven answer.
|
|
194
|
+
|
|
195
|
+
### Provider scorecards
|
|
196
|
+
|
|
197
|
+
```python
|
|
198
|
+
cards = client.list_providers() # default: last 7 days
|
|
199
|
+
for card in cards.providers:
|
|
200
|
+
print(card.name, card.fresh_rate, card.deviation)
|
|
201
|
+
|
|
202
|
+
card = client.get_provider("pyth", pair="BTC/USD") # one source
|
|
203
|
+
```
|
|
204
|
+
|
|
205
|
+
`fresh_rate` is the share of sampled rounds in which the source was inside
|
|
206
|
+
its staleness window — the closest thing here to uptime. Deviation is
|
|
207
|
+
measured against the round median, not against truth.
|
|
208
|
+
|
|
209
|
+
### Realtime prices (off-chain, 1 second)
|
|
210
|
+
|
|
211
|
+
A median across live venue WebSockets, republished every second. **This is
|
|
212
|
+
not the value a contract reads** — use the feeds endpoints for anything
|
|
213
|
+
that must agree with on-chain state, and this feed for charts, tickers and
|
|
214
|
+
alerts. Every tick carries `age_ms`/`stale` (on list/single reads) so you
|
|
215
|
+
never have to guess how current a number is.
|
|
216
|
+
|
|
217
|
+
```python
|
|
218
|
+
prices = client.list_prices(["BTC", "ETH"])
|
|
219
|
+
tick = client.get_price("BTC")
|
|
220
|
+
print(tick.price, tick.venues) # the venue readings behind it
|
|
221
|
+
|
|
222
|
+
# Server-Sent Events: a snapshot frame, then one tick per symbol/second.
|
|
223
|
+
for message in client.stream_prices(symbols=["BTC"]):
|
|
224
|
+
if message.event == "tick":
|
|
225
|
+
print(message.data.symbol, message.data.price)
|
|
226
|
+
```
|
|
227
|
+
|
|
228
|
+
At most 5 concurrent streams per caller — filter with `symbols` rather
|
|
229
|
+
than opening several connections.
|
|
230
|
+
|
|
231
|
+
### Daily price book
|
|
232
|
+
|
|
233
|
+
One price per asset per 00:00 UTC boundary, kept permanently. The
|
|
234
|
+
settlement shape: exact day in, one price out — it never substitutes a
|
|
235
|
+
neighbouring day.
|
|
236
|
+
|
|
237
|
+
```python
|
|
238
|
+
coverage = client.daily_coverage() # check for gaps before charting
|
|
239
|
+
board = client.daily_board(day="2026-08-27", asset_class="crypto")
|
|
240
|
+
series = client.daily_series("BTC", from_="2026-01-01")
|
|
241
|
+
snapshot = client.daily_price("NVDA", "2026-08-27")
|
|
242
|
+
print(snapshot.price.price, snapshot.price.source)
|
|
243
|
+
```
|
|
244
|
+
|
|
245
|
+
Read a row's `source` before trusting it for settlement: `price-stream`
|
|
246
|
+
and `equity-median` rows are live captures, `onchain:` rows come from the
|
|
247
|
+
aggregator, `backfill:` rows are external daily candles seeded for days
|
|
248
|
+
that predate the service.
|
|
249
|
+
|
|
250
|
+
### Randomness and events
|
|
251
|
+
|
|
252
|
+
```python
|
|
253
|
+
rand = client.get_randomness() # 404 on chains without a contract
|
|
254
|
+
for req in rand.recent_requests:
|
|
255
|
+
print(req.sequence_number, req.fulfilled, req.randomness)
|
|
256
|
+
|
|
257
|
+
events = client.list_events()
|
|
258
|
+
event = client.get_event(events.events[0].event_id)
|
|
259
|
+
print(event.question, event.aggregated.outcome)
|
|
260
|
+
```
|
|
261
|
+
|
|
262
|
+
### Legacy routes
|
|
263
|
+
|
|
264
|
+
The deprecated query-param routes (`/v1/feeds?chainId=`, `/v1/randomness`,
|
|
265
|
+
`/v1/events`) are covered by `list_feeds_legacy`, `get_feed_legacy`,
|
|
266
|
+
`get_value_legacy`, `get_randomness_legacy`, `list_events_legacy` and
|
|
267
|
+
`get_event_legacy`. New integrations should use the chain-scoped methods:
|
|
268
|
+
unlike the legacy guard, the scoped routes return 404 for an unknown chain
|
|
269
|
+
instead of silently serving another chain's prices.
|
|
270
|
+
|
|
271
|
+
## Errors
|
|
272
|
+
|
|
273
|
+
Every HTTP failure raises `SquidlorApiError` (mirroring the official
|
|
274
|
+
TypeScript SDK), carrying `status`, `code` and `retry_after_sec`:
|
|
275
|
+
|
|
276
|
+
```python
|
|
277
|
+
from squidlor import SquidlorClient, SquidlorApiError, RateLimitError
|
|
278
|
+
|
|
279
|
+
client = SquidlorClient()
|
|
280
|
+
try:
|
|
281
|
+
client.get_value("BTC/USD")
|
|
282
|
+
except RateLimitError as err:
|
|
283
|
+
print("slow down for", err.retry_after_sec, "seconds")
|
|
284
|
+
except SquidlorApiError as err:
|
|
285
|
+
print(err.status, err.code, err.message)
|
|
286
|
+
```
|
|
287
|
+
|
|
288
|
+
Subclasses: `AuthenticationError` (401), `NotFoundError` (404),
|
|
289
|
+
`RateLimitError` (429), `ServiceUnavailableError` (503). Connection-level
|
|
290
|
+
failures raise `SquidlorTransportError`. Many route-guard errors carry only
|
|
291
|
+
a human-readable `message` and no `code` — switch on `status`, not on the
|
|
292
|
+
message text.
|
|
293
|
+
|
|
294
|
+
The client retries 429/5xx responses and transport errors with exponential
|
|
295
|
+
backoff (honouring `Retry-After`); tune with `max_retries` and
|
|
296
|
+
`backoff_factor`, or disable with `max_retries=0`.
|
|
297
|
+
|
|
298
|
+
**Poll politely.** Responses are cached server-side for 10 seconds and
|
|
299
|
+
feeds only change when an update lands on-chain. Polling every second gets
|
|
300
|
+
you the same bytes ten times and burns your quota; once every 10–30
|
|
301
|
+
seconds is plenty for a live dashboard. Use `updated_at` to detect real
|
|
302
|
+
change.
|
|
303
|
+
|
|
304
|
+
## Development
|
|
305
|
+
|
|
306
|
+
```bash
|
|
307
|
+
git clone <this repo> && cd squidlor-python-client
|
|
308
|
+
python -m venv .venv && source .venv/bin/activate
|
|
309
|
+
pip install -e ".[dev]"
|
|
310
|
+
pytest # unit tests, HTTP mocked with respx — no network needed
|
|
311
|
+
ruff check .
|
|
312
|
+
python -m build # sdist + wheel
|
|
313
|
+
```
|
|
314
|
+
|
|
315
|
+
A runnable end-to-end example against the live API lives in
|
|
316
|
+
[`examples/quickstart.py`](examples/quickstart.py).
|
|
317
|
+
|
|
318
|
+
## Notes on coverage
|
|
319
|
+
|
|
320
|
+
Method names map one-to-one onto the OpenAPI operations served at
|
|
321
|
+
`/openapi.json`, plus the three documented endpoints that page describes
|
|
322
|
+
but the served spec does not list (`/at`, `/at/proof`, `/providers`). For
|
|
323
|
+
`/at`, the requested moment is sent as the `at` query parameter (with
|
|
324
|
+
`tolerance` in seconds, as documented); the point-in-time, proof and
|
|
325
|
+
scorecard models keep the full response payload in `.raw` so nothing the
|
|
326
|
+
API returns is lost while those shapes settle.
|
squidlor-0.1.0/README.md
ADDED
|
@@ -0,0 +1,294 @@
|
|
|
1
|
+
# squidlor — Python client for the Squidlor REST API
|
|
2
|
+
|
|
3
|
+
A typed Python client for the [Squidlor](https://squidlor.com) Aggregator
|
|
4
|
+
REST API: the on-chain oracle state of the Squidlor price feeds, exposed as
|
|
5
|
+
JSON over HTTPS.
|
|
6
|
+
|
|
7
|
+
Squidlor is a price-oracle network. Every price this client returns from the
|
|
8
|
+
feeds endpoints is derived from a live read of an on-chain `Aggregator`
|
|
9
|
+
contract — the same value a smart contract would have read at that moment —
|
|
10
|
+
plus the recorded history, per-source audit trail and provider scorecards
|
|
11
|
+
that the chain itself does not store.
|
|
12
|
+
|
|
13
|
+
- **Docs:** https://docs.squidlor.com/api
|
|
14
|
+
- **Machine-readable spec (OpenAPI 3.1):** https://api.squidlor.com/aggregator/openapi.json
|
|
15
|
+
- **License:** MIT
|
|
16
|
+
|
|
17
|
+
> **Never use this API as the price input to on-chain logic.** It is an
|
|
18
|
+
> HTTP endpoint: responses are cached for ~10 seconds and can be
|
|
19
|
+
> intercepted, none of which is true of an `eth_call`. For contracts, read
|
|
20
|
+
> the aggregator directly. This client is for dashboards, bots, analytics
|
|
21
|
+
> and agents.
|
|
22
|
+
|
|
23
|
+
## Installation
|
|
24
|
+
|
|
25
|
+
```bash
|
|
26
|
+
pip install squidlor
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
Requires Python 3.9+. The only runtime dependency is
|
|
30
|
+
[`httpx`](https://www.python-httpx.org/).
|
|
31
|
+
|
|
32
|
+
## Quick start
|
|
33
|
+
|
|
34
|
+
No API key is needed to start — the data is public on-chain state.
|
|
35
|
+
|
|
36
|
+
```python
|
|
37
|
+
from squidlor import SquidlorClient
|
|
38
|
+
|
|
39
|
+
with SquidlorClient() as client:
|
|
40
|
+
# Just the number: the on-chain median for a pair.
|
|
41
|
+
value = client.get_value("BTC/USD")
|
|
42
|
+
print(value.value, value.healthy_count, value.updated_at)
|
|
43
|
+
# Decimal('41652.6') 1 1796474967
|
|
44
|
+
|
|
45
|
+
# Every feed on the chain (Arc by default), with live medians.
|
|
46
|
+
for feed in client.list_feeds().feeds:
|
|
47
|
+
print(feed.pair, feed.median, feed.healthy_count, "/", feed.total_sources)
|
|
48
|
+
|
|
49
|
+
# Full state of one feed, including every source behind the median.
|
|
50
|
+
feed = client.get_feed("BTC/USD")
|
|
51
|
+
for source in feed.sources:
|
|
52
|
+
print(source.name, source.price, "stale:", source.is_stale)
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
Pairs are written `BTC/USD` (the client converts them to the `BTC_USD`
|
|
56
|
+
path form for you) and are case-insensitive. Prices the API returns as
|
|
57
|
+
decimal strings are exposed as `decimal.Decimal` — no float precision loss.
|
|
58
|
+
|
|
59
|
+
### With an API key
|
|
60
|
+
|
|
61
|
+
A key raises your rate limits and unlocks per-project usage stats. Get one
|
|
62
|
+
(free) at [build.squidlor.com](https://build.squidlor.com).
|
|
63
|
+
|
|
64
|
+
```python
|
|
65
|
+
client = SquidlorClient(api_key="sq_live_...")
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
| Tier | Requests/minute | History lookback |
|
|
69
|
+
|-------------|-----------------|------------------|
|
|
70
|
+
| No key | 30 (per IP) | 30 days |
|
|
71
|
+
| Free key | 300 | 30 days |
|
|
72
|
+
| Pro | 3,000 | unlimited |
|
|
73
|
+
|
|
74
|
+
After every call, `client.last_response` holds the rate-limit headers of
|
|
75
|
+
the most recent response (`rate_limit`, `rate_remaining`, `tier`,
|
|
76
|
+
`history_clamped`, …), so you can see which tier you were billed against
|
|
77
|
+
and whether a history window was clamped to your plan's lookback.
|
|
78
|
+
|
|
79
|
+
### Async
|
|
80
|
+
|
|
81
|
+
Every method also exists on `AsyncSquidlorClient` with the same signature:
|
|
82
|
+
|
|
83
|
+
```python
|
|
84
|
+
import asyncio
|
|
85
|
+
from squidlor import AsyncSquidlorClient
|
|
86
|
+
|
|
87
|
+
async def main():
|
|
88
|
+
async with AsyncSquidlorClient() as client:
|
|
89
|
+
value = await client.get_value("ETH/USD")
|
|
90
|
+
print(value.value)
|
|
91
|
+
|
|
92
|
+
asyncio.run(main())
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
## What you can read
|
|
96
|
+
|
|
97
|
+
### Feeds — on-chain aggregator state
|
|
98
|
+
|
|
99
|
+
```python
|
|
100
|
+
client.list_feeds() # every feed on a chain
|
|
101
|
+
client.list_feeds(5042) # chain by slug or numeric id
|
|
102
|
+
client.get_feed("BTC/USD") # full state, incl. every source
|
|
103
|
+
client.get_value("BTC/USD") # just the number
|
|
104
|
+
client.get_constituents("NVDA/USD") # live quotes behind the equity leg
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
`get_constituents` is for USD equity pairs only. It returns both the stored
|
|
108
|
+
on-chain leg and a live recomputation (`live_off_chain_median`) — what
|
|
109
|
+
Squidlor *would* publish right now. The live figure is **not** the on-chain
|
|
110
|
+
number and must never be substituted for it; the API repeats this in the
|
|
111
|
+
`warning` field of every response, and the model carries it through.
|
|
112
|
+
|
|
113
|
+
A feed whose aggregate cannot currently be read (too few healthy sources)
|
|
114
|
+
still appears in `list_feeds`, with `peek_error` set and `median` absent;
|
|
115
|
+
`get_value` raises `ServiceUnavailableError` instead. Always check the
|
|
116
|
+
status first — never treat a missing value as zero.
|
|
117
|
+
|
|
118
|
+
### History, candles and the audit trail
|
|
119
|
+
|
|
120
|
+
These are served from the recorded rounds, so they need a deployment with
|
|
121
|
+
history enabled (the production one has it). On the anonymous and free
|
|
122
|
+
tiers the window is clamped to 30 days — not rejected: you get the data
|
|
123
|
+
plus `X-History-Clamped: true`, visible as
|
|
124
|
+
`client.last_response.history_clamped`.
|
|
125
|
+
|
|
126
|
+
```python
|
|
127
|
+
history = client.get_history("BTC/USD", interval="1h", limit=100)
|
|
128
|
+
for point in history.points: # oldest-first
|
|
129
|
+
print(point.ts, point.median)
|
|
130
|
+
|
|
131
|
+
candles = client.get_ohlc("BTC/USD", interval="1h")
|
|
132
|
+
for candle in candles.candles:
|
|
133
|
+
print(candle.t, candle.open, candle.high, candle.low, candle.close)
|
|
134
|
+
|
|
135
|
+
# The audit trail: every source's price at each sampled round, its
|
|
136
|
+
# deviation from the median in basis points, and its staleness flag.
|
|
137
|
+
audit = client.get_audit("BTC/USD", flagged=True) # only anomalous rounds
|
|
138
|
+
for round_ in audit.rounds: # newest-first
|
|
139
|
+
print(round_.ts, round_.median, round_.flag_reasons)
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
`from_` / `to` accept unix seconds, unix milliseconds, ISO-8601 strings or
|
|
143
|
+
`datetime` objects.
|
|
144
|
+
|
|
145
|
+
### Point-in-time reads and proofs
|
|
146
|
+
|
|
147
|
+
```python
|
|
148
|
+
at = client.get_price_at("BTC/USD", at=1785973410, tolerance=300)
|
|
149
|
+
print(at.offset_seconds) # how far the observation sits
|
|
150
|
+
print(at.observation.median) # ...and what every source said
|
|
151
|
+
|
|
152
|
+
proof = client.get_price_proof("BTC/USD", at=1785973410)
|
|
153
|
+
print(proof.root, proof.leaf, proof.proof) # verify inclusion yourself
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
Recording is sampled, so an exact-timestamp answer does not exist and the
|
|
157
|
+
endpoint never pretends it does: you get the nearest observation with its
|
|
158
|
+
distance attached. Outside `tolerance` the API answers 404
|
|
159
|
+
`NO_OBSERVATION`. Proofs are anchored per closed period; an observation in
|
|
160
|
+
the still-open period is not provable yet, and the endpoint says so rather
|
|
161
|
+
than returning an unproven answer.
|
|
162
|
+
|
|
163
|
+
### Provider scorecards
|
|
164
|
+
|
|
165
|
+
```python
|
|
166
|
+
cards = client.list_providers() # default: last 7 days
|
|
167
|
+
for card in cards.providers:
|
|
168
|
+
print(card.name, card.fresh_rate, card.deviation)
|
|
169
|
+
|
|
170
|
+
card = client.get_provider("pyth", pair="BTC/USD") # one source
|
|
171
|
+
```
|
|
172
|
+
|
|
173
|
+
`fresh_rate` is the share of sampled rounds in which the source was inside
|
|
174
|
+
its staleness window — the closest thing here to uptime. Deviation is
|
|
175
|
+
measured against the round median, not against truth.
|
|
176
|
+
|
|
177
|
+
### Realtime prices (off-chain, 1 second)
|
|
178
|
+
|
|
179
|
+
A median across live venue WebSockets, republished every second. **This is
|
|
180
|
+
not the value a contract reads** — use the feeds endpoints for anything
|
|
181
|
+
that must agree with on-chain state, and this feed for charts, tickers and
|
|
182
|
+
alerts. Every tick carries `age_ms`/`stale` (on list/single reads) so you
|
|
183
|
+
never have to guess how current a number is.
|
|
184
|
+
|
|
185
|
+
```python
|
|
186
|
+
prices = client.list_prices(["BTC", "ETH"])
|
|
187
|
+
tick = client.get_price("BTC")
|
|
188
|
+
print(tick.price, tick.venues) # the venue readings behind it
|
|
189
|
+
|
|
190
|
+
# Server-Sent Events: a snapshot frame, then one tick per symbol/second.
|
|
191
|
+
for message in client.stream_prices(symbols=["BTC"]):
|
|
192
|
+
if message.event == "tick":
|
|
193
|
+
print(message.data.symbol, message.data.price)
|
|
194
|
+
```
|
|
195
|
+
|
|
196
|
+
At most 5 concurrent streams per caller — filter with `symbols` rather
|
|
197
|
+
than opening several connections.
|
|
198
|
+
|
|
199
|
+
### Daily price book
|
|
200
|
+
|
|
201
|
+
One price per asset per 00:00 UTC boundary, kept permanently. The
|
|
202
|
+
settlement shape: exact day in, one price out — it never substitutes a
|
|
203
|
+
neighbouring day.
|
|
204
|
+
|
|
205
|
+
```python
|
|
206
|
+
coverage = client.daily_coverage() # check for gaps before charting
|
|
207
|
+
board = client.daily_board(day="2026-08-27", asset_class="crypto")
|
|
208
|
+
series = client.daily_series("BTC", from_="2026-01-01")
|
|
209
|
+
snapshot = client.daily_price("NVDA", "2026-08-27")
|
|
210
|
+
print(snapshot.price.price, snapshot.price.source)
|
|
211
|
+
```
|
|
212
|
+
|
|
213
|
+
Read a row's `source` before trusting it for settlement: `price-stream`
|
|
214
|
+
and `equity-median` rows are live captures, `onchain:` rows come from the
|
|
215
|
+
aggregator, `backfill:` rows are external daily candles seeded for days
|
|
216
|
+
that predate the service.
|
|
217
|
+
|
|
218
|
+
### Randomness and events
|
|
219
|
+
|
|
220
|
+
```python
|
|
221
|
+
rand = client.get_randomness() # 404 on chains without a contract
|
|
222
|
+
for req in rand.recent_requests:
|
|
223
|
+
print(req.sequence_number, req.fulfilled, req.randomness)
|
|
224
|
+
|
|
225
|
+
events = client.list_events()
|
|
226
|
+
event = client.get_event(events.events[0].event_id)
|
|
227
|
+
print(event.question, event.aggregated.outcome)
|
|
228
|
+
```
|
|
229
|
+
|
|
230
|
+
### Legacy routes
|
|
231
|
+
|
|
232
|
+
The deprecated query-param routes (`/v1/feeds?chainId=`, `/v1/randomness`,
|
|
233
|
+
`/v1/events`) are covered by `list_feeds_legacy`, `get_feed_legacy`,
|
|
234
|
+
`get_value_legacy`, `get_randomness_legacy`, `list_events_legacy` and
|
|
235
|
+
`get_event_legacy`. New integrations should use the chain-scoped methods:
|
|
236
|
+
unlike the legacy guard, the scoped routes return 404 for an unknown chain
|
|
237
|
+
instead of silently serving another chain's prices.
|
|
238
|
+
|
|
239
|
+
## Errors
|
|
240
|
+
|
|
241
|
+
Every HTTP failure raises `SquidlorApiError` (mirroring the official
|
|
242
|
+
TypeScript SDK), carrying `status`, `code` and `retry_after_sec`:
|
|
243
|
+
|
|
244
|
+
```python
|
|
245
|
+
from squidlor import SquidlorClient, SquidlorApiError, RateLimitError
|
|
246
|
+
|
|
247
|
+
client = SquidlorClient()
|
|
248
|
+
try:
|
|
249
|
+
client.get_value("BTC/USD")
|
|
250
|
+
except RateLimitError as err:
|
|
251
|
+
print("slow down for", err.retry_after_sec, "seconds")
|
|
252
|
+
except SquidlorApiError as err:
|
|
253
|
+
print(err.status, err.code, err.message)
|
|
254
|
+
```
|
|
255
|
+
|
|
256
|
+
Subclasses: `AuthenticationError` (401), `NotFoundError` (404),
|
|
257
|
+
`RateLimitError` (429), `ServiceUnavailableError` (503). Connection-level
|
|
258
|
+
failures raise `SquidlorTransportError`. Many route-guard errors carry only
|
|
259
|
+
a human-readable `message` and no `code` — switch on `status`, not on the
|
|
260
|
+
message text.
|
|
261
|
+
|
|
262
|
+
The client retries 429/5xx responses and transport errors with exponential
|
|
263
|
+
backoff (honouring `Retry-After`); tune with `max_retries` and
|
|
264
|
+
`backoff_factor`, or disable with `max_retries=0`.
|
|
265
|
+
|
|
266
|
+
**Poll politely.** Responses are cached server-side for 10 seconds and
|
|
267
|
+
feeds only change when an update lands on-chain. Polling every second gets
|
|
268
|
+
you the same bytes ten times and burns your quota; once every 10–30
|
|
269
|
+
seconds is plenty for a live dashboard. Use `updated_at` to detect real
|
|
270
|
+
change.
|
|
271
|
+
|
|
272
|
+
## Development
|
|
273
|
+
|
|
274
|
+
```bash
|
|
275
|
+
git clone <this repo> && cd squidlor-python-client
|
|
276
|
+
python -m venv .venv && source .venv/bin/activate
|
|
277
|
+
pip install -e ".[dev]"
|
|
278
|
+
pytest # unit tests, HTTP mocked with respx — no network needed
|
|
279
|
+
ruff check .
|
|
280
|
+
python -m build # sdist + wheel
|
|
281
|
+
```
|
|
282
|
+
|
|
283
|
+
A runnable end-to-end example against the live API lives in
|
|
284
|
+
[`examples/quickstart.py`](examples/quickstart.py).
|
|
285
|
+
|
|
286
|
+
## Notes on coverage
|
|
287
|
+
|
|
288
|
+
Method names map one-to-one onto the OpenAPI operations served at
|
|
289
|
+
`/openapi.json`, plus the three documented endpoints that page describes
|
|
290
|
+
but the served spec does not list (`/at`, `/at/proof`, `/providers`). For
|
|
291
|
+
`/at`, the requested moment is sent as the `at` query parameter (with
|
|
292
|
+
`tolerance` in seconds, as documented); the point-in-time, proof and
|
|
293
|
+
scorecard models keep the full response payload in `.raw` so nothing the
|
|
294
|
+
API returns is lost while those shapes settle.
|