Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ tests/*
!tests/_mock_api.py
!tests/test_timestamps.py
!tests/test_spec_fixes.py
!tests/test_slug_encoding.py
!tests/test_websocket_full_depth.py
!tests/test_webhooks.py
!tests/test_webhook_signature.py
Expand Down
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,8 @@ deployments in the SDK, mainnet (`client.lighter`) and Robinhood Chain
`OrdersResource`, and Hyperliquid core keeps `LiquidationsResource`.

### Fixed
- `hip4.outcomes.get_by_slug()` URL-encodes the slug. Slugs with spaces,
colons, `#` or `/` reached the wrong route before.
- `trades.list()` and `alist()` send `cursor` back exactly as the API
returned it. A trades cursor is an opaque string such as
`"1790640000578_218303497631402"` (Lighter adds a third part), and it was
Expand Down
5 changes: 3 additions & 2 deletions oxarchive/resources/outcomes.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from __future__ import annotations

from typing import Any, List, Optional
from urllib.parse import quote

from ..http import HttpClient
from ..types import CursorResponse, Hip4OutcomeAggregate, Hip4Question, ResponseMeta
Expand Down Expand Up @@ -96,12 +97,12 @@ def get_by_slug(self, slug: str) -> Hip4OutcomeAggregate:
:class:`Hip4OutcomeAggregate` with ``aggregated_oi`` populated, like
:py:meth:`get`.
"""
data = self._http.get(f"{self._base_path}/outcomes/by-slug/{slug}")
data = self._http.get(f"{self._base_path}/outcomes/by-slug/{quote(slug, safe='')}")
return Hip4OutcomeAggregate.model_validate(data["data"])

async def aget_by_slug(self, slug: str) -> Hip4OutcomeAggregate:
"""Async version of get_by_slug()."""
data = await self._http.aget(f"{self._base_path}/outcomes/by-slug/{slug}")
data = await self._http.aget(f"{self._base_path}/outcomes/by-slug/{quote(slug, safe='')}")
return Hip4OutcomeAggregate.model_validate(data["data"])


Expand Down
21 changes: 21 additions & 0 deletions tests/test_slug_encoding.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
"""HIP-4 outcome by slug: the slug is URL-encoded as one path segment."""

import asyncio

from tests._mock_api import envelope, mock_client

SLUG = "june-fed-rate-change-no change: #2/3"
ENCODED = "/v1/hyperliquid/hip4/outcomes/by-slug/june-fed-rate-change-no%20change%3A%20%232%2F3"


def test_get_by_slug_encodes_the_slug() -> None:
client, api = mock_client(lambda p, q: envelope({"outcome_id": 1, "sides": []}))
try:
client.hyperliquid.hip4.outcomes.get_by_slug(SLUG)
except Exception:
pass # response parsing is not under test; the request path is
try:
asyncio.run(client.hyperliquid.hip4.outcomes.aget_by_slug(SLUG))
except Exception:
pass
assert api.raw_paths[:2] == [ENCODED, ENCODED]
Loading