Hyperliquid

Hyperliquid blockchain integration adapter.

This subpackage provides an instrument provider, data and execution clients, configurations, and constants for connecting to and interacting with Hyperliquid’s API.

For convenience, the most commonly used symbols are re-exported at the subpackage’s top level, so downstream code can simply import from nautilus_trader.adapters.hyperliquid.

class HyperliquidAllDexsAssetCtxs

Bases: Data

Python data object for normalized Hyperliquid allDexsAssetCtxs payloads.

property ts_event: int

int

UNIX timestamp (nanoseconds) when the data event occurred.

Return type:

int

Type:

Data.ts_event

property ts_init: int

int

UNIX timestamp (nanoseconds) when the instance was created.

Return type:

int

Type:

Data.ts_init

static from_pyo3(pyo3_all_ctxs: Any) HyperliquidAllDexsAssetCtxs
classmethod fully_qualified_name(cls) str

Return the fully qualified name for the Data class.

Return type:

str

classmethod is_signal(cls, str name='') bool

Determine if the current class is a signal type, optionally checking for a specific signal name.

Parameters:

name (str, optional) – The specific signal name to check. If name not provided or if an empty string is passed, the method checks whether the class name indicates a general signal type. If name is provided, the method checks if the class name corresponds to that specific signal.

Returns:

True if the class name matches the signal type or the specific signal name, otherwise False.

Return type:

bool

class HyperliquidAllMids

Bases: Data

Python data object for Hyperliquid allMids payload.

Notes

allMids uses coin -> instrument mapping during decoding. Ensure the instrument provider is configured with load_all=True (or sufficient load_ids) so incoming coins can be mapped to InstrumentId.

property ts_event: int

int

UNIX timestamp (nanoseconds) when the data event occurred.

Return type:

int

Type:

Data.ts_event

property ts_init: int

int

UNIX timestamp (nanoseconds) when the instance was created.

Return type:

int

Type:

Data.ts_init

static from_pyo3(pyo3_all_mids: Any) HyperliquidAllMids
classmethod fully_qualified_name(cls) str

Return the fully qualified name for the Data class.

Return type:

str

classmethod is_signal(cls, str name='') bool

Determine if the current class is a signal type, optionally checking for a specific signal name.

Parameters:

name (str, optional) – The specific signal name to check. If name not provided or if an empty string is passed, the method checks whether the class name indicates a general signal type. If name is provided, the method checks if the class name corresponds to that specific signal.

Returns:

True if the class name matches the signal type or the specific signal name, otherwise False.

Return type:

bool

class HyperliquidDataClientConfig

Bases: LiveDataClientConfig

Configuration for HyperliquidDataClient instances.

Parameters:
  • product_types (tuple[HyperliquidProductType, ...], optional) – The Hyperliquid product types to load for the client instrument provider. If None then the instrument provider defaults are used.

  • environment (HyperliquidEnvironment, optional) – The Hyperliquid environment for the client (MAINNET or TESTNET). If None then defaults to MAINNET.

  • base_url_ws (str, optional) – The WebSocket client custom endpoint override.

  • proxy_url (str, optional) – Optional proxy URL for HTTP and WebSocket transports.

  • http_timeout_secs (PositiveInt, default 10) – The timeout (seconds) for HTTP requests.

product_types: tuple[HyperliquidProductType, ...] | None
environment: HyperliquidEnvironment | None
base_url_ws: str | None
proxy_url: str | None
transport_backend: TransportBackend | None
http_timeout_secs: Annotated[int, msgspec.Meta(gt=0)]
dict() dict[str, Any]

Return a dictionary representation of the configuration.

Return type:

dict[str, Any]

classmethod fully_qualified_name() str

Return the fully qualified name for the NautilusConfig class.

Return type:

str

handle_revised_bars: bool
property id: str

Return the hashed identifier for the configuration.

Return type:

str

instrument_provider: InstrumentProviderConfig
json() bytes

Return serialized JSON encoded bytes.

Return type:

bytes

json_primitives() dict[str, Any]

Return a dictionary representation of the configuration with JSON primitive types as values.

Return type:

dict[str, Any]

classmethod json_schema() dict[str, Any]

Generate a JSON schema for this configuration class.

Return type:

dict[str, Any]

classmethod parse(raw: bytes | str) Any

Return a decoded object of the given cls.

Parameters:
  • cls (type) – The type to decode to.

  • raw (bytes or str) – The raw bytes or JSON string to decode.

Return type:

Any

routing: RoutingConfig
validate() bool

Return whether the configuration can be represented as valid JSON.

Return type:

bool

class HyperliquidDexAssetCtx

Bases: object

One normalized allDexsAssetCtxs entry for a single instrument.

static from_pyo3(pyo3_entry: Any) HyperliquidDexAssetCtx
class HyperliquidExecClientConfig

Bases: LiveExecClientConfig

Configuration for HyperliquidExecutionClient instances.

Parameters:
  • private_key (str, optional) – The Hyperliquid EVM private key. If None then will source the HYPERLIQUID_PK or HYPERLIQUID_TESTNET_PK environment variable based on environment.

  • vault_address (str, optional) – The vault address for vault trading. If None then will source the HYPERLIQUID_VAULT or HYPERLIQUID_TESTNET_VAULT environment variable based on environment.

  • account_address (str, optional) – The main account address when using an agent wallet (API sub-key). When set, this address is used for balance queries, position reports, and WebSocket subscriptions instead of the address derived from the private key. Signing still uses the agent wallet’s private key. If None and no explicit vault_address is set, then will source the HYPERLIQUID_ACCOUNT_ADDRESS environment variable.

  • product_types (tuple[HyperliquidProductType, ...], optional) – The Hyperliquid product types to load for the client instrument provider. If None then the instrument provider defaults are used.

  • environment (HyperliquidEnvironment, optional) – The Hyperliquid environment for the client (MAINNET or TESTNET). If None then defaults to MAINNET.

  • base_url_ws (str, optional) – The WebSocket client custom endpoint override.

  • proxy_url (str, optional) – Optional proxy URL for HTTP and WebSocket transports.

  • max_retries (PositiveInt, optional) – The maximum number of times a submit, cancel or modify order request will be retried.

  • retry_delay_initial_ms (PositiveInt, optional) – The initial delay (milliseconds) between retries. Short delays with frequent retries may result in account bans.

  • retry_delay_max_ms (PositiveInt, optional) – The maximum delay (milliseconds) between retries.

  • http_timeout_secs (PositiveInt, default 10) – The timeout (seconds) for HTTP requests.

  • ws_post_timeout_secs (PositiveInt, default 10) – The timeout (seconds) for WebSocket post trading requests.

  • normalize_prices (bool, default True) – If order prices should be normalized to 5 significant figures before submission. Hyperliquid enforces a maximum of 5 significant figures on all prices, which is a dynamic constraint that depends on the price magnitude and cannot be fully encoded in the static instrument tick size. When enabled, prices are automatically rounded to comply with this rule. Disable if you want full control over price formatting.

  • include_builder_attribution (bool, default True) – If True, eligible mainnet orders include the zero-fee Nautilus builder code. Set False to opt out of builder attribution.

Warning

A short retry_delay with frequent retries may result in account bans.

private_key: str | None
vault_address: str | None
account_address: str | None
product_types: tuple[HyperliquidProductType, ...] | None
environment: HyperliquidEnvironment | None
base_url_ws: str | None
proxy_url: str | None
transport_backend: TransportBackend | None
max_retries: Annotated[int, msgspec.Meta(gt=0)] | None
retry_delay_initial_ms: Annotated[int, msgspec.Meta(gt=0)] | None
retry_delay_max_ms: Annotated[int, msgspec.Meta(gt=0)] | None
http_timeout_secs: Annotated[int, msgspec.Meta(gt=0)]
ws_post_timeout_secs: Annotated[int, msgspec.Meta(gt=0)]
normalize_prices: bool
include_builder_attribution: bool
dict() dict[str, Any]

Return a dictionary representation of the configuration.

Return type:

dict[str, Any]

classmethod fully_qualified_name() str

Return the fully qualified name for the NautilusConfig class.

Return type:

str

property id: str

Return the hashed identifier for the configuration.

Return type:

str

instrument_provider: InstrumentProviderConfig
json() bytes

Return serialized JSON encoded bytes.

Return type:

bytes

json_primitives() dict[str, Any]

Return a dictionary representation of the configuration with JSON primitive types as values.

Return type:

dict[str, Any]

classmethod json_schema() dict[str, Any]

Generate a JSON schema for this configuration class.

Return type:

dict[str, Any]

classmethod parse(raw: bytes | str) Any

Return a decoded object of the given cls.

Parameters:
  • cls (type) – The type to decode to.

  • raw (bytes or str) – The raw bytes or JSON string to decode.

Return type:

Any

routing: RoutingConfig
validate() bool

Return whether the configuration can be represented as valid JSON.

Return type:

bool

class HyperliquidImpactPrices

Bases: object

Normalized Hyperliquid impact prices (best bid and ask).

class HyperliquidInstrumentProvider

Bases: InstrumentProvider

Load spot and perpetual instruments from Hyperliquid’s REST /info API.

instruments_pyo3() list[Any]

Return the cached PyO3 instruments (for WebSocket client).

Return type:

list[nautilus_pyo3.Instrument]

async load_all_async(filters: dict | None = None) None

Load the latest instruments into the provider asynchronously, optionally applying the given filters.

add(instrument: Instrument) None

Add the given instrument to the provider.

Parameters:

instrument (Instrument) – The instrument to add.

add_bulk(instruments: list[Instrument]) None

Add the given instruments bulk to the provider.

Parameters:

instruments (list[Instrument]) – The instruments to add.

add_currency(currency: Currency) None

Add the given currency to the provider.

Parameters:

currency (Currency) – The currency to add.

property count: int

Return the count of instruments held by the provider.

Return type:

int

currencies() dict[str, Currency]

Return all currencies held by the instrument provider.

Return type:

dict[str, Currency]

currency(code: str) Currency | None

Return the currency with the given code (if found).

Parameters:

code (str) – The currency code.

Return type:

Currency or None

Raises:

ValueError – If code is not a valid string.

find(instrument_id: InstrumentId) Instrument | None

Return the instrument for the given instrument ID (if found).

Parameters:

instrument_id (InstrumentId) – The ID for the instrument

Return type:

Instrument or None

get_all() dict[InstrumentId, Instrument]

Return all loaded instruments as a map keyed by instrument ID.

If no instruments loaded, will return an empty dict.

Return type:

dict[InstrumentId, Instrument]

async initialize(reload: bool = False) None

Initialize the instrument provider.

Parameters:

reload (bool, default False) – If True, then will always reload instruments. If False, then will immediately return if already loaded.

list_all() list[Instrument]

Return all loaded instruments.

Return type:

list[Instrument]

load(instrument_id: InstrumentId, filters: dict | None = None) None

Load the instrument for the given ID into the provider, optionally applying the given filters.

Parameters:
  • instrument_id (InstrumentId) – The instrument ID to load.

  • filters (frozendict[str, Any] or dict[str, Any], optional) – The venue specific instrument loading filters to apply.

load_all(filters: dict | None = None) None

Load the latest instruments into the provider, optionally applying the given filters.

Parameters:

filters (frozendict[str, Any] or dict[str, Any], optional) – The venue specific instrument loading filters to apply.

async load_async(instrument_id: InstrumentId, filters: dict | None = None) None

Load the instrument for the given ID into the provider asynchronously, optionally applying the given filters.

The default implementation delegates to load_ids_async. Subclasses with per-instrument fetch capability should override this method.

Parameters:
  • instrument_id (InstrumentId) – The instrument ID to load.

  • filters (frozendict[str, Any] or dict[str, Any], optional) – The venue specific instrument loading filters to apply.

load_ids(instrument_ids: list[InstrumentId], filters: dict | None = None) None

Load the instruments for the given IDs into the provider, optionally applying the given filters.

Parameters:
  • instrument_ids (list[InstrumentId]) – The instrument IDs to load.

  • filters (frozendict[str, Any] or dict[str, Any], optional) – The venue specific instrument loading filters to apply.

async load_ids_async(instrument_ids: list[InstrumentId], filters: dict | None = None) None

Load the instruments for the given IDs into the provider, optionally applying the given filters.

The default implementation calls load_all_async (since many venue APIs only support bulk fetches) and then filters the provider to retain only the requested instruments plus any previously loaded ones.

Subclasses with per-instrument fetch capability should override this method.

Parameters:
  • instrument_ids (list[InstrumentId]) – The instrument IDs to load.

  • filters (frozendict[str, Any] or dict[str, Any], optional) – The venue specific instrument loading filters to apply.

class HyperliquidLiveDataClientFactory

Bases: LiveDataClientFactory

Provides a Hyperliquid live data client factory.

static create(loop: AbstractEventLoop, name: str, config: HyperliquidDataClientConfig, msgbus: MessageBus, cache: Cache, clock: LiveClock) HyperliquidDataClient

Create a new Hyperliquid data client.

Parameters:
  • loop (asyncio.AbstractEventLoop) – The event loop for the client.

  • name (str) – The custom client ID.

  • config (HyperliquidDataClientConfig) – The client configuration.

  • msgbus (MessageBus) – The message bus for the client.

  • cache (Cache) – The cache for the client.

  • clock (LiveClock) – The clock for the instrument provider.

Return type:

HyperliquidDataClient

class HyperliquidLiveExecClientFactory

Bases: LiveExecClientFactory

Provides a Hyperliquid live execution client factory.

static create(loop: AbstractEventLoop, name: str, config: HyperliquidExecClientConfig, msgbus: MessageBus, cache: Cache, clock: LiveClock) HyperliquidExecutionClient

Create a new Hyperliquid execution client.

Parameters:
  • loop (asyncio.AbstractEventLoop) – The event loop for the client.

  • name (str) – The custom client ID.

  • config (HyperliquidExecClientConfig) – The client configuration.

  • msgbus (MessageBus) – The message bus for the client.

  • cache (Cache) – The cache for the client.

  • clock (LiveClock) – The clock for the client.

Return type:

HyperliquidExecutionClient

class HyperliquidOpenInterest

Bases: Data

Python data object for Hyperliquid open interest updates.

property ts_event: int

int

UNIX timestamp (nanoseconds) when the data event occurred.

Return type:

int

Type:

Data.ts_event

property ts_init: int

int

UNIX timestamp (nanoseconds) when the instance was created.

Return type:

int

Type:

Data.ts_init

static from_pyo3(pyo3_open_interest: Any) HyperliquidOpenInterest
classmethod fully_qualified_name(cls) str

Return the fully qualified name for the Data class.

Return type:

str

classmethod is_signal(cls, str name='') bool

Determine if the current class is a signal type, optionally checking for a specific signal name.

Parameters:

name (str, optional) – The specific signal name to check. If name not provided or if an empty string is passed, the method checks whether the class name indicates a general signal type. If name is provided, the method checks if the class name corresponds to that specific signal.

Returns:

True if the class name matches the signal type or the specific signal name, otherwise False.

Return type:

bool

class HyperliquidProductType

Bases: str, Enum

Supported Hyperliquid product types for instrument discovery.

SPOT = 'spot'
PERP = 'perp'
PERP_HIP3 = 'perp_hip3'
OUTCOME = 'outcome'
property is_spot: bool
property is_perp: bool

Returns True for both standard perps and HIP-3 builder-deployed perps.

property is_perp_hip3: bool
property is_outcome: bool
encode(encoding='utf-8', errors='strict')

Encode the string using the codec registered for encoding.

encoding

The encoding in which to encode the string.

errors

The error handling scheme to use for encoding errors. The default is ‘strict’ meaning that encoding errors raise a UnicodeEncodeError. Other possible values are ‘ignore’, ‘replace’ and ‘xmlcharrefreplace’ as well as any other name registered with codecs.register_error that can handle UnicodeEncodeErrors.

replace(old, new, /, count=-1)

Return a copy with all occurrences of substring old replaced by new.

count

Maximum number of occurrences to replace. -1 (the default value) means replace all occurrences.

If the optional argument count is given, only the first count occurrences are replaced.

split(sep=None, maxsplit=-1)

Return a list of the substrings in the string, using sep as the separator string.

sep

The separator used to split the string.

When set to None (the default value), will split on any whitespace character (including n r t f and spaces) and will discard empty strings from the result.

maxsplit

Maximum number of splits. -1 (the default value) means no limit.

Splitting starts at the front of the string and works to the end.

Note, str.split() is mainly useful for data that has been intentionally delimited. With natural text that includes punctuation, consider using the regular expression module.

rsplit(sep=None, maxsplit=-1)

Return a list of the substrings in the string, using sep as the separator string.

sep

The separator used to split the string.

When set to None (the default value), will split on any whitespace character (including n r t f and spaces) and will discard empty strings from the result.

maxsplit

Maximum number of splits. -1 (the default value) means no limit.

Splitting starts at the end of the string and works to the front.

join(iterable, /)

Concatenate any number of strings.

The string whose method is called is inserted in between each given string. The result is returned as a new string.

Example: ‘.’.join([‘ab’, ‘pq’, ‘rs’]) -> ‘ab.pq.rs’

capitalize()

Return a capitalized version of the string.

More specifically, make the first character have upper case and the rest lower case.

casefold()

Return a version of the string suitable for caseless comparisons.

title()

Return a version of the string where each word is titlecased.

More specifically, words start with uppercased characters and all remaining cased characters have lower case.

center(width, fillchar=' ', /)

Return a centered string of length width.

Padding is done using the specified fill character (default is a space).

count()

Return the number of non-overlapping occurrences of substring sub in string S[start:end].

Optional arguments start and end are interpreted as in slice notation.

expandtabs(tabsize=8)

Return a copy where all tab characters are expanded using spaces.

If tabsize is not given, a tab size of 8 characters is assumed.

find()

Return the lowest index in S where substring sub is found, such that sub is contained within S[start:end].

Optional arguments start and end are interpreted as in slice notation. Return -1 on failure.

partition(sep, /)

Partition the string into three parts using the given separator.

This will search for the separator in the string. If the separator is found, returns a 3-tuple containing the part before the separator, the separator itself, and the part after it.

If the separator is not found, returns a 3-tuple containing the original string and two empty strings.

index()

Return the lowest index in S where substring sub is found, such that sub is contained within S[start:end].

Optional arguments start and end are interpreted as in slice notation. Raises ValueError when the substring is not found.

ljust(width, fillchar=' ', /)

Return a left-justified string of length width.

Padding is done using the specified fill character (default is a space).

lower()

Return a copy of the string converted to lowercase.

lstrip(chars=None, /)

Return a copy of the string with leading whitespace removed.

If chars is given and not None, remove characters in chars instead.

rfind()

Return the highest index in S where substring sub is found, such that sub is contained within S[start:end].

Optional arguments start and end are interpreted as in slice notation. Return -1 on failure.

rindex()

Return the highest index in S where substring sub is found, such that sub is contained within S[start:end].

Optional arguments start and end are interpreted as in slice notation. Raises ValueError when the substring is not found.

rjust(width, fillchar=' ', /)

Return a right-justified string of length width.

Padding is done using the specified fill character (default is a space).

rstrip(chars=None, /)

Return a copy of the string with trailing whitespace removed.

If chars is given and not None, remove characters in chars instead.

rpartition(sep, /)

Partition the string into three parts using the given separator.

This will search for the separator in the string, starting at the end. If the separator is found, returns a 3-tuple containing the part before the separator, the separator itself, and the part after it.

If the separator is not found, returns a 3-tuple containing two empty strings and the original string.

splitlines(keepends=False)

Return a list of the lines in the string, breaking at line boundaries.

Line breaks are not included in the resulting list unless keepends is given and true.

strip(chars=None, /)

Return a copy of the string with leading and trailing whitespace removed.

If chars is given and not None, remove characters in chars instead.

swapcase()

Convert uppercase characters to lowercase and lowercase characters to uppercase.

translate(table, /)

Replace each character in the string using the given translation table.

table

Translation table, which must be a mapping of Unicode ordinals to Unicode ordinals, strings, or None.

The table must implement lookup/indexing via __getitem__, for instance a dictionary or list. If this operation raises LookupError, the character is left untouched. Characters mapped to None are deleted.

upper()

Return a copy of the string converted to uppercase.

startswith()

Return True if the string starts with the specified prefix, False otherwise.

prefix

A string or a tuple of strings to try.

start

Optional start position. Default: start of the string.

end

Optional stop position. Default: end of the string.

endswith()

Return True if the string ends with the specified suffix, False otherwise.

suffix

A string or a tuple of strings to try.

start

Optional start position. Default: start of the string.

end

Optional stop position. Default: end of the string.

removeprefix(prefix, /)

Return a str with the given prefix string removed if present.

If the string starts with the prefix string, return string[len(prefix):]. Otherwise, return a copy of the original string.

removesuffix(suffix, /)

Return a str with the given suffix string removed if present.

If the string ends with the suffix string and that suffix is not empty, return string[:-len(suffix)]. Otherwise, return a copy of the original string.

isascii()

Return True if all characters in the string are ASCII, False otherwise.

ASCII characters have code points in the range U+0000-U+007F. Empty string is ASCII too.

islower()

Return True if the string is a lowercase string, False otherwise.

A string is lowercase if all cased characters in the string are lowercase and there is at least one cased character in the string.

isupper()

Return True if the string is an uppercase string, False otherwise.

A string is uppercase if all cased characters in the string are uppercase and there is at least one cased character in the string.

istitle()

Return True if the string is a title-cased string, False otherwise.

In a title-cased string, upper- and title-case characters may only follow uncased characters and lowercase characters only cased ones.

isspace()

Return True if the string is a whitespace string, False otherwise.

A string is whitespace if all characters in the string are whitespace and there is at least one character in the string.

isdecimal()

Return True if the string is a decimal string, False otherwise.

A string is a decimal string if all characters in the string are decimal and there is at least one character in the string.

isdigit()

Return True if the string is a digit string, False otherwise.

A string is a digit string if all characters in the string are digits and there is at least one character in the string.

isnumeric()

Return True if the string is a numeric string, False otherwise.

A string is numeric if all characters in the string are numeric and there is at least one character in the string.

isalpha()

Return True if the string is an alphabetic string, False otherwise.

A string is alphabetic if all characters in the string are alphabetic and there is at least one character in the string.

isalnum()

Return True if the string is an alpha-numeric string, False otherwise.

A string is alpha-numeric if all characters in the string are alpha-numeric and there is at least one character in the string.

isidentifier()

Return True if the string is a valid Python identifier, False otherwise.

Call keyword.iskeyword(s) to test whether string s is a reserved identifier, such as “def” or “class”.

isprintable()

Return True if all characters in the string are printable, False otherwise.

A character is printable if repr() may use it in its output.

zfill(width, /)

Pad a numeric string with zeros on the left, to fill a field of the given width.

The string is never truncated.

format(*args, **kwargs)

Return a formatted version of the string, using substitutions from args and kwargs. The substitutions are identified by braces (‘{’ and ‘}’).

format_map(mapping, /)

Return a formatted version of the string, using substitutions from mapping. The substitutions are identified by braces (‘{’ and ‘}’).

static maketrans()

Return a translation table usable for str.translate().

If there is only one argument, it must be a dictionary mapping Unicode ordinals (integers) or characters to Unicode ordinals, strings or None. Character keys will be then converted to ordinals. If there are two arguments, they must be strings of equal length, and in the resulting dictionary, each character in x will be mapped to the character at the same position in y. If there is a third argument, it must be a string, whose characters will be mapped to None in the result.