Skip to content

Commit f8bbb7e

Browse files
create spotMetaAndAssetCtxs function (#42)
1 parent 37952fa commit f8bbb7e

File tree

2 files changed

+55
-8
lines changed

2 files changed

+55
-8
lines changed

hyperliquid/info.py

Lines changed: 52 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from hyperliquid.api import API
2-
from hyperliquid.utils.types import Any, Callable, Meta, SpotMeta, Optional, Subscription, cast, Cloid
2+
from hyperliquid.utils.types import Any, Callable, Meta, SpotMeta, SpotMetaAndAssetCtxs, Optional, Subscription, cast, Cloid
33
from hyperliquid.websocket_manager import WebsocketManager
44

55

@@ -179,24 +179,68 @@ def spot_meta(self) -> SpotMeta:
179179
180180
Returns:
181181
{
182-
tokens: [
182+
universe: [
183183
{
184+
tokens: [int, int],
184185
name: str,
185-
szDecimals: int,
186-
weiDecimals: int
186+
index: int,
187+
isCanonical: bool
187188
},
188189
...
189-
],
190-
universe: [
190+
]
191+
tokens: [
191192
{
192193
name: str,
193-
tokens: [int, int]
194+
szDecimals: int,
195+
weiDecimals: int,
196+
index: int,
197+
tokenId: str,
198+
isCanonical: bool
194199
},
195200
...
196-
]
201+
],
197202
}
198203
"""
199204
return cast(SpotMeta, self.post("/info", {"type": "spotMeta"}))
205+
206+
def spot_meta_and_asset_ctxs(self) -> SpotMetaAndAssetCtxs:
207+
"""Retrieve exchange spot asset contexts
208+
209+
POST /info
210+
211+
Returns:
212+
[
213+
{
214+
universe: [
215+
{
216+
name: str,
217+
tokens: [int, int]
218+
}
219+
...
220+
],
221+
tokens: [
222+
{
223+
name: str,
224+
szDecimals: int,
225+
weiDecimals int
226+
},
227+
...
228+
]
229+
},
230+
[
231+
{
232+
dayNtlVlm: float,
233+
markPx: float,
234+
midPx: float,
235+
prevDayPx: float,
236+
circulatingSupply: float,
237+
coin: str
238+
}
239+
...
240+
]
241+
]
242+
"""
243+
return cast(SpotMetaAndAssetCtxs, self.post("/info", {"type": "spotMetaAndAssetCtxs"}))
200244

201245
def funding_history(self, coin: str, startTime: int, endTime: Optional[int] = None) -> Any:
202246
"""Retrieve funding history for a given coin

hyperliquid/utils/types.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@
2929
)
3030
SpotMeta = TypedDict("SpotMeta", {"universe": List[SpotAssetInfo], "tokens": List[SpotTokenInfo]})
3131

32+
SpotAssetCtx = TypedDict("SpotAssetCtx", {"dayNtlVlm": str, "markPx": str, "midPx": Optional[str], "prevDayPx": str, "circulatingSupply": str, "coin": str})
33+
SpotMetaAndAssetCtxs = Tuple[SpotMeta, List[SpotAssetCtx]]
34+
3235
AllMidsSubscription = TypedDict("AllMidsSubscription", {"type": Literal["allMids"]})
3336
L2BookSubscription = TypedDict("L2BookSubscription", {"type": Literal["l2Book"], "coin": str})
3437
TradesSubscription = TypedDict("TradesSubscription", {"type": Literal["trades"], "coin": str})

0 commit comments

Comments
 (0)