hyperliquid 0.4.66__py3-none-any.whl
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.
- hyperliquid/__init__.py +7 -0
- hyperliquid/ccxt/__init__.py +101 -0
- hyperliquid/ccxt/abstract/hyperliquid.py +6 -0
- hyperliquid/ccxt/async_support/__init__.py +80 -0
- hyperliquid/ccxt/async_support/base/__init__.py +1 -0
- hyperliquid/ccxt/async_support/base/exchange.py +2095 -0
- hyperliquid/ccxt/async_support/base/throttler.py +50 -0
- hyperliquid/ccxt/async_support/base/ws/__init__.py +38 -0
- hyperliquid/ccxt/async_support/base/ws/aiohttp_client.py +147 -0
- hyperliquid/ccxt/async_support/base/ws/cache.py +213 -0
- hyperliquid/ccxt/async_support/base/ws/client.py +214 -0
- hyperliquid/ccxt/async_support/base/ws/fast_client.py +97 -0
- hyperliquid/ccxt/async_support/base/ws/functions.py +59 -0
- hyperliquid/ccxt/async_support/base/ws/future.py +69 -0
- hyperliquid/ccxt/async_support/base/ws/order_book.py +78 -0
- hyperliquid/ccxt/async_support/base/ws/order_book_side.py +174 -0
- hyperliquid/ccxt/async_support/hyperliquid.py +3446 -0
- hyperliquid/ccxt/base/__init__.py +27 -0
- hyperliquid/ccxt/base/decimal_to_precision.py +174 -0
- hyperliquid/ccxt/base/errors.py +267 -0
- hyperliquid/ccxt/base/exchange.py +6767 -0
- hyperliquid/ccxt/base/precise.py +297 -0
- hyperliquid/ccxt/base/types.py +577 -0
- hyperliquid/ccxt/hyperliquid.py +3445 -0
- hyperliquid/ccxt/pro/__init__.py +21 -0
- hyperliquid/ccxt/pro/hyperliquid.py +997 -0
- hyperliquid/ccxt/static_dependencies/__init__.py +1 -0
- hyperliquid/ccxt/static_dependencies/ecdsa/__init__.py +14 -0
- hyperliquid/ccxt/static_dependencies/ecdsa/_version.py +520 -0
- hyperliquid/ccxt/static_dependencies/ecdsa/curves.py +56 -0
- hyperliquid/ccxt/static_dependencies/ecdsa/der.py +221 -0
- hyperliquid/ccxt/static_dependencies/ecdsa/ecdsa.py +310 -0
- hyperliquid/ccxt/static_dependencies/ecdsa/ellipticcurve.py +197 -0
- hyperliquid/ccxt/static_dependencies/ecdsa/keys.py +332 -0
- hyperliquid/ccxt/static_dependencies/ecdsa/numbertheory.py +531 -0
- hyperliquid/ccxt/static_dependencies/ecdsa/rfc6979.py +100 -0
- hyperliquid/ccxt/static_dependencies/ecdsa/util.py +266 -0
- hyperliquid/ccxt/static_dependencies/ethereum/__init__.py +7 -0
- hyperliquid/ccxt/static_dependencies/ethereum/abi/__init__.py +16 -0
- hyperliquid/ccxt/static_dependencies/ethereum/abi/abi.py +19 -0
- hyperliquid/ccxt/static_dependencies/ethereum/abi/base.py +152 -0
- hyperliquid/ccxt/static_dependencies/ethereum/abi/codec.py +217 -0
- hyperliquid/ccxt/static_dependencies/ethereum/abi/constants.py +3 -0
- hyperliquid/ccxt/static_dependencies/ethereum/abi/decoding.py +565 -0
- hyperliquid/ccxt/static_dependencies/ethereum/abi/encoding.py +720 -0
- hyperliquid/ccxt/static_dependencies/ethereum/abi/exceptions.py +139 -0
- hyperliquid/ccxt/static_dependencies/ethereum/abi/grammar.py +443 -0
- hyperliquid/ccxt/static_dependencies/ethereum/abi/packed.py +13 -0
- hyperliquid/ccxt/static_dependencies/ethereum/abi/py.typed +0 -0
- hyperliquid/ccxt/static_dependencies/ethereum/abi/registry.py +643 -0
- hyperliquid/ccxt/static_dependencies/ethereum/abi/tools/__init__.py +3 -0
- hyperliquid/ccxt/static_dependencies/ethereum/abi/tools/_strategies.py +230 -0
- hyperliquid/ccxt/static_dependencies/ethereum/abi/utils/__init__.py +0 -0
- hyperliquid/ccxt/static_dependencies/ethereum/abi/utils/numeric.py +83 -0
- hyperliquid/ccxt/static_dependencies/ethereum/abi/utils/padding.py +27 -0
- hyperliquid/ccxt/static_dependencies/ethereum/abi/utils/string.py +19 -0
- hyperliquid/ccxt/static_dependencies/ethereum/account/__init__.py +3 -0
- hyperliquid/ccxt/static_dependencies/ethereum/account/encode_typed_data/__init__.py +4 -0
- hyperliquid/ccxt/static_dependencies/ethereum/account/encode_typed_data/encoding_and_hashing.py +239 -0
- hyperliquid/ccxt/static_dependencies/ethereum/account/encode_typed_data/helpers.py +40 -0
- hyperliquid/ccxt/static_dependencies/ethereum/account/messages.py +263 -0
- hyperliquid/ccxt/static_dependencies/ethereum/account/py.typed +0 -0
- hyperliquid/ccxt/static_dependencies/ethereum/hexbytes/__init__.py +5 -0
- hyperliquid/ccxt/static_dependencies/ethereum/hexbytes/_utils.py +54 -0
- hyperliquid/ccxt/static_dependencies/ethereum/hexbytes/main.py +65 -0
- hyperliquid/ccxt/static_dependencies/ethereum/hexbytes/py.typed +0 -0
- hyperliquid/ccxt/static_dependencies/ethereum/typing/__init__.py +63 -0
- hyperliquid/ccxt/static_dependencies/ethereum/typing/abi.py +6 -0
- hyperliquid/ccxt/static_dependencies/ethereum/typing/bls.py +7 -0
- hyperliquid/ccxt/static_dependencies/ethereum/typing/discovery.py +5 -0
- hyperliquid/ccxt/static_dependencies/ethereum/typing/encoding.py +7 -0
- hyperliquid/ccxt/static_dependencies/ethereum/typing/enums.py +17 -0
- hyperliquid/ccxt/static_dependencies/ethereum/typing/ethpm.py +9 -0
- hyperliquid/ccxt/static_dependencies/ethereum/typing/evm.py +20 -0
- hyperliquid/ccxt/static_dependencies/ethereum/typing/networks.py +1122 -0
- hyperliquid/ccxt/static_dependencies/ethereum/typing/py.typed +0 -0
- hyperliquid/ccxt/static_dependencies/ethereum/utils/__init__.py +115 -0
- hyperliquid/ccxt/static_dependencies/ethereum/utils/abi.py +72 -0
- hyperliquid/ccxt/static_dependencies/ethereum/utils/address.py +171 -0
- hyperliquid/ccxt/static_dependencies/ethereum/utils/applicators.py +151 -0
- hyperliquid/ccxt/static_dependencies/ethereum/utils/conversions.py +190 -0
- hyperliquid/ccxt/static_dependencies/ethereum/utils/currency.py +107 -0
- hyperliquid/ccxt/static_dependencies/ethereum/utils/curried/__init__.py +269 -0
- hyperliquid/ccxt/static_dependencies/ethereum/utils/debug.py +20 -0
- hyperliquid/ccxt/static_dependencies/ethereum/utils/decorators.py +132 -0
- hyperliquid/ccxt/static_dependencies/ethereum/utils/encoding.py +6 -0
- hyperliquid/ccxt/static_dependencies/ethereum/utils/exceptions.py +4 -0
- hyperliquid/ccxt/static_dependencies/ethereum/utils/functional.py +75 -0
- hyperliquid/ccxt/static_dependencies/ethereum/utils/hexadecimal.py +74 -0
- hyperliquid/ccxt/static_dependencies/ethereum/utils/humanize.py +188 -0
- hyperliquid/ccxt/static_dependencies/ethereum/utils/logging.py +159 -0
- hyperliquid/ccxt/static_dependencies/ethereum/utils/module_loading.py +31 -0
- hyperliquid/ccxt/static_dependencies/ethereum/utils/numeric.py +43 -0
- hyperliquid/ccxt/static_dependencies/ethereum/utils/py.typed +0 -0
- hyperliquid/ccxt/static_dependencies/ethereum/utils/toolz.py +76 -0
- hyperliquid/ccxt/static_dependencies/ethereum/utils/types.py +54 -0
- hyperliquid/ccxt/static_dependencies/ethereum/utils/typing/__init__.py +18 -0
- hyperliquid/ccxt/static_dependencies/ethereum/utils/typing/misc.py +14 -0
- hyperliquid/ccxt/static_dependencies/ethereum/utils/units.py +31 -0
- hyperliquid/ccxt/static_dependencies/keccak/__init__.py +3 -0
- hyperliquid/ccxt/static_dependencies/keccak/keccak.py +197 -0
- hyperliquid/ccxt/static_dependencies/lark/__init__.py +38 -0
- hyperliquid/ccxt/static_dependencies/lark/__pyinstaller/__init__.py +6 -0
- hyperliquid/ccxt/static_dependencies/lark/__pyinstaller/hook-lark.py +14 -0
- hyperliquid/ccxt/static_dependencies/lark/ast_utils.py +59 -0
- hyperliquid/ccxt/static_dependencies/lark/common.py +86 -0
- hyperliquid/ccxt/static_dependencies/lark/exceptions.py +292 -0
- hyperliquid/ccxt/static_dependencies/lark/grammar.py +130 -0
- hyperliquid/ccxt/static_dependencies/lark/grammars/__init__.py +0 -0
- hyperliquid/ccxt/static_dependencies/lark/indenter.py +143 -0
- hyperliquid/ccxt/static_dependencies/lark/lark.py +658 -0
- hyperliquid/ccxt/static_dependencies/lark/lexer.py +678 -0
- hyperliquid/ccxt/static_dependencies/lark/load_grammar.py +1428 -0
- hyperliquid/ccxt/static_dependencies/lark/parse_tree_builder.py +391 -0
- hyperliquid/ccxt/static_dependencies/lark/parser_frontends.py +257 -0
- hyperliquid/ccxt/static_dependencies/lark/parsers/__init__.py +0 -0
- hyperliquid/ccxt/static_dependencies/lark/parsers/cyk.py +340 -0
- hyperliquid/ccxt/static_dependencies/lark/parsers/earley.py +314 -0
- hyperliquid/ccxt/static_dependencies/lark/parsers/earley_common.py +42 -0
- hyperliquid/ccxt/static_dependencies/lark/parsers/earley_forest.py +801 -0
- hyperliquid/ccxt/static_dependencies/lark/parsers/grammar_analysis.py +203 -0
- hyperliquid/ccxt/static_dependencies/lark/parsers/lalr_analysis.py +332 -0
- hyperliquid/ccxt/static_dependencies/lark/parsers/lalr_interactive_parser.py +158 -0
- hyperliquid/ccxt/static_dependencies/lark/parsers/lalr_parser.py +122 -0
- hyperliquid/ccxt/static_dependencies/lark/parsers/lalr_parser_state.py +110 -0
- hyperliquid/ccxt/static_dependencies/lark/parsers/xearley.py +165 -0
- hyperliquid/ccxt/static_dependencies/lark/py.typed +0 -0
- hyperliquid/ccxt/static_dependencies/lark/reconstruct.py +107 -0
- hyperliquid/ccxt/static_dependencies/lark/tools/__init__.py +70 -0
- hyperliquid/ccxt/static_dependencies/lark/tools/nearley.py +202 -0
- hyperliquid/ccxt/static_dependencies/lark/tools/serialize.py +32 -0
- hyperliquid/ccxt/static_dependencies/lark/tools/standalone.py +196 -0
- hyperliquid/ccxt/static_dependencies/lark/tree.py +267 -0
- hyperliquid/ccxt/static_dependencies/lark/tree_matcher.py +186 -0
- hyperliquid/ccxt/static_dependencies/lark/tree_templates.py +180 -0
- hyperliquid/ccxt/static_dependencies/lark/utils.py +343 -0
- hyperliquid/ccxt/static_dependencies/lark/visitors.py +596 -0
- hyperliquid/ccxt/static_dependencies/marshmallow/__init__.py +81 -0
- hyperliquid/ccxt/static_dependencies/marshmallow/base.py +65 -0
- hyperliquid/ccxt/static_dependencies/marshmallow/class_registry.py +94 -0
- hyperliquid/ccxt/static_dependencies/marshmallow/decorators.py +231 -0
- hyperliquid/ccxt/static_dependencies/marshmallow/error_store.py +60 -0
- hyperliquid/ccxt/static_dependencies/marshmallow/exceptions.py +71 -0
- hyperliquid/ccxt/static_dependencies/marshmallow/fields.py +2114 -0
- hyperliquid/ccxt/static_dependencies/marshmallow/orderedset.py +89 -0
- hyperliquid/ccxt/static_dependencies/marshmallow/py.typed +0 -0
- hyperliquid/ccxt/static_dependencies/marshmallow/schema.py +1228 -0
- hyperliquid/ccxt/static_dependencies/marshmallow/types.py +12 -0
- hyperliquid/ccxt/static_dependencies/marshmallow/utils.py +378 -0
- hyperliquid/ccxt/static_dependencies/marshmallow/validate.py +678 -0
- hyperliquid/ccxt/static_dependencies/marshmallow/warnings.py +2 -0
- hyperliquid/ccxt/static_dependencies/marshmallow_dataclass/__init__.py +1047 -0
- hyperliquid/ccxt/static_dependencies/marshmallow_dataclass/collection_field.py +51 -0
- hyperliquid/ccxt/static_dependencies/marshmallow_dataclass/lazy_class_attribute.py +45 -0
- hyperliquid/ccxt/static_dependencies/marshmallow_dataclass/mypy.py +71 -0
- hyperliquid/ccxt/static_dependencies/marshmallow_dataclass/py.typed +0 -0
- hyperliquid/ccxt/static_dependencies/marshmallow_dataclass/typing.py +14 -0
- hyperliquid/ccxt/static_dependencies/marshmallow_dataclass/union_field.py +82 -0
- hyperliquid/ccxt/static_dependencies/marshmallow_oneofschema/__init__.py +1 -0
- hyperliquid/ccxt/static_dependencies/marshmallow_oneofschema/one_of_schema.py +193 -0
- hyperliquid/ccxt/static_dependencies/marshmallow_oneofschema/py.typed +0 -0
- hyperliquid/ccxt/static_dependencies/msgpack/__init__.py +55 -0
- hyperliquid/ccxt/static_dependencies/msgpack/exceptions.py +48 -0
- hyperliquid/ccxt/static_dependencies/msgpack/ext.py +168 -0
- hyperliquid/ccxt/static_dependencies/msgpack/fallback.py +951 -0
- hyperliquid/ccxt/static_dependencies/parsimonious/__init__.py +10 -0
- hyperliquid/ccxt/static_dependencies/parsimonious/exceptions.py +105 -0
- hyperliquid/ccxt/static_dependencies/parsimonious/expressions.py +479 -0
- hyperliquid/ccxt/static_dependencies/parsimonious/grammar.py +487 -0
- hyperliquid/ccxt/static_dependencies/parsimonious/nodes.py +325 -0
- hyperliquid/ccxt/static_dependencies/parsimonious/utils.py +40 -0
- hyperliquid/ccxt/static_dependencies/starknet/__init__.py +0 -0
- hyperliquid/ccxt/static_dependencies/starknet/abi/v0/__init__.py +2 -0
- hyperliquid/ccxt/static_dependencies/starknet/abi/v0/model.py +44 -0
- hyperliquid/ccxt/static_dependencies/starknet/abi/v0/parser.py +216 -0
- hyperliquid/ccxt/static_dependencies/starknet/abi/v0/schemas.py +72 -0
- hyperliquid/ccxt/static_dependencies/starknet/abi/v0/shape.py +63 -0
- hyperliquid/ccxt/static_dependencies/starknet/abi/v1/__init__.py +2 -0
- hyperliquid/ccxt/static_dependencies/starknet/abi/v1/model.py +39 -0
- hyperliquid/ccxt/static_dependencies/starknet/abi/v1/parser.py +220 -0
- hyperliquid/ccxt/static_dependencies/starknet/abi/v1/parser_transformer.py +179 -0
- hyperliquid/ccxt/static_dependencies/starknet/abi/v1/schemas.py +66 -0
- hyperliquid/ccxt/static_dependencies/starknet/abi/v1/shape.py +47 -0
- hyperliquid/ccxt/static_dependencies/starknet/abi/v2/__init__.py +2 -0
- hyperliquid/ccxt/static_dependencies/starknet/abi/v2/model.py +89 -0
- hyperliquid/ccxt/static_dependencies/starknet/abi/v2/parser.py +293 -0
- hyperliquid/ccxt/static_dependencies/starknet/abi/v2/parser_transformer.py +192 -0
- hyperliquid/ccxt/static_dependencies/starknet/abi/v2/schemas.py +132 -0
- hyperliquid/ccxt/static_dependencies/starknet/abi/v2/shape.py +107 -0
- hyperliquid/ccxt/static_dependencies/starknet/cairo/__init__.py +0 -0
- hyperliquid/ccxt/static_dependencies/starknet/cairo/data_types.py +123 -0
- hyperliquid/ccxt/static_dependencies/starknet/cairo/deprecated_parse/__init__.py +0 -0
- hyperliquid/ccxt/static_dependencies/starknet/cairo/deprecated_parse/cairo_types.py +77 -0
- hyperliquid/ccxt/static_dependencies/starknet/cairo/deprecated_parse/parser.py +46 -0
- hyperliquid/ccxt/static_dependencies/starknet/cairo/deprecated_parse/parser_transformer.py +138 -0
- hyperliquid/ccxt/static_dependencies/starknet/cairo/felt.py +64 -0
- hyperliquid/ccxt/static_dependencies/starknet/cairo/type_parser.py +121 -0
- hyperliquid/ccxt/static_dependencies/starknet/cairo/v1/__init__.py +0 -0
- hyperliquid/ccxt/static_dependencies/starknet/cairo/v1/type_parser.py +59 -0
- hyperliquid/ccxt/static_dependencies/starknet/cairo/v2/__init__.py +0 -0
- hyperliquid/ccxt/static_dependencies/starknet/cairo/v2/type_parser.py +77 -0
- hyperliquid/ccxt/static_dependencies/starknet/ccxt_utils.py +7 -0
- hyperliquid/ccxt/static_dependencies/starknet/common.py +15 -0
- hyperliquid/ccxt/static_dependencies/starknet/constants.py +39 -0
- hyperliquid/ccxt/static_dependencies/starknet/hash/__init__.py +0 -0
- hyperliquid/ccxt/static_dependencies/starknet/hash/address.py +79 -0
- hyperliquid/ccxt/static_dependencies/starknet/hash/compiled_class_hash_objects.py +111 -0
- hyperliquid/ccxt/static_dependencies/starknet/hash/selector.py +16 -0
- hyperliquid/ccxt/static_dependencies/starknet/hash/storage.py +12 -0
- hyperliquid/ccxt/static_dependencies/starknet/hash/utils.py +78 -0
- hyperliquid/ccxt/static_dependencies/starknet/models/__init__.py +0 -0
- hyperliquid/ccxt/static_dependencies/starknet/models/typed_data.py +45 -0
- hyperliquid/ccxt/static_dependencies/starknet/serialization/__init__.py +24 -0
- hyperliquid/ccxt/static_dependencies/starknet/serialization/_calldata_reader.py +40 -0
- hyperliquid/ccxt/static_dependencies/starknet/serialization/_context.py +142 -0
- hyperliquid/ccxt/static_dependencies/starknet/serialization/data_serializers/__init__.py +10 -0
- hyperliquid/ccxt/static_dependencies/starknet/serialization/data_serializers/_common.py +82 -0
- hyperliquid/ccxt/static_dependencies/starknet/serialization/data_serializers/array_serializer.py +43 -0
- hyperliquid/ccxt/static_dependencies/starknet/serialization/data_serializers/bool_serializer.py +37 -0
- hyperliquid/ccxt/static_dependencies/starknet/serialization/data_serializers/byte_array_serializer.py +66 -0
- hyperliquid/ccxt/static_dependencies/starknet/serialization/data_serializers/cairo_data_serializer.py +71 -0
- hyperliquid/ccxt/static_dependencies/starknet/serialization/data_serializers/enum_serializer.py +71 -0
- hyperliquid/ccxt/static_dependencies/starknet/serialization/data_serializers/felt_serializer.py +50 -0
- hyperliquid/ccxt/static_dependencies/starknet/serialization/data_serializers/named_tuple_serializer.py +58 -0
- hyperliquid/ccxt/static_dependencies/starknet/serialization/data_serializers/option_serializer.py +43 -0
- hyperliquid/ccxt/static_dependencies/starknet/serialization/data_serializers/output_serializer.py +40 -0
- hyperliquid/ccxt/static_dependencies/starknet/serialization/data_serializers/payload_serializer.py +72 -0
- hyperliquid/ccxt/static_dependencies/starknet/serialization/data_serializers/struct_serializer.py +36 -0
- hyperliquid/ccxt/static_dependencies/starknet/serialization/data_serializers/tuple_serializer.py +36 -0
- hyperliquid/ccxt/static_dependencies/starknet/serialization/data_serializers/uint256_serializer.py +76 -0
- hyperliquid/ccxt/static_dependencies/starknet/serialization/data_serializers/uint_serializer.py +100 -0
- hyperliquid/ccxt/static_dependencies/starknet/serialization/data_serializers/unit_serializer.py +32 -0
- hyperliquid/ccxt/static_dependencies/starknet/serialization/errors.py +10 -0
- hyperliquid/ccxt/static_dependencies/starknet/serialization/factory.py +229 -0
- hyperliquid/ccxt/static_dependencies/starknet/serialization/function_serialization_adapter.py +110 -0
- hyperliquid/ccxt/static_dependencies/starknet/serialization/tuple_dataclass.py +59 -0
- hyperliquid/ccxt/static_dependencies/starknet/utils/__init__.py +0 -0
- hyperliquid/ccxt/static_dependencies/starknet/utils/constructor_args_translator.py +86 -0
- hyperliquid/ccxt/static_dependencies/starknet/utils/iterable.py +13 -0
- hyperliquid/ccxt/static_dependencies/starknet/utils/schema.py +13 -0
- hyperliquid/ccxt/static_dependencies/starknet/utils/typed_data.py +182 -0
- hyperliquid/ccxt/static_dependencies/starkware/__init__.py +0 -0
- hyperliquid/ccxt/static_dependencies/starkware/crypto/__init__.py +0 -0
- hyperliquid/ccxt/static_dependencies/starkware/crypto/fast_pedersen_hash.py +50 -0
- hyperliquid/ccxt/static_dependencies/starkware/crypto/math_utils.py +78 -0
- hyperliquid/ccxt/static_dependencies/starkware/crypto/signature.py +2344 -0
- hyperliquid/ccxt/static_dependencies/starkware/crypto/utils.py +63 -0
- hyperliquid/ccxt/static_dependencies/sympy/__init__.py +0 -0
- hyperliquid/ccxt/static_dependencies/sympy/core/__init__.py +0 -0
- hyperliquid/ccxt/static_dependencies/sympy/core/intfunc.py +35 -0
- hyperliquid/ccxt/static_dependencies/sympy/external/__init__.py +0 -0
- hyperliquid/ccxt/static_dependencies/sympy/external/gmpy.py +345 -0
- hyperliquid/ccxt/static_dependencies/sympy/external/importtools.py +187 -0
- hyperliquid/ccxt/static_dependencies/sympy/external/ntheory.py +637 -0
- hyperliquid/ccxt/static_dependencies/sympy/external/pythonmpq.py +341 -0
- hyperliquid/ccxt/static_dependencies/toolz/__init__.py +26 -0
- hyperliquid/ccxt/static_dependencies/toolz/_signatures.py +784 -0
- hyperliquid/ccxt/static_dependencies/toolz/_version.py +520 -0
- hyperliquid/ccxt/static_dependencies/toolz/compatibility.py +30 -0
- hyperliquid/ccxt/static_dependencies/toolz/curried/__init__.py +101 -0
- hyperliquid/ccxt/static_dependencies/toolz/curried/exceptions.py +22 -0
- hyperliquid/ccxt/static_dependencies/toolz/curried/operator.py +22 -0
- hyperliquid/ccxt/static_dependencies/toolz/dicttoolz.py +339 -0
- hyperliquid/ccxt/static_dependencies/toolz/functoolz.py +1049 -0
- hyperliquid/ccxt/static_dependencies/toolz/itertoolz.py +1057 -0
- hyperliquid/ccxt/static_dependencies/toolz/recipes.py +46 -0
- hyperliquid/ccxt/static_dependencies/toolz/utils.py +9 -0
- hyperliquid/ccxt/static_dependencies/typing_inspect/__init__.py +0 -0
- hyperliquid/ccxt/static_dependencies/typing_inspect/typing_inspect.py +851 -0
- hyperliquid-0.4.66.dist-info/LICENSE +21 -0
- hyperliquid-0.4.66.dist-info/METADATA +219 -0
- hyperliquid-0.4.66.dist-info/RECORD +274 -0
- hyperliquid-0.4.66.dist-info/WHEEL +5 -0
- hyperliquid-0.4.66.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,997 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
|
|
3
|
+
# PLEASE DO NOT EDIT THIS FILE, IT IS GENERATED AND WILL BE OVERWRITTEN:
|
|
4
|
+
# https://github.com/ccxt/ccxt/blob/master/CONTRIBUTING.md#how-to-contribute-code
|
|
5
|
+
|
|
6
|
+
import ccxt.async_support
|
|
7
|
+
from ccxt.async_support.base.ws.cache import ArrayCache, ArrayCacheBySymbolById, ArrayCacheByTimestamp
|
|
8
|
+
from ccxt.base.types import Any, Int, Market, Num, Order, OrderBook, OrderRequest, OrderSide, OrderType, Str, Strings, Ticker, Tickers, Trade
|
|
9
|
+
from ccxt.async_support.base.ws.client import Client
|
|
10
|
+
from typing import List
|
|
11
|
+
from ccxt.base.errors import ExchangeError
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
from ccxt.async_support import hyperliquid as hyperliquidAsync
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
class hyperliquid(hyperliquidAsync):
|
|
18
|
+
|
|
19
|
+
def describe(self) -> Any:
|
|
20
|
+
return self.deep_extend(super(hyperliquid, self).describe(), {
|
|
21
|
+
'has': {
|
|
22
|
+
'ws': True,
|
|
23
|
+
'createOrderWs': True,
|
|
24
|
+
'createOrdersWs': True,
|
|
25
|
+
'editOrderWs': True,
|
|
26
|
+
'watchBalance': False,
|
|
27
|
+
'watchMyTrades': True,
|
|
28
|
+
'watchOHLCV': True,
|
|
29
|
+
'watchOrderBook': True,
|
|
30
|
+
'watchOrders': True,
|
|
31
|
+
'watchTicker': True,
|
|
32
|
+
'watchTickers': True,
|
|
33
|
+
'watchTrades': True,
|
|
34
|
+
'watchTradesForSymbols': False,
|
|
35
|
+
'watchPosition': False,
|
|
36
|
+
},
|
|
37
|
+
'urls': {
|
|
38
|
+
'api': {
|
|
39
|
+
'ws': {
|
|
40
|
+
'public': 'wss://api.hyperliquid.xyz/ws',
|
|
41
|
+
},
|
|
42
|
+
},
|
|
43
|
+
'test': {
|
|
44
|
+
'ws': {
|
|
45
|
+
'public': 'wss://api.hyperliquid-testnet.xyz/ws',
|
|
46
|
+
},
|
|
47
|
+
},
|
|
48
|
+
},
|
|
49
|
+
'options': {
|
|
50
|
+
},
|
|
51
|
+
'streaming': {
|
|
52
|
+
'ping': self.ping,
|
|
53
|
+
'keepAlive': 20000,
|
|
54
|
+
},
|
|
55
|
+
'exceptions': {
|
|
56
|
+
'ws': {
|
|
57
|
+
'exact': {
|
|
58
|
+
},
|
|
59
|
+
},
|
|
60
|
+
},
|
|
61
|
+
})
|
|
62
|
+
|
|
63
|
+
async def create_orders_ws(self, orders: List[OrderRequest], params={}):
|
|
64
|
+
"""
|
|
65
|
+
create a list of trade orders using WebSocket post request
|
|
66
|
+
|
|
67
|
+
https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/exchange-endpoint#place-an-order
|
|
68
|
+
|
|
69
|
+
:param Array orders: list of orders to create, each object should contain the parameters required by createOrder, namely symbol, type, side, amount, price and params
|
|
70
|
+
:param dict [params]: extra parameters specific to the exchange API endpoint
|
|
71
|
+
:returns dict: an `order structure <https://docs.ccxt.com/#/?id=order-structure>`
|
|
72
|
+
"""
|
|
73
|
+
await self.load_markets()
|
|
74
|
+
url = self.urls['api']['ws']['public']
|
|
75
|
+
ordersRequest = self.createOrdersRequest(orders, params)
|
|
76
|
+
wrapped = self.wrap_as_post_action(ordersRequest)
|
|
77
|
+
request = self.safe_dict(wrapped, 'request', {})
|
|
78
|
+
requestId = self.safe_string(wrapped, 'requestId')
|
|
79
|
+
response = await self.watch(url, requestId, request, requestId)
|
|
80
|
+
responseOjb = self.safe_dict(response, 'response', {})
|
|
81
|
+
data = self.safe_dict(responseOjb, 'data', {})
|
|
82
|
+
statuses = self.safe_list(data, 'statuses', [])
|
|
83
|
+
return self.parse_orders(statuses, None)
|
|
84
|
+
|
|
85
|
+
async def create_order_ws(self, symbol: str, type: OrderType, side: OrderSide, amount: float, price: Num = None, params={}):
|
|
86
|
+
"""
|
|
87
|
+
create a trade order using WebSocket post request
|
|
88
|
+
|
|
89
|
+
https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/exchange-endpoint#place-an-order
|
|
90
|
+
|
|
91
|
+
:param str symbol: unified symbol of the market to create an order in
|
|
92
|
+
:param str type: 'market' or 'limit'
|
|
93
|
+
:param str side: 'buy' or 'sell'
|
|
94
|
+
:param float amount: how much of currency you want to trade in units of base currency
|
|
95
|
+
:param float [price]: the price at which the order is to be fulfilled, in units of the quote currency, ignored in market orders
|
|
96
|
+
:param dict [params]: extra parameters specific to the exchange API endpoint
|
|
97
|
+
:param str [params.timeInForce]: 'Gtc', 'Ioc', 'Alo'
|
|
98
|
+
:param bool [params.postOnly]: True or False whether the order is post-only
|
|
99
|
+
:param bool [params.reduceOnly]: True or False whether the order is reduce-only
|
|
100
|
+
:param float [params.triggerPrice]: The price at which a trigger order is triggered at
|
|
101
|
+
:param str [params.clientOrderId]: client order id,(optional 128 bit hex string e.g. 0x1234567890abcdef1234567890abcdef)
|
|
102
|
+
:param str [params.slippage]: the slippage for market order
|
|
103
|
+
:param str [params.vaultAddress]: the vault address for order
|
|
104
|
+
:returns dict: an `order structure <https://docs.ccxt.com/#/?id=order-structure>`
|
|
105
|
+
"""
|
|
106
|
+
await self.load_markets()
|
|
107
|
+
order, globalParams = self.parseCreateEditOrderArgs(None, symbol, type, side, amount, price, params)
|
|
108
|
+
orders = await self.create_orders_ws([order], globalParams)
|
|
109
|
+
return orders[0]
|
|
110
|
+
|
|
111
|
+
async def edit_order_ws(self, id: str, symbol: str, type: str, side: str, amount: Num = None, price: Num = None, params={}):
|
|
112
|
+
"""
|
|
113
|
+
edit a trade order
|
|
114
|
+
|
|
115
|
+
https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/exchange-endpoint#modify-multiple-orders
|
|
116
|
+
|
|
117
|
+
:param str id: cancel order id
|
|
118
|
+
:param str symbol: unified symbol of the market to create an order in
|
|
119
|
+
:param str type: 'market' or 'limit'
|
|
120
|
+
:param str side: 'buy' or 'sell'
|
|
121
|
+
:param float amount: how much of currency you want to trade in units of base currency
|
|
122
|
+
:param float [price]: the price at which the order is to be fulfilled, in units of the quote currency, ignored in market orders
|
|
123
|
+
:param dict [params]: extra parameters specific to the exchange API endpoint
|
|
124
|
+
:param str [params.timeInForce]: 'Gtc', 'Ioc', 'Alo'
|
|
125
|
+
:param bool [params.postOnly]: True or False whether the order is post-only
|
|
126
|
+
:param bool [params.reduceOnly]: True or False whether the order is reduce-only
|
|
127
|
+
:param float [params.triggerPrice]: The price at which a trigger order is triggered at
|
|
128
|
+
:param str [params.clientOrderId]: client order id,(optional 128 bit hex string e.g. 0x1234567890abcdef1234567890abcdef)
|
|
129
|
+
:param str [params.vaultAddress]: the vault address for order
|
|
130
|
+
:returns dict: an `order structure <https://docs.ccxt.com/#/?id=order-structure>`
|
|
131
|
+
"""
|
|
132
|
+
await self.load_markets()
|
|
133
|
+
market = self.market(symbol)
|
|
134
|
+
url = self.urls['api']['ws']['public']
|
|
135
|
+
order, globalParams = self.parseCreateEditOrderArgs(id, symbol, type, side, amount, price, params)
|
|
136
|
+
postRequest = self.editOrdersRequest([order], globalParams)
|
|
137
|
+
wrapped = self.wrap_as_post_action(postRequest)
|
|
138
|
+
request = self.safe_dict(wrapped, 'request', {})
|
|
139
|
+
requestId = self.safe_string(wrapped, 'requestId')
|
|
140
|
+
response = await self.watch(url, requestId, request, requestId)
|
|
141
|
+
# response is the same self.edit_order
|
|
142
|
+
responseObject = self.safe_dict(response, 'response', {})
|
|
143
|
+
dataObject = self.safe_dict(responseObject, 'data', {})
|
|
144
|
+
statuses = self.safe_list(dataObject, 'statuses', [])
|
|
145
|
+
first = self.safe_dict(statuses, 0, {})
|
|
146
|
+
return self.parse_order(first, market)
|
|
147
|
+
|
|
148
|
+
async def watch_order_book(self, symbol: str, limit: Int = None, params={}) -> OrderBook:
|
|
149
|
+
"""
|
|
150
|
+
watches information on open orders with bid(buy) and ask(sell) prices, volumes and other data
|
|
151
|
+
|
|
152
|
+
https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/websocket/subscriptions
|
|
153
|
+
|
|
154
|
+
:param str symbol: unified symbol of the market to fetch the order book for
|
|
155
|
+
:param int [limit]: the maximum amount of order book entries to return
|
|
156
|
+
:param dict [params]: extra parameters specific to the exchange API endpoint
|
|
157
|
+
:returns dict: A dictionary of `order book structures <https://docs.ccxt.com/#/?id=order-book-structure>` indexed by market symbols
|
|
158
|
+
"""
|
|
159
|
+
await self.load_markets()
|
|
160
|
+
market = self.market(symbol)
|
|
161
|
+
symbol = market['symbol']
|
|
162
|
+
messageHash = 'orderbook:' + symbol
|
|
163
|
+
url = self.urls['api']['ws']['public']
|
|
164
|
+
request: dict = {
|
|
165
|
+
'method': 'subscribe',
|
|
166
|
+
'subscription': {
|
|
167
|
+
'type': 'l2Book',
|
|
168
|
+
'coin': market['base'] if market['swap'] else market['id'],
|
|
169
|
+
},
|
|
170
|
+
}
|
|
171
|
+
message = self.extend(request, params)
|
|
172
|
+
orderbook = await self.watch(url, messageHash, message, messageHash)
|
|
173
|
+
return orderbook.limit()
|
|
174
|
+
|
|
175
|
+
async def un_watch_order_book(self, symbol: str, params={}) -> Any:
|
|
176
|
+
"""
|
|
177
|
+
unWatches information on open orders with bid(buy) and ask(sell) prices, volumes and other data
|
|
178
|
+
|
|
179
|
+
https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/websocket/subscriptions
|
|
180
|
+
|
|
181
|
+
:param str symbol: unified symbol of the market to fetch the order book for
|
|
182
|
+
:param dict [params]: extra parameters specific to the exchange API endpoint
|
|
183
|
+
:returns dict: A dictionary of `order book structures <https://docs.ccxt.com/#/?id=order-book-structure>` indexed by market symbols
|
|
184
|
+
"""
|
|
185
|
+
await self.load_markets()
|
|
186
|
+
market = self.market(symbol)
|
|
187
|
+
symbol = market['symbol']
|
|
188
|
+
subMessageHash = 'orderbook:' + symbol
|
|
189
|
+
messageHash = 'unsubscribe:' + subMessageHash
|
|
190
|
+
url = self.urls['api']['ws']['public']
|
|
191
|
+
id = str(self.nonce())
|
|
192
|
+
request: dict = {
|
|
193
|
+
'id': id,
|
|
194
|
+
'method': 'unsubscribe',
|
|
195
|
+
'subscription': {
|
|
196
|
+
'type': 'l2Book',
|
|
197
|
+
'coin': market['base'] if market['swap'] else market['id'],
|
|
198
|
+
},
|
|
199
|
+
}
|
|
200
|
+
message = self.extend(request, params)
|
|
201
|
+
return await self.watch(url, messageHash, message, messageHash)
|
|
202
|
+
|
|
203
|
+
def handle_order_book(self, client, message):
|
|
204
|
+
#
|
|
205
|
+
# {
|
|
206
|
+
# "channel": "l2Book",
|
|
207
|
+
# "data": {
|
|
208
|
+
# "coin": "BTC",
|
|
209
|
+
# "time": 1710131872708,
|
|
210
|
+
# "levels": [
|
|
211
|
+
# [
|
|
212
|
+
# {
|
|
213
|
+
# "px": "68674.0",
|
|
214
|
+
# "sz": "0.97139",
|
|
215
|
+
# "n": 4
|
|
216
|
+
# }
|
|
217
|
+
# ],
|
|
218
|
+
# [
|
|
219
|
+
# {
|
|
220
|
+
# "px": "68675.0",
|
|
221
|
+
# "sz": "0.04396",
|
|
222
|
+
# "n": 1
|
|
223
|
+
# }
|
|
224
|
+
# ]
|
|
225
|
+
# ]
|
|
226
|
+
# }
|
|
227
|
+
# }
|
|
228
|
+
#
|
|
229
|
+
entry = self.safe_dict(message, 'data', {})
|
|
230
|
+
coin = self.safe_string(entry, 'coin')
|
|
231
|
+
marketId = self.coinToMarketId(coin)
|
|
232
|
+
market = self.market(marketId)
|
|
233
|
+
symbol = market['symbol']
|
|
234
|
+
rawData = self.safe_list(entry, 'levels', [])
|
|
235
|
+
data: dict = {
|
|
236
|
+
'bids': self.safe_list(rawData, 0, []),
|
|
237
|
+
'asks': self.safe_list(rawData, 1, []),
|
|
238
|
+
}
|
|
239
|
+
timestamp = self.safe_integer(entry, 'time')
|
|
240
|
+
snapshot = self.parse_order_book(data, symbol, timestamp, 'bids', 'asks', 'px', 'sz')
|
|
241
|
+
if not (symbol in self.orderbooks):
|
|
242
|
+
ob = self.order_book(snapshot)
|
|
243
|
+
self.orderbooks[symbol] = ob
|
|
244
|
+
orderbook = self.orderbooks[symbol]
|
|
245
|
+
orderbook.reset(snapshot)
|
|
246
|
+
messageHash = 'orderbook:' + symbol
|
|
247
|
+
client.resolve(orderbook, messageHash)
|
|
248
|
+
|
|
249
|
+
async def watch_ticker(self, symbol: str, params={}) -> Ticker:
|
|
250
|
+
"""
|
|
251
|
+
|
|
252
|
+
https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/websocket/subscriptions
|
|
253
|
+
|
|
254
|
+
watches a price ticker, a statistical calculation with the information calculated over the past 24 hours for a specific market
|
|
255
|
+
:param str symbol: unified symbol of the market to fetch the ticker for
|
|
256
|
+
:param dict [params]: extra parameters specific to the exchange API endpoint
|
|
257
|
+
:returns dict: a `ticker structure <https://docs.ccxt.com/#/?id=ticker-structure>`
|
|
258
|
+
"""
|
|
259
|
+
market = self.market(symbol)
|
|
260
|
+
symbol = market['symbol']
|
|
261
|
+
tickers = await self.watch_tickers([symbol], params)
|
|
262
|
+
return tickers[symbol]
|
|
263
|
+
|
|
264
|
+
async def watch_tickers(self, symbols: Strings = None, params={}) -> Tickers:
|
|
265
|
+
"""
|
|
266
|
+
watches a price ticker, a statistical calculation with the information calculated over the past 24 hours for all markets of a specific list
|
|
267
|
+
|
|
268
|
+
https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/websocket/subscriptions
|
|
269
|
+
|
|
270
|
+
:param str[] symbols: unified symbol of the market to fetch the ticker for
|
|
271
|
+
:param dict [params]: extra parameters specific to the exchange API endpoint
|
|
272
|
+
:returns dict: a `ticker structure <https://docs.ccxt.com/#/?id=ticker-structure>`
|
|
273
|
+
"""
|
|
274
|
+
await self.load_markets()
|
|
275
|
+
symbols = self.market_symbols(symbols, None, True)
|
|
276
|
+
messageHash = 'tickers'
|
|
277
|
+
url = self.urls['api']['ws']['public']
|
|
278
|
+
request: dict = {
|
|
279
|
+
'method': 'subscribe',
|
|
280
|
+
'subscription': {
|
|
281
|
+
'type': 'webData2', # allMids
|
|
282
|
+
'user': '0x0000000000000000000000000000000000000000',
|
|
283
|
+
},
|
|
284
|
+
}
|
|
285
|
+
tickers = await self.watch(url, messageHash, self.extend(request, params), messageHash)
|
|
286
|
+
if self.newUpdates:
|
|
287
|
+
return self.filter_by_array_tickers(tickers, 'symbol', symbols)
|
|
288
|
+
return self.tickers
|
|
289
|
+
|
|
290
|
+
async def un_watch_tickers(self, symbols: Strings = None, params={}) -> Any:
|
|
291
|
+
"""
|
|
292
|
+
unWatches a price ticker, a statistical calculation with the information calculated over the past 24 hours for all markets of a specific list
|
|
293
|
+
|
|
294
|
+
https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/websocket/subscriptions
|
|
295
|
+
|
|
296
|
+
:param str[] symbols: unified symbol of the market to fetch the ticker for
|
|
297
|
+
:param dict [params]: extra parameters specific to the exchange API endpoint
|
|
298
|
+
:returns dict: a `ticker structure <https://docs.ccxt.com/#/?id=ticker-structure>`
|
|
299
|
+
"""
|
|
300
|
+
await self.load_markets()
|
|
301
|
+
symbols = self.market_symbols(symbols, None, True)
|
|
302
|
+
subMessageHash = 'tickers'
|
|
303
|
+
messageHash = 'unsubscribe:' + subMessageHash
|
|
304
|
+
url = self.urls['api']['ws']['public']
|
|
305
|
+
request: dict = {
|
|
306
|
+
'method': 'unsubscribe',
|
|
307
|
+
'subscription': {
|
|
308
|
+
'type': 'webData2', # allMids
|
|
309
|
+
'user': '0x0000000000000000000000000000000000000000',
|
|
310
|
+
},
|
|
311
|
+
}
|
|
312
|
+
return await self.watch(url, messageHash, self.extend(request, params), messageHash)
|
|
313
|
+
|
|
314
|
+
async def watch_my_trades(self, symbol: Str = None, since: Int = None, limit: Int = None, params={}) -> List[Trade]:
|
|
315
|
+
"""
|
|
316
|
+
watches information on multiple trades made by the user
|
|
317
|
+
|
|
318
|
+
https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/websocket/subscriptions
|
|
319
|
+
|
|
320
|
+
:param str symbol: unified market symbol of the market orders were made in
|
|
321
|
+
:param int [since]: the earliest time in ms to fetch orders for
|
|
322
|
+
:param int [limit]: the maximum number of order structures to retrieve
|
|
323
|
+
:param dict [params]: extra parameters specific to the exchange API endpoint
|
|
324
|
+
:param str [params.user]: user address, will default to self.walletAddress if not provided
|
|
325
|
+
:returns dict[]: a list of `order structures <https://docs.ccxt.com/#/?id=order-structure>`
|
|
326
|
+
"""
|
|
327
|
+
userAddress = None
|
|
328
|
+
userAddress, params = self.handlePublicAddress('watchMyTrades', params)
|
|
329
|
+
await self.load_markets()
|
|
330
|
+
messageHash = 'myTrades'
|
|
331
|
+
if symbol is not None:
|
|
332
|
+
symbol = self.symbol(symbol)
|
|
333
|
+
messageHash += ':' + symbol
|
|
334
|
+
url = self.urls['api']['ws']['public']
|
|
335
|
+
request: dict = {
|
|
336
|
+
'method': 'subscribe',
|
|
337
|
+
'subscription': {
|
|
338
|
+
'type': 'userFills',
|
|
339
|
+
'user': userAddress,
|
|
340
|
+
},
|
|
341
|
+
}
|
|
342
|
+
message = self.extend(request, params)
|
|
343
|
+
trades = await self.watch(url, messageHash, message, messageHash)
|
|
344
|
+
if self.newUpdates:
|
|
345
|
+
limit = trades.getLimit(symbol, limit)
|
|
346
|
+
return self.filter_by_symbol_since_limit(trades, symbol, since, limit, True)
|
|
347
|
+
|
|
348
|
+
def handle_ws_tickers(self, client: Client, message):
|
|
349
|
+
#
|
|
350
|
+
# {
|
|
351
|
+
# "channel": "webData2",
|
|
352
|
+
# "data": {
|
|
353
|
+
# "meta": {
|
|
354
|
+
# "universe": [
|
|
355
|
+
# {
|
|
356
|
+
# "szDecimals": 5,
|
|
357
|
+
# "name": "BTC",
|
|
358
|
+
# "maxLeverage": 50,
|
|
359
|
+
# "onlyIsolated": False
|
|
360
|
+
# },
|
|
361
|
+
# ...
|
|
362
|
+
# ],
|
|
363
|
+
# },
|
|
364
|
+
# "assetCtxs": [
|
|
365
|
+
# {
|
|
366
|
+
# "funding": "0.00003005",
|
|
367
|
+
# "openInterest": "2311.50778",
|
|
368
|
+
# "prevDayPx": "63475.0",
|
|
369
|
+
# "dayNtlVlm": "468043329.64289033",
|
|
370
|
+
# "premium": "0.00094264",
|
|
371
|
+
# "oraclePx": "64712.0",
|
|
372
|
+
# "markPx": "64774.0",
|
|
373
|
+
# "midPx": "64773.5",
|
|
374
|
+
# "impactPxs": [
|
|
375
|
+
# "64773.0",
|
|
376
|
+
# "64774.0"
|
|
377
|
+
# ]
|
|
378
|
+
# },
|
|
379
|
+
# ...
|
|
380
|
+
# ],
|
|
381
|
+
# "spotAssetCtxs": [
|
|
382
|
+
# {
|
|
383
|
+
# "prevDayPx": "0.20937",
|
|
384
|
+
# "dayNtlVlm": "11188888.61984999",
|
|
385
|
+
# "markPx": "0.19722",
|
|
386
|
+
# "midPx": "0.197145",
|
|
387
|
+
# "circulatingSupply": "598760557.12072003",
|
|
388
|
+
# "coin": "PURR/USDC"
|
|
389
|
+
# },
|
|
390
|
+
# ...
|
|
391
|
+
# ],
|
|
392
|
+
# }
|
|
393
|
+
# }
|
|
394
|
+
#
|
|
395
|
+
# spot
|
|
396
|
+
rawData = self.safe_dict(message, 'data', {})
|
|
397
|
+
spotAssets = self.safe_list(rawData, 'spotAssetCtxs', [])
|
|
398
|
+
parsedTickers = []
|
|
399
|
+
for i in range(0, len(spotAssets)):
|
|
400
|
+
assetObject = spotAssets[i]
|
|
401
|
+
marketId = self.safe_string(assetObject, 'coin')
|
|
402
|
+
market = self.safe_market(marketId, None, None, 'spot')
|
|
403
|
+
ticker = self.parse_ws_ticker(assetObject, market)
|
|
404
|
+
parsedTickers.append(ticker)
|
|
405
|
+
# perpetuals
|
|
406
|
+
meta = self.safe_dict(rawData, 'meta', {})
|
|
407
|
+
universe = self.safe_list(meta, 'universe', [])
|
|
408
|
+
assetCtxs = self.safe_list(rawData, 'assetCtxs', [])
|
|
409
|
+
for i in range(0, len(universe)):
|
|
410
|
+
data = self.extend(
|
|
411
|
+
self.safe_dict(universe, i, {}),
|
|
412
|
+
self.safe_dict(assetCtxs, i, {})
|
|
413
|
+
)
|
|
414
|
+
id = data['name'] + '/USDC:USDC'
|
|
415
|
+
market = self.safe_market(id, None, None, 'swap')
|
|
416
|
+
ticker = self.parse_ws_ticker(data, market)
|
|
417
|
+
parsedTickers.append(ticker)
|
|
418
|
+
tickers = self.index_by(parsedTickers, 'symbol')
|
|
419
|
+
client.resolve(tickers, 'tickers')
|
|
420
|
+
|
|
421
|
+
def parse_ws_ticker(self, rawTicker, market: Market = None) -> Ticker:
|
|
422
|
+
return self.parse_ticker(rawTicker, market)
|
|
423
|
+
|
|
424
|
+
def handle_my_trades(self, client: Client, message):
|
|
425
|
+
#
|
|
426
|
+
# {
|
|
427
|
+
# "channel": "userFills",
|
|
428
|
+
# "data": {
|
|
429
|
+
# "isSnapshot": True,
|
|
430
|
+
# "user": "0x15f43d1f2dee81424afd891943262aa90f22cc2a",
|
|
431
|
+
# "fills": [
|
|
432
|
+
# {
|
|
433
|
+
# "coin": "BTC",
|
|
434
|
+
# "px": "72528.0",
|
|
435
|
+
# "sz": "0.11693",
|
|
436
|
+
# "side": "A",
|
|
437
|
+
# "time": 1710208712815,
|
|
438
|
+
# "startPosition": "0.11693",
|
|
439
|
+
# "dir": "Close Long",
|
|
440
|
+
# "closedPnl": "-0.81851",
|
|
441
|
+
# "hash": "0xc5adaf35f8402750c218040b0a7bc301130051521273b6f398b3caad3e1f3f5f",
|
|
442
|
+
# "oid": 7484888874,
|
|
443
|
+
# "crossed": True,
|
|
444
|
+
# "fee": "2.968244",
|
|
445
|
+
# "liquidationMarkPx": null,
|
|
446
|
+
# "tid": 567547935839686,
|
|
447
|
+
# "cloid": null
|
|
448
|
+
# }
|
|
449
|
+
# ]
|
|
450
|
+
# }
|
|
451
|
+
# }
|
|
452
|
+
#
|
|
453
|
+
entry = self.safe_dict(message, 'data', {})
|
|
454
|
+
if self.myTrades is None:
|
|
455
|
+
limit = self.safe_integer(self.options, 'tradesLimit', 1000)
|
|
456
|
+
self.myTrades = ArrayCacheBySymbolById(limit)
|
|
457
|
+
trades = self.myTrades
|
|
458
|
+
symbols: dict = {}
|
|
459
|
+
data = self.safe_list(entry, 'fills', [])
|
|
460
|
+
dataLength = len(data)
|
|
461
|
+
if dataLength == 0:
|
|
462
|
+
return
|
|
463
|
+
for i in range(0, len(data)):
|
|
464
|
+
rawTrade = data[i]
|
|
465
|
+
parsed = self.parse_ws_trade(rawTrade)
|
|
466
|
+
symbol = parsed['symbol']
|
|
467
|
+
symbols[symbol] = True
|
|
468
|
+
trades.append(parsed)
|
|
469
|
+
keys = list(symbols.keys())
|
|
470
|
+
for i in range(0, len(keys)):
|
|
471
|
+
currentMessageHash = 'myTrades:' + keys[i]
|
|
472
|
+
client.resolve(trades, currentMessageHash)
|
|
473
|
+
# non-symbol specific
|
|
474
|
+
messageHash = 'myTrades'
|
|
475
|
+
client.resolve(trades, messageHash)
|
|
476
|
+
|
|
477
|
+
async def watch_trades(self, symbol: str, since: Int = None, limit: Int = None, params={}) -> List[Trade]:
|
|
478
|
+
# s
|
|
479
|
+
# @method
|
|
480
|
+
# @name hyperliquid#watchTrades
|
|
481
|
+
# @description watches information on multiple trades made in a market
|
|
482
|
+
# @see https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/websocket/subscriptions
|
|
483
|
+
# @param {string} symbol unified market symbol of the market trades were made in
|
|
484
|
+
# @param {int} [since] the earliest time in ms to fetch trades for
|
|
485
|
+
# @param {int} [limit] the maximum number of trade structures to retrieve
|
|
486
|
+
# @param {object} [params] extra parameters specific to the exchange API endpoint
|
|
487
|
+
# @returns {object[]} a list of `trade structures <https://docs.ccxt.com/#/?id=trade-structure>`
|
|
488
|
+
#
|
|
489
|
+
await self.load_markets()
|
|
490
|
+
market = self.market(symbol)
|
|
491
|
+
symbol = market['symbol']
|
|
492
|
+
messageHash = 'trade:' + symbol
|
|
493
|
+
url = self.urls['api']['ws']['public']
|
|
494
|
+
request: dict = {
|
|
495
|
+
'method': 'subscribe',
|
|
496
|
+
'subscription': {
|
|
497
|
+
'type': 'trades',
|
|
498
|
+
'coin': market['base'] if market['swap'] else market['id'],
|
|
499
|
+
},
|
|
500
|
+
}
|
|
501
|
+
message = self.extend(request, params)
|
|
502
|
+
trades = await self.watch(url, messageHash, message, messageHash)
|
|
503
|
+
if self.newUpdates:
|
|
504
|
+
limit = trades.getLimit(symbol, limit)
|
|
505
|
+
return self.filter_by_since_limit(trades, since, limit, 'timestamp', True)
|
|
506
|
+
|
|
507
|
+
async def un_watch_trades(self, symbol: str, params={}) -> Any:
|
|
508
|
+
"""
|
|
509
|
+
unWatches information on multiple trades made in a market
|
|
510
|
+
|
|
511
|
+
https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/websocket/subscriptions
|
|
512
|
+
|
|
513
|
+
:param str symbol: unified market symbol of the market trades were made in
|
|
514
|
+
:param dict [params]: extra parameters specific to the exchange API endpoint
|
|
515
|
+
:returns dict[]: a list of `trade structures <https://docs.ccxt.com/#/?id=trade-structure>`
|
|
516
|
+
"""
|
|
517
|
+
await self.load_markets()
|
|
518
|
+
market = self.market(symbol)
|
|
519
|
+
symbol = market['symbol']
|
|
520
|
+
subMessageHash = 'trade:' + symbol
|
|
521
|
+
messageHash = 'unsubscribe:' + subMessageHash
|
|
522
|
+
url = self.urls['api']['ws']['public']
|
|
523
|
+
request: dict = {
|
|
524
|
+
'method': 'unsubscribe',
|
|
525
|
+
'subscription': {
|
|
526
|
+
'type': 'trades',
|
|
527
|
+
'coin': market['base'] if market['swap'] else market['id'],
|
|
528
|
+
},
|
|
529
|
+
}
|
|
530
|
+
message = self.extend(request, params)
|
|
531
|
+
return await self.watch(url, messageHash, message, messageHash)
|
|
532
|
+
|
|
533
|
+
def handle_trades(self, client: Client, message):
|
|
534
|
+
#
|
|
535
|
+
# {
|
|
536
|
+
# "channel": "trades",
|
|
537
|
+
# "data": [
|
|
538
|
+
# {
|
|
539
|
+
# "coin": "BTC",
|
|
540
|
+
# "side": "A",
|
|
541
|
+
# "px": "68517.0",
|
|
542
|
+
# "sz": "0.005",
|
|
543
|
+
# "time": 1710125266669,
|
|
544
|
+
# "hash": "0xc872699f116e012186620407fc08a802015e0097c5cce74710697f7272e6e959",
|
|
545
|
+
# "tid": 981894269203506
|
|
546
|
+
# }
|
|
547
|
+
# ]
|
|
548
|
+
# }
|
|
549
|
+
#
|
|
550
|
+
entry = self.safe_list(message, 'data', [])
|
|
551
|
+
first = self.safe_dict(entry, 0, {})
|
|
552
|
+
coin = self.safe_string(first, 'coin')
|
|
553
|
+
marketId = self.coinToMarketId(coin)
|
|
554
|
+
market = self.market(marketId)
|
|
555
|
+
symbol = market['symbol']
|
|
556
|
+
if not (symbol in self.trades):
|
|
557
|
+
limit = self.safe_integer(self.options, 'tradesLimit', 1000)
|
|
558
|
+
stored = ArrayCache(limit)
|
|
559
|
+
self.trades[symbol] = stored
|
|
560
|
+
trades = self.trades[symbol]
|
|
561
|
+
for i in range(0, len(entry)):
|
|
562
|
+
data = self.safe_dict(entry, i)
|
|
563
|
+
trade = self.parse_ws_trade(data)
|
|
564
|
+
trades.append(trade)
|
|
565
|
+
messageHash = 'trade:' + symbol
|
|
566
|
+
client.resolve(trades, messageHash)
|
|
567
|
+
|
|
568
|
+
def parse_ws_trade(self, trade: dict, market: Market = None) -> Trade:
|
|
569
|
+
#
|
|
570
|
+
# fetchMyTrades
|
|
571
|
+
#
|
|
572
|
+
# {
|
|
573
|
+
# "coin": "BTC",
|
|
574
|
+
# "px": "72528.0",
|
|
575
|
+
# "sz": "0.11693",
|
|
576
|
+
# "side": "A",
|
|
577
|
+
# "time": 1710208712815,
|
|
578
|
+
# "startPosition": "0.11693",
|
|
579
|
+
# "dir": "Close Long",
|
|
580
|
+
# "closedPnl": "-0.81851",
|
|
581
|
+
# "hash": "0xc5adaf35f8402750c218040b0a7bc301130051521273b6f398b3caad3e1f3f5f",
|
|
582
|
+
# "oid": 7484888874,
|
|
583
|
+
# "crossed": True,
|
|
584
|
+
# "fee": "2.968244",
|
|
585
|
+
# "liquidationMarkPx": null,
|
|
586
|
+
# "tid": 567547935839686,
|
|
587
|
+
# "cloid": null
|
|
588
|
+
# }
|
|
589
|
+
#
|
|
590
|
+
# fetchTrades
|
|
591
|
+
#
|
|
592
|
+
# {
|
|
593
|
+
# "coin": "BTC",
|
|
594
|
+
# "side": "A",
|
|
595
|
+
# "px": "68517.0",
|
|
596
|
+
# "sz": "0.005",
|
|
597
|
+
# "time": 1710125266669,
|
|
598
|
+
# "hash": "0xc872699f116e012186620407fc08a802015e0097c5cce74710697f7272e6e959",
|
|
599
|
+
# "tid": 981894269203506
|
|
600
|
+
# }
|
|
601
|
+
#
|
|
602
|
+
timestamp = self.safe_integer(trade, 'time')
|
|
603
|
+
price = self.safe_string(trade, 'px')
|
|
604
|
+
amount = self.safe_string(trade, 'sz')
|
|
605
|
+
coin = self.safe_string(trade, 'coin')
|
|
606
|
+
marketId = self.coinToMarketId(coin)
|
|
607
|
+
market = self.safe_market(marketId, None)
|
|
608
|
+
symbol = market['symbol']
|
|
609
|
+
id = self.safe_string(trade, 'tid')
|
|
610
|
+
side = self.safe_string(trade, 'side')
|
|
611
|
+
if side is not None:
|
|
612
|
+
side = 'sell' if (side == 'A') else 'buy'
|
|
613
|
+
fee = self.safe_string(trade, 'fee')
|
|
614
|
+
return self.safe_trade({
|
|
615
|
+
'info': trade,
|
|
616
|
+
'timestamp': timestamp,
|
|
617
|
+
'datetime': self.iso8601(timestamp),
|
|
618
|
+
'symbol': symbol,
|
|
619
|
+
'id': id,
|
|
620
|
+
'order': None,
|
|
621
|
+
'type': None,
|
|
622
|
+
'side': side,
|
|
623
|
+
'takerOrMaker': None,
|
|
624
|
+
'price': price,
|
|
625
|
+
'amount': amount,
|
|
626
|
+
'cost': None,
|
|
627
|
+
'fee': {'cost': fee, 'currency': 'USDC'},
|
|
628
|
+
}, market)
|
|
629
|
+
|
|
630
|
+
async def watch_ohlcv(self, symbol: str, timeframe='1m', since: Int = None, limit: Int = None, params={}) -> List[list]:
|
|
631
|
+
"""
|
|
632
|
+
watches historical candlestick data containing the open, high, low, close price, and the volume of a market
|
|
633
|
+
|
|
634
|
+
https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/websocket/subscriptions
|
|
635
|
+
|
|
636
|
+
:param str symbol: unified symbol of the market to fetch OHLCV data for
|
|
637
|
+
:param str timeframe: the length of time each candle represents
|
|
638
|
+
:param int [since]: timestamp in ms of the earliest candle to fetch
|
|
639
|
+
:param int [limit]: the maximum amount of candles to fetch
|
|
640
|
+
:param dict [params]: extra parameters specific to the exchange API endpoint
|
|
641
|
+
:returns int[][]: A list of candles ordered, open, high, low, close, volume
|
|
642
|
+
"""
|
|
643
|
+
await self.load_markets()
|
|
644
|
+
market = self.market(symbol)
|
|
645
|
+
symbol = market['symbol']
|
|
646
|
+
url = self.urls['api']['ws']['public']
|
|
647
|
+
request: dict = {
|
|
648
|
+
'method': 'subscribe',
|
|
649
|
+
'subscription': {
|
|
650
|
+
'type': 'candle',
|
|
651
|
+
'coin': market['base'] if market['swap'] else market['id'],
|
|
652
|
+
'interval': timeframe,
|
|
653
|
+
},
|
|
654
|
+
}
|
|
655
|
+
messageHash = 'candles:' + timeframe + ':' + symbol
|
|
656
|
+
message = self.extend(request, params)
|
|
657
|
+
ohlcv = await self.watch(url, messageHash, message, messageHash)
|
|
658
|
+
if self.newUpdates:
|
|
659
|
+
limit = ohlcv.getLimit(symbol, limit)
|
|
660
|
+
return self.filter_by_since_limit(ohlcv, since, limit, 0, True)
|
|
661
|
+
|
|
662
|
+
async def un_watch_ohlcv(self, symbol: str, timeframe='1m', params={}) -> Any:
|
|
663
|
+
"""
|
|
664
|
+
watches historical candlestick data containing the open, high, low, close price, and the volume of a market
|
|
665
|
+
|
|
666
|
+
https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/websocket/subscriptions
|
|
667
|
+
|
|
668
|
+
:param str symbol: unified symbol of the market to fetch OHLCV data for
|
|
669
|
+
:param str timeframe: the length of time each candle represents
|
|
670
|
+
:param dict [params]: extra parameters specific to the exchange API endpoint
|
|
671
|
+
:returns int[][]: A list of candles ordered, open, high, low, close, volume
|
|
672
|
+
"""
|
|
673
|
+
await self.load_markets()
|
|
674
|
+
market = self.market(symbol)
|
|
675
|
+
symbol = market['symbol']
|
|
676
|
+
url = self.urls['api']['ws']['public']
|
|
677
|
+
request: dict = {
|
|
678
|
+
'method': 'unsubscribe',
|
|
679
|
+
'subscription': {
|
|
680
|
+
'type': 'candle',
|
|
681
|
+
'coin': market['base'] if market['swap'] else market['id'],
|
|
682
|
+
'interval': timeframe,
|
|
683
|
+
},
|
|
684
|
+
}
|
|
685
|
+
subMessageHash = 'candles:' + timeframe + ':' + symbol
|
|
686
|
+
messagehash = 'unsubscribe:' + subMessageHash
|
|
687
|
+
message = self.extend(request, params)
|
|
688
|
+
return await self.watch(url, messagehash, message, messagehash)
|
|
689
|
+
|
|
690
|
+
def handle_ohlcv(self, client: Client, message):
|
|
691
|
+
#
|
|
692
|
+
# {
|
|
693
|
+
# channel: 'candle',
|
|
694
|
+
# data: {
|
|
695
|
+
# t: 1710146280000,
|
|
696
|
+
# T: 1710146339999,
|
|
697
|
+
# s: 'BTC',
|
|
698
|
+
# i: '1m',
|
|
699
|
+
# o: '71400.0',
|
|
700
|
+
# c: '71411.0',
|
|
701
|
+
# h: '71422.0',
|
|
702
|
+
# l: '71389.0',
|
|
703
|
+
# v: '1.20407',
|
|
704
|
+
# n: 20
|
|
705
|
+
# }
|
|
706
|
+
# }
|
|
707
|
+
#
|
|
708
|
+
data = self.safe_dict(message, 'data', {})
|
|
709
|
+
base = self.safe_string(data, 's')
|
|
710
|
+
marketId = self.coinToMarketId(base)
|
|
711
|
+
symbol = self.safe_symbol(marketId)
|
|
712
|
+
timeframe = self.safe_string(data, 'i')
|
|
713
|
+
if not (symbol in self.ohlcvs):
|
|
714
|
+
self.ohlcvs[symbol] = {}
|
|
715
|
+
if not (timeframe in self.ohlcvs[symbol]):
|
|
716
|
+
limit = self.safe_integer(self.options, 'OHLCVLimit', 1000)
|
|
717
|
+
stored = ArrayCacheByTimestamp(limit)
|
|
718
|
+
self.ohlcvs[symbol][timeframe] = stored
|
|
719
|
+
ohlcv = self.ohlcvs[symbol][timeframe]
|
|
720
|
+
parsed = self.parse_ohlcv(data)
|
|
721
|
+
ohlcv.append(parsed)
|
|
722
|
+
messageHash = 'candles:' + timeframe + ':' + symbol
|
|
723
|
+
client.resolve(ohlcv, messageHash)
|
|
724
|
+
|
|
725
|
+
def handle_ws_post(self, client: Client, message: dict):
|
|
726
|
+
# {
|
|
727
|
+
# channel: "post",
|
|
728
|
+
# data: {
|
|
729
|
+
# id: <number>,
|
|
730
|
+
# response: {
|
|
731
|
+
# type: "info" | "action" | "error",
|
|
732
|
+
# payload: {...}
|
|
733
|
+
# }
|
|
734
|
+
# }
|
|
735
|
+
data = self.safe_dict(message, 'data')
|
|
736
|
+
id = self.safe_string(data, 'id')
|
|
737
|
+
response = self.safe_dict(data, 'response')
|
|
738
|
+
payload = self.safe_dict(response, 'payload')
|
|
739
|
+
client.resolve(payload, id)
|
|
740
|
+
|
|
741
|
+
async def watch_orders(self, symbol: Str = None, since: Int = None, limit: Int = None, params={}) -> List[Order]:
|
|
742
|
+
"""
|
|
743
|
+
watches information on multiple orders made by the user
|
|
744
|
+
|
|
745
|
+
https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/websocket/subscriptions
|
|
746
|
+
|
|
747
|
+
:param str symbol: unified market symbol of the market orders were made in
|
|
748
|
+
:param int [since]: the earliest time in ms to fetch orders for
|
|
749
|
+
:param int [limit]: the maximum number of order structures to retrieve
|
|
750
|
+
:param dict [params]: extra parameters specific to the exchange API endpoint
|
|
751
|
+
:param str [params.user]: user address, will default to self.walletAddress if not provided
|
|
752
|
+
:returns dict[]: a list of `order structures <https://docs.ccxt.com/#/?id=order-structure>`
|
|
753
|
+
"""
|
|
754
|
+
await self.load_markets()
|
|
755
|
+
userAddress = None
|
|
756
|
+
userAddress, params = self.handlePublicAddress('watchOrders', params)
|
|
757
|
+
market = None
|
|
758
|
+
messageHash = 'order'
|
|
759
|
+
if symbol is not None:
|
|
760
|
+
market = self.market(symbol)
|
|
761
|
+
symbol = market['symbol']
|
|
762
|
+
messageHash = messageHash + ':' + symbol
|
|
763
|
+
url = self.urls['api']['ws']['public']
|
|
764
|
+
request: dict = {
|
|
765
|
+
'method': 'subscribe',
|
|
766
|
+
'subscription': {
|
|
767
|
+
'type': 'orderUpdates',
|
|
768
|
+
'user': userAddress,
|
|
769
|
+
},
|
|
770
|
+
}
|
|
771
|
+
message = self.extend(request, params)
|
|
772
|
+
orders = await self.watch(url, messageHash, message, messageHash)
|
|
773
|
+
if self.newUpdates:
|
|
774
|
+
limit = orders.getLimit(symbol, limit)
|
|
775
|
+
return self.filter_by_symbol_since_limit(orders, symbol, since, limit, True)
|
|
776
|
+
|
|
777
|
+
def handle_order(self, client: Client, message):
|
|
778
|
+
#
|
|
779
|
+
# {
|
|
780
|
+
# channel: 'orderUpdates',
|
|
781
|
+
# data: [
|
|
782
|
+
# {
|
|
783
|
+
# order: {
|
|
784
|
+
# coin: 'BTC',
|
|
785
|
+
# side: 'B',
|
|
786
|
+
# limitPx: '30000.0',
|
|
787
|
+
# sz: '0.001',
|
|
788
|
+
# oid: 7456484275,
|
|
789
|
+
# timestamp: 1710163596492,
|
|
790
|
+
# origSz: '0.001'
|
|
791
|
+
# },
|
|
792
|
+
# status: 'open',
|
|
793
|
+
# statusTimestamp: 1710163596492
|
|
794
|
+
# }
|
|
795
|
+
# ]
|
|
796
|
+
# }
|
|
797
|
+
#
|
|
798
|
+
data = self.safe_list(message, 'data', [])
|
|
799
|
+
if self.orders is None:
|
|
800
|
+
limit = self.safe_integer(self.options, 'ordersLimit', 1000)
|
|
801
|
+
self.orders = ArrayCacheBySymbolById(limit)
|
|
802
|
+
dataLength = len(data)
|
|
803
|
+
if dataLength == 0:
|
|
804
|
+
return
|
|
805
|
+
stored = self.orders
|
|
806
|
+
messageHash = 'order'
|
|
807
|
+
marketSymbols: dict = {}
|
|
808
|
+
for i in range(0, len(data)):
|
|
809
|
+
rawOrder = data[i]
|
|
810
|
+
order = self.parse_order(rawOrder)
|
|
811
|
+
stored.append(order)
|
|
812
|
+
symbol = self.safe_string(order, 'symbol')
|
|
813
|
+
marketSymbols[symbol] = True
|
|
814
|
+
keys = list(marketSymbols.keys())
|
|
815
|
+
for i in range(0, len(keys)):
|
|
816
|
+
symbol = keys[i]
|
|
817
|
+
innerMessageHash = messageHash + ':' + symbol
|
|
818
|
+
client.resolve(stored, innerMessageHash)
|
|
819
|
+
client.resolve(stored, messageHash)
|
|
820
|
+
|
|
821
|
+
def handle_error_message(self, client: Client, message):
|
|
822
|
+
#
|
|
823
|
+
# {
|
|
824
|
+
# "channel": "error",
|
|
825
|
+
# "data": "Error parsing JSON into valid websocket request: {\"type\": \"allMids\"}"
|
|
826
|
+
# }
|
|
827
|
+
#
|
|
828
|
+
channel = self.safe_string(message, 'channel', '')
|
|
829
|
+
ret_msg = self.safe_string(message, 'data', '')
|
|
830
|
+
if channel == 'error':
|
|
831
|
+
raise ExchangeError(self.id + ' ' + ret_msg)
|
|
832
|
+
else:
|
|
833
|
+
return False
|
|
834
|
+
|
|
835
|
+
def handle_order_book_unsubscription(self, client: Client, subscription: dict):
|
|
836
|
+
#
|
|
837
|
+
# "subscription":{
|
|
838
|
+
# "type":"l2Book",
|
|
839
|
+
# "coin":"BTC",
|
|
840
|
+
# "nSigFigs":5,
|
|
841
|
+
# "mantissa":null
|
|
842
|
+
# }
|
|
843
|
+
#
|
|
844
|
+
coin = self.safe_string(subscription, 'coin')
|
|
845
|
+
marketId = self.coinToMarketId(coin)
|
|
846
|
+
symbol = self.safe_symbol(marketId)
|
|
847
|
+
subMessageHash = 'orderbook:' + symbol
|
|
848
|
+
messageHash = 'unsubscribe:' + subMessageHash
|
|
849
|
+
self.clean_unsubscription(client, subMessageHash, messageHash)
|
|
850
|
+
if symbol in self.orderbooks:
|
|
851
|
+
del self.orderbooks[symbol]
|
|
852
|
+
|
|
853
|
+
def handle_trades_unsubscription(self, client: Client, subscription: dict):
|
|
854
|
+
#
|
|
855
|
+
coin = self.safe_string(subscription, 'coin')
|
|
856
|
+
marketId = self.coinToMarketId(coin)
|
|
857
|
+
symbol = self.safe_symbol(marketId)
|
|
858
|
+
subMessageHash = 'trade:' + symbol
|
|
859
|
+
messageHash = 'unsubscribe:' + subMessageHash
|
|
860
|
+
self.clean_unsubscription(client, subMessageHash, messageHash)
|
|
861
|
+
if symbol in self.trades:
|
|
862
|
+
del self.trades[symbol]
|
|
863
|
+
|
|
864
|
+
def handle_tickers_unsubscription(self, client: Client, subscription: dict):
|
|
865
|
+
#
|
|
866
|
+
subMessageHash = 'tickers'
|
|
867
|
+
messageHash = 'unsubscribe:' + subMessageHash
|
|
868
|
+
self.clean_unsubscription(client, subMessageHash, messageHash)
|
|
869
|
+
symbols = list(self.tickers.keys())
|
|
870
|
+
for i in range(0, len(symbols)):
|
|
871
|
+
del self.tickers[symbols[i]]
|
|
872
|
+
|
|
873
|
+
def handle_ohlcv_unsubscription(self, client: Client, subscription: dict):
|
|
874
|
+
coin = self.safe_string(subscription, 'coin')
|
|
875
|
+
marketId = self.coinToMarketId(coin)
|
|
876
|
+
symbol = self.safe_symbol(marketId)
|
|
877
|
+
interval = self.safe_string(subscription, 'interval')
|
|
878
|
+
timeframe = self.find_timeframe(interval)
|
|
879
|
+
subMessageHash = 'candles:' + timeframe + ':' + symbol
|
|
880
|
+
messageHash = 'unsubscribe:' + subMessageHash
|
|
881
|
+
self.clean_unsubscription(client, subMessageHash, messageHash)
|
|
882
|
+
if symbol in self.ohlcvs:
|
|
883
|
+
if timeframe in self.ohlcvs[symbol]:
|
|
884
|
+
del self.ohlcvs[symbol][timeframe]
|
|
885
|
+
|
|
886
|
+
def handle_subscription_response(self, client: Client, message):
|
|
887
|
+
# {
|
|
888
|
+
# "channel":"subscriptionResponse",
|
|
889
|
+
# "data":{
|
|
890
|
+
# "method":"unsubscribe",
|
|
891
|
+
# "subscription":{
|
|
892
|
+
# "type":"l2Book",
|
|
893
|
+
# "coin":"BTC",
|
|
894
|
+
# "nSigFigs":5,
|
|
895
|
+
# "mantissa":null
|
|
896
|
+
# }
|
|
897
|
+
# }
|
|
898
|
+
# }
|
|
899
|
+
#
|
|
900
|
+
# {
|
|
901
|
+
# "channel":"subscriptionResponse",
|
|
902
|
+
# "data":{
|
|
903
|
+
# "method":"unsubscribe",
|
|
904
|
+
# "subscription":{
|
|
905
|
+
# "type":"trades",
|
|
906
|
+
# "coin":"PURR/USDC"
|
|
907
|
+
# }
|
|
908
|
+
# }
|
|
909
|
+
# }
|
|
910
|
+
#
|
|
911
|
+
data = self.safe_dict(message, 'data', {})
|
|
912
|
+
method = self.safe_string(data, 'method')
|
|
913
|
+
if method == 'unsubscribe':
|
|
914
|
+
subscription = self.safe_dict(data, 'subscription', {})
|
|
915
|
+
type = self.safe_string(subscription, 'type')
|
|
916
|
+
if type == 'l2Book':
|
|
917
|
+
self.handle_order_book_unsubscription(client, subscription)
|
|
918
|
+
elif type == 'trades':
|
|
919
|
+
self.handle_trades_unsubscription(client, subscription)
|
|
920
|
+
elif type == 'webData2':
|
|
921
|
+
self.handle_tickers_unsubscription(client, subscription)
|
|
922
|
+
elif type == 'candle':
|
|
923
|
+
self.handle_ohlcv_unsubscription(client, subscription)
|
|
924
|
+
|
|
925
|
+
def handle_message(self, client: Client, message):
|
|
926
|
+
#
|
|
927
|
+
# {
|
|
928
|
+
# "channel":"subscriptionResponse",
|
|
929
|
+
# "data":{
|
|
930
|
+
# "method":"unsubscribe",
|
|
931
|
+
# "subscription":{
|
|
932
|
+
# "type":"l2Book",
|
|
933
|
+
# "coin":"BTC",
|
|
934
|
+
# "nSigFigs":5,
|
|
935
|
+
# "mantissa":null
|
|
936
|
+
# }
|
|
937
|
+
# }
|
|
938
|
+
# }
|
|
939
|
+
#
|
|
940
|
+
if self.handle_error_message(client, message):
|
|
941
|
+
return
|
|
942
|
+
topic = self.safe_string(message, 'channel', '')
|
|
943
|
+
methods: dict = {
|
|
944
|
+
'pong': self.handle_pong,
|
|
945
|
+
'trades': self.handle_trades,
|
|
946
|
+
'l2Book': self.handle_order_book,
|
|
947
|
+
'candle': self.handle_ohlcv,
|
|
948
|
+
'orderUpdates': self.handle_order,
|
|
949
|
+
'userFills': self.handle_my_trades,
|
|
950
|
+
'webData2': self.handle_ws_tickers,
|
|
951
|
+
'post': self.handle_ws_post,
|
|
952
|
+
'subscriptionResponse': self.handle_subscription_response,
|
|
953
|
+
}
|
|
954
|
+
exacMethod = self.safe_value(methods, topic)
|
|
955
|
+
if exacMethod is not None:
|
|
956
|
+
exacMethod(client, message)
|
|
957
|
+
return
|
|
958
|
+
keys = list(methods.keys())
|
|
959
|
+
for i in range(0, len(keys)):
|
|
960
|
+
key = keys[i]
|
|
961
|
+
if topic.find(keys[i]) >= 0:
|
|
962
|
+
method = methods[key]
|
|
963
|
+
method(client, message)
|
|
964
|
+
return
|
|
965
|
+
|
|
966
|
+
def ping(self, client: Client):
|
|
967
|
+
return {
|
|
968
|
+
'method': 'ping',
|
|
969
|
+
}
|
|
970
|
+
|
|
971
|
+
def handle_pong(self, client: Client, message):
|
|
972
|
+
#
|
|
973
|
+
# {
|
|
974
|
+
# "channel": "pong"
|
|
975
|
+
# }
|
|
976
|
+
#
|
|
977
|
+
client.lastPong = self.safe_integer(message, 'pong')
|
|
978
|
+
return message
|
|
979
|
+
|
|
980
|
+
def request_id(self) -> float:
|
|
981
|
+
requestId = self.sum(self.safe_integer(self.options, 'requestId', 0), 1)
|
|
982
|
+
self.options['requestId'] = requestId
|
|
983
|
+
return requestId
|
|
984
|
+
|
|
985
|
+
def wrap_as_post_action(self, request: dict) -> dict:
|
|
986
|
+
requestId = self.request_id()
|
|
987
|
+
return {
|
|
988
|
+
'requestId': requestId,
|
|
989
|
+
'request': {
|
|
990
|
+
'method': 'post',
|
|
991
|
+
'id': requestId,
|
|
992
|
+
'request': {
|
|
993
|
+
'type': 'action',
|
|
994
|
+
'payload': request,
|
|
995
|
+
},
|
|
996
|
+
},
|
|
997
|
+
}
|